Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

# How to Calculate Intermediate Delay in ns3

To calculate intermediate delay in ns3, we have to measure the delay at every hop in a multi-hop network. Intermediate delay is defined as the time taken for a packet to travel from one node to the next node. Below are the steps to calculate intermediate delay.

Steps for calculating network burstiness

1. Set up the simulation :
• To simulate the network, create a network topology with nodes, protocols and links configured.
1. Install applications :
• On the nodes, setup applications to generate and receive traffic.
1. Trace the packets :
• To record the send and receive times of packets at each node, use ns3 tracing capabilities.
1. Calculate intermediate delay :
• Subtract the send time from the receive time for each packet at each intermediate node.

Example of a simple Multi-Hop Network

Create a basic three-node linear topology where Node 0 sends packets to Node 2 via Node 1.

set up the simulation

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/point-to-point-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“IntermediateDelayExample”);

void RxTrace (Ptr<const Packet> packet, const Address &address, std::string nodeName, std::string context)

{

NS_LOG_UNCOND (“Packet received at ” << nodeName << ” at time ” << Simulator::Now ().GetSeconds () << ” seconds”);

}

int main (int argc, char *argv[])

{

// Create three nodes

NodeContainer nodes;

nodes.Create (3);

PointToPointHelper pointToPoint;

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

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

// Install link devices on nodes

NetDeviceContainer devices01, devices12;

devices01 = pointToPoint.Install (nodes.Get (0), nodes.Get (1));

devices12 = pointToPoint.Install (nodes.Get (1), nodes.Get (2));

// Install the internet stack

InternetStackHelper stack;

stack.Install (nodes);

// Set up the UDP echo server on Node 2

uint16_t port = 9; // well-known echo port number

UdpEchoServerHelper echoServer (port);

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

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

// Set up the UDP echo client on Node 0

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

echoClient.SetAttribute (“Interval”, TimeValue (Seconds (0.1))); // 10 packets per second

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

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

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

// Enable packet receive tracing on Node 1 and Node 2

Config::Connect (“/NodeList/1/DeviceList/*/MacRx”, MakeBoundCallback (&RxTrace, “Node 1”));

Config::Connect (“/NodeList/2/DeviceList/*/MacRx”, MakeBoundCallback (&RxTrace, “Node 2”));

// Enable tracing

AsciiTraceHelper ascii;

pointToPoint.EnableAsciiAll (ascii.CreateFileStream (“intermediate-delay.tr”));

// Run the simulation

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

1. Install applications

In the above example, on Node 2 a UDP echo server is installed. and on Node 2, a UDP echo client is installed. The client sends 1000 packets, each 1024 bytes in size, at an interval of 0.01 seconds.

1. Trace the packets

There are several ways to trace packets in ns3. In our example, packet receive tracing is enabled on Node 1 and Node 2 using the Config::Connect method.

1. Calculate Intermediate Delay

Parse the trace file to extract the times of packets at each node and calculate the delay between hops after the simulation.

Example Python Script to Calculate Intermediate Delay

Below is an example python scrip to calculate intermediate delay.

import re

# Initialize dictionaries to store send and receive times

# Regular expression to match the trace output

pattern = re.compile(r”Packet received at Node (\d) at time (\d+\.\d+) seconds”)

# Parse the trace file

with open(“intermediate-delay.tr”, “r”) as trace_file:

for line in trace_file:

match = pattern.search(line)

if match:

node = match.group(1)

time = float(match.group(2))

if node == “1”:

elif node == “2”:

# Calculate intermediate delays

intermediate_delays = []

intermediate_delays.append(delay)

# Calculate average intermediate delay

average_intermediate_delay = sum(intermediate_delays) / len(intermediate_delays) if intermediate_delays else 0

print(f”Average Intermediate Delay: {average_intermediate_delay} seconds”)

Explanation

1. Simulation setup :

Three-node linear topology is created. Those nodes are connected using a point-to-point link.

1. Application setup :

On Node 2, a UDP echo server is installed. and On Node 0, a UDP echo client is installed. Configure the client to send a specified number of packets at a specified interval.

1. Packet tracing :

To record the receive times of packets, enable packet receive tracing on Node 1 and Node 2.

1. Calculate Intermediate Delay :

Parse the trace file to extract the receive times of packets at each node. Calculate the delay between Node 0 and Node 1, and between Node 1 and Node 2, then compute the average intermediate delay.

We have conducted an analysis of the intermediate delay in ns3 by measuring the delay at each hop in a multi-hop network. Additionally, we provide additional information on intermediate delay.

Our developers are pleased to provide you with advice on project performance for your current project. Moreover, we continue with a thorough comparative analysis. Furthermore, we offer comprehensive details on calculating Intermediate Delay in ns3simulation. For ideal outcomes, please call ns3simulation.com.