How to Calculate Network Service Level Agreements in NS2

To Calculate Service Level Agreements (SLAs) in NS2 have needs to include an evaluating the network’s capability to satisfy the particular parameters and thresholds defined by the SLA. SLAs usually specify performance guarantees like uptime, latency, throughput, packet loss, and jitter, among other conditions. In NS2, we can replicate these parameters and compare them against the agreed SLA values to control whether the network satisfy or violates the SLA.

Here’s how to estimate the SLAs in NS2 step by step:

Step-by-Step Implementation:

  1. Define SLA Metrics

The typical SLA metrics include:

  • Uptime: The percentage of time the network (or specific links/nodes) is available.
  • Latency: The average delay experienced by packets in the course of transmission.
  • Throughput: The amount of data successfully routed per unit time.
  • Packet loss: The percentage of packets that is lost during transmission.
  • Jitter: The variation in packet delay (important for real-time applications like VoIP).
  1. Set up the NS2 Simulation

Configure a network topology in NS2 with nodes and links, and setup the traffic that will flow via the network. Here’s an sample simulation script:

# 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 between nodes

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

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

# Set up UDP traffic between n0 and 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 example:

  • The traffic is created among nodes n0 and n2 over a link from n0 -> n1 -> n2.
  • The simulation executes for 5 seconds, with traffic created among 0.5 and 4.5 seconds.
  1. Capture SLA Data from the Trace File

The trace file (out.tr) created by NS2 logs events like packet enqueue (+), dequeue (-), and drop (d). we can utilize this trace file to estimate SLA-related metrics such as throughput, latency, packet loss, and jitter.

Example trace files entry:

+ 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.510500 0 1 udp 500 ——- 1 0.0 0.0 1.0

  1. Calculate SLA Metrics

Uptime Calculation

To calculate uptime, we need to monitor the time in course of which each link or node is available. If any links or nodes go down during the simulation, we estimate the uptime as the total available time divided by the simulation time.

If we establish a failure (using rtmodel-at down), we can evaluate the downtime and uptime as follows:

# Calculate total uptime of a link (assuming the link goes down at 2.0 seconds and up at 3.5 seconds)

awk ‘

{

if ($1 == “d” && $3 == “0” && $4 == “1”) {  # Detect when the link goes down

down_time = $2;

}

if ($1 == “r” && $3 == “0” && $4 == “1”) {  # Detect when the link comes back up

up_time = $2;

downtime = up_time – down_time;

}

}

END {

total_time = 5.0;  # Total simulation time

uptime = total_time – downtime;

print “Link Uptime:”, (uptime / total_time) * 100, “%”;

}’ out.tr

This script estimates the uptime as a percentage of the total simulation time.

Latency (Delay) Calculation

To estimate latency, we analyse the difference among the time a packet is sent and when it is received.

Here’s an AWK script to compute the average delay:

awk ‘

{

if ($1 == “+”) {

send_time[$7] = $2;  # Record packet send time using packet ID

}

if ($1 == “-“) {

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

delay = $2 – send_time[$7];  # Calculate delay

total_delay += delay;

count++;

}

}

}

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

This script records the send time for each packet, estimates the delay for each successfully transmitted packet, and calculate the average delay.

Throughput Calculation

Throughput is estimated as the total number of bytes successfully routed over time. we can extract throughput from the trace file as follows:

awk ‘

{

if ($1 == “-” && $4 == “udp”) {

total_bytes += $6;  # Count total bytes transmitted

}

}

END { print “Throughput:”, total_bytes / 5.0, “bytes/sec”; }’ out.tr

This script estimates the total number of bytes routed and divides it by the simulation time to estimate throughput.

Packet Loss Calculation

Packet loss can be evaluated by summing up the number of packets dropped (d events) in the course of the simulation.

Here’s an AWK script to analyse packet loss:

awk ‘

{

if ($1 == “+”) {

total_packets++;

}

if ($1 == “d”) {

dropped_packets++;

}

}

END { print “Packet Loss Percentage:”, (dropped_packets / total_packets) * 100, “%”; }’ out.tr

This script counts the total number of packets sent and the number of dropped packets, and then estimates the packet loss percentage.

Jitter Calculation

Jitter is the variation in delay among consecutive packets. We can estimate jitter by evaluating the difference in delays among consecutive packets:

awk ‘

{

if ($1 == “+”) {

send_time[$7] = $2;  # Record send time

}

if ($1 == “-“) {

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

delay = $2 – send_time[$7];

if (prev_delay != “”) {

jitter_sum += (delay – prev_delay > 0) ? delay – prev_delay : prev_delay – delay;

}

prev_delay = delay;

count++;

}

}

}

END { print “Average Jitter:”, jitter_sum / (count – 1), “seconds” }’ out.tr

This script estimates jitter by evaluating the difference in delays among consecutive packets and estimating the average jitter.

  1. Compare against SLA Thresholds

Once we estimated the key parameters, compare them to the SLA thresholds to validate either the network meets the SLA requirements.

For example, if the SLA specifies:

  • Latency ≤ 50ms
  • Throughput ≥ 500 kbps
  • Packet Loss ≤ 1%

We can compare the estimated values to these thresholds and control if the SLA is met or violated.

  1. Post-Processing and Visualization

We can plot the SLA metrics like latency, throughput, and jitter over time to envision how well the network meets the SLA. Here’s an sample using Python (matplotlib):

import matplotlib.pyplot as plt

# Example data for latency over time

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

latency = [0.010, 0.012, 0.015, 0.011, 0.013, 0.016, 0.014, 0.012, 0.011]

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

plt.title(‘Latency Over Time’)

plt.xlabel(‘Time (seconds)’)

plt.ylabel(‘Latency (seconds)’)

plt.axhline(y=0.050, color=’r’, linestyle=’–‘, label=’SLA Threshold’)

plt.legend()

plt.grid(True)

plt.show()

Summary

To estimate network Service Level Agreements (SLAs) in NS2:

  1. Define SLA metrics: Uptime, latency, throughput, packet loss, and jitter.
  2. Set up the simulation: To mimic the network traffic and potential failures.
  3. Capture trace data: measure the trace file for events such as packet transmission, drops, and delays.
  4. Calculate SLA metrics: Utilize AWK scripts to estimate the parameters such as uptime, delay, throughput, packet loss, and jitter.
  5. Compare against SLA thresholds: Make sure the estimated values meet or exceed the SLA desires.
  6. Visualize the results: Utilize tools such as Python or Excel to plot the parameters and measure SLA compliance.

In this page we learned and get knowledge about how to calculate the service level agreements in the network using the ns2 tool. We will offer a comprehensive overview of the service level agreements as simulated in various scenarios.

To ensure complete support for Network Service Level Agreements in the NS2 project, please provide us with your requirements, and we will assist you in achieving optimal project results.