233 #include "ns3/applications-module.h"
234 #include "ns3/bridge-module.h"
235 #include "ns3/core-module.h"
236 #include "ns3/csma-module.h"
237 #include "ns3/internet-module.h"
238 #include "ns3/network-module.h"
239 #include "ns3/point-to-point-module.h"
251 #define vssearch(loc, vec) std::find((vec).begin(), (vec).end(), (loc)) != (vec).end()
254 main(
int argc,
char* argv[])
261 int simDurationSeconds = 60;
263 bool enableUdpMultiSW =
true;
264 bool enableUdpSingleSW =
true;
266 std::string pcapLocations =
"";
269 std::string csmaXLinkDataRate =
"100Mbps";
270 std::string csmaXLinkDelay =
"500ns";
272 std::string csmaYLinkDataRate =
"10Mbps";
273 std::string csmaYLinkDelay =
"500ns";
275 std::string p2pLinkDataRate =
"5Mbps";
276 std::string p2pLinkDelay =
"50ms";
278 uint16_t udpEchoPort = 9;
285 cmd.Usage(
"NOTE: valid --pcap arguments are: 't2,t3,b2,b3,trlan,trwan,brlan,brwan'");
287 cmd.AddValue(
"verbose",
"Enable printing informational messages",
verbose);
289 cmd.AddValue(
"duration",
"Duration of simulation.", simDurationSeconds);
291 cmd.AddValue(
"udpMultiSW",
"Enable udp over multi-switch links", enableUdpMultiSW);
292 cmd.AddValue(
"udpSingleSW",
"Enable udp over single-switch links", enableUdpSingleSW);
294 cmd.AddValue(
"pcap",
"Comma separated list of PCAP Locations to tap", pcapLocations);
295 cmd.AddValue(
"snapLen",
"PCAP packet capture length", snapLen);
297 cmd.AddValue(
"csmaXRate",
"CSMA X Link data rate", csmaXLinkDataRate);
298 cmd.AddValue(
"csmaXDelay",
"CSMA X Link delay", csmaXLinkDelay);
300 cmd.AddValue(
"csmaYRate",
"CSMA Y Link data rate", csmaYLinkDataRate);
301 cmd.AddValue(
"csmaYDelay",
"CSMA Y Link delay", csmaYLinkDelay);
303 cmd.AddValue(
"p2pRate",
"P2P Link data rate", p2pLinkDataRate);
304 cmd.AddValue(
"p2pDelay",
"P2P Link delay", p2pLinkDelay);
306 cmd.Parse(argc, argv);
320 const std::vector<std::string> pcapTaps{
334 std::vector<std::string> pcapLocationVec;
335 if (!pcapLocations.empty())
337 std::stringstream sStream(pcapLocations);
339 while (sStream.good())
342 getline(sStream, substr,
',');
345 pcapLocationVec.push_back(substr);
349 NS_LOG_ERROR(
"WARNING: Unrecognized PCAP location: <" + substr +
">");
353 for (
auto ploc = pcapLocationVec.begin(); ploc != pcapLocationVec.end(); ++ploc)
428 NS_LOG_INFO(
"L2: Create a " << csmaXLinkDataRate <<
" " << csmaXLinkDelay
429 <<
" CSMA link for csmaX for LANs.");
437 NS_LOG_INFO(
"L2: Create a " << csmaYLinkDataRate <<
" " << csmaYLinkDelay
438 <<
" CSMA link for csmaY for LANs.");
446 NS_LOG_INFO(
"L2: Connect nodes on top LAN together with half-duplex CSMA links.");
463 NS_LOG_INFO(
"L2: Connect nodes on bottom LAN together with half-duplex CSMA links.");
482 NS_LOG_INFO(
"L2: Create a " << p2pLinkDataRate <<
" " << p2pLinkDelay
483 <<
" Point-to-Point link for the WAN.");
492 NS_LOG_INFO(
"L2: Connect the routers together with the Point-to-Point WAN link.");
503 ts4nd.
Add(link_t2_ts4.
Get(1));
504 ts4nd.
Add(link_ts4_ts3.
Get(0));
508 ts3nd.
Add(link_ts4_ts3.
Get(1));
509 ts3nd.
Add(link_ts3_ts2.
Get(0));
513 ts2nd.
Add(link_ts3_ts2.
Get(1));
514 ts2nd.
Add(link_ts2_ts1.
Get(0));
518 ts1nd.
Add(link_ts2_ts1.
Get(1));
519 ts1nd.
Add(link_t3_ts1.
Get(1));
520 ts1nd.
Add(link_tr_ts1.
Get(1));
524 bs1nd.
Add(link_br_bs1.
Get(1));
525 bs1nd.
Add(link_bs2_bs1.
Get(1));
526 bs1nd.
Add(link_b3_bs1.
Get(1));
530 bs2nd.
Add(link_bs2_bs1.
Get(0));
531 bs2nd.
Add(link_bs3_bs2.
Get(1));
535 bs3nd.
Add(link_bs3_bs2.
Get(0));
536 bs3nd.
Add(link_bs4_bs3.
Get(1));
540 bs4nd.
Add(link_bs4_bs3.
Get(0));
541 bs4nd.
Add(link_bs5_bs4.
Get(1));
545 bs5nd.
Add(link_bs5_bs4.
Get(0));
546 bs5nd.
Add(link_b2_bs5.
Get(1));
572 NS_LOG_INFO(
"L3: Install the ns3 IP stack on udp client and server nodes.");
574 ns3IpStack.
Install(endpointNodes);
579 NS_LOG_INFO(
"L3: Install the ns3 IP stack on routers.");
581 ns3IpStack.
Install(routerNodes);
589 topLanIpDevices.
Add(link_tr_ts1.
Get(0));
590 topLanIpDevices.
Add(link_t2_ts4.
Get(0));
591 topLanIpDevices.
Add(link_t3_ts1.
Get(0));
594 ipv4.SetBase(
"192.168.1.0",
"255.255.255.0");
595 ipv4.Assign(topLanIpDevices);
600 NS_LOG_INFO(
"L3: Assign bottom LAN IP Addresses.");
603 botLanIpDevices.
Add(link_br_bs1.
Get(0));
604 botLanIpDevices.
Add(link_b2_bs5.
Get(0));
605 botLanIpDevices.
Add(link_b3_bs1.
Get(0));
608 ipv4.SetBase(
"192.168.2.0",
"255.255.255.0");
609 ipv4.Assign(botLanIpDevices);
616 ipv4.SetBase(
"76.1.1.0",
"255.255.255.0");
617 ipv4.Assign(link_tr_br);
630 if (enableUdpMultiSW)
635 NS_LOG_INFO(
"APP: Multi-Switch UDP server (on node b2 of bottom LAN)");
646 NS_LOG_INFO(
"APP: Multi-Switch UDP client (on node t2 of top LAN)");
650 uint32_t maxPacketCount = (simDurationSeconds - 2.0) / 0.005;
666 if (enableUdpSingleSW)
671 NS_LOG_INFO(
"APP: Single-Switch UDP server (on node t3 of top LAN)");
682 NS_LOG_INFO(
"APP: Single-Switch UDP client (on node b3 bottom LAN)");
686 uint32_t maxPacketCount = (simDurationSeconds - 2.0) / 0.005;
705 NS_LOG_INFO(
"Set up to print routing tables at T=0.1s");
708 Create<OutputStreamWrapper>(
"global-routing-multi-switch-plus-router.routes",
716 NS_LOG_INFO(
"Configure PCAP Tracing (if any configured).");
721 if (
vssearch(
"t2", pcapLocationVec))
723 csmaX.
EnablePcap(
"t2.pcap", topLanIpDevices.
Get(1),
true,
true);
729 if (
vssearch(
"b2", pcapLocationVec))
731 csmaY.
EnablePcap(
"b2.pcap", botLanIpDevices.
Get(1),
true,
true);
737 if (
vssearch(
"b3", pcapLocationVec))
739 csmaY.
EnablePcap(
"b3.pcap", botLanIpDevices.
Get(2),
true,
true);
745 if (
vssearch(
"t3", pcapLocationVec))
747 csmaX.
EnablePcap(
"t3.pcap", topLanIpDevices.
Get(2),
true,
true);
753 if (
vssearch(
"trlan", pcapLocationVec))
755 csmaY.
EnablePcap(
"trlan.pcap", topLanIpDevices.
Get(0),
true,
true);
761 if (
vssearch(
"brlan", pcapLocationVec))
763 csmaX.
EnablePcap(
"brlan.pcap", botLanIpDevices.
Get(0),
true,
true);
769 if (
vssearch(
"trwan", pcapLocationVec))
771 p2p.EnablePcap(
"trwan.pcap", link_tr_br.
Get(0),
true,
true);
777 if (
vssearch(
"brwan", pcapLocationVec))
779 p2p.EnablePcap(
"brwan.pcap", link_tr_br.
Get(1),
true,
true);
785 NS_LOG_INFO(
"Run Simulation for " << simDurationSeconds <<
" seconds.");
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Add capability to bridge multiple LAN segments (IEEE 802.1D bridging)
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c)
This method creates an ns3::BridgeNetDevice with the attributes configured by BridgeHelper::SetDevice...
Parse command-line arguments.
build a set of CsmaNetDevice objects
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
static void PrintRoutingTableAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of all nodes at a particular time.
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
static const uint32_t SNAPLEN_DEFAULT
Default value for maximum octets to save per packet.
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
Build a set of PointToPointNetDevice objects.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
Create an application which sends a UDP packet and waits for an echo of this packet.
Create a server application which waits for input UDP packets and sends them back to the original sen...
Hold an unsigned integer type.
#define vssearch(loc, vec)
void SetDefault(std::string name, const AttributeValue &value)
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
@ LOG_LEVEL_INFO
LOG_INFO and above.
static const uint32_t packetSize
Packet size generated at the AP.