To simulate a Token Ring Topology using NS2 that includes making a network in which nodes are associated within a circular set up and communication is managed by a token-passing mechanism. In a Token Ring network, only the node that possesses the token can transmit data, we make sure that single node sends at a time, minimizing collisions in the network.
The network simulator NS2 doesn’t directly support the token-passing mechanism creatively, however we can replicate the behavior by managing which nodes are permitted to transmit data that replicating the possession of the token.
Here’s a simple approach on how to replicate a Token Ring Topology project using NS2:
Steps to Simulate Token Ring Topology Projects in NS2
- Set up NS2 Environment:
Make sure NS2 is installed and set up on the machine. Because Token Ring uses a circular connection of nodes, we will be mimicked it by making a ring topology of nodes and manage when each node can transmit the data.
- Understanding Token Ring Topology:
- In a Token Ring Topology, all nodes are associated within a circular fashion in which each node is related to two neighbors.
- A token circulates all over the ring. Simply the node with the token is permitted to send data. After transmission then the token is passed to the following node within the ring.
- This technique make sure collision-free communication however launches more delay because of token passing.
- Create a TCL Script for Token Ring Topology:
Following is a TCL script to replicate a Token Ring Topology including 4 nodes with the help of NS2. The nodes are related within a ring, and we manually manage the timing of packet transmissions to replicate the token possession.
Token Ring Topology Simulation
# Create a new simulator instance
set ns [new Simulator]
# Open a NAM trace file for visualization
set nf [open out.nam w]
$ns namtrace-all $nf
# ======= Token Ring Topology =======
# Create 4 nodes for the token ring topology
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
# Create duplex links between the nodes to form a ring
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns duplex-link $n1 $n2 10Mb 10ms DropTail
$ns duplex-link $n2 $n3 10Mb 10ms DropTail
$ns duplex-link $n3 $n0 10Mb 10ms DropTail ;# Complete the ring
# ======= Simulating Token Passing =======
# Attach UDP agents to the nodes, but control when they can send packets (simulate token passing)
# Attach UDP agents for nodes
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
set udp2 [new Agent/UDP]
$ns attach-agent $n2 $udp2
set udp3 [new Agent/UDP]
$ns attach-agent $n3 $udp3
# Attach Null agents (traffic sinks) for receiving packets
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
set null1 [new Agent/Null]
$ns attach-agent $n2 $null1
set null2 [new Agent/Null]
$ns attach-agent $n3 $null2
set null3 [new Agent/Null]
$ns attach-agent $n0 $null3
# ======= Simulate Token Passing Control =======
# Connect the UDP agents to Null agents and schedule traffic to simulate token passing
$ns connect $udp0 $null0
$ns connect $udp1 $null1
$ns connect $udp2 $null2
$ns connect $udp3 $null3
# Create CBR traffic generators and attach them to UDP agents, but control when they start (token passing)
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 512
$cbr0 set rate_ 100Kb
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetSize_ 512
$cbr1 set rate_ 100Kb
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $udp2
$cbr2 set packetSize_ 512
$cbr2 set rate_ 100Kb
set cbr3 [new Application/Traffic/CBR]
$cbr3 attach-agent $udp3
$cbr3 set packetSize_ 512
$cbr3 set rate_ 100Kb
# Simulate token passing by controlling when each node can send traffic
# Only one node sends traffic at a time (imitating token possession)
# Token held by node 0, starts sending at 1 second
$ns at 1.0 “$cbr0 start”
$ns at 2.0 “$cbr0 stop”
# Token passed to node 1, starts sending at 2.5 seconds
$ns at 2.5 “$cbr1 start”
$ns at 3.5 “$cbr1 stop”
# Token passed to node 2, starts sending at 4.0 seconds
$ns at 4.0 “$cbr2 start”
$ns at 5.0 “$cbr2 stop”
# Token passed to node 3, starts sending at 5.5 seconds
$ns at 5.5 “$cbr3 start”
$ns at 6.5 “$cbr3 stop”
# End the simulation at 7.0 seconds
$ns at 7.0 “finish”
# Procedure to end the simulation
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
# Run the simulation
$ns run
- Explanation of the Code:
- Nodes: Four nodes (n0, n1, n2, and n3) are made that denoting the devices within the Token Ring network.
- Ring Links: Duplex links are made among each pair of consecutive nodes, which forming a ring. The last link attaches node n3 back to node n0 to finish the ring.
- UDP Agents: Each node has a UDP agent connected for transmitting the packets and a Null agent connected to receive packets.
- Traffic Generation: Constant Bit Rate (CBR) traffic generators are connected to the UDP agents. Unique node transmits the data at a time that replicating the token possession.
- Token Passing Simulation: The script mimics token passing by managing the beginning and ending times of traffic for each node. For example, node n0 begins transmitting the data at 1.0 seconds and ends at 2.0 seconds. The token is delivered to the node n1 that begins transmitting at 2.5 seconds, etc.,
- Simulation End: The simulation ends at 7.0 seconds, and for visualization the outcomes are saved in a .nam file.
- Run the Simulation:
- We need to save the script as token_ring_topology.tcl.
- We can open a terminal and traverse to the folder in which the script is saved.
- Execute the simulation using:
ns token_ring_topology.tcl
- The simulation will make an out.nam file, which can be opened utilizing the Network Animator (NAM) for visualization.
- Visualization in NAM:
- We can open the out.nam file within NAM to envision the token ring topology. We will observe four nodes are attached in a ring, including data being transmitted one node at a time in a controlled sequence, which simulating the behavior of token passing.
- Customization and Enhancements:
- Increase the Number of Nodes: We can maximize the amount of nodes by appending more nodes and changing the token-passing sequence. Just insert additional nodes and change the link connections and traffic schedules.
- Token Delay: We can replicate the delay in token send by inserting small gaps among the stop and start times of diverse nodes’ transmissions.
- TCP Traffic: We can substitute the UDP agents with TCP agents if we need to replicate the reliable communication within the token ring network:
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n1 $sink0
$ns connect $tcp0 $sink0
- Performance Metrics: We can insert trace files to estimate the performance parameters like throughput, delay, and packet loss:
set tracefile [open trace.tr w]
$ns trace-all $tracefile
- Performance Analysis:
To investigate the performance of the Token Ring topology, we can:
- Assess throughput to find out how much data is efficiently sent in the token-holding period.
- Calculate latency to observe how long data takes to attain its destination once a token is sent among the nodes.
- Examine packet loss if we replicate the situations in which the network may be congested or the links are changeable.
We had given the step-by-step demonstration on how to simulate the Token Ring Topology projects and how to analyse their performance using NS2 simulation tool that has simulation process with sample coding. You will get any details about this manual in the future from us.
To simulate a Token Ring Topology Projects Using NS2, we share step by step instruction, get tailored research help from phdprime.com team.