How to implement zone protocol in ns2

 

To implement a zone-based routing protocol like Zone Routing Protocol (ZRP) in Network Simulator 2 (NS2) has needs to generate the network to exploit both proactive and reactive routing techniques within various zones of the network. ZRP is a hybrid routing protocol that divides the network into zones by using proactive routing within zones and reactive routing among the zones. Here, the given below is the brief structure to implement the zone protocol in ns2:

Step-by-Step Guide to Implement ZRP in NS2

Step 1: Understand the ZRP Protocol

Zone Routing Protocol (ZRP) is a hybrid protocol that integrates the advantages of proactive and reactive routing:

  • Intra-zone routing: Uses proactive routing such as OLSR or DSDV within a node’s local zone.
  • Inter-zone routing: Uses reactive routing such as AODV or DSR for interaction among the zones.

Step 2: Modify or Extend NS2 for ZRP

NS2 does not contain a built-in implementation of ZRP, so executing the ZRP needs to adjusting or expanding the NS2. Here’s how we can approach it:

  1. Create ZRP Logic: ZRP integrates diverse routing strategies. We need to execute the logic that decides when to use proactive and reactive routing. This can be completed by adjusting the existing NS2 modules or generating the new ones.
    • Proactive Routing (Intra-zone): Apply or use an existing protocol such as OLSR or DSDV.
    • Reactive Routing (Inter-zone): Execute or use an existing protocol such as AODV or DSR.
    • Zone Management: Execute logic to describe and handle zones around each node. This contains to generate a new ZRP class that manage the integration of these routing strategies.
  2. Add ZRP Class to NS2: Write a new C++ class that manages the zone routing logic by combined both proactive and reactive components.
    • Generate a file, e.g., zrp.cc, in the NS2 directory.
    • Add a header file, zrp.h, to describe the ZRP class.

zrp.h

#include “agent.h”

#include “olsr.h” // or dsdv.h

#include “aodv.h” // or dsr.h

class ZRP : public Agent {

public:

ZRP();

int command(int argc, const char*const* argv);

void recv(Packet* p, Handler*);

void intraZoneRouting();   // Proactive routing within zones

void interZoneRouting();   // Reactive routing between zones

void zoneManagement();     // Logic to manage zones

protected:

int zoneRadius;  // Define zone radius

// Other necessary member variables

};

zrp.cc

#include “zrp.h”

ZRP::ZRP() : Agent(PT_UDP) {

// Initialization

zoneRadius = 2; // Example zone radius

}

int ZRP::command(int argc, const char*const* argv) {

// Command handling

}

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

// Packet receiving logic

// Call intraZoneRouting() or interZoneRouting() based on the packet’s destination

}

void ZRP::intraZoneRouting() {

// Proactive routing logic within the zone

}

void ZRP::interZoneRouting() {

// Reactive routing logic between zones

}

void ZRP::zoneManagement() {

// Logic to manage zones, maintain zone membership, etc.

}

  1. Modify the Makefile: Update the NS2 Makefile to contain the new ZRP files.
    • Edit the Makefile.in or Makefile to contain the zrp.o in the compilation process.

OBJ_CC = zrp.o $(OBJ_CC)

  1. Rebuild NS2: After adding the protocol code and updating the Makefile, we need to rebuild NS2.

cd ns-2.xx/

make clean

make

Step 3: Create a Tcl Simulation Script

Once we have executed and compiled the ZRP protocol, we can generate a Tcl script to mimic a scenario using ZRP.

Example Tcl script:

# 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)     10                         ;# Number of nodes

set val(rp)     ZRP                        ;# Routing Protocol (Your new protocol)

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]

}

# Define node positions, traffic patterns, etc.

# Run the simulation

$ns run

Step 4: Run the Simulation

  1. Save the Tcl script (zrp_example.tcl).
  2. Open a terminal and navigate to the directory in which we saved the Tcl script.
  3. Execute the simulation using the following command:

ns zrp_example.tcl

This command will create trace files and optionally a network animation file (if enabled in script).

Step 5: Analyse the Results

Use trace files and the network animator (NAM) to evaluate the performance of the ZRP protocol, concentrates on parameters such as route discovery time, energy consumption, and network overhead.

Step 6: Visualize the Results (Optional)

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

nam zrp_example.nam

This will open the NAM window, in which we can see the network topology and the characteristics of ZRP during the simulation.

Additional Considerations

  • Zone Radius: Test with diverse zone radii to see how they impact the protocol’s performance.
  • Mobility: Validate ZRP in diverse mobility scenarios to familiarize its adaptability.
  • Performance Metrics: Assess and relate the ZRP’s performance in terms of latency, packet delivery ratio, and control overhead.

We demonstrate and show how the ZRP protocol will generate the network then applies the ZRP protocol in network that executed by using ns2 tool. We plan to provide the detailed information regarding the ZRP protocol implementation process in further manuals. For the implementation of the zone protocol in NS2, visit ns2project.com. Our team specializes in zones and reactive routing, ensuring your project is completed with expertise. Let us handle your needs!