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 (std::vector<std::string>::const_iterator ploc = pcapLocationVec.begin();
354 ploc != pcapLocationVec.end();
430 NS_LOG_INFO(
"L2: Create a " << csmaXLinkDataRate <<
" " << csmaXLinkDelay
431 <<
" CSMA link for csmaX for LANs.");
439 NS_LOG_INFO(
"L2: Create a " << csmaYLinkDataRate <<
" " << csmaYLinkDelay
440 <<
" CSMA link for csmaY for LANs.");
448 NS_LOG_INFO(
"L2: Connect nodes on top LAN together with half-duplex CSMA links.");
465 NS_LOG_INFO(
"L2: Connect nodes on bottom LAN together with half-duplex CSMA links.");
484 NS_LOG_INFO(
"L2: Create a " << p2pLinkDataRate <<
" " << p2pLinkDelay
485 <<
" Point-to-Point link for the WAN.");
494 NS_LOG_INFO(
"L2: Connect the routers together with the Point-to-Point WAN link.");
505 ts4nd.
Add(link_t2_ts4.
Get(1));
506 ts4nd.
Add(link_ts4_ts3.
Get(0));
510 ts3nd.
Add(link_ts4_ts3.
Get(1));
511 ts3nd.
Add(link_ts3_ts2.
Get(0));
515 ts2nd.
Add(link_ts3_ts2.
Get(1));
516 ts2nd.
Add(link_ts2_ts1.
Get(0));
520 ts1nd.
Add(link_ts2_ts1.
Get(1));
521 ts1nd.
Add(link_t3_ts1.
Get(1));
522 ts1nd.
Add(link_tr_ts1.
Get(1));
526 bs1nd.
Add(link_br_bs1.
Get(1));
527 bs1nd.
Add(link_bs2_bs1.
Get(1));
528 bs1nd.
Add(link_b3_bs1.
Get(1));
532 bs2nd.
Add(link_bs2_bs1.
Get(0));
533 bs2nd.
Add(link_bs3_bs2.
Get(1));
537 bs3nd.
Add(link_bs3_bs2.
Get(0));
538 bs3nd.
Add(link_bs4_bs3.
Get(1));
542 bs4nd.
Add(link_bs4_bs3.
Get(0));
543 bs4nd.
Add(link_bs5_bs4.
Get(1));
547 bs5nd.
Add(link_bs5_bs4.
Get(0));
548 bs5nd.
Add(link_b2_bs5.
Get(1));
574 NS_LOG_INFO(
"L3: Install the ns3 IP stack on udp client and server nodes.");
576 ns3IpStack.
Install(endpointNodes);
581 NS_LOG_INFO(
"L3: Install the ns3 IP stack on routers.");
583 ns3IpStack.
Install(routerNodes);
591 topLanIpDevices.
Add(link_tr_ts1.
Get(0));
592 topLanIpDevices.
Add(link_t2_ts4.
Get(0));
593 topLanIpDevices.
Add(link_t3_ts1.
Get(0));
596 ipv4.
SetBase(
"192.168.1.0",
"255.255.255.0");
597 ipv4.
Assign(topLanIpDevices);
602 NS_LOG_INFO(
"L3: Assign bottom LAN IP Addresses.");
605 botLanIpDevices.
Add(link_br_bs1.
Get(0));
606 botLanIpDevices.
Add(link_b2_bs5.
Get(0));
607 botLanIpDevices.
Add(link_b3_bs1.
Get(0));
610 ipv4.
SetBase(
"192.168.2.0",
"255.255.255.0");
611 ipv4.
Assign(botLanIpDevices);
618 ipv4.
SetBase(
"76.1.1.0",
"255.255.255.0");
632 if (enableUdpMultiSW)
637 NS_LOG_INFO(
"APP: Multi-Switch UDP server (on node b2 of bottom LAN)");
648 NS_LOG_INFO(
"APP: Multi-Switch UDP client (on node t2 of top LAN)");
652 uint32_t maxPacketCount = (simDurationSeconds - 2.0) / 0.005;
668 if (enableUdpSingleSW)
673 NS_LOG_INFO(
"APP: Single-Switch UDP server (on node t3 of top LAN)");
684 NS_LOG_INFO(
"APP: Single-Switch UDP client (on node b3 bottom LAN)");
688 uint32_t maxPacketCount = (simDurationSeconds - 2.0) / 0.005;
707 NS_LOG_INFO(
"Set up to print routing tables at T=0.1s");
710 Create<OutputStreamWrapper>(
"global-routing-multi-switch-plus-router.routes",
718 NS_LOG_INFO(
"Configure PCAP Tracing (if any configured).");
723 if (
vssearch(
"t2", pcapLocationVec))
725 csmaX.
EnablePcap(
"t2.pcap", topLanIpDevices.
Get(1),
true,
true);
731 if (
vssearch(
"b2", pcapLocationVec))
733 csmaY.
EnablePcap(
"b2.pcap", botLanIpDevices.
Get(1),
true,
true);
739 if (
vssearch(
"b3", pcapLocationVec))
741 csmaY.
EnablePcap(
"b3.pcap", botLanIpDevices.
Get(2),
true,
true);
747 if (
vssearch(
"t3", pcapLocationVec))
749 csmaX.
EnablePcap(
"t3.pcap", topLanIpDevices.
Get(2),
true,
true);
755 if (
vssearch(
"trlan", pcapLocationVec))
757 csmaY.
EnablePcap(
"trlan.pcap", topLanIpDevices.
Get(0),
true,
true);
763 if (
vssearch(
"brlan", pcapLocationVec))
765 csmaX.
EnablePcap(
"brlan.pcap", botLanIpDevices.
Get(0),
true,
true);
771 if (
vssearch(
"trwan", pcapLocationVec))
779 if (
vssearch(
"brwan", pcapLocationVec))
787 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.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
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.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
NetDeviceContainer Install(NodeContainer c)
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.
AttributeValue implementation for Time.
Create an application which sends a UDP packet and waits for an echo of this packet.
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
ApplicationContainer Install(Ptr< Node > node) const
Create a udp echo client application on the specified node.
Create a server application which waits for input UDP packets and sends them back to the original sen...
ApplicationContainer Install(Ptr< Node > node) const
Create a UdpEchoServerApplication on the specified Node.
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.