How to Calculate Network Buffering in NS2

To calculate the Network Buffering in NS2 means that how packets are logged in a queue (or buffer) before being transmitted. It influences network performance, particularly based on delay, packet loss and throughput. To experience tailored research work you can approach us we provide you with best outcomes.  We have to evaluate the queue activities as well as metrics including queue size, queue delay and packet drops because of buffer overflow to calculate the buffering in ns2:

Here’s how you can calculate and evaluate buffering in NS2:

Steps to Calculate Network Buffering in NS2:

  1. Set Up the Simulation in NS2

First, define your network topology and make sure you have queues built on the network links. In NS2, buffering is executed by queues at each node for outgoing packets, and by default, NS2 uses a DropTail queue, yet other queue management algorithms like RED (Random Early Detection) can be used.

Below is an example simulation script with queues:

# Create NS2 simulator instance

set ns [new Simulator]

# Open trace file for output

set tracefile [open out.tr w]

$ns trace-all $tracefile

# Define nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

# Create links with DropTail queues

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

$ns queue-limit $n0 $n1 50   ;# Set queue limit to 50 packets for link n0-n1

$ns duplex-link $n1 $n2 1Mb 10ms DropTail

# Set up traffic (UDP traffic from n0 to n2)

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set null0 [new Agent/Null]

$ns attach-agent $n2 $null0

$ns connect $udp0 $null0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

# Start and stop traffic

$ns at 0.5 “$cbr0 start”

$ns at 4.5 “$cbr0 stop”

# End simulation

$ns at 5.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run simulation

$ns run

In this script:

  • A DropTail queue is configured on the link amongst n0 and n1, with a limit of 50 packets.
  • Traffic is created among nodes n0 and n2.
  1. Enable Queue Monitoring in NS2

Observe the buffering activities using the queue-monitor command in NS2. This will record enqueue, dequeue, and packet drop events in an individual file.

# Enable queue monitoring for the link n0-n1

$ns queue-monitor $n0 $n1 [open “queue-monitor-n0-n1.tr” w]

This command will produce a file (queue-monitor-n0-n1.tr) that logs the queue actions for the link amongst n0 and n1.

  1. Capture Buffering Data from the Trace File

NS2’s default trace file logs crucial events related to buffering, like:

  • +: Packet enqueued (arrival at the queue).
  • : Packet dequeued (departure from the queue for transmission).
  • d: Packet dropped (due to buffer overflow).

Example of trace file entries:

+ 0.500000 0 1 udp 500 ——- 1 0.0 0.0 1.0

– 0.510000 0 1 udp 500 ——- 1 0.0 0.0 1.0

d 0.520000 0 1 udp 500 ——- 1 0.0 0.0 1.0  # Packet drop due to full buffer

  1. Calculate Buffering Metrics

Queue Size

You can compute the queue size by summing up how many packets are enqueued and dequeued at any specified time.

Here’s an AWK script to measure the average queue size:

awk ‘

{

if ($1 == “+”) {

enqueue[$3]++;

}

if ($1 == “-“) {

dequeue[$3]++;

}

}

END {

for (link in enqueue) {

avg_queue_size = (enqueue[link] – dequeue[link]);

print “Average Queue Size for Link”, link, “:”, avg_queue_size;

}

}’ out.tr

This script quantifies the difference between enqueued and dequeued packets for each link to define the average queue size over the simulation.

Queue Delay (Buffering Delay)

Queue delay is the time a packet spends waiting in the queue before being transmitted. You can estimate this by discovering the time difference amongst the enqueue (+) and dequeue (-) events for each packet.

Here’s an AWK script to calculate the average queue delay:

awk ‘

{

if ($1 == “+”) {

enqueue_time[$7] = $2;  # Store enqueue time using packet ID ($7)

}

if ($1 == “-“) {

if (enqueue_time[$7] != “”) {

delay = $2 – enqueue_time[$7];  # Calculate delay (dequeue time – enqueue time)

total_delay += delay;

count++;

}

}

}

END { print “Average Queue Delay:”, total_delay / count, “seconds”; }’ out.tr

This script measures the average queue delay by tracking the enqueue time and comparing it with the dequeue time for each packet.

Packet Drops (Due to Buffer Overflow)

You can compute the amount of packets dropped because of buffer overflow by totaling the number of drop (d) events in the trace file.

Here’s an AWK script to calculate the number of dropped packets:

awk ‘

{

if ($1 == “d”) {

dropped_packets++;

}

}

END { print “Total Dropped Packets (Buffer Overflow):”, dropped_packets; }’ out.tr

This script sums how many packets were dropped due to buffer overflow.

  1. Analyze Buffering Behavior

We can analyse the performance of the network’s buffering mechanism by calculating the queue size, queue delay, and packet drop rate,. Here are some things to look for:

  • High queue size: Denotes heavy traffic, leading to longer delays and capable buffer overflows.
  • High queue delay: Represents packets are waiting too long in the buffer, which can degrade network performance, certainly for real-time applications.
  • High packet drop rate: Signifies the buffer is frequently full, which can result in packet loss and minimized throughput.
  1. Visualize Buffering Data

You can plot the buffering activities over time using Python (matplotlib) or other visualization tools. For instance, you can visualize the average queue size or queue delay:

Example Python Plot for Queue Size Over Time:

import matplotlib.pyplot as plt

# Example data for queue size over time

time = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5]

queue_size = [5, 10, 15, 25, 30, 35, 20, 10, 5]  # Example queue size data

plt.plot(time, queue_size, marker=’o’)

plt.title(‘Queue Size Over Time’)

plt.xlabel(‘Time (seconds)’)

plt.ylabel(‘Queue Size (packets)’)

plt.grid(True)

plt.show()

This can give you a clear picture of how the queue size varies over time.

Summary

To compute network buffering in NS2:

  1. Set up the simulation: Develop your network with nodes, links, and queues.
  2. Enable queue monitoring: The queue-monitor command is used to track enqueue, dequeue, and drop events.
  3. Analyze buffering metrics: Process the trace file and calculate the following by using AWK or Python:
    • Queue size: How many packets are in the queue.
    • Queue delay: How long packets wait in the queue.
    • Packet drops: How many packets are dropped because of buffer overflow.
  4. Visualize the results: Plot the metrics over time to evaluate buffering actions.

The delivered approach will guide you to learn about how to set up the simplified network simulation and how to define the droptail queue into the simulation to  calculate the network buffering using ns2 tool. If you need any details of this manual, we will provide it through another report.