How to Implement Bus Topology in NS2

 

To implement the bus topology in Network Simulator 2 (NS2), we have to develop a network where each node shares an individual communication channel, alike to a realistic network. In this topology, all nodes are linked to a one central cable (“bus”) and interaction from one node is broadcast to all other nodes. Yet, ns2 mainly simulates point-to-point links, so we have to replicate the bus topology with the help of shared link including broadcast medium or shared duplex links. You can get to implement the bus topology in ns2 by following the below steps:

Steps to Simulate a Bus Topology in NS2:

  1. Define the Network Topology:
    • You can use a hub-and-spoke style of link connections where all nodes link to a central hub or switch to mimic the shared communication medium in a bus topology.
  2. Simulate a Shared Medium:
    • Rather than using separate point-to-point links, you replicate a bus topology by building multiple duplex links amongst all the nodes and a single “hub” node. This hub node indicates the shared bus in the topology.
  3. Simulate Broadcast Communication:
    • Any communication from one node can be broadcast to all other nodes via the hub.

Example of Bus Topology Implementation in NS2 (Hub-Based):

# Create a new simulator

set ns [new Simulator]

# Open the trace file for output

set tracefile [open out.tr w]

$ns trace-all $tracefile

# Define nodes in the network (4 nodes for simplicity)

set n0 [$ns node]  ;# Node 0

set n1 [$ns node]  ;# Node 1

set n2 [$ns node]  ;# Node 2

set n3 [$ns node]  ;# Node 3

set hub [$ns node] ;# The hub representing the shared bus

# Create duplex links between nodes and the central hub (simulating the bus)

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

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

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

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

# Set up TCP agents and sinks for node-to-node communication

set tcp0 [new Agent/TCP]

set sink0 [new Agent/TCPSink]

$ns attach-agent $n0 $tcp0

$ns attach-agent $n1 $sink0

$ns connect $tcp0 $sink0

# Simulate traffic from node 0 to node 1

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ns at 1.0 “$ftp0 start”

# Repeat the process for communication between other nodes

set tcp1 [new Agent/TCP]

set sink1 [new Agent/TCPSink]

$ns attach-agent $n2 $tcp1

$ns attach-agent $n3 $sink1

$ns connect $tcp1 $sink1

# Simulate traffic from node 2 to node 3

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ns at 2.0 “$ftp1 start”

# Schedule simulation end after 10 seconds

$ns at 10.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run the simulation

$ns run

Explanation of the Script:

  1. Nodes:
    • n0, n1, n2, n3 represent four network nodes that are part of the bus topology.
    • hub indicates the common bus, which is a central node that replicates the shared communication medium of a bus topology.
  2. Links:
    • Each node is linked to the hub using duplex links with 1 Mb bandwidth and a 10 ms delay.
    • This configuration simulates a shared bus topology where all nodes share the same communication medium (signified by the hub).
  3. Traffic Simulation:
    • TCP agents are added to simulate communication amongst the nodes. For instance, n0 sends traffic to n1, and n2 sends traffic to n3.
    • FTP traffic is produced to simulate file exchange amongst nodes.
  4. Simulation End:
    • The simulation executes for 10 seconds and then stops, permitting you to assess the traffic flows and performance metrics.

Post-Simulation Analysis:

  1. Trace File Analysis:
    • Once the simulation is done, compute the trace file (out.tr) to monitor the communication amongst nodes as well as the traffic flows through the hub that replicates the shared bus medium.
  2. NAM Visualization:
    • Visualize the bus topology by using NAM (Network Animator). You can monitor how all communication passes through the hub, replicating the shared nature of a bus topology.
  3. Performance Metrics:
    • Compute metrics like delay, throughput, and packet loss to evaluate how effectively the bus topology functions in this simulation.

Enhancing the Simulation:

  1. Collision Simulation:
    • You can launch traffic from several nodes to the hub instantaneously to simulate network collisions, which are typical in bus topologies without proper collision identification mechanisms.
  2. Broadcast Traffic:
    • Fine-tune the script to simulate broadcast communication where one node sends a message, and all other nodes receive it, simulating a true bus-like broadcast activities.
  3. Increasing Node Count:
    • Simulate a bigger bus topology with more communication traffic over a shared medium by attaching more nodes to the network.
  4. Dynamic Traffic Patterns:
    • Research with various traffic patterns and protocols (such as UDP rather than TCP) to monitor how they works in a bus topology.

In this demonstration, we helped you to know more about how to implement the bus topology using ns2 simulation and how to enhance the simulation network and how to analyse it to visualize. If you need any extra details of bus or any other topologies, we will provide them.

Our team specializes in projects involving Bus Topology within the NS2 tool. For those seeking customized research solutions, we invite you to visit ns2project.com for personalized support. By collaborating with us, you can expect high-quality implementation outcomes, along with comprehensive comparative analysis results.