How to Implement Fisheye Protocol in NS2

To implement the Fisheye State Routing (FSR) protocol in NS2, we need to simulate the distinct method to handle the routing information in mobile ad hoc networks (MANETs). It decreases overhead by keeping precise information about closer nodes and less accurate information are farther way nodes that are parallel to these concepts. The given below is the brief structured approach to implement the protocol using ns2:

Step-by-Step Implementation:

Step 1: Understand Fisheye State Routing (FSR)

FSR is a proactive routing protocol where each node maintains a topology table that has the distance to every other node in the network. The frequency of updating the routing information minimizes with the distance from the source node.

Step 2: Set Up NS2

Make sure to install and configure the ns2 on your computer. Authenticate the installation by running a basic simulation.

Step 3: Implement FSR Protocol

  1. Create the FSR Agent Class (C++)

Execute the FSR protocol by setting up a new C++ class that manages the following below:

  • Topology Table Maintenance: Each node should maintain a table of distances to all other nodes.
  • Periodic Updates: Nodes should interchange routing information occasionally, with changing frequency depends on distance.

Here’s a basic structure:

#include <agent.h>

#include <packet.h>

#include <trace.h>

#include <address.h>

#include <map>

class FSR_Agent : public Agent {

public:

FSR_Agent();

void recv(Packet* p, Handler* h);

void sendUpdate();

void updateTopologyTable(Packet* p);

protected:

std::map<int, int> topologyTable_; // Node ID -> Distance

double lastUpdateTime_;

double updateInterval_;

};

// Constructor

FSR_Agent::FSR_Agent() : Agent(PT_UDP), lastUpdateTime_(0), updateInterval_(1.0) {

// Initialization code here

// Initialize topology table with self distance as 0

topologyTable_[addr()] = 0;

}

// Packet reception

void FSR_Agent::recv(Packet* p, Handler* h) {

updateTopologyTable(p);

}

// Send periodic update

void FSR_Agent::sendUpdate() {

if (Scheduler::instance().clock() – lastUpdateTime_ >= updateInterval_) {

Packet* p = allocpkt();

// Fill the packet with topology information

// …

send(p, 0);

lastUpdateTime_ = Scheduler::instance().clock();

}

}

// Update topology table with received information

void FSR_Agent::updateTopologyTable(Packet* p) {

// Extract topology information from packet and update table

// Adjust the update frequency based on distance

}

  1. Integrate the FSR Agent into NS2
  1. Modify the Makefile: Attach your new FSR class to the NS2 Makefile so that it gets compiled with the rest of the simulator.
  2. Recompile NS2:

make clean

make

Step 4: Create a Tcl Script to Simulate FSR

Generate a Tcl script to replicate a network using FSR, after it is executed and compiled.

Example Tcl Script:

# Create a simulator object

set ns [new Simulator]

# Define the topology

set val(chan)   Channel/WirelessChannel

set val(prop)   Propagation/TwoRayGround

set val(netif)  Phy/WirelessPhy

set val(mac)    Mac/802_11

set val(ifq)    Queue/DropTail/PriQueue

set val(ll)     LL

set val(ant)    Antenna/OmniAntenna

set val(ifqlen) 50

set val(nn)     10

set val(x)      1000

set val(y)      1000

set val(stop)   100.0

set val(rp)     FSR   ;# Routing protocol

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

}

# Define node positions and movement model

$node_(0) set X_ 100.0; $node_(0) set Y_ 200.0

$node_(1) set X_ 200.0; $node_(1) set Y_ 300.0

$node_(2) set X_ 300.0; $node_(2) set Y_ 400.0

$node_(3) set X_ 400.0; $node_(3) set Y_ 500.0

$node_(4) set X_ 500.0; $node_(4) set Y_ 600.0

# Set up traffic sources

set udp [new Agent/UDP]

$ns attach-agent $node_(0) $udp

set null [new Agent/Null]

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

$ns connect $udp $null

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set packetSize_ 512

$cbr set interval_ 0.1

$cbr start

# Simulation end

$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 5: Run the Simulation

  1. Save the Tcl script (fsr_example.tcl).
  2. Open a terminal and traverse to the directory where you saved the Tcl script.
  3. Enter the given command to execute the simulation.

ns fsr_example.tcl

Step 6: Analyze the Results

  • Utilize trace files and the network animator (NAM) to assess the performance of the FSR protocol, concentrating on metrics like routing overhead, packet delivery ratio, and end-to-end delay.
  • Test how the routing precision varies with distance in the network and how it influences overall performance.

Additional Considerations

  • Routing Update Frequency: Alter the update frequency according to the distance to discover the optimal balance amongst routing accuracy and overhead.
  • Performance Comparison: Compare FSR’s performance with other routing protocols like AODV or DSDV to understand its advantages in various scenarios.

Throughout this manual, we have delivered the implementation details for the Fisheye State Protocol (FSR) in ns2 scenarios. Start by defining the agent class and then integrating it into the simulation network. We can analyze the outcome for the future enhancements. For the implementation of the Fisheye Protocol in NS2, you may visit ns2project.com, where we provide a variety of excellent project ideas and topics. Additionally, we offer performance analysis services for your project.