Tutorial: 5. Conceptual Overview — Tutorial (nsnam.org)

Node: host or edge devices in simulations

Application: user-level applications represented in OOP methods

Channel: manage communication subnetwork objects and connecting nodes to them

Net Device: to communicate between nodes (through channels), we need a network driver/software simulator → NetDevice

  1. Create network topology

    NodeContainer → holds multiples nodes

    PointToPointHelper → create link btw nodes

    XXX.SetDeviceAttribute(’DataRate’, StringValue(”5Mbps”)); → set the data rate

    InternetStackHelper → creates the stack (installs TCP/UDP/IP) on each of the nodes in the node container

    Ipv4AddressHelper → sets the IP address of the nodes automatically

    Ipv4InterfaceContainer → list of Ipv4Interface objects

  2. Create Application layers

    image.png

image.png

  1. Logging

    Can use system variables to set Log on or off

    export 'NS_LOG=UdpEchoClientApplication=level_all|prefix_func|prefix_time\\
    				:UdpEchoServerApplication=level_all|prefix_func|prefix_time'
    

This will set the LOGS for all levels (network, application), prefix_func (see which function is leaving which log), and and prefix_time (to see the time stamps for each function running).

image.png

We can also add our custom logs within the code:

image.png

Building and running it won’t show the log. We have to remember to set the log component definition that we set in the start of our code:

In our C++ Code:

NS_LOG_COMPONENT_DEFINE("FirstScriptExample");

In Bash Command:

export 'NS_LOG=FirstScriptExample=info'
  1. Adding parameters through command line:

    Similar to python’s ArgumentParser

    image.png

  2. Generating Traces (.tr file or .pcap file)

    Two main parties: i) independent tracing source ii) tracing sinks

    Trace Sink: consumer of events and data provided by the trace sources

    Trace Source: must be connected to other piece of code that actually do smth useful

    image.png

    This generates the following:

    + 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 1032 49153 > 10) Payload (size=1024)
    - 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 1032 49153 > 10) Payload (size=1024)
    r 2.25732 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 1032 49153 > 10) Payload (size=1024)
    + 2.25732 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.2 > 10.1.1.1) ns3::UdpHeader (length: 1032 10 > 49153) Payload (size=1024)
    - 2.25732 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.2 > 10.1.1.1) ns3::UdpHeader (length: 1032 10 > 49153) Payload (size=1024)
    r 2.51465 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.2 > 10.1.1.1) ns3::UdpHeader (length: 1032 10 > 49153) Payload (size=1024)
    

    Background of Symbols:

    Definition of Symbols:

    To make traces in pcap:

    pointToPoint.EnablePcapAll("myfirst");
    

    WiFi Station Simulation

    Can also log the movement of wifi stations:

    void
    CourseChange(std::string context, Ptr<const MobilityModel> model)
    {
      Vector position = model->GetPosition();
      NS_LOG_UNCOND(context <<
                  " x = " << position.x << ", y = " << position.y);
    }
    
    ...
    
    std::ostringstream oss;
    oss << "/NodeList/" << wifiStaNodes.Get(nWifi - 1)->GetId()
        << "/$ns3::MobilityModel/CourseChange";
    
    Config::Connect(oss.str(), MakeCallback(&CourseChange));
    

Note: we can also change the queueing models in ns-3 (has different maximum packet size that it can hold)

PointToPointHelper p2p;
p2p.SetQueue("ns3::DropTailQueue", "MaxSize", StringValue("50p"));

Queue disk installed on NetDevice can be modified through traffic control helper:

InternetStackHelper stack;
stack.Install(nodes);

TrafficControlHelper tch;
tch.SetRootQueueDisc("ns3::CoDelQueueDisc", "MaxSize", StringValue("1000p"));
tch.Install(devices);

or

InternetStackHelper stack;
stack.Install(nodes);

TrafficControlHelper tch;
tch.SetRootQueueDisc("ns3::CoDelQueueDisc", "MaxSize", StringValue("1000p"));
tch.SetQueueLimits("ns3::DynamicQueueLimits", "HoldTime", StringValue("4ms"));
tch.Install(devices);