How to Calculate Network Scalability in NS2

To calculate network scalability in NS2 has includes measure on how the performance of the network variations as the number of nodes, traffic loads, or network size increases. To measure scalability, we often track the parameters like latency, throughput, packet delivery ratio, and other performance indicators as we improve the scale of the network. Below is a step-by-step guide on how to calculate and evaluate network scalability in NS2:

Step-by-Step Implementation:

  1. Define Network Scalability Metrics

To evaluate network scalability, consider the following parameters:

  • Throughput: The rate at which data is successfully delivered over the network.
  • Latency: The delay in packet delivery as network size increases.
  • Packet Loss: The number of packets dropped as network size increases.
  • Packet Delivery Ratio (PDR): The ratio of successfully delivered packets to the total packets sent.
  • Routing Overhead: The amount of routing control packets relative to data packets.
  • Energy Efficiency: (for wireless networks) how energy consumption scales with the network size.
  1. Set up a Scalable Simulation in NS2

To model the multiple simulation scenarios with changing network sizes and traffic loads. We can adjust the number of nodes and traffic patterns for each scenario.

Example of a simple setup with increasing nodes:

# 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 (scale the network size by increasing node count)

set node_count 10 ;# Example with 10 nodes

for {set i 0} {$i < $node_count} {incr i} {

set n$i [$ns node]

}

# Create links between nodes (for scalability, increase links proportionally)

for {set i 0} {$i < $node_count} {incr i} {

for {set j [expr $i + 1]} {$j < $node_count} {incr j} {

$ns duplex-link $n$i $n$j 1Mb 10ms DropTail

}

}

# Set up traffic (scale traffic with more nodes)

for {set i 0} {$i < $node_count} {incr i} {

if {$i % 2 == 0} {

set udp$i [new Agent/UDP]

$ns attach-agent $n$i $udp$i

set null$i [new Agent/Null]

$ns attach-agent $n[expr $i+1] $null$i

$ns connect $udp$i $null$i

set cbr$i [new Application/Traffic/CBR]

$cbr$i set packetSize_ 500

$cbr$i set interval_ 0.005

$cbr$i attach-agent $udp$i

$ns at 0.5 “$cbr$i start”

$ns at 4.5 “$cbr$i stop”

}

}

# Run the simulation for each network size

$ns at 5.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run the simulation

$ns run

  1. Collect Data from Trace File

NS2 creates a trace file (e.g., out.tr) that logs all events in the network. The key fields in the trace file for scalability analysis has:

  • Throughput: Number of bytes delivered over time.
  • Latency: Time difference among packet sent and received events.
  • Packet Loss: Dropped packet events.
  • Routing Overhead: Number of control packets generated.
  1. Measure and Analyze Scalability Metrics

After executing the simulations, we can measure the trace file to calculate parameters as the network size increases. Use tools such as AWK, Python, or MATLAB to process the trace file and estimate the scalability metrics.

Example 1: Calculate Throughput

Throughput can be intended by counting the number of bytes successfully delivered over the simulation time.

# AWK script to calculate throughput

awk ‘$1 == “r” && $4 == “tcp” { total_bytes += $6 } END { print “Throughput: “, (total_bytes * 8) / 5.0, “bps” }’ out.tr

This script estimates the throughput in bits per second, assuming a 5-second simulation time.

Example 2: Calculate Latency

To compute the average delay, extract the packet send (+) and receive (r) times, and calculate the difference for each packet.

awk ‘$1 == “+” && $4 == “tcp” { send_time[$7] = $2 }

$1 == “r” && $4 == “tcp” { latency += ($2 – send_time[$7]); count++ }

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

Example 3: Packet Delivery Ratio (PDR)

PDR is the ratio of successfully received packets to the total sent packets.

# AWK script to calculate PDR

awk ‘$1 == “+” { sent++ }

$1 == “r” { received++ }

END { print “Packet Delivery Ratio: “, received/sent }’ out.tr

Example 4: Routing Overhead

Routing overhead is considered by summing up the number of control packets sent and dividing it by the total number of data packets sent.

awk ‘$4 == “RTR” { rtr_count++ }

$4 == “tcp” && $1 == “+” { data_count++ }

END { print “Routing Overhead: “, rtr_count/data_count }’ out.tr

  1. Plot and Compare Scalability Metrics

Once, we have collected the parameters from different simulation executes (with increasing number of nodes or traffic load), we can envision the scalability trends. For example, plot throughput, latency, PDR, and routing overhead against the number of nodes or traffic load to monitor on how the performance scales.

Example: Python Plotting Script

import matplotlib.pyplot as plt

# Example data for different network sizes

nodes = [10, 20, 30, 40, 50]

throughput = [500000, 950000, 1300000, 1600000, 1800000]  # Example throughput data

plt.plot(nodes, throughput, marker=’o’)

plt.title(‘Throughput vs Network Size’)

plt.xlabel(‘Number of Nodes’)

plt.ylabel(‘Throughput (bps)’)

plt.grid(True)

plt.show()

  1. Scalability Interpretation
  • Good scalability: If throughput upsurges proportionally with the number of nodes and latency, packet loss, and routing overhead remain stable or improve slowly.
  • Poor scalability: If throughput saturates, latency increases drastically, and packet loss or routing overhead raises quickly as the network size upsurges.

In the above manual, we validate the comprehensive procedures to compute and evaluate the network scalability that has implementation procedures and sample snippets were given to evaluate in ns2 tool. Additional specific details regarding the network scalability will be provided. For complete project support just share with us the  requirements we wil help you with best project outcomes.