How to Calculate Network Hubs in Ns2

To calculate and simulate the network hubs within NS2 (Network Simulator 2) that are not explicitly modelled as physical Layer 1 devices since NS2 mainly concentrates on the higher-layer network simulations (Layer 3 and above). Though, we can be replicated the performance of a hub using broadcast communication, in which a central node forwards the data to all other nodes connected to it. A hub necessarily simulates incoming traffic on one interface to all other connected nodes and replicating a shared medium. Approach us for any types of project details we will help you with original project ideas and topics.  We distribute the simple method to replicate and compute the hub-like behaviour in NS2:

Steps to Simulate a Hub in NS2

  1. Set up a Central Node (Hub Behaviour) The central node will be performed such as a hub, connecting to numerous nodes and forwarding traffic to all other nodes. Every packet transmitted to the hub will be simulated and sent to all other connected nodes.
  2. Create the NS2 Simulation Script following is an instance NS2 simulation script in which a central node (acting like a hub) connects to several other nodes.

Example NS2 Script to Simulate Hub Behaviour

# 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 (hub is n0, other nodes are n1, n2, n3)

set hub [$ns node]   ;# Central node acting as a hub

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

# Create duplex links between hub and all other nodes

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

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

$ns duplex-link $hub $n3 1Mb 10ms DropTail

# Set up UDP traffic from n1 to hub

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

set null1 [new Agent/Null]

$ns attach-agent $hub $null1

$ns connect $udp1 $null1

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packetSize_ 500

$cbr1 set interval_ 0.01

$cbr1 attach-agent $udp1

# Set up UDP traffic from hub to n2 and n3 (hub forwards packets)

set udp2 [new Agent/UDP]

$ns attach-agent $hub $udp2

set null2 [new Agent/Null]

$ns attach-agent $n2 $null2

$ns connect $udp2 $null2

set udp3 [new Agent/UDP]

$ns attach-agent $hub $udp3

set null3 [new Agent/Null]

$ns attach-agent $n3 $null3

$ns connect $udp3 $null3

# Start and stop traffic

$ns at 0.5 “$cbr1 start”

$ns at 4.5 “$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

Explanation of the Script:

  • Hub Node: The node hub performs such as a hub, which forwards traffic to all connected nodes.
  • Links: The hub node is connected to n1, n2, and n3 through the duplex links.
  • Traffic:
    • n1 transmits traffic to the hub node.
    • The hub node simulates this traffic to both n2 and n3, replicating a hub’s behaviour of broadcasting incoming packets to all connected devices.
  1. Calculate Hub Performance Metrics

In a hub, the significant performance metrics to assess contain:

  • Traffic broadcast: Make certain that the hub effectively forwards the traffic to all connected nodes.
  • Throughput: Compute the total data successfully sent over the hub.
  • Packet Loss: Measure packet loss by reason of network congestion or buffer overflows at the hub.

Throughput Calculation

To compute the throughput at the hub, we can be observed the number of packets are forwarded to n2 and n3. We can be used the trace file (out.tr) to extract throughput information.

Given below is an AWK script to calculate throughput:

awk ‘

{

if ($1 == “-” && $3 == “hub” && ($4 == “n2” || $4 == “n3”)) {

total_bytes += $6;  # Count total bytes forwarded by hub

}

}

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

This script estimates the throughput in bytes for each second at the hub by adding the bytes forwarded to n2 and n3 during the 5-second simulation.

Packet Loss Calculation

Packet loss happens when the hub is unable to forward the packets because of congestion. We can be computed the packet loss by counting dropped packets.

Here’s an AWK script to calculate packet loss:

awk ‘

{

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

dropped_packets++;

}

}

END { print “Packet Loss at Hub:”, dropped_packets, “packets”; }’ out.tr

This script counts the number of dropped packets at the hub.

  1. Simulate Multiple Hubs

If we require to replicate numerous hubs then we can be made extra hub nodes and setup them similarly. Each hub will perform as a central point for its connected nodes, simulation traffic to those nodes.

  1. Analyse Hub Behaviour

We can be evaluated the performance of the hub by examining:

  • Traffic flow: Make sure that traffic from one node is forwarded to all other connected nodes.
  • Congestion: If the hub experiences congestion then some packets can be dropped because of the buffer overflows.
  • Efficiency: Estimate whether the hub can effectively manage the traffic without dropping packets or introducing excessive delay.

Summary

Although NS2 does not explicitly replicate the Layer 1 hubs, we can simulate the hub behaviour using a central node, which forwards the packets to all connected nodes. To estimate the performance of it replicated hub, we can be assessed:

  • Throughput: Evaluate the total amount of traffic effectively forwarded by the hub.
  • Packet loss: Compute how many packets are dropped by reason of buffer overflow or congestion.

Above method presented the step-by-step guide to support you to replicate and calculate the Network Hubs and analyse the hubs behaviour using the tool NS2. We will provide any details regarding this manual, if needed.