How to Start Bus Topology Projects Using NS2

To start a Bus Topology using NS2 (Network Simulator 2), we will want to make a single shared interaction channel in which several nodes are interact. This kind of topology is generally used in LANs and it is best model to learn the behaviour of network within shared mediums.

Below is a detailed procedure to get started Bus Topology project in NS2:

Steps to Start Bus Topology Projects in NS2

  1. Understand Bus Topology
  • Topology Structure:
    • Every node is associated to a single interaction line in shared medium.
    • Data moves in both directions near to the bus topology, and nodes pay attention to packets that are directed to them.
  • Applications:
    • It helps to replicate the Ethernet-like situations.
    • Appropriate to identify collision and manage the studies.
  1. Set Up NS2
  1. Install NS2: We should set up NS2 on the system properly.

sudo apt-get install ns2

  1. Verify Installation: Confirm installation with an example simulation script:

ns example.tcl

  1. Define Bus Topology

In a bus topology:

  • Nodes are linked to a single shared link.
  • A hub or switch can replicate the shared medium using NS2.

Example Bus Topology:

  • Nodes: n0, n1, n2, n3…
  • Shared Link: It is replicated by broadcast model.
  1. TCL Script for Bus Topology

Below is an instance TCL script for simulating Bus Topology:

Bus Topology TCL Script

# Initialize NS2 Simulator

set ns [new Simulator]

set tracefile [open bus_topology.tr w]

$ns trace-all $tracefile

# Define nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

# Create a shared link (Bus)

set bus [$ns make-broadcast-link 1Mb 10ms]

# Attach nodes to the shared bus

$ns attach-node-to-bus $n0 $bus

$ns attach-node-to-bus $n1 $bus

$ns attach-node-to-bus $n2 $bus

$ns attach-node-to-bus $n3 $bus

# Attach agents

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 udp1 [new Agent/UDP]

$ns attach-agent $n2 $udp1

set null1 [new Agent/Null]

$ns attach-agent $n3 $null1

$ns connect $udp1 $null1

# Traffic generation

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set interval_ 0.1

$cbr0 attach-agent $udp0

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packetSize_ 512

$cbr1 set interval_ 0.2

$cbr1 attach-agent $udp1

# Start traffic

$ns at 1.0 “$cbr0 start”

$ns at 2.0 “$cbr1 start”

# End simulation

$ns at 5.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

$ns run

  1. Key Features to Simulate
  • Broadcast Traffic: Make sure that all nodes may obtain packets which are transmitted traffic on the shared link.
  • Collision Detection: Mimic and estimate the impacts of packet collisions.
  • Throughput and Latency: Examine how shared interaction impacts the performance.
  1. Analyze Trace File
  • We can utilise trace file (bus_topology.tr) that includes specifics of packet transmissions and receptions.
  • Obtain certain data to leverage the filters:
    • Broadcast packets:

grep “Bcast” bus_topology.tr > broadcast_packets.log

    • Dropped packets:

grep “drop” bus_topology.tr > dropped_packets.log

  1. Visualize Results

Envision the performance outcomes to utilize Gnuplot tools:

  1. Throughput over time:

set title “Bus Topology Throughput”

plot “throughput.log” using 1:2 with lines title “Throughput”

  1. Collision Analysis: Design packet collisions depend on the function of time.
  1. Extend the Simulation
  2. Simulate CSMA/CD (Collision Detection)

Execute the Carrier Sense Multiple Access including Collision Detection (CSMA/CD) for bus topology:

  • Before sending, nodes detect the medium.
  • Resend the packets if collisions exist.
  1. Analyze Performance
  • Integrate additional nodes and examine the influence over:
    • Throughput: Estimate the bandwidth utilization.
    • Delay: Measure latency within shared medium.
  1. Integrate Network Protocols
  • Observe the behavior within bus topologies with the support of TCP or custom protocols.
  1. Optional: Modify NS2 Core

For further simulations, we can:

  1. C++ Code for Collision Handling: Fine-tune recv() for replicating the collisions within shared links.

void BusLink::recv(Packet* p) {

if (isCollision(p)) {

drop(p);

} else {

forward(p);

}

}

  1. Custom Protocols: Execute a custom agent for certain bus topology tests.

Tools and Resources

  • Wireshark: Examine the traffic that is generated in the course of the simulation leveraging the tools like Wireshark.
  • Gnuplot: Envision the performance parameters to utilise Gnuplot.
  • NS2 Documentation: Recommendation to prolong the functionality of NS2.

Enhancements

  • Replicate real-world situations such as:
    • Ethernet Networks: Design CSMA/CD-based interaction.
    • IoT Applications: For resource-constrained networks, we will need to utilize bus topology.

Finally, we had successfully delivered the significant procedures to simulate and analyse the Bus topology Projects and visualize its outcomes using NS2 simulation tool also we deliver the sample snippets. More information will be shared about this process in upcoming manual.