How to Simulate ZRP Protocol Projects Using NS3

To simulate Zone Routing Protocol (ZRP) in ns3 has needs to follow numerous steps and it is a hybrid routing protocol for mobile ad-hoc networks (MANETs), is not executed directly. But, we can replicate ZRP by executing it using the combination of proactive (intra-zone) and reactive (inter-zone) protocols. ZRP depend on a proactive routing protocol within a particular zone radius and a reactive protocol for routing outside the zone.

While ZRP is a hybrid protocol, we can simulate the intra-zone (within the zone) interaction uses a proactive protocol such as OLSR (Optimized Link State Routing) or DSDV (Destination-Sequenced Distance Vector) and inter-zone (outside the zone) communication using a reactive protocol such as AODV (Ad-hoc On-demand Distance Vector) or DSR (Dynamic Source Routing).

In this guide, I will demonstrated on how to simulate a ZRP-like routing protocol by integrating proactive and reactive routing protocols in NS3.

Steps to Simulate ZRP-like Protocol in NS3

  1. Install NS3

Make sure we have NS3 installed.

  1. Understanding ZRP (Zone Routing Protocol)

ZRP divides the network into zones based on a defined zone radius. Each node uses:

  • Proactive routing protocol (such as OLSR or DSDV) within the zone (intra-zone).
  • Reactive routing protocol (such as AODV or DSR) for nodes outside the zone (inter-zone).

In this simulation, we can describe two protocols:

  • Proactive Protocol (Intra-Zone): We will use OLSR.
  • Reactive Protocol (Inter-Zone): We will use AODV.
  1. Create a Simulation Script

Here’s a general outline of how we can inegrate the proactive and reactive protocols to mimic ZRP-like behavior.

  1. Include Necessary Headers

We require the necessary headers for network, mobility, routing protocols (OLSR and AODV), and other required modules.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/mobility-module.h”

#include “ns3/olsr-helper.h”       // For OLSR (Intra-zone proactive protocol)

#include “ns3/aodv-module.h”       // For AODV (Inter-zone reactive protocol)

#include “ns3/wifi-module.h”

#include “ns3/applications-module.h”

#include “ns3/netanim-module.h”

  1. Create and Install Nodes

Generate a set of mobile nodes to signify the nodes in the ad-hoc network.

NodeContainer nodes;

nodes.Create(10);  // Create 10 nodes

  1. Configure Wi-Fi Communication

To permit wireless communication, that requires setting up the Wi-Fi devices. The Wi-Fi devices will be installed on all the nodes to permit them to interact in an ad-hoc network.

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

wifiPhy.SetChannel(wifiChannel.Create());

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211g);  // Use 802.11g standard

wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);

WifiMacHelper wifiMac;

wifiMac.SetType(“ns3::AdhocWifiMac”);  // Ad-hoc MAC

NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);

  1. Install Internet Stack and Routing Protocols (Proactive and Reactive)

We need to install the Internet stack (TCP/IP protocols) and configure both the proactive (intra-zone) and reactive (inter-zone) protocols.

  • OLSR will handle intra-zone routing.
  • AODV will handle inter-zone routing.

InternetStackHelper internet;

OlsrHelper olsr;  // Proactive (intra-zone) protocol

AodvHelper aodv;  // Reactive (inter-zone) protocol

Ipv4ListRoutingHelper list;

list.Add(olsr, 10);  // Add OLSR with a higher priority (intra-zone proactive routing)

list.Add(aodv, 20);  // Add AODV with lower priority (inter-zone reactive routing)

internet.SetRoutingHelper(list);  // Combine both OLSR and AODV

internet.Install(nodes);

  1. Assign IP Addresses

Allocate IP addresses to the wireless devices, enabling the nodes to interact through IP.

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);  // Class C network

Ipv4InterfaceContainer interfaces = address.Assign(devices);

  1. Set up Mobility Model

Set up the mobility model to replicate node movement. For ZRP, node mobility impacts how routing protocols communicate while zones are dynamic.

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

“MinX”, DoubleValue(0.0),

“MinY”, DoubleValue(0.0),

“DeltaX”, DoubleValue(10.0),

“DeltaY”, DoubleValue(10.0),

“GridWidth”, UintegerValue(3),

“LayoutType”, StringValue(“RowFirst”));

mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,

“Speed”, StringValue(“ns3::UniformRandomVariable[Min=1.0|Max=5.0]”),

“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=0.2]”),

“PositionAllocator”, StringValue(“ns3::GridPositionAllocator”));

mobility.Install(nodes);

  1. Set Up Applications

Configure applications to emulate traffic among nodes. Here, one node will behave as the server and another node as the client.

  • Server (Sink Application):

uint16_t port = 8080;

UdpEchoServerHelper echoServer(port);

ApplicationContainer serverApp = echoServer.Install(nodes.Get(0));  // Install on node 0 (server)

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(20.0));

  • Client (OnOff Application):

UdpEchoClientHelper echoClient(interfaces.GetAddress(0), port);  // Client communicating with server (node 0)

echoClient.SetAttribute(“MaxPackets”, UintegerValue(50));

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));

ApplicationContainer clientApp = echoClient.Install(nodes.Get(5));  // Client is on node 5

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(20.0));

  1. Enable Tracing and Animation

Permit packet tracing for detailed evaluation and animation to envision the simulation.

wifiPhy.EnablePcapAll(“zrp_simulation”);  // Enable pcap tracing for all nodes

AnimationInterface anim(“zrp_simulation.xml”);  // Animation output for NetAnim

  1. Run the Simulation

Set the stop time and execute the simulation.

Simulator::Stop(Seconds(20.0));

Simulator::Run();

Simulator::Destroy();

  1. Example Full Script for ZRP-like Simulation

Here’s the full NS3 script that integrates OLSR (proactive) and AODV (reactive) to emulate ZRP-like behavior:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/wifi-module.h”

#include “ns3/mobility-module.h”

#include “ns3/olsr-helper.h”

#include “ns3/aodv-module.h”

#include “ns3/applications-module.h”

#include “ns3/netanim-module.h”

using namespace ns3;

int main(int argc, char *argv[]) {

// Step 1: Create nodes

NodeContainer nodes;

nodes.Create(10);  // Create 10 nodes

// Step 2: Configure Wi-Fi devices

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

wifiPhy.SetChannel(wifiChannel.Create());

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211g);  // Use 802.11g

wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);

WifiMacHelper wifiMac;

wifiMac.SetType(“ns3::AdhocWifiMac”);  // Ad-hoc MAC

NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);

// Step 3: Install internet stack and routing protocols (OLSR + AODV)

InternetStackHelper internet;

OlsrHelper olsr;  // Proactive protocol (intra-zone)

AodvHelper aodv;  // Reactive protocol (inter-zone)

Ipv4ListRoutingHelper list;

list.Add(olsr, 10);  // Higher priority for OLSR (proactive)

list.Add(aodv, 20);  // Lower priority for AODV (reactive)

internet.SetRoutingHelper(list);

internet.Install(nodes);

// Step 4: Assign IP addresses

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);  // Class C network

Ipv4InterfaceContainer interfaces = address.Assign(devices);

// Step 5: Set up mobility model

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

“MinX”, DoubleValue(0.0),

“MinY”, DoubleValue(0.0),

“DeltaX”, DoubleValue(10.0),

“DeltaY”, DoubleValue(10.0),

“GridWidth”, UintegerValue(3),

“LayoutType”, StringValue(“RowFirst”));

mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,

“Speed”, StringValue(“ns3::UniformRandomVariable[Min=1.0|Max=5.0]”),

“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=0.2]”),

“PositionAllocator”, StringValue(“ns3::GridPositionAllocator”));

mobility.Install(nodes);

// Step 6: Install applications (Server on node 0, Client on node 5)

uint16_t port = 8080;

UdpEchoServerHelper echoServer(port);

ApplicationContainer serverApp = echoServer.Install(nodes.Get(0));

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(20.0));

UdpEchoClientHelper echoClient(interfaces.GetAddress(0), port);  // Client on node 5 communicating with server on node 0

echoClient.SetAttribute(“MaxPackets”, UintegerValue(50));

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));

ApplicationContainer clientApp = echoClient.Install(nodes.Get(5));  // Client is node 5

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(20.0));

// Step 7: Enable tracing and animation

wifiPhy.EnablePcapAll(“zrp_simulation”);

AnimationInterface anim(“zrp_simulation.xml”);

// Step 8: Run the simulation

Simulator::Stop(Seconds(20.0));

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Running the Simulation
  • Compile and run the script using NS3’s waf system:

./waf build

./waf –run <your_script_name>

  1. Analyse Results
  • PCAP Tracing: The pcap files created can be measured using tools such as Wireshark.
  • NetAnim: We can open the created XML file in NetAnim to envision the simulation and node movements.
  1. Tuning the ZRP Parameters

We can tune the zone radius (intra-zone range) by modifying the metrics of the mobility model or even generate a custom ZRP implementation if we required more control over the protocol’s behaviour.

In this module, we had been successfully simulated the Zone routing protocol in ns3 tool with examples. If you need more information regarding this process we offered it.

For any research assistance in the ZRP protocol projects. Using the NS3 tool, please direct all of your research inquiries to phdprime.com, and we will provide you with the best results.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2