ns-3

How does ns3 implement processing delay inside protocol layer?


I just begin reading the source code of ns3. I begin with the first.cc example, then into the udp-echo-client.cc -> ipv4-raw-socket-impl.cc -> ipv4-interface.cc -> traffic-control-layer.cc following the sending of the packet.

I find that upper layers call the send method of lower layers directly during the processing of an event, instead of scheduling another event. So how does ns3 implement the processing delay inside a protocol layer? For example, the UDP layer takes 10us processing the packet before send it to IP layer.

Sorry if my question is silly. Any pointing to the right direction to understand ns3 design would be appreciated.


Solution

  • In general, ns-3 does not model processing delays for sending/receiving/forwarding of packets. There are a few exceptions, such as the MAC-to-PHY delay in an LTE/NR system, and some specialized models like DOCSIS, but the TCP/IP stack and Wi-Fi do not have built-in configurable processing delay capability.

    However, processing delay can be inserted into many models by locating the relevant point in the reception stack and refactoring a direct method call into a scheduled (with delay) call. For instance, to insert processing delay into the UDP reception path, one could take a statement such as:

    (*endPoint)->ForwardUp(packet->Copy(), header, udpHeader.GetSourcePort(), interface);
    

    and wrap it within a method such as:

    Simulator::Schedule (MicroSeconds (10), &UdpL4Protocol::ForwardUpAfterDelay, this, packet->Copy (), header, udpHeader.GetSourcePort ());
    

    and further, change the magic number of 10 us into a configurable Time attribute.