How to Implement On Internal Protocols in NS2
To implement an internal routing protocols with in NS2 simulator that normally refers to setup the network to use and Interior Gateway Protocol (IGP), like OSPF (Open Shortest Path First), RIP (Routing Information Protocol), or EIGRP (Enhanced Interior Gateway Routing Protocol). These protocols are used in a unique autonomous system (AS) to route traffic.
The simulation tool NS2 doesn’t have direct support for the furthered interior protocols such as OSPF or EIGRP out of the box. However it does support the easier protocols like RIP. Given below is a simplest procedure that helps to set up a simple simulation using the RIP, as an instance of this protocol.
Step-by-Step Guide to Implement Internal Protocols in NS2
Step 1: Install NS2
Make sure that NS2 is installed on the system. Then, download it from the NS2 webpage and we follow the installation instructions particular to the operating system.
Step 2: Choose an Interior Protocol
As NS2 supports RIP as a built-in protocol, we can use it to mimic internal routing in a network.
Step 3: Create a Simulation Script
To make a Tcl script to set up the network and mimic routing using the selected interior protocol.
Example: Implementing RIP in NS2
- Create a new Tcl script: Open a text editor and make a new file, for instance, rip_example.tcl.
- Set up the simulation environment: Describe the simulator, set up the network topology, and configure the metrics particular to the simulation.
# Create a simulator object
set ns [new Simulator]
# Define options for the simulation
set val(chan) Channel/WirelessChannel ;# Channel type
set val(prop) Propagation/TwoRayGround ;# Propagation model
set val(netif) Phy/WirelessPhy ;# Network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# Interface Queue type
set val(ll) LL ;# Link layer type
set val(ant) Antenna/OmniAntenna ;# Antenna type
set val(ifqlen) 50 ;# Max packet in ifq
set val(nn) 5 ;# Number of nodes
set val(rp) RIP ;# Routing Protocol (RIP)
set val(x) 500 ;# X dimension of topography
set val(y) 500 ;# Y dimension of topography
set val(stop) 10.0 ;# Simulation time
# Initialize the topology object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# Create the God object
create-god $val(nn)
# Configure the nodes
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
# Create nodes
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns node]
$node_($i) random-motion 0
}
# Define node movement (Optional for mobile nodes)
$node_(0) set X_ 50.0
$node_(0) set Y_ 50.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 150.0
$node_(1) set Y_ 100.0
$node_(1) set Z_ 0.0
$node_(2) set X_ 250.0
$node_(2) set Y_ 150.0
$node_(2) set Z_ 0.0
$node_(3) set X_ 350.0
$node_(3) set Y_ 200.0
$node_(3) set Z_ 0.0
$node_(4) set X_ 450.0
$node_(4) set Y_ 250.0
$node_(4) set Z_ 0.0
- Setup traffic sources:
# Setup a UDP agent and attach it to node 0
set udp [new Agent/UDP]
$ns attach-agent $node_(0) $udp
# Setup CBR (Constant Bit Rate) application to generate traffic
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 512
$cbr set interval_ 0.1
$cbr start
# Setup a Null agent (sink) on node 4
set null [new Agent/Null]
$ns attach-agent $node_(4) $null
# Connect the agents
$ns connect $udp $null
- Setup simulation end:
# Define simulation end time
$ns at $val(stop) “stop”
$ns at $val(stop) “$ns nam-end-wireless $val(stop)”
$ns at $val(stop) “exit 0”
proc stop {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
}
# Run the simulation
$ns run
Step 4: Run the Simulation
- We can save the Tcl script like rip_example.tcl.
- Open a terminal and navigate to the directory in which we can saved the Tcl script.
- Run the simulation using the below command:
ns rip_example.tcl
The above command will generate trace files, optionally a network animation file if allowed in the script.
Step 5: Analyse the Results
We can use the trace files and the network animator (NAM) to estimate the performance of the RIP protocol, concentration on the parameters like route convergence time, packet delivery ratio, and network overhead.
Step 6: Visualize the Results (Optional)
If we have permitted the network animator (NAM) in the script then we can visualize the simulation:
nam rip_example.nam
It will open the NAM window in which we can observe the network topology and the behaviour of the RIP protocol when the simulation.
Additional Considerations
- Subnetting: If the network involves subnetting, make sure the IP addressing and routing tables are set up appropriately.
- Network Size: Change the number of nodes to monitor how the protocol scales.
- Mobility: Investigate the protocol under numerous mobility scenarios to know how it manages the dynamic topologies.
- Performance Metrics: Assess and compare the performance of various interior protocols such as delay, packet delivery ratio, and routing overhead.
Extending the Implementation
If we want more sophisticated interior routing behaviour then we have to either execute the custom logic or expand NS2 to support protocols such as OSPF or EIGRP that needs in-depth C++ programming in the NS2 framework. For simple interior routing simulations, using RIP as described overhead is a straightforward method.
The procedure for Internal Protocols was executed methodically, then implemented using the simulation tool ns2. We will explore this topic in depth using different simulation tools as needed offering a complete analysis.
Get ready for a detailed performance analysis designed specifically for you. We provide excellent outcomes for Internal Protocols in NS2 implementation, along with fresh research ideas. We work on OSPF or EIGRP simulations, tailored to fit the unique needs of your project.