How to Implement Mixed Topology in NS2

To implement the mixed topology in Network Simulator 2 (ns2), we have to develop a network that contains various kinds of topologies includes a integration of star, ring and bus topologies inside a single simulation. The below guide have the necessary details of mixed topology’s implementation in ns2:

Step-by-Step Implementation:

  1. Install ns2:

Make certain that you have installed and configured the ns2 properly on your computer.

  1. Create a TCL Script:

Configure the network simulation by using tcl (Tool Command Language) in ns2. You will design a TCL script to define the mixed topology.

  1. Define Network Nodes:

First, set up the network nodes in the TCL script. Each node indicates a network device.

set ns [new Simulator]

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

  1. Create Links:

Build links amongst nodes to create several topologies. For example:

  • Star Topology: One central node linked to numerous peripheral nodes.

set star_central [$ns node]

for {set i 0} {$i < 3} {incr i} {

set star_node[$i] [$ns node]

$ns duplex-link $star_central $star_node[$i] 1Mb 10ms DropTail

}

  • Ring Topology: Nodes connected in a circular fashion.

set n4 [$ns node]

set n5 [$ns node]

set n6 [$ns node]

 

$ns duplex-link $n4 $n5 1Mb 10ms DropTail

$ns duplex-link $n5 $n6 1Mb 10ms DropTail

$ns duplex-link $n6 $n4 1Mb 10ms DropTail

  • Bus Topology: Nodes linked to a common backbone.

set backbone [$ns node]

$ns duplex-link $backbone $n7 1Mb 10ms DropTail

$ns duplex-link $backbone $n8 1Mb 10ms DropTail

$ns duplex-link $backbone $n9 1Mb 10ms DropTail

  1. Interconnect Different Topologies:

You can interconnect various topologies to build a mixed topology network.

$ns duplex-link $star_central $n4 1Mb 10ms DropTail

$ns duplex-link $backbone $star_central 1Mb 10ms DropTail

  1. Define Traffic Sources and Sinks:

Simulate network traffic amongst nodes by stating the traffic sources.

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set null0 [new Agent/Null]

$ns attach-agent $n9 $null0

$ns connect $udp0 $null0

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 1000

$cbr0 set interval_ 0.005

  1. Start and Stop Simulation:

Determine the start and end times for the simulation.

$ns at 0.0 “$cbr0 start”

$ns at 4.5 “$cbr0 stop”

$ns at 5.0 “finish”

  1. Run the Simulation:

Store the TCL script and execute it using ns2.

ns mixed_topology.tcl

  1. Analyze Results:

In ns2, visualize the simulation or evaluate the outcomes trace file created by using NAM (Network Animator).

Example TCL Script:

Here’s a basic example of what a mixed topology might look like:

set ns [new Simulator]

# Nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

set n6 [$ns node]

set n7 [$ns node]

set n8 [$ns node]

set n9 [$ns node]

# Links (Star Topology)

set star_central [$ns node]

for {set i 0} {$i < 3} {incr i} {

set star_node[$i] [$ns node]

$ns duplex-link $star_central $star_node[$i] 1Mb 10ms DropTail

}

# Links (Ring Topology)

$ns duplex-link $n4 $n5 1Mb 10ms DropTail

$ns duplex-link $n5 $n6 1Mb 10ms DropTail

$ns duplex-link $n6 $n4 1Mb 10ms DropTail

# Links (Bus Topology)

set backbone [$ns node]

$ns duplex-link $backbone $n7 1Mb 10ms DropTail

$ns duplex-link $backbone $n8 1Mb 10ms DropTail

$ns duplex-link $backbone $n9 1Mb 10ms DropTail

# Interconnect topologies

$ns duplex-link $star_central $n4 1Mb 10ms DropTail

$ns duplex-link $backbone $star_central 1Mb 10ms DropTail

# Traffic sources

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set null0 [new Agent/Null]

$ns attach-agent $n9 $null0

$ns connect $udp0 $null0

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 1000

$cbr0 set interval_ 0.005

# Simulation time

$ns at 0.0 “$cbr0 start”

$ns at 4.5 “$cbr0 stop”

$ns at 5.0 “finish”

# Execute the simulation

$ns run

Through this manual, we have provided the step-by-step approach on how to implement the mixed topology in ns2 which is nothing but a incorporation of several other topologies like star, bus, ring and so on. We were also offered some samples with snippet codes for your references.

We are here to enhance your experience with Mixed Topology in NS2 implementation. Our expert team offers top-notch topic assistance tailored to your needs. For the best guidance on simulations related to your projects, reach out to ns2project.com today.