To simulate Global Routing projects utilizing NS2, we can leverage the built-in Global Routing Protocol obtainable within NS2 that calculates the routes according to the static, centralized view of the network. Global routing is frequently utilized within network simulations in which routes are predetermined and do not modify for the period of the simulation.
Following is a step-by-step instruction to simulate global routing using NS2.
Steps to Simulate Global Routing in NS2
- Set Up NS2 Environment
Make certain that NS2 is installed and running on the machine. We can check this by running:
ns
If NS2 is installed appropriately then this command will open the NS2 shell.
- Understanding Global Routing
In Global Routing, a centralized controller (or global knowledge) calculates the optimal routes for every node at the beginning of the simulation. Routes are usually static and do not modify during the simulation if not explicitly changed. Global routing offers an overall view of the network topology and creates routing decisions rely on that view.
- Write a TCL Script for Global Routing
Following is an instance TCL script to configure a network using Global Routing.
# Create a simulator object
set ns [new Simulator]
# Open trace and NAM output files
set tracefile [open out.tr w]
set namfile [open out.nam w]
$ns trace-all $tracefile
$ns namtrace-all $namfile
# Define network topology
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
# Create links between nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 512Kb 20ms DropTail
$ns duplex-link $n3 $n4 1Mb 15ms DropTail
$ns duplex-link $n4 $n0 1Mb 20ms DropTail
# Enable global routing
$ns rtproto Static
# Create a UDP agent and attach it to node n0 (source)
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a Null agent and attach it to node n4 (destination)
set null0 [new Agent/Null]
$ns attach-agent $n4 $null0
# Connect the source (n0) to the destination (n4)
$ns connect $udp0 $null0
# Create a CBR traffic generator and attach it to the UDP agent
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 512
$cbr0 set interval_ 0.01
$cbr0 attach-agent $udp0
# Schedule the traffic to start and stop
$ns at 1.0 “$cbr0 start”
$ns at 4.5 “$cbr0 stop”
$ns at 5.0 “finish”
# Define the finish procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
# Run the simulation
$ns run
- Explanation of the Script
- Global Routing: The command $ns rtproto Static allows global routing. This makes sure that routing decisions are calculated centrally at begin of the simulation rely on a static view of the network topology.
- Network Topology: The simulation describes five nodes connected within a loop. Each link has certain bandwidth and delay parameters that replicating diverse network link conditions.
- Traffic: A Constant Bit Rate (CBR) traffic generator is made on node n0 and transmits traffic to node n4.
- Running the Simulation
We can save the TCL script as global_routing.tcl and then execute it in the terminal:
ns global_routing.tcl
It will generate two output files:
- Trace File (out.tr): Includes packet transmissions and routing decisions.
- NAM File (out.nam): Can be utilized to envision the network and traffic.
- Visualizing the Simulation
To envision the simulation using NAM, execute:
nam out.nam
We will observe how the packets are routed from the source (n0) to the destination (n4) utilizing the global routing decisions calculated at the start of the simulation.
- Modifying the Script for Dynamic Changes
Even though global routing is normally static, we can replicate dynamic behaviour by manually modifying routes in the course of the simulation. For instance, if we require replicating a change in the route at a particular time then we can change the route utilizing the rtmodel command:
# Change the route dynamically at 3.0 seconds
$ns at 3.0 “$n1 add-route-to-destination $n4 2” ;# Change route to use an alternative path
It permits to simulate a few dynamic routing changes in the global routing context.
- Analyzing the Trace File
The trace file (out.tr) includes detailed data regarding packet transmissions, routing decisions, and traffic flow. We can be used grep or awk to extract parameters like:
- Packet Delivery Ratio (PDR): The percentage of efficiently delivered packets.
- Latency: The time taken for packets to travel from origin to destination.
- Throughput: The amount of data effectively sent over the network.
For instance, to calculate the number of packets received at the destination:
grep “^r” out.tr | wc -l
- Performance Evaluation
Estimate the performance of global routing by:
- Scaling the network: Maximizes the amount of nodes and links to replicate larger network topologies.
- Varying link conditions: Modify the bandwidth, delay, or packet drop rates to replicate diverse network conditions.
- Testing traffic load: Alter the traffic generation to maximize or minimize the load and monitor how global routing executes.
The simulation and analysis of the Global Routing Projects were done that computes the routes according to the static, with the help of above simplified approach with related example coding using NS2 simulation environment. Likewise, we will also be delivered more specific insights regarding this topic based on your request.
We are the ideal team to assist you with your Global Routing Protocol needs. If you require expert help, please reach out to us at phdprime.com. We are committed to guiding you through every stage of your project, ensuring the best outcomes for your Global Routing Projects using NS2.