How to Calculate Network Bridging in NS2

To calculate the Network Bridging in Network Simulator 2 (NS2) indicates the process of replicating the performance of a network bridge that connects various network segments at the data link layer (Layer 2 of the OSI model). It usually operates by dispatching packets in terms of MAC addresses, learning which addresses are on each side of the bridge and filtering traffic correspondingly. In NS2, we can replicate and evaluate the activities of a bridge by setting up nodes to behave like bridges and observing how they forward packets.

Although NS2 mainly simulates networking at Layer 3 (network layer), you can still replicate a simple bridging features by using several nodes to link various network segments and analysing how they manage traffic among those segments.

Here is an approach to calculate the network bridging in NS2:

Steps to Simulate and Calculate Network Bridging in NS2

  1. Set Up the Network Topology

You can simulate a network bridge by designing a node in NS2 to behave like an intermediary amongst various network segments. The bridge will forward traffic among these segments in terms of predefined policies or simple dispatching logic.

Here’s an example of how to build a basic bridging scenario:

# 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]    ;# Node in Network A

set n1 [$ns node]    ;# Node in Network B

set n2 [$ns node]    ;# Node in Network C (Bridge)

set n3 [$ns node]    ;# Node in Network A

set n4 [$ns node]    ;# Node in Network B

# Create links between nodes

$ns duplex-link $n0 $n2 1Mb 10ms DropTail    ;# n0 to Bridge (n2)

$ns duplex-link $n2 $n1 1Mb 10ms DropTail    ;# Bridge (n2) to n1

$ns duplex-link $n3 $n2 1Mb 10ms DropTail    ;# n3 to Bridge (n2)

$ns duplex-link $n2 $n4 1Mb 10ms DropTail    ;# Bridge (n2) to n4

# Set up traffic (UDP traffic between n0 and n1, n3 and n4)

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set null0 [new Agent/Null]

$ns attach-agent $n1 $null0

$ns connect $udp0 $null0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

# Second traffic flow from n3 to n4

set udp1 [new Agent/UDP]

$ns attach-agent $n3 $udp1

set null1 [new Agent/Null]

$ns attach-agent $n4 $null1

$ns connect $udp1 $null1

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packetSize_ 500

$cbr1 set interval_ 0.005

$cbr1 attach-agent $udp1

# Start and stop traffic

$ns at 0.5 “$cbr0 start”

$ns at 0.6 “$cbr1 start”

$ns at 4.5 “$cbr0 stop”

$ns at 4.6 “$cbr1 stop”

# End simulation

$ns at 5.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run the simulation

$ns run

In this setup:

  • n2 acts as the bridge amongst the two separate networks (one containing nodes n0 and n3, and the other containing nodes n1 and n4).
  • Traffic flows amidst nodes on opposite sides of the bridge.
  • Traffic flows over the bridge, which dispatches packets from n0 to n1 and from n3 to n4.
  1. Understand Bridging Behavior

The bridge (n2) in this simulation forwards traffic depends on simple Layer 2 forwarding rules:

  • Forwarding: Packets received from one side of the network are forwarded to the correct destination on the other side of the bridge.
  • Filtering: The bridge evades pointless forwarding by only delivering packets to nodes that need them.
  1. Analyze Bridging Behavior

To analyze the bridging behavior in NS2, focus on the below metrics:

  • Forwarding time: How long it takes for the bridge to forward packets from one network segment to another.
  • Throughput across the bridge: The amount of traffic successfully forwarded by the bridge.
  • Packet loss: If the bridge drops packets because of congestion or other issues.
  1. Capture Data from the Trace File

The trace file (out.tr) records key events like packet transmission, forwarding, and drops. To assess bridging, concentrate on how packets travel over the bridge (n2).

Example trace file entries:

+ 0.500000 0 2 udp 500 ——- 1 0.0 0.0 1.0   ;# Packet enqueued at n0 for forwarding to bridge

– 0.510000 2 1 udp 500 ——- 1 0.0 0.0 1.0   ;# Packet forwarded by bridge to n1

  1. Calculate Bridging Metrics

Forwarding Time

The forwarding time is the time it takes for a packet to be obtained at the bridge and then forwarded to the destination node. You can compute this by estimating the difference amongst the time a packet is acquired at the bridge and the time it is forwarded.

Here’s an AWK script to measure forwarding time for the bridge:

awk ‘

{

if ($1 == “+” && $3 == “2”) {

enqueue_time[$7] = $2;  # Store time when packet is enqueued at the bridge

}

if ($1 == “-” && $3 == “2”) {

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

forwarding_time = $2 – enqueue_time[$7];  # Calculate forwarding time

total_forwarding_time += forwarding_time;

count++;

}

}

}

END {

print “Average Forwarding Time at Bridge:”, total_forwarding_time / count, “seconds”;

}’ out.tr

This script calculates the average forwarding time by relating the enqueue and dequeue times of packets at the bridge (n2).

Throughput Across the Bridge

Throughput is the entire amount of bytes successfully forwarded by the bridge. You can calculate this by counting the sizes of packets forwarded by the bridge.

Here’s an AWK script to calculate throughput across the bridge:

awk ‘

{

if ($1 == “-” && $3 == “2”) {

total_bytes += $6;  # Add the size of each packet forwarded by the bridge

}

}

END {

print “Throughput at Bridge:”, total_bytes / 5.0, “bytes/sec”;  # Assuming 5 seconds of simulation

}’ out.tr

This script calculates the total number of bytes forwarded by the bridge and divides it by the total simulation time.

Packet Loss

Packet loss can be computed by totalling how many packets are dropped at the bridge. Packet drops might happen because of congestion or buffer overflow.

Here’s an AWK script to count packet drops at the bridge:

awk ‘

{

if ($1 == “d” && $3 == “2”) {

dropped_packets++;

}

}

END {

print “Total Packets Dropped at Bridge:”, dropped_packets;

}’ out.tr

This script sums the total of packets dropped at the bridge.

  1. Visualize Bridging Metrics

You can visualize the bridging metrics (like forwarding time, throughput, and packet loss) using Python or another tool. For instance, you can plot the throughput over time.

Example Python Plot for Throughput:

import matplotlib.pyplot as plt

# Example throughput data (bytes/sec)

time = [1, 2, 3, 4, 5]

throughput = [800, 900, 850, 950, 880]  # Example throughput values

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

plt.title(‘Throughput Across the Bridge’)

plt.xlabel(‘Time (seconds)’)

plt.ylabel(‘Throughput (bytes/sec)’)

plt.grid(True)

plt.show()

This will give you a clear view of how throughput varies over time as packets are forwarded via the bridge.

  1. Interpret the Results
  • High forwarding time: If the forwarding time is high, it may denote congestion or inefficient forwarding at the bridge.
  • Low throughput: Low throughput may recommend that the bridge is becoming a bottleneck.
  • High packet loss: High packet loss at the bridge represents that packets are being dropped, capably because of buffer overflow or congestion.

We had clearly aggregated the information to provide the demonstration steps on how to compute the network bridging in the ns2 simulation by developing a node that acts like intermediary node that links the numerous network parts. If needed, we will deliver any details of this bridging or their estimation of other metrics.

Our team assists you in calculating Network Bridging using the NS2 tool. Additionally, we offer the best project ideas and topics curated by our experts to ensure you achieve the most favorable outcomes. Please provide us with all relevant parameter details, and we will conduct a comparison to deliver optimal results.