**How to Calculate Network Burstiness in NS2**

To calculate the Network Burstiness in NS2 means that the variation or irregularity in a packet arrival times through the network. High burstiness indicates that packets are transferred in sudden bursts, causing potential congestion, delays or packet loss. It is crucial aspects to assess in networks, particularly in traffic-heavy situations like multimedia transmission or bursty applications.

To estimate **network burstiness** in NS2, you will need to evaluate the timing of packet transmissions and receptions. Usually, burstiness can be computed by looking at **inter-arrival times** (the time amongst consecutive packet arrivals) and **traffic rate variations** over time.

**Steps to Calculate Network Burstiness in NS2**

**Generate Trace File**

Evaluate the burstiness by producing a trace file from your NS2 simulation. The trace file will log the send (+), receive (r), and drop (d) events, along with their timestamps.

Make sure that your NS2 simulation is set up to create a trace file:

set tracefile [open out.tr w]

$ns trace-all $tracefile

The trace file will contain timestamps for each packet’s transmission and reception, which can be used to estimate burstiness.

**Identify Packet Transmission and Arrival Events**

In the trace file, you will look for packet transmission (+) and reception (r) events. Each line in the trace file normally looks like this:

+ 0.12345 0 1 tcp 1040 ——- [0 0 1 0] ——- [1:0 0:0 32 0] [0] 0 0

r 0.45678 1 0 tcp 1040 ——- [0 1 0 0] ——- [0:0 1:0 32 0] [0] 0 0

Here:

- + indicates a packet transmission event.
- r indicates a packet reception event.
- 0.12345 and 0.45678 are timestamps (in seconds).
- tcp indicates the packet type (TCP in this case).
- 1040 is the packet size in bytes.

You can aim on the r (reception) events to assess the burstiness of incoming traffic at the receiver.

**Calculate Inter-Arrival Times**

One way to quantify burstiness is by computing the **inter-arrival times**, which is the time amongst consecutive packet receptions. High variability in inter-arrival times suggests bursty traffic.

**AWK Script to Calculate Inter-Arrival Times:**

awk ‘{

if ($1 == “r” && $4 == “tcp”) {

if (last_arrival_time > 0) {

inter_arrival_time = $2 – last_arrival_time;

print “Inter-Arrival Time: ” inter_arrival_time ” seconds”;

}

last_arrival_time = $2; # $2 is the timestamp

}

}’ out.tr

In this script:

- last_arrival_time keeps track of the previous packet’s arrival time.
- inter_arrival_time is quantified as the difference amongst the current packet’s timestamp and the previous packet’s timestamp.

If the inter-arrival times changes significantly, it indicates bursty traffic.

**Calculate Coefficient of Variation (CV)**

To quantify burstiness, you can estimate the **Coefficient of Variation (CV)** of the inter-arrival times. CV is a standardized measure of dispersion and is given by:

CV=σμ\text{CV} = \frac{\sigma}{\mu}CV=μσ

Where:

**σ**is the standard deviation of inter-arrival times.**μ**is the mean inter-arrival time.

**Python Script to Calculate CV:**

You can parse the trace file and measure CV using Python. Here’s an example script:

import numpy as np

# Parse the trace file to extract inter-arrival times

def calculate_inter_arrival_times(tracefile):

inter_arrival_times = []

last_arrival_time = None

with open(tracefile, ‘r’) as f:

for line in f:

if line.startswith(‘r’) and ‘tcp’ in line:

data = line.split()

current_time = float(data[1]) # $2 is the timestamp

if last_arrival_time is not None:

inter_arrival_time = current_time – last_arrival_time

inter_arrival_times.append(inter_arrival_time)

last_arrival_time = current_time

return inter_arrival_times

# Calculate the coefficient of variation

def calculate_cv(inter_arrival_times):

mean = np.mean(inter_arrival_times)

std_dev = np.std(inter_arrival_times)

cv = std_dev / mean if mean != 0 else 0

return cv

# Usage

tracefile = “out.tr”

inter_arrival_times = calculate_inter_arrival_times(tracefile)

cv = calculate_cv(inter_arrival_times)

print(f”Coefficient of Variation (CV): {cv}”)

This script:

- Reads the trace file and measures inter-arrival times amongst consecutive packet receptions.
**NumPy**is used to calculate the**mean**and**standard deviation**of inter-arrival times, and then computes the**Coefficient of Variation (CV)**.

A higher CV denotes more bursty traffic, while a lower CV suggests more regular packet arrivals.

**Plot Traffic Rate Over Time**

Another way to visually analyze burstiness is by plotting the **traffic rate** over time. You can build a time-based histogram of packet arrivals or quantify the amount of packets obtained in fixed time intervals.

Here’s how you can compute the sum of packets received in 1-second intervals using an AWK script:

awk ‘{

if ($1 == “r” && $4 == “tcp”) {

interval = int($2); # Group by time interval (1 second)

packet_count[interval]++;

}

} END {

for (i in packet_count) {

print “Time Interval: ” i “, Packets Received: ” packet_count[i];

}

}’ out.tr

This script:

- Groups packet receptions into 1-second intervals.
- Sums the number of packets acquired in each interval, which helps assess how packet arrivals differs over time.

**Plotting in Python:**

You can plot the packet reception rate over time by using Python and **matplotlib**:

import matplotlib.pyplot as plt

# Parse the trace file and group packet arrivals by time intervals

def parse_trace_for_traffic_rate(tracefile, interval_duration=1.0):

packet_count_per_interval = {}

with open(tracefile, ‘r’) as f:

for line in f:

if line.startswith(‘r’) and ‘tcp’ in line:

data = line.split()

current_time = float(data[1])

interval = int(current_time // interval_duration)

if interval in packet_count_per_interval:

packet_count_per_interval[interval] += 1

else:

packet_count_per_interval[interval] = 1

return packet_count_per_interval

# Plot traffic rate over time

def plot_traffic_rate(packet_count_per_interval):

intervals = sorted(packet_count_per_interval.keys())

packet_counts = [packet_count_per_interval[i] for i in intervals]

plt.plot(intervals, packet_counts, marker=’o’)

plt.xlabel(“Time Interval (s)”)

plt.ylabel(“Packets Received”)

plt.title(“Traffic Rate Over Time”)

plt.show()

# Usage

tracefile = “out.tr”

packet_count_per_interval = parse_trace_for_traffic_rate(tracefile)

plot_traffic_rate(packet_count_per_interval)

This script:

- Groups packet receptions into 1-second intervals.
- Plots the packet reception rate over time to help envision burstiness.

If you see sharp spikes in packet reception, the traffic is bursty. If the rate is relatively constant, the traffic is smooth and consistent.

**Use the Burstiness Index (BI)**

The **Burstiness Index (BI)** is another metric that can be used to compute burstiness. It is given by:

Burstiness Index=max(Inter-Arrival Times)−min(Inter-Arrival Times)max(Inter-Arrival Times)+min(Inter-Arrival Times)\text{Burstiness Index} = \frac{\max(\text{Inter-Arrival Times}) – \min(\text{Inter-Arrival Times})}{\max(\text{Inter-Arrival Times}) + \min(\text{Inter-Arrival Times})}Burstiness Index=max(Inter-Arrival Times)+min(Inter-Arrival Times)max(Inter-Arrival Times)−min(Inter-Arrival Times)

A **BI** close to 1 represents high burstiness, while a value closer to 0 signifies regular traffic.

**Python Code to Calculate Burstiness Index (BI):**

def calculate_burstiness_index(inter_arrival_times):

if len(inter_arrival_times) == 0:

return 0

max_inter_arrival = max(inter_arrival_times)

min_inter_arrival = min(inter_arrival_times)

if max_inter_arrival + min_inter_arrival == 0:

return 0

bi = (max_inter_arrival – min_inter_arrival) / (max_inter_arrival + min_inter_arrival)

return bi

# Calculate BI

bi = calculate_burstiness_index(inter_arrival_times)

print(f”Burstiness Index (BI): {bi}”)

This script quantifies the **Burstiness Index (BI)**, which helps computes the degree of burstiness in the traffic.

Utilize the offered computational process to understand the steps, examples, formulas regarding the quantification of Network Burstiness using ns2 simulator tool. Burstiness is a time variations taken by packets in a network scenario. If needed, we will provide the set up using another simulation.

To assess network burstiness using the NS2 tool, we are here to provide you with optimal results. Reach out to ns2project.com for exceptional outcomes. Simply provide us with your parameter details, and we will analyze and compare them to deliver a comprehensive performance analysis of your project’s networking capabilities.