How to Begin Implement Network End to End Delay in NS3

To implement and study the Network End-to-End Delay in ns-3, follow these steps. End-to-End Delay is a performance of parameter metric which compute the duration for a packet to travel from the sender to the receiver with the network.

Steps to Begin Implement Network End to End Delay in NS3

  1. Understand End-to-End Delay

End-to-End Delay is computed as:

End-to-End Delay=Packet Arrival Time−Packet Sent Time\text{End-to-End Delay} = \text{Packet Arrival Time} – \text{Packet Sent Time}End-to-End Delay=Packet Arrival Time−Packet Sent Time

  1. Set up Your Environment

Assure the tool ns3 is install and setting. Familiarize by simple ns-3 scripting.

  1. Create the Network Topology

Example: Point-to-Point Network

NodeContainer nodes;

nodes.Create(2);

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));

pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));

NetDeviceContainer devices;

devices = pointToPoint.Install(nodes);

Example: Wireless Network

YansWifiChannelHelper channel = YansWifiChannelHelper::Default();

YansWifiPhyHelper phy = YansWifiPhyHelper::Default();

phy.SetChannel(channel.Create());

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211n);

WifiMacHelper mac;

mac.SetType(“ns3::AdhocWifiMac”);

NodeContainer wifiNodes;

wifiNodes.Create(3);

NetDeviceContainer wifiDevices;

wifiDevices = wifi.Install(phy, mac, wifiNodes);

  1. Set up the Internet Stack

Download the Internet stack for ensure the IP-based communication:

InternetStackHelper stack;

stack.Install(nodes);

 

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign(devices);

  1. Install Applications to Generate Traffic

Example: UDP Traffic

UdpEchoServerHelper echoServer(9);

ApplicationContainer serverApps = echoServer.Install(nodes.Get(1));

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 9);

echoClient.SetAttribute(“MaxPackets”, UintegerValue(100));

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(0.01))); // 10ms interval

echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));

ApplicationContainer clientApps = echoClient.Install(nodes.Get(0));

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(10.0));

  1. Monitor End-to-End Delay

We can track the end-to-end delay through performance metrices for timestamps in packets after forward and received.

Attach Callbacks for Packet Sent and Received

Track Packet Sent Time

std::map<uint64_t, Time> sentTimes;

void PacketSentCallback(Ptr<const Packet> packet) {

uint64_t packetId = packet->GetUid(); // Unique ID for the packet

sentTimes[packetId] = Simulator::Now();

std::cout << “Packet Sent: ID=” << packetId << ” at ” << Simulator::Now().GetSeconds() << “s” << std::endl;

}

devices.Get(0)->TraceConnectWithoutContext(“MacTx”, MakeCallback(&PacketSentCallback));

Track Packet Received Time

void PacketReceivedCallback(Ptr<const Packet> packet) {

uint64_t packetId = packet->GetUid();

if (sentTimes.find(packetId) != sentTimes.end()) {

Time sentTime = sentTimes[packetId];

Time receivedTime = Simulator::Now();

double delay = (receivedTime – sentTime).GetSeconds();

std::cout << “Packet Received: ID=” << packetId << ” at ” << receivedTime.GetSeconds()

<< “s, Delay: ” << delay << “s” << std::endl;

}

}

devices.Get(1)->TraceConnectWithoutContext(“MacRx”, MakeCallback(&PacketReceivedCallback));

  1. Use FlowMonitor for Automated Delay Calculation

The element can be automatically monitoring the parameter metrics FlowMonitorHelper, has containing the end-to-end delay.

Configure FlowMonitor

FlowMonitorHelper flowmon;

Ptr<FlowMonitor> monitor = flowmon.InstallAll();

Simulator::Stop(Seconds(10.0));

Simulator::Run();

monitor->CheckForLostPackets();

Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());

std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();

for (auto& flow : stats) {

Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(flow.first);

std::cout << “Flow ID: ” << flow.first

<< ” (” << t.sourceAddress << ” -> ” << t.destinationAddress << “)\n”;

std::cout << ”  End-to-End Delay: ”

<< flow.second.delaySum.GetSeconds() / flow.second.rxPackets << “s\n”;

}

Simulator::Destroy();

  1. Visualize Results
  • Distribute the delay data for a file plotting.
  • Use tools such as MATLAB or Excel for investigate the trends.
  • Use NetAnim for envision the replication of network.
  1. Experiment and Optimize
  • Different the connection delay using SetChannelAttribute.
  • Validate by changed the kinds of congestion for instance TCP, UDP.
  • It replicates the various network topologies and examines the effect of delay.
  1. Run the Simulation

It executes for the replication and validates the outcomes:

Simulator::Run();

Simulator::Destroy();

In this demonstration we get to know and gain knowledge regarding the Network End to End Delay concepts and their evaluation process to deploy in the ns3 implementation tool. A dedicated manual will be shared to handle further questions about this project.