To implement the zone-based routing protocol in OMNeT++ like Zone Routing Protocol (ZRP) that has numerous steps and the ZRP is a hybrid routing protocol that integrates the proactive and reactive techniques. Here, we provide the procedures to implement the ZRP in OMNeT++.
Step-by-Step Implementation:
Step 1: Set Up OMNeT++ and INET Framework
Step 2: Understand ZRP Protocol
ZRP divides the network into zones and uses proactive routing inside the zones and reactive routing among zones. Key components contain:
Step 3: Create the ZRP Protocol Modules
We need to generate multiple modules for ZRP: IARP, IERP, and BRP.
Define the Modules in .ned File
Create a .ned file for the ZRP protocol modules.
simple IARP
{
parameters:
double helloInterval @unit(s) = default(5s); // Interval for sending hello messages
gates:
input fromNetworkLayer;
output toNetworkLayer;
}
simple IERP
{
parameters:
double routeRequestTimeout @unit(s) = default(2s); // Timeout for route requests
gates:
input fromNetworkLayer;
output toNetworkLayer;
}
simple BRP
{
parameters:
double bordercastInterval @unit(s) = default(1s); // Interval for bordercast
gates:
input fromIarp;
input fromIerp;
output toNetworkLayer;
}
simple ZRP
{
parameters:
double zoneRadius @unit(m) = default(2); // Radius of the zone
gates:
input fromAppLayer;
output toAppLayer;
input fromNetworkLayer;
output toNetworkLayer;
}
Implement the Modules in C++
Create the corresponding .cc and .h files for each module.
IARP.h
#ifndef __IARP_H_
#define __IARP_H_
#include <omnetpp.h>
#include “inet/networklayer/contract/IRoutingTable.h”
#include “inet/networklayer/common/L3AddressResolver.h”
#include “inet/networklayer/ipv4/IPv4Datagram.h”
using namespace omnetpp;
using namespace inet;
class IARP : public cSimpleModule
{
private:
double helloInterval;
cMessage *helloMsg;
IRoutingTable *routingTable;
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
void sendHello();
void processHello(cMessage *msg);
public:
IARP();
virtual ~IARP();
};
#endif
IARP.cc
#include “IARP.h”
Define_Module(IARP);
IARP::IARP()
{
helloMsg = nullptr;
}
IARP::~IARP()
{
cancelAndDelete(helloMsg);
}
void IARP::initialize()
{
helloInterval = par(“helloInterval”);
routingTable = getModuleFromPar<IRoutingTable>(par(“routingTableModule”), this);
helloMsg = new cMessage(“sendHello”);
scheduleAt(simTime() + helloInterval, helloMsg);
}
void IARP::handleMessage(cMessage *msg)
{
if (msg == helloMsg)
{
sendHello();
scheduleAt(simTime() + helloInterval, helloMsg);
}
else
{
processHello(msg);
}
}
void IARP::sendHello()
{
cMessage *hello = new cMessage(“Hello”);
send(hello, “toNetworkLayer”);
}
void IARP::processHello(cMessage *msg)
{
// Implement processing of Hello message
delete msg;
}
IERP.h
#ifndef __IERP_H_
#define __IERP_H_
#include <omnetpp.h>
#include “inet/networklayer/contract/IRoutingTable.h”
#include “inet/networklayer/common/L3AddressResolver.h”
#include “inet/networklayer/ipv4/IPv4Datagram.h”
using namespace omnetpp;
using namespace inet;
class IERP : public cSimpleModule
{
private:
double routeRequestTimeout;
cMessage *routeRequestMsg;
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
void sendRouteRequest();
void processRouteRequest(cMessage *msg);
void processRouteReply(cMessage *msg);
public
IERP();
virtual ~IERP();
};
#endif
IERP.cc
#include “IERP.h”
Define_Module(IERP);
IERP::IERP()
{
routeRequestMsg = nullptr;
}
IERP::~IERP()
{
cancelAndDelete(routeRequestMsg);
}
void IERP::initialize()
{
routeRequestTimeout = par(“routeRequestTimeout”);
routeRequestMsg = new cMessage(“sendRouteRequest”);
scheduleAt(simTime() + uniform(0, routeRequestTimeout), routeRequestMsg);
}
void IERP::handleMessage(cMessage *msg)
{
if (msg == routeRequestMsg)
{
sendRouteRequest();
scheduleAt(simTime() + routeRequestTimeout, routeRequestMsg);
}
else if (strcmp(msg->getName(), “RouteRequest”) == 0)
{
processRouteRequest(msg);
}
else if (strcmp(msg->getName(), “RouteReply”) == 0)
{
processRouteReply(msg);
}
else
{
// Handle other messages
}
}
void IERP::sendRouteRequest()
{
cMessage *routeRequest = new cMessage(“RouteRequest”);
send(routeRequest, “toNetworkLayer”);
}
void IERP::processRouteRequest(cMessage *msg)
{
// Implement processing of Route Request message
delete msg;
}
void IERP::processRouteReply(cMessage *msg)
{
// Implement processing of Route Reply message
delete msg;
}
BRP.h
#ifndef __BRP_H_
#define __BRP_H_
#include <omnetpp.h>
using namespace omnetpp;
class BRP : public cSimpleModule
{
private:
double bordercastInterval;
cMessage *bordercastMsg;
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
void performBordercast();
public:
BRP();
virtual ~BRP();
};
#endif
BRP.cc
#include “BRP.h”
Define_Module(BRP);
BRP::BRP()
{
bordercastMsg = nullptr;
}
BRP::~BRP()
{
cancelAndDelete(bordercastMsg);
}
void BRP::initialize()
{
bordercastInterval = par(“bordercastInterval”);
bordercastMsg = new cMessage(“performBordercast”);
scheduleAt(simTime() + bordercastInterval, bordercastMsg);
}
void BRP::handleMessage(cMessage *msg)
{
if (msg == bordercastMsg)
{
performBordercast();
scheduleAt(simTime() + bordercastInterval, bordercastMsg);
}
else
{
// Handle other messages
}
}
void BRP::performBordercast()
{
// Implement bordercasting logic
}
ZRP.h
#ifndef __ZRP_H_
#define __ZRP_H_
#include <omnetpp.h>
using namespace omnetpp;
class ZRP : public cSimpleModule
{
private:
double zoneRadius;
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
public:
ZRP();
virtual ~ZRP();
};
#endif
ZRP.cc
#include “ZRP.h”
Define_Module(ZRP);
ZRP::ZRP()
{
}
ZRP::~ZRP()
{
}
void ZRP::initialize()
{
zoneRadius = par(“zoneRadius”);
// Initialize IARP, IERP, and BRP modules
}
void ZRP::handleMessage(cMessage *msg)
{
// Implement handling of messages between IARP, IERP, and BRP
}
Step 4: Integrate with Simulation Model
Incorporate ZRP modules into a network simulation model.
Network Configuration .ned File
network ZRPNetwork
{
submodules:
host1: StandardHost {
parameters:
@display(“p=100,100”);
}
host2: StandardHost {
parameters:
@display(“p=300,100”);
}
// Add more hosts as needed
connections:
host1.pppg++ <–> { @display(“m=100,100”); } <–> host2.pppg++;
}
omnetpp.ini Configuration
network = ZRPNetwork
*.host*.pppg[*].queue.typename = “DropTailQueue”
*.host*.ipv4.routingTable = “inet.networklayer.routing.manet.Router”
*.host*.networkLayer.networkProtocol.typename = “IPv4NetworkLayer”
*.host*.application[*].typename = “UDPBasicApp”
*.host*.application[*].destAddresses = “host1” // Set destination as needed
*.host*.application[*].destPort = 2000
*.host*.application[*].startTime = uniform(0s, 10s)
*.host*.application[*].sendInterval = uniform(1s, 2s)
*.host*.application[*].packetLength = 512B
*.host*.app[0].typename = “ZRP”
Step 5: Test and Debug
As we discussed earlier about how the zone-based routing protocol will perform in OMNeT++ tool and we help to provide further information about how the OMNeT++ will adapt in diverse settings.
The developers at omnet-manual.com provide assistance with the implementation and simulation of the zone protocol in OMNeT++. For further support, please follow us.