UDP: End to End Delay Measurement
Topology
N0(UDP Sender)----P2Plink(5Mbps,2ms)---N1(UDP Sink)
After simulation, I will show how to parse the trace file to get the end to end delay.
delay-udp.cc (put this file under scratch)
#include <fstream> #include <string.h> #include "ns3/core-module.h" #include "ns3/internet-module.h" #include "ns3/point-to-point-module.h" #include "ns3/packet-sink.h" #include "ns3/packet-sink-helper.h" #include "ns3/on-off-helper.h" using namespace ns3; NS_LOG_COMPONENT_DEFINE ("DelayUDP"); int main (int argc, char *argv[]) { NS_LOG_INFO ("Create nodes."); NodeContainer n; n.Create (2); InternetStackHelper internet; internet.Install (n); NS_LOG_INFO ("Create channels."); PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); pointToPoint.SetDeviceAttribute("Mtu", UintegerValue(1400)); NetDeviceContainer p2pDevices; p2pDevices = pointToPoint.Install (n); Ipv4AddressHelper ipv4; NS_LOG_INFO ("Assign IP Addresses."); ipv4.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer i = ipv4.Assign (p2pDevices); NS_LOG_INFO ("Create Applications."); PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), 9)); ApplicationContainer sinkApp = sinkHelper.Install (n.Get(1)); InetSocketAddress sinkSocket (i.GetAddress (1), 9); OnOffHelper server ("ns3::UdpSocketFactory", sinkSocket); server.SetAttribute ("PacketSize", UintegerValue (172)); // G.711 encoding, 20ms delay, 160bytes +12bytes(rtp) server.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); server.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); server.SetAttribute ("DataRate", DataRateValue (DataRate ("64Kbps"))); ApplicationContainer serverApp = server.Install (n.Get(0)); sinkApp.Start (Seconds (0.0)); serverApp.Start (Seconds (1.0));
Simulator::Stop (Seconds (12.0)); //pointToPoint.EnablePcapAll("delay-udp"); AsciiTraceHelper ascii; pointToPoint.EnableAsciiAll(ascii.CreateFileStream("delay-udp.tr")); NS_LOG_INFO ("Run Simulation."); Simulator::Run (); Simulator::Destroy (); NS_LOG_INFO ("Done."); } |
Execution
After simulation, you will get “delay-udp.tr”.
+ 1.0215 /NodeList/0/DeviceList/1/$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: 200 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 180 49153 > 9) Payload (size=172) - 1.0215 /NodeList/0/DeviceList/1/$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: 200 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 180 49153 > 9) Payload (size=172) r 1.02382 /NodeList/1/DeviceList/1/$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: 200 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 180 49153 > 9) Payload (size=172) + 1.043 /NodeList/0/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1 protocol 17 offset (bytes) 0 flags [none] length: 200 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 180 49153 > 9) Payload (size=172) …………………………………………………………………………………………………………………………………………………………. |
With different network scenarios, you may get different trace formats. But the idea is similar. You just need to change the awk file and you will get the results.
getDelay.awk
BEGIN { src="10.1.1.1"; # sender IP address dst="10.1.1.2)"; #receiver IP address sent = 0; received = 0; highest_pkt_id = 0; total_delay = 0; } { event=$1 #+:enque -:deque r:receive time=$2 #event time id=$19 #pkt id sip=$29 #source ip dip=$31 #destination ip if (id>highest_pkt_id) highest_pkt_id=id
if (event=="+" && sip==src && dip==dst){ sendtime[$19]=$2 sent++ }
if (event=="r" && sip==src && dip==dst){ recvtime[$19]=$2 received++ } } END { #print "sent:" sent " received:" received for(id=0; id<=highest_pkt_id;id++){ stime=sendtime[id]; rtime=recvtime[id]; if( stime < rtime) printf("%d %f %f\n", id, stime, rtime-stime); } } |
Execution (The first column is the packet id, the second is pkt sending time, and the third is the end-to-end delay time.)
Last Modified: 2022/2/6 done
[Author]
Dr. Chih-Heng Ke
Department
of Computer Science and Information Engineering, National Quemoy
University, Kinmen, Taiwan
Email:
smallko@gmail.com