237 #include "ns3/core-module.h" 238 #include "ns3/network-module.h" 239 #include "ns3/applications-module.h" 240 #include "ns3/bridge-module.h" 241 #include "ns3/csma-module.h" 242 #include "ns3/point-to-point-module.h" 243 #include "ns3/internet-module.h" 252 #define vssearch(loc,vec) std::find ((vec).begin (), (vec).end (), (loc)) != (vec).end () 255 main (
int argc,
char *argv[])
262 int simDurationSeconds = 60;
264 bool enableUdpMultiSW =
true;
265 bool enableUdpSingleSW =
true;
267 std::string pcapLocations =
"";
270 std::string csmaXLinkDataRate =
"100Mbps";
271 std::string csmaXLinkDelay =
"500ns";
273 std::string csmaYLinkDataRate =
"10Mbps";
274 std::string csmaYLinkDelay =
"500ns";
276 std::string p2pLinkDataRate =
"5Mbps";
277 std::string p2pLinkDelay =
"50ms";
279 uint16_t udpEchoPort = 9;
287 cmd.Usage (
"NOTE: valid --pcap arguments are: 't2,t3,b2,b3,trlan,trwan,brlan,brwan'");
289 cmd.AddValue (
"verbose",
"Enable printing informational messages",
verbose);
291 cmd.AddValue (
"duration",
"Duration of simulation.", simDurationSeconds);
293 cmd.AddValue (
"udpMultiSW",
"Enable udp over multi-switch links", enableUdpMultiSW);
294 cmd.AddValue (
"udpSingleSW",
"Enable udp over single-switch links", enableUdpSingleSW);
296 cmd.AddValue (
"pcap",
"Comma separated list of PCAP Locations to tap", pcapLocations);
297 cmd.AddValue (
"snapLen",
"PCAP packet capture length", snapLen);
299 cmd.AddValue (
"csmaXRate",
"CSMA X Link data rate", csmaXLinkDataRate);
300 cmd.AddValue (
"csmaXDelay",
"CSMA X Link delay", csmaXLinkDelay);
302 cmd.AddValue (
"csmaYRate",
"CSMA Y Link data rate", csmaYLinkDataRate);
303 cmd.AddValue (
"csmaYDelay",
"CSMA Y Link delay", csmaYLinkDelay);
305 cmd.AddValue (
"p2pRate",
"P2P Link data rate", p2pLinkDataRate);
306 cmd.AddValue (
"p2pDelay",
"P2P Link delay", p2pLinkDelay);
308 cmd.Parse (argc, argv);
323 std::vector<std::string> pcapTaps;
324 pcapTaps.push_back (
"t2");
325 pcapTaps.push_back (
"t3");
326 pcapTaps.push_back (
"b2");
327 pcapTaps.push_back (
"b3");
328 pcapTaps.push_back (
"trlan");
329 pcapTaps.push_back (
"trwan");
330 pcapTaps.push_back (
"brlan");
331 pcapTaps.push_back (
"brwan");
336 std::vector<std::string> pcapLocationVec;
337 if (pcapLocations !=
"")
339 std::stringstream sStream (pcapLocations);
341 while ( sStream.good () )
344 getline ( sStream, substr,
',' );
347 pcapLocationVec.push_back ( substr );
351 NS_LOG_ERROR (
"WARNING: Unrecognized PCAP location: <" + substr +
">");
355 for (std::vector<std::string>::const_iterator
356 ploc = pcapLocationVec.begin ();
357 ploc != pcapLocationVec.end ();
435 csmaXLinkDataRate <<
" " <<
436 csmaXLinkDelay <<
" CSMA link for csmaX for LANs.");
445 csmaYLinkDataRate <<
" " <<
446 csmaYLinkDelay <<
" CSMA link for csmaY for LANs.");
454 NS_LOG_INFO (
"L2: Connect nodes on top LAN together with half-duplex CSMA links.");
471 NS_LOG_INFO (
"L2: Connect nodes on bottom LAN together with half-duplex CSMA links.");
492 p2pLinkDataRate <<
" " <<
493 p2pLinkDelay <<
" Point-to-Point link for the WAN.");
502 NS_LOG_INFO (
"L2: Connect the routers together with the Point-to-Point WAN link.");
513 ts4nd.
Add (link_t2_ts4.
Get (1));
514 ts4nd.
Add (link_ts4_ts3.
Get (0));
518 ts3nd.
Add (link_ts4_ts3.
Get (1));
519 ts3nd.
Add (link_ts3_ts2.
Get (0));
523 ts2nd.
Add (link_ts3_ts2.
Get (1));
524 ts2nd.
Add (link_ts2_ts1.
Get (0));
528 ts1nd.
Add (link_ts2_ts1.
Get (1));
529 ts1nd.
Add (link_t3_ts1.
Get (1));
530 ts1nd.
Add (link_tr_ts1.
Get (1));
535 bs1nd.
Add (link_br_bs1.
Get (1));
536 bs1nd.
Add (link_bs2_bs1.
Get (1));
537 bs1nd.
Add (link_b3_bs1.
Get (1));
541 bs2nd.
Add (link_bs2_bs1.
Get (0));
542 bs2nd.
Add (link_bs3_bs2.
Get (1));
546 bs3nd.
Add (link_bs3_bs2.
Get (0));
547 bs3nd.
Add (link_bs4_bs3.
Get (1));
551 bs4nd.
Add (link_bs4_bs3.
Get (0));
552 bs4nd.
Add (link_bs5_bs4.
Get (1));
556 bs5nd.
Add (link_bs5_bs4.
Get (0));
557 bs5nd.
Add (link_b2_bs5.
Get (1));
584 NS_LOG_INFO (
"L3: Install the ns3 IP stack on udp client and server nodes.");
586 ns3IpStack.
Install (endpointNodes);
591 NS_LOG_INFO (
"L3: Install the ns3 IP stack on routers.");
593 ns3IpStack.
Install (routerNodes);
601 topLanIpDevices.
Add (link_tr_ts1.
Get (0));
602 topLanIpDevices.
Add (link_t2_ts4.
Get (0));
603 topLanIpDevices.
Add (link_t3_ts1.
Get (0));
606 ipv4.
SetBase (
"192.168.1.0",
"255.255.255.0");
607 ipv4.
Assign (topLanIpDevices);
612 NS_LOG_INFO (
"L3: Assign bottom LAN IP Addresses.");
615 botLanIpDevices.
Add (link_br_bs1.
Get (0));
616 botLanIpDevices.
Add (link_b2_bs5.
Get (0));
617 botLanIpDevices.
Add (link_b3_bs1.
Get (0));
620 ipv4.
SetBase (
"192.168.2.0",
"255.255.255.0");
621 ipv4.
Assign (botLanIpDevices);
628 ipv4.
SetBase (
"76.1.1.0",
"255.255.255.0");
644 if (enableUdpMultiSW)
649 NS_LOG_INFO (
"APP: Multi-Switch UDP server (on node b2 of bottom LAN)");
660 NS_LOG_INFO (
"APP: Multi-Switch UDP client (on node t2 of top LAN)");
664 uint32_t maxPacketCount = (simDurationSeconds - 2.0) / 0.005;
680 if (enableUdpSingleSW)
685 NS_LOG_INFO (
"APP: Single-Switch UDP server (on node t3 of top LAN)");
696 NS_LOG_INFO (
"APP: Single-Switch UDP client (on node b3 bottom LAN)");
700 uint32_t maxPacketCount = (simDurationSeconds - 2.0) / 0.005;
720 NS_LOG_INFO (
"Set up to print routing tables at T=0.1s");
723 Create<OutputStreamWrapper> (
"global-routing-multi-switch-plus-router.routes", std::ios::out);
732 NS_LOG_INFO (
"Configure PCAP Tracing (if any configured).");
737 if (
vssearch (
"t2",pcapLocationVec))
739 csmaX.
EnablePcap (
"t2.pcap", topLanIpDevices.
Get (1),
true,
true);
745 if (
vssearch (
"b2",pcapLocationVec))
747 csmaY.
EnablePcap (
"b2.pcap", botLanIpDevices.
Get (1),
true,
true);
753 if (
vssearch (
"b3",pcapLocationVec))
755 csmaY.
EnablePcap (
"b3.pcap", botLanIpDevices.
Get (2),
true,
true);
761 if (
vssearch (
"t3",pcapLocationVec))
763 csmaX.
EnablePcap (
"t3.pcap", topLanIpDevices.
Get (2),
true,
true);
769 if (
vssearch (
"trlan",pcapLocationVec))
771 csmaY.
EnablePcap (
"trlan.pcap", topLanIpDevices.
Get (0),
true,
true);
777 if (
vssearch (
"brlan",pcapLocationVec))
779 csmaX.
EnablePcap (
"brlan.pcap", botLanIpDevices.
Get (0),
true,
true);
785 if (
vssearch (
"trwan",pcapLocationVec))
787 p2p.
EnablePcap (
"trwan.pcap", link_tr_br.
Get (0),
true,
true);
793 if (
vssearch (
"brwan",pcapLocationVec))
795 p2p.
EnablePcap (
"brwan.pcap", link_tr_br.
Get (1),
true,
true);
802 NS_LOG_INFO (
"Run Simulation for " << simDurationSeconds <<
" seconds.");
holds a vector of ns3::Application pointers.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Simulation virtual time values and global simulation resolution.
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
Hold variables of type string.
NetDeviceContainer Install(NodeContainer c)
ApplicationContainer Install(Ptr< Node > node) const
Create a UdpEchoServerApplication on the specified Node.
Create an application which sends a UDP packet and waits for an echo of this packet.
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Create a server application which waits for input UDP packets and sends them back to the original sen...
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
AttributeValue implementation for Time.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
Add capability to bridge multiple LAN segments (IEEE 802.1D bridging)
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
ApplicationContainer Install(Ptr< Node > node) const
Create a udp echo client application on the specified node.
static const uint32_t SNAPLEN_DEFAULT
Default value for maximum octets to save per packet.
build a set of CsmaNetDevice objects
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c)
This method creates an ns3::BridgeNetDevice with the attributes configured by BridgeHelper::SetDevice...
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Ipv4 addresses are stored in host order in this class.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
Helper class that adds ns3::Ipv4GlobalRouting objects.
#define vssearch(loc, vec)
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
static const uint32_t packetSize
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
static void PrintRoutingTableAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of all nodes at a particular time.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.