To simulate Centralized Routing using NS2, we want executing a routing mechanism in which a central controller creates routing decisions for all nodes within the network. Unlike distributed routing protocols (e.g., distance-vector or link-state) that centralized routing encompasses accumulating global network information at a central entity that then find out and distributes the optimal routing paths to the network nodes.
Here’s a general strategy on how to simulate centralized routing using NS2.
Steps to Simulate Centralized Routing in NS2
- Set Up NS2 Environment
Make certain NS2 is installed and working on the system. We can verify this by running:
ns
If NS2 is installed then this command will begin the NS2 shell.
- Understanding Centralized Routing
In Centralized Routing, all nodes transmit their topology or traffic information to a central controller that calculates the optimal paths and transmits back the routing data to each node. It is normal in software-defined networks (SDN) in which a central controller chooses routing paths depends on a global view of the network.
- Simulating Centralized Routing
NS2 does not directly support centralized routing protocols, as it mostly deals with distributed routing algorithms. But, we can be mimicked centralized routing by controlling routing tables manually within the TCL script, or by making a custom central controller, which computes the paths and updates the routes consequently.
- Writing a TCL Script for Centralized Routing
Below is an example TCL script in which routing decisions are centralized and manually set up for all nodes.
# 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 with six 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]
# Create links between nodes (with different delays)
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n0 $n2 1Mb 15ms DropTail
$ns duplex-link $n1 $n3 1Mb 20ms DropTail
$ns duplex-link $n2 $n3 1Mb 25ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
$ns duplex-link $n3 $n5 1Mb 15ms DropTail
# Define static routing (centralized routing)
# Manually configure the routes (simulating centralized decision-making)
$n0 add-route-to-destination $n4 1 ;# Route via n1 and n3
$n1 add-route-to-destination $n4 1 ;# Route via n3
$n3 add-route-to-destination $n4 1 ;# Direct link to n4
$n2 add-route-to-destination $n4 1 ;# Route via n3
$n5 add-route-to-destination $n4 1 ;# Direct link to n4
# Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a Null agent and attach it to node n4
set null4 [new Agent/Null]
$ns attach-agent $n4 $null4
# Connect the source and destination agents
$ns connect $udp0 $null4
# 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.005
$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
- Centralized Routing: The routes are manually set up utilizing add-route-to-destination, which replicating a central controller creating routing decisions and pushing the routes to the nodes. Each node is explicitly expressed how to attain the destination.
- Network Topology: Six nodes are related with duplex links, with distinct delays that signifying link weights.
- Traffic: A Constant Bit Rate (CBR) traffic generator is connected to the UDP agent on n0 that transmitting traffic to n4.
- Running the Simulation
We can save the TCL script as centralized_routing.tcl and execute it with the below command:
ns centralized_routing.tcl
It will generate two output files:
- Trace File (out.tr): Includes all events relevant to packet transmission, routing decisions, and so on.
- NAM File (out.nam): Can be utilized to envision the network and routing behaviour.
- Visualizing the Simulation
To envision the simulation, open the NAM file:
nam out.nam
The NAM visualization will indicate how packets are routed according to the centralized routing decisions.
- Simulating Dynamic Routing Changes
If we need to replicate a central controller dynamically updating routes (as in SDN) then we can manually modify routes for the period of the simulation using rtmodel commands. For instance:
# Change the route dynamically at 3.0 seconds
$ns at 3.0 “$n0 add-route-to-destination $n4 2” ;# Change route via n2
This replicates a central controller, which updates the routing tables actively in the course of the simulation.
- Analysing the Trace File
The trace file (out.tr) includes detailed data regarding the packet transmissions and routing decisions. We can examine the trace file to assess key parameters like:
- Packet Delivery Ratio (PDR): The percentage of effectively delivered packets.
- Latency: The time it takes for packets to travel from the origin to the destination.
- Routing Overhead: Because routing is centrally handled, routing overhead will be minimal in this simulation.
We can utilize grep or awk to investigate the trace file. For sample, to calculate the amount of packets received:
grep “^r” out.tr | wc -l
- Performance Evaluation
Estimate the performance of centralized routing by:
- Scalability: Experiment how centralized routing performs as maximizes the amount of nodes.
- Dynamic Updates: Replicate dynamic route changes to observe how the network responds to new routing decisions.
- Traffic Load: Change the traffic load to experiment the effectiveness of centralized routing under heavy network load.
We carried out in-depth simulation approach and detailed evaluation of the Centralized Routing Projects using NS2 virtual environment and we are prepared to extend the findings with more information on this projects if necessary.
If you need help with any kind of simulation, just send us the details of your project, and we’ll provide you with the best results. For network analysis evaluations, keep in contact with us, and we’ll give you a thorough explanation.