How to Implement Hybrid Protocols Route in NS2

To implement the Hybrid Protocols Route in Network Simulator 2 (ns2), we have to integrate the mechanisms of both proactive and reactive routing methods to accomplish better scalability and performance in dynamic networks like mobile ad-hoc networks (MANETs) or wireless sensor networks (WSNs). This protocol often break downs the network into zone where proactive routing is used inside a zone and reactive routing is used amongst zones.

If you want to set up Hybrid Protocols Route in NS2 the right way, make sure to visit ns2project.com. Our skilled developers provide great help. You can get advice on improving your project’s comparison performance from our experts.

Example of a Hybrid Routing Protocol:

One widespread sample of a hybrid routing protocol is Zone Routing Protocol (ZRP). In ZRP:

  • Intra-zone routing uses proactive routing (e.g., table-driven like DSDV) inside a defined zone around each node.
  • Inter-zone routing uses reactive routing (e.g., on-demand like AODV) amongst zones when packets need to move beyond the local zone.

Step-by-Step Guide to Implementing Hybrid Routing in NS2

  1. Design the Hybrid Protocol

The protocol will have two elements:

  1. Intra-Zone Routing (Proactive): Nodes maintain up-to-date routes inside a certain zone using a proactive routing protocol. For example, each node keeps a routing table for all nodes into its zone.
  2. Inter-Zone Routing (Reactive): For nodes outside the zone, the protocol depend on on a reactive approach, where routes are founded only when required.
  1. Define the Zone Structure

In the hybrid protocol, each node sets up a zone in terms of parameter like the count of hops (zone radius). Nodes insides this zone communicates using a proactive approach, and nodes outside the zone are accessed through reactive routing.

  1. Implement Intra-Zone Routing (Proactive Component)

The proactive component will retain the routing tables updated for nodes into the zone of a given radius. You can use an available proactive protocol includes DSDV (Destination Sequenced Distance Vector), and alter it to restrict its scope within the configured zone.

Example Code for Intra-Zone Routing (Using DSDV):

class IntraZoneRouting {

public:

IntraZoneRouting(int zoneRadius);

void updateRoutingTable(Packet* p);  // Update routing table for nodes within the zone

void recv(Packet* p);  // Handle incoming packets within the zone

protected:

int zoneRadius;  // Define the size of the zone (in hops)

map<int, vector<int>> routingTable;  // Routing table for intra-zone communication

};

// Constructor to initialize zone radius

IntraZoneRouting::IntraZoneRouting(int radius) : zoneRadius(radius) {}

// Update the routing table based on received packet (intra-zone routing)

void IntraZoneRouting::updateRoutingTable(Packet* p) {

hdr_ip* iph = HDR_IP(p);

int src = iph->src();

int dest = iph->dst();

// Add/update entry in the routing table for nodes within the zone

if (getHopCount(src, dest) <= zoneRadius) {

routingTable[dest].push_back(src);

}

}

// Handle received packets and check if they are intra-zone

void IntraZoneRouting::recv(Packet* p) {

hdr_ip* iph = HDR_IP(p);

int src = iph->src();

int dest = iph->dst();

// If the destination is within the zone, use proactive routing

if (getHopCount(src, dest) <= zoneRadius) {

forwardPacketWithinZone(p);

} else {

// Otherwise, trigger inter-zone routing

triggerInterZoneRouting(p);

}

}

  1. Implement Inter-Zone Routing (Reactive Component)

For inter-zone routing, use a reactive protocol like AODV or DSR. When a node needs to deliver a packet to a destination outside its zone, it starts route discovery by broadcasting a route request (RREQ).

Example Code for Inter-Zone Routing (Using AODV):

class InterZoneRouting {

public:

InterZoneRouting();

void sendRREQ(Packet* p);  // Send route request for nodes outside the zone

void recvRREP(Packet* p);  // Receive route reply from the destination

protected:

map<int, vector<int>> routeCache;  // Cache routes for inter-zone routing

};

// Constructor for initializing inter-zone routing

InterZoneRouting::InterZoneRouting() {}

// Send a route request for destinations outside the zone

void InterZoneRouting::sendRREQ(Packet* p) {

hdr_ip* iph = HDR_IP(p);

int dest = iph->dst();

// Broadcast route request (RREQ) to discover route to the destination

if (routeCache.find(dest) == routeCache.end()) {

broadcastRREQ(dest);

}

}

// Receive and process route reply (RREP)

void InterZoneRouting::recvRREP(Packet* p) {

hdr_ip* iph = HDR_IP(p);

int src = iph->src();

int dest = iph->dst();

// Store the discovered route in the route cache

routeCache[dest].push_back(src);

}

  1. Integrate Intra-Zone and Inter-Zone Routing

The hybrid routing protocol will integrate the proactive and reactive elements. The protocol will first verify if the destination is in the node’s zone. If so, it will use intra-zone routing. If the destination is outside the zone, it will use inter-zone routing to discover the route.

Example Code for Hybrid Routing Protocol:

class HybridRoutingProtocol {

public:

HybridRoutingProtocol(int zoneRadius);

void recv(Packet* p);  // Handle received packets and route them appropriately

protected:

IntraZoneRouting intraZoneRouting;  // Proactive routing for intra-zone

InterZoneRouting interZoneRouting;  // Reactive routing for inter-zone

};

// Constructor to initialize hybrid routing

HybridRoutingProtocol::HybridRoutingProtocol(int radius)

: intraZoneRouting(radius), interZoneRouting() {}

// Handle received packets and choose routing method

void HybridRoutingProtocol::recv(Packet* p) {

hdr_ip* iph = HDR_IP(p);

int src = iph->src();

int dest = iph->dst();

// Use proactive routing if the destination is within the zone

if (getHopCount(src, dest) <= intraZoneRouting.zoneRadius) {

intraZoneRouting.recv(p);

} else {

// Use reactive routing for destinations outside the zone

interZoneRouting.sendRREQ(p);

}

}

  1. Simulate Hybrid Routing in NS2

After the protocol is executed, simulate it in NS2 by generating nodes, including the hybrid routing agents, and setting up the simulation parameters. Configure node placement, movement, and traffic patterns by using Tcl scripts.

Example Tcl Script for Hybrid Routing Simulation:

# Create a simulator instance

set ns [new Simulator]

# Create nodes

set node1 [$ns node]

set node2 [$ns node]

set node3 [$ns node]

set node4 [$ns node]

# Attach hybrid routing agents to the nodes

set agent1 [new Agent/HybridRoutingProtocol]

set agent2 [new Agent/HybridRoutingProtocol]

set agent3 [new Agent/HybridRoutingProtocol]

set agent4 [new Agent/HybridRoutingProtocol]

$ns attach-agent $node1 $agent1

$ns attach-agent $node2 $agent2

$ns attach-agent $node3 $agent3

$ns attach-agent $node4 $agent4

# Set up traffic between nodes

set udp1 [new Agent/UDP]

$ns attach-agent $node1 $udp1

$ns connect $udp1 $agent4

# Create traffic source

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 512

$cbr set interval_ 0.5

$cbr attach-agent $udp1

# Start the traffic

$ns at 1.0 “$cbr start”

# Run the simulation

$ns run

  1. Evaluate the Hybrid Protocol’s Performance

After running the simulation, you can compute the performance of the hybrid routing protocol using metrics like:

  • Packet Delivery Ratio (PDR): The percentage of successfully sended packets.
  • Average Latency: The delay experienced by packets.
  • Control Overhead: The number of control traffic builded by the proactive and reactive elements.
  • Scalability: How well the protocol operates as the network size increases.
  • Zone Radius Sensitivity: How the size of the zone impacts the performance, balancing proactive and reactive routing.

In this demonstration, we gathered the details for you to acquire the knowledge of the initialization and evaluation of Hybrid Protocol Route’s implementation in ns2 and you can also expand the existing models for future use. We will intent to provide the extra informations through another simulation.