How to Implement Classful Protocol in NS2

 

To implement a classful routing protocol in NS2 (Network Simulator 2), we are normally want to mimic the performance of the older routing protocols which do not support subnetting or classless inter-domain routing (CIDR). This routing protocols like RIP (Routing Information Protocol) in these initial versions are instances of protocols which follow to the classful routing concept in which the IP addresses are split into classes such as A, B, C with fixed subnet masks.

Implementing a Classful Protocol in NS2

Because NS2 does not explicitly differentiate among the classful and classless routing, and to execute the classful routing protocol within NS2 that needs to include mimicking the behaviour of the traditional routing protocol with the suitable settings. Given below is a structured approach on how we can set up a simulation using RIP as an instance of a classful protocol:

Step 1: Install NS2

Make sure that NS2 is installed on the system. We can download it from the NS2 webpage and we pursue the installation instructions are particular to the operating system.

Step 2: Create a Simulation Script

We want to make a Tcl script to setup the network simulation including a classful routing protocol.

Example: Implementing RIP as a Classful Protocol in NS2

  1. Create a new Tcl script: Open a text editor and make a new file, for instance, classful_rip_example.tcl.
  2. Set up the simulation environment: Describe the simulator, configure the network topology, and setup the metrics exact 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 (Simulating RIP as classful)

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 -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

  1. Create nodes and define network addresses:

As classful routing protocols work including the fixed subnet masks, and make sure the nodes are use addresses corresponding to Class A, B, or C.

# Create nodes

for {set i 0} {$i < $val(nn)} {incr i} {

set node_($i) [$ns node]

$node_($i) random-motion 0

}

# Assign IP addresses (assuming Class A addresses for simplicity)

$node_(0) set-address “10.0.0.1/8”

$node_(1) set-address “10.0.0.2/8”

$node_(2) set-address “10.0.0.3/8”

$node_(3) set-address “10.0.0.4/8”

$node_(4) set-address “10.0.0.5/8”

  1. 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 1

set null [new Agent/Null]

$ns attach-agent $node_(1) $null

# Connect the agents

$ns connect $udp $null

  1. 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 3: Run the Simulation

  1. We can save the Tcl script such as classful_rip_example.tcl.
  2. Open a terminal and navigate to the directory in which we can saved the Tcl script.
  3. Run the simulation using the below command:

ns classful_rip_example.tcl

The above command will produce the trace files and optionally a network animation file if permitted in the script.

Step 4: Analyse the Results

We can use the tools such as awk, perl, or further scripting languages to process the trace files made by NS2 to evaluate the performance of the classful routing protocol.

Step 5: Visualize the Results (Optional)

If we have permitted the network animator (NAM) in the script, we can visualize the simulation:

nam classful_rip_example.nam

It will open the NAM window in which we can see the network topology and the behaviour of the RIP protocol when the simulation.

Additional Considerations:

  • Subnet Masks: Classful routing protocols are integrally use the default subnet masks according to the class of the IP address. Make sure that the IP addressing scheme reflects this.
  • Performance Metrics: We can gather the parameters like packet delivery ratio, end-to-end delay, and routing overhead to assess the performance of the classful protocol.
  • Network Topology: Test with various network topologies to observe how the protocol manages numerous scenarios

A complete step-by-step approach was undertaken for the Classful protocol, utilizing the simulation tool for setup and analysis. If you would like more information about this topic we will offer. We provide assistance with the network comparison analysis for your project. Receive customized support from us for implementing Classful Protocol in NS2, as we will guide you through every step of the process. Explore the best project topics available at ns2project.com.