How to Implement Extended Bus Topology in NS2

To implement the Extended Bus Topology in Network Simulator 2 (ns2), we have to configure a simulation with nodes that are linked to a common interactive medium or bus. In this topology, extra bus fragment are connected through repeaters or hubs to enable more nodes to be part of the network however not degrading the performance. It is alike to hierarchical or segmented bus, but with repeaters or hubs expanding the entire bus. Follow the below instructions to implement the extended bus topology in ns2:

Steps to Implement Extended Bus Topology in NS2

  1. Set Up NS2

Make certain that you have NS2 installed on your system. If not, install it using the following command:

sudo apt-get update

sudo apt-get install ns2

  1. Understanding the Extended Bus Topology

In an extended bus topology:

  • Nodes are linked to a common bus.
  • Extra bus segments are linked using repeaters or hubs, which serve to extend the bus and link more nodes.
  • Communication amongst nodes on various segments of the bus happens through the repeaters/hubs.
  1. Create a TCL Script for Extended Bus Topology

Follow the sample TCL script to execute an Extended Bus Topology. In this instance, nodes are connected to two bus segments, and the segments are connected via a central hub.

Example TCL Script for Extended Bus Topology:

# Define the simulator

set ns [new Simulator]

# Open trace files

set tracefile [open extended_bus_out.tr w]

set namfile [open extended_bus_out.nam w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Create a topography object

set topo [new Topography]

$topo load_flatgrid 500 500

# Create a channel for wired links (bus segments)

set chan [new Channel/WiredChannel]

# Define a hub/repeater to extend the bus

set hub [$ns node]

# Define nodes for the first bus segment connected to hub

set node_0 [$ns node]

set node_1 [$ns node]

set node_2 [$ns node]

# Define nodes for the second bus segment connected to hub

set node_3 [$ns node]

set node_4 [$ns node]

set node_5 [$ns node]

# Position the hub and nodes for visualization in NAM

$hub set X_ 300.0

$hub set Y_ 250.0

# Position the nodes for the first bus segment

$node_0 set X_ 100.0

$node_0 set Y_ 200.0

$node_1 set X_ 150.0

$node_1 set Y_ 200.0

$node_2 set X_ 200.0

$node_2 set Y_ 200.0

# Position the nodes for the second bus segment

$node_3 set X_ 400.0

$node_3 set Y_ 200.0

$node_4 set X_ 450.0

$node_4 set Y_ 200.0

$node_5 set X_ 500.0

$node_5 set Y_ 200.0

# Connect nodes in the first bus segment to the hub

$ns duplex-link $node_0 $hub 100Mb 10ms DropTail

$ns duplex-link $node_1 $hub 100Mb 10ms DropTail

$ns duplex-link $node_2 $hub 100Mb 10ms DropTail

# Connect nodes in the second bus segment to the hub

$ns duplex-link $node_3 $hub 100Mb 10ms DropTail

$ns duplex-link $node_4 $hub 100Mb 10ms DropTail

$ns duplex-link $node_5 $hub 100Mb 10ms DropTail

# Setup traffic flow between nodes on different bus segments

# Traffic from node_0 (first bus segment) to node_4 (second bus segment)

set udp0 [new Agent/UDP]

set null0 [new Agent/Null]

$ns attach-agent $node_0 $udp0

$ns attach-agent $node_4 $null0

$ns connect $udp0 $null0

# Create CBR (Constant Bit Rate) traffic

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set interval_ 0.05

$cbr0 attach-agent $udp0

# Start traffic at time 1.0 second

$ns at 1.0 “$cbr0 start”

# Schedule simulation end

$ns at 10.0 “finish”

# Finish procedure to close the simulation

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam extended_bus_out.nam &

exit 0

}

# Run the simulation

$ns run

Explanation of the Script:

  1. Extended Bus with Hub/Repeater:
    • A central hub (hub) serves as the repeater that links two bus segments.
    • The first bus segment has node_0, node_1, and node_2, all of which are connected to the hub.
    • The second bus segment contains node_3, node_4, and node_5, also connected to the hub.
  2. Node Positioning:
    • Nodes are located in a linear fashion (representing a bus) with positions stated using set X_ and set Y_ for visual indication in NAM.
  3. Duplex Links:
    • All nodes in both bus segments are connected to the central hub with duplex links. These links signify the connections amongst the nodes and the bus. Each link has a bandwidth of 100Mb and a delay of 10ms.
  4. Traffic Setup:
    • Traffic is produced from node_0 (on the first bus segment) to node_4 (on the second bus segment). The UDP agent delivers traffic, and use CBR (Constant Bit Rate) application to design packets.
  5. Trace and NAM Visualization:
    • The script builds trace files (extended_bus_out.tr) and a NAM file (extended_bus_out.nam) that can be visualized using NAM (Network Animator).
  1. Run the Simulation

Store the script , for instance: extended_bus_topology.tcl and execute it in NS2:

ns extended_bus_topology.tcl

To view the network using NAM, use:

nam extended_bus_out.nam

Customization:

  1. Adding More Bus Segments:
    • You can attach additional bus segments by stating more hubs or repeaters and linking them to additional nodes. This will extend the bus topology further.
  2. Multiple Repeaters:
    • If you want more bus segments, build a multi-level bus structure by including more hubs. For instance, a third segment could be attached with another repeater linking it to the existing bus.
  3. Traffic Flows:
    • Include additional traffic flows between different nodes on the extended bus by configuring more agents and applications. For instance, you could set up traffic between node_1 and node_5.
  4. Link Parameters:
    • Modify the bandwidth and delay of the links amongst nodes and the hub to replicate various network conditions.

The given procedure will guide you to learn regarding how to set up the simplified network simulation and how to define the tcl script for the accomplishment of Extended Bus Topology using ns2 tool. If you need any details of this manual, we will provide it through another report.

For implementation support of Extended Bus Topology in NS2, you can connect with ns2project.com for expert guidance. We offer topic assistance to ensure your projects are completed on schedule by our skilled developers.