How to Implement Centralized Routing in NS2
To implement the Centralized routing in Network Simulator 2 (ns2), we have to configure a centralized routing authority that measures the routes for all nodes in the network. Unlike distributed routes in which each node solely defines the best route, this routing depends on a central controller (usually means “routing server” or “controller”) to estimate the routes and distribute the routing information to all nodes.
Due to the NS2 is primarily constructed for distributed routing protocols (for instance: AODV, DSR), executing centralized routing needs manual configuration of the routes or altering the NS2 source code to replicate a centralized routing controller.
Below are two ways you can approach the implementation of centralized routing:
Step-by-Step Implementation:
- Predefined Static Routing (Simulating Centralized Control)
In this method, you can manually state the routes for all the nodes in the network. This simulates centralized routing since the routes are predefined and do not vary dynamically.
Example TCL Script for Static Centralized Routing:
# Create the simulator object
set ns [new Simulator]
# Open a trace file to record the simulation
set tracefile [open centralized_trace.tr w]
$ns trace-all $tracefile
# Open a nam file for network animation
set namfile [open centralized_routing.nam w]
$ns namtrace-all $namfile
# Define the finish procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam centralized_routing.nam &
exit 0
}
# Create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
# Define the links between the nodes (bandwidth and delay)
$ns duplex-link $n0 $n1 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 2Mb 10ms DropTail
$ns duplex-link $n3 $n4 2Mb 10ms DropTail
# Manually configure the centralized routing paths (static routing)
# Define routes at node n0 to reach all other nodes
$n0 set rtable [list \
[list 1 $n1] \
[list 2 $n2] \
[list 3 $n3] \
[list 4 $n4]]
# Define routes for other nodes
$n1 set rtable [list \
[list 0 $n0] \
[list 2 $n2] \
[list 3 $n3] \
[list 4 $n4]]
# Repeat the above for all nodes in the network. You are essentially manually defining the centralized routing table.
# Create traffic (UDP agents)
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null0 [new Agent/Null]
$ns attach-agent $n4 $null0
# Connect the UDP agent to the Null agent
$ns connect $udp0 $null0
# Create CBR traffic
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 512
$cbr0 set interval_ 0.1
$cbr0 attach-agent $udp0
# Schedule the start and stop of traffic
$ns at 1.0 “$cbr0 start”
$ns at 5.0 “$cbr0 stop”
# Schedule the end of the simulation
$ns at 10.0 “finish”
# Run the simulation
$ns run
Explanation of the Script:
- Nodes and Links: This script builds a simple 5-node network with duplex links.
- Manual Routing Tables: The routes are manually generated for each node, simulating a centralized routing controller. For instance, the route table for node n0 is manually defined to route packets to n1, n2, n3, and n4. This simulates centralized control since the routing decisions are pre-calculated and loaded into each node.
- Traffic Setup: A UDP agent delivers traffic from node n0 to node n4, with CBR traffic stating the packet size and break.
- Centralized Routing with Custom C++ Implementation
For a more realistic execution of centralized routing, you would need to accomplish a central routing controller in the NS2 C++ source code. Here’s the plan of how you can approach this:
Steps for Centralized Routing in C++:
- Create a Central Controller: Generate a central routing controller by modifying C++ code. This controller should be responsible for calculating the best routes for all the nodes in the network. You can execute the controller as a new module in NS2.
- Gather Network Topology Information: The central controller would aggregate network topology information contains the status of links, bandwidth, delays, and node positions.
- Run a Centralized Routing Algorithm: The controller could execute a centralized routing algorithm like Dijkstra’s algorithm to measure the shortest path for each pair of nodes.
- Distribute Routing Tables: Once the controller assesses the routing tables, it will allocate them to all the nodes in the network. This could be accomplished by fine-tuning each node’s routing table in the simulation.
- Modify Source Code for Routing Decisions: Enforce the central controller to make routing decisions and propagate them to the nodes by adjusting the ~/ns-2.x/route.cc or similar file.
Here’s a high-level overview of what the C++ implementation would involve:
- Create a new class for the centralized controller: Create a class that executes the centralized routing logic.
- Implement routing logic: Estimate the shortest paths amongst all nodes by establishing Dijkstra’s algorithm or another routing algorithm.
- Modify the nodes’ routing tables: Once the controller computes the routes, update the routing tables in all the nodes.
- Running the Simulation
Once you have written the custom C++ code, you need to recompile NS2 with the tuned source code. You can do this by directing to your NS2 installation directory and running:
./configure
make clean
make
You can execute the simulation with your TCL script to see how the centralized routing functions in the network, after the compilation.
- Using Software-Defined Networking (SDN) in NS2
Another technique to replicate centralized routing is by incorporating Software-Defined Networking (SDN) principles, where a central controller makes all the routing decisions. You can use tools like NS3 for SDN-based centralized routing simulation, but if you want to stay inside NS2, you can execute a custom SDN-like central controller.
In this approach, we successfully provided the guide to implement a simple centralized routing protocol in NS2 by predefining the static routing and executing custom C++ class or you can use software-defined Networking. If you need any details regarding this process, we can provide it. ns2project.com team are prepared to provide you with top-notch implementation guidance on Centralized Routing in NS2. Additionally, we have shared excellent research ideas customized to fit your project concepts.