222#include "ns3/applications-module.h" 
  223#include "ns3/bridge-module.h" 
  224#include "ns3/core-module.h" 
  225#include "ns3/csma-module.h" 
  226#include "ns3/internet-module.h" 
  227#include "ns3/network-module.h" 
  228#include "ns3/point-to-point-module.h" 
  240#define vssearch(loc, vec) std::find((vec).begin(), (vec).end(), (loc)) != (vec).end() 
  243main(
int argc, 
char* argv[])
 
  250    int simDurationSeconds = 60;
 
  252    bool enableUdpMultiSW = 
true;
 
  253    bool enableUdpSingleSW = 
true;
 
  255    std::string pcapLocations = 
"";
 
  258    std::string csmaXLinkDataRate = 
"100Mbps";
 
  259    std::string csmaXLinkDelay = 
"500ns";
 
  261    std::string csmaYLinkDataRate = 
"10Mbps";
 
  262    std::string csmaYLinkDelay = 
"500ns";
 
  264    std::string p2pLinkDataRate = 
"5Mbps";
 
  265    std::string p2pLinkDelay = 
"50ms";
 
  267    uint16_t udpEchoPort = 9; 
 
  274    cmd.Usage(
"NOTE: valid --pcap arguments are: 't2,t3,b2,b3,trlan,trwan,brlan,brwan'");
 
  276    cmd.AddValue(
"verbose", 
"Enable printing informational messages", 
verbose);
 
  278    cmd.AddValue(
"duration", 
"Duration of simulation.", simDurationSeconds);
 
  280    cmd.AddValue(
"udpMultiSW", 
"Enable udp over multi-switch links", enableUdpMultiSW);
 
  281    cmd.AddValue(
"udpSingleSW", 
"Enable udp over single-switch links", enableUdpSingleSW);
 
  283    cmd.AddValue(
"pcap", 
"Comma separated list of PCAP Locations to tap", pcapLocations);
 
  284    cmd.AddValue(
"snapLen", 
"PCAP packet capture length", snapLen);
 
  286    cmd.AddValue(
"csmaXRate", 
"CSMA X Link data rate", csmaXLinkDataRate);
 
  287    cmd.AddValue(
"csmaXDelay", 
"CSMA X Link delay", csmaXLinkDelay);
 
  289    cmd.AddValue(
"csmaYRate", 
"CSMA Y Link data rate", csmaYLinkDataRate);
 
  290    cmd.AddValue(
"csmaYDelay", 
"CSMA Y Link delay", csmaYLinkDelay);
 
  292    cmd.AddValue(
"p2pRate", 
"P2P Link data rate", p2pLinkDataRate);
 
  293    cmd.AddValue(
"p2pDelay", 
"P2P Link delay", p2pLinkDelay);
 
  295    cmd.Parse(argc, argv);
 
  309    const std::vector<std::string> pcapTaps{
 
  323    std::vector<std::string> pcapLocationVec;
 
  324    if (!pcapLocations.empty())
 
  326        std::stringstream sStream(pcapLocations);
 
  328        while (sStream.good())
 
  331            getline(sStream, substr, 
',');
 
  334                pcapLocationVec.push_back(substr);
 
  338                NS_LOG_ERROR(
"WARNING: Unrecognized PCAP location: <" + substr + 
">");
 
  342        for (
auto ploc = pcapLocationVec.begin(); ploc != pcapLocationVec.end(); ++ploc)
 
  417    NS_LOG_INFO(
"L2: Create a " << csmaXLinkDataRate << 
" " << csmaXLinkDelay
 
  418                                << 
" CSMA link for csmaX for LANs.");
 
  426    NS_LOG_INFO(
"L2: Create a " << csmaYLinkDataRate << 
" " << csmaYLinkDelay
 
  427                                << 
" CSMA link for csmaY for LANs.");
 
  435    NS_LOG_INFO(
"L2: Connect nodes on top LAN together with half-duplex CSMA links.");
 
  452    NS_LOG_INFO(
"L2: Connect nodes on bottom LAN together with half-duplex CSMA links.");
 
  471    NS_LOG_INFO(
"L2: Create a " << p2pLinkDataRate << 
" " << p2pLinkDelay
 
  472                                << 
" Point-to-Point link for the WAN.");
 
  475    p2p.SetDeviceAttribute(
"DataRate", 
StringValue(p2pLinkDataRate));
 
  476    p2p.SetChannelAttribute(
"Delay", 
StringValue(p2pLinkDelay));
 
  481    NS_LOG_INFO(
"L2: Connect the routers together with the Point-to-Point WAN link.");
 
  492    ts4nd.
Add(link_t2_ts4.
Get(1));
 
  493    ts4nd.
Add(link_ts4_ts3.
Get(0));
 
  497    ts3nd.
Add(link_ts4_ts3.
Get(1));
 
  498    ts3nd.
Add(link_ts3_ts2.
Get(0));
 
  502    ts2nd.
Add(link_ts3_ts2.
Get(1));
 
  503    ts2nd.
Add(link_ts2_ts1.
Get(0));
 
  507    ts1nd.
Add(link_ts2_ts1.
Get(1));
 
  508    ts1nd.
Add(link_t3_ts1.
Get(1));
 
  509    ts1nd.
Add(link_tr_ts1.
Get(1));
 
  513    bs1nd.
Add(link_br_bs1.
Get(1));
 
  514    bs1nd.
Add(link_bs2_bs1.
Get(1));
 
  515    bs1nd.
Add(link_b3_bs1.
Get(1));
 
  519    bs2nd.
Add(link_bs2_bs1.
Get(0));
 
  520    bs2nd.
Add(link_bs3_bs2.
Get(1));
 
  524    bs3nd.
Add(link_bs3_bs2.
Get(0));
 
  525    bs3nd.
Add(link_bs4_bs3.
Get(1));
 
  529    bs4nd.
Add(link_bs4_bs3.
Get(0));
 
  530    bs4nd.
Add(link_bs5_bs4.
Get(1));
 
  534    bs5nd.
Add(link_bs5_bs4.
Get(0));
 
  535    bs5nd.
Add(link_b2_bs5.
Get(1));
 
  561    NS_LOG_INFO(
"L3: Install the ns3 IP stack on udp client and server nodes.");
 
  563    ns3IpStack.
Install(endpointNodes);
 
  568    NS_LOG_INFO(
"L3: Install the ns3 IP stack on routers.");
 
  570    ns3IpStack.
Install(routerNodes);
 
  578    topLanIpDevices.
Add(link_tr_ts1.
Get(0)); 
 
  579    topLanIpDevices.
Add(link_t2_ts4.
Get(0)); 
 
  580    topLanIpDevices.
Add(link_t3_ts1.
Get(0)); 
 
  583    ipv4.SetBase(
"192.168.1.0", 
"255.255.255.0");
 
  584    ipv4.Assign(topLanIpDevices);
 
  589    NS_LOG_INFO(
"L3: Assign bottom LAN IP Addresses.");
 
  592    botLanIpDevices.
Add(link_br_bs1.
Get(0)); 
 
  593    botLanIpDevices.
Add(link_b2_bs5.
Get(0)); 
 
  594    botLanIpDevices.
Add(link_b3_bs1.
Get(0)); 
 
  597    ipv4.SetBase(
"192.168.2.0", 
"255.255.255.0");
 
  598    ipv4.Assign(botLanIpDevices);
 
  605    ipv4.SetBase(
"76.1.1.0", 
"255.255.255.0");
 
  606    ipv4.Assign(link_tr_br);
 
  619    if (enableUdpMultiSW)
 
  624        NS_LOG_INFO(
"APP: Multi-Switch UDP server (on node b2 of bottom LAN)");
 
  635        NS_LOG_INFO(
"APP: Multi-Switch UDP client (on node t2 of top LAN)");
 
  639        uint32_t maxPacketCount = (simDurationSeconds - 2.0) / 0.005;
 
  643        client.SetAttribute(
"MaxPackets", 
UintegerValue(maxPacketCount));
 
  644        client.SetAttribute(
"Interval", 
TimeValue(interPacketInterval));
 
  655    if (enableUdpSingleSW)
 
  660        NS_LOG_INFO(
"APP: Single-Switch UDP server (on node t3 of top LAN)");
 
  671        NS_LOG_INFO(
"APP: Single-Switch UDP client (on node b3 bottom LAN)");
 
  675        uint32_t maxPacketCount = (simDurationSeconds - 2.0) / 0.005;
 
  679        client.SetAttribute(
"MaxPackets", 
UintegerValue(maxPacketCount));
 
  680        client.SetAttribute(
"Interval", 
TimeValue(interPacketInterval));
 
  694    NS_LOG_INFO(
"Set up to print routing tables at T=0.1s");
 
  705    NS_LOG_INFO(
"Configure PCAP Tracing (if any configured).");
 
  710    if (
vssearch(
"t2", pcapLocationVec))
 
  712        csmaX.
EnablePcap(
"t2.pcap", topLanIpDevices.
Get(1), 
true, 
true);
 
  718    if (
vssearch(
"b2", pcapLocationVec))
 
  720        csmaY.
EnablePcap(
"b2.pcap", botLanIpDevices.
Get(1), 
true, 
true);
 
  726    if (
vssearch(
"b3", pcapLocationVec))
 
  728        csmaY.
EnablePcap(
"b3.pcap", botLanIpDevices.
Get(2), 
true, 
true);
 
  734    if (
vssearch(
"t3", pcapLocationVec))
 
  736        csmaX.
EnablePcap(
"t3.pcap", topLanIpDevices.
Get(2), 
true, 
true);
 
  742    if (
vssearch(
"trlan", pcapLocationVec))
 
  744        csmaY.
EnablePcap(
"trlan.pcap", topLanIpDevices.
Get(0), 
true, 
true);
 
  750    if (
vssearch(
"brlan", pcapLocationVec))
 
  752        csmaX.
EnablePcap(
"brlan.pcap", botLanIpDevices.
Get(0), 
true, 
true);
 
  758    if (
vssearch(
"trwan", pcapLocationVec))
 
  760        p2p.EnablePcap(
"trwan.pcap", link_tr_br.
Get(0), 
true, 
true);
 
  766    if (
vssearch(
"brwan", pcapLocationVec))
 
  768        p2p.EnablePcap(
"brwan.pcap", link_tr_br.
Get(1), 
true, 
true);
 
  774    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.
Smart pointer class similar to boost::intrusive_ptr.
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.
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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
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.