To implement the Associativity-Based Routing (ABR) protocol in OMNeT++ requires multiple steps. For mobile ad hoc networks (MANETs), we have to use ABR which is an on-demand routing protocol has uses the stability of links, measured by the associativity ticks, to select the most stable paths. A detailed guide to help you implement ABR in OMNeT++ using the INET framework in the following below:
Step-by-Step Implementation:
Step 1: Set Up OMNeT++ and INET Framework
Step 2: Understand ABR Protocol
To signify the stability of the links, ABR uses associativity ticks. Higher associativity ticks indicate a more stable link. The protocol has the following key steps:
Step 3: Create the ABR Protocol Module
Define the Module in .ned File
Create a .ned file for the ABR protocol module.
simple ABR
{
parameters:
@display(“i=block/cogwheel”);
double helloInterval @unit(s) = default(1s);
double routeLifetime @unit(s) = default(60s);
gates:
input fromNetworkLayer;
output toNetworkLayer;
input fromMacLayer;
output toMacLayer;
}
Implement the Module in C++
Generate the corresponding .cc and .h files.
ABR.h
#ifndef __ABR_H_
#define __ABR_H_
#include <omnetpp.h>
#include “inet/networklayer/contract/IRoutingTable.h”
#include “inet/common/INETDefs.h”
#include “inet/common/geometry/common/Coord.h”
#include <map>
#include <vector>
using namespace omnetpp;
using namespace inet;
class ABR : public cSimpleModule
{
private:
double helloInterval;
double routeLifetime;
IRoutingTable *routingTable;
cMessage *helloMsg;
std::map<L3Address, int> associativityTable; // Stores associativity ticks
std::map<L3Address, simtime_t> routeExpiryTable; // Stores route expiry times
std::map<L3Address, L3Address> routeTable; // Maps destination to next hop
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
void sendHello();
void processHello(cMessage *msg);
void sendRREQ(L3Address destAddr);
void processRREQ(cMessage *msg);
void sendRREP(L3Address destAddr);
void processRREP(cMessage *msg);
void processRERR(cMessage *msg);
void updateAssociativityTable(L3Address neighbor);
void maintainRoutes();
public:
ABR();
virtual ~ABR();
};
#endif
ABR.cc
#include “ABR.h”
#include “inet/networklayer/common/L3AddressResolver.h”
Define_Module(ABR);
ABR::ABR()
{
helloMsg = nullptr;
}
ABR::~ABR()
{
cancelAndDelete(helloMsg);
}
void ABR::initialize()
{
helloInterval = par(“helloInterval”);
routeLifetime = par(“routeLifetime”);
routingTable = getModuleFromPar<IRoutingTable>(par(“routingTableModule”), this);
helloMsg = new cMessage(“sendHello”);
scheduleAt(simTime() + helloInterval, helloMsg);
}
void ABR::handleMessage(cMessage *msg)
{
if (msg == helloMsg)
{
sendHello();
scheduleAt(simTime() + helloInterval, helloMsg);
}
else if (strcmp(msg->getName(), “Hello”) == 0)
{
processHello(msg);
}
else if (strcmp(msg->getName(), “RREQ”) == 0)
{
processRREQ(msg);
}
else if (strcmp(msg->getName(), “RREP”) == 0)
{
processRREP(msg);
}
else if (strcmp(msg->getName(), “RERR”) == 0)
{
processRERR(msg);
}
else if (dynamic_cast<cPacket *>(msg))
{
// Handle incoming data packets
L3Address dest = L3AddressResolver().resolve(msg->par(“destAddr”).stringValue());
if (routeTable.find(dest) != routeTable.end())
{
// Forward the packet to the next hop
send(msg, “toMacLayer”);
}
else
{
// Drop the packet if no route found
delete msg;
}
}
else
{
// Handle other messages
}
}
void ABR::sendHello()
{
cMessage *hello = new cMessage(“Hello”);
send(hello, “toMacLayer”);
}
void ABR::processHello(cMessage *msg)
{
// Process received hello message
L3Address sender = L3AddressResolver().resolve(msg->getSenderModule()->getFullPath().c_str());
updateAssociativityTable(sender);
delete msg;
}
void ABR::sendRREQ(L3Address destAddr)
{
cMessage *rreq = new cMessage(“RREQ”);
rreq->addPar(“destAddr”) = destAddr.str().c_str();
send(rreq, “toMacLayer”);
}
void ABR::processRREQ(cMessage *msg)
{
// Implement processing of RREQ message
L3Address srcAddr = L3AddressResolver().resolve(msg->par(“srcAddr”).stringValue());
L3Address destAddr = L3AddressResolver().resolve(msg->par(“destAddr”).stringValue());
if (routeTable.find(destAddr) != routeTable.end())
{
sendRREP(destAddr);
}
else
{
// Forward the RREQ
send(msg, “toMacLayer”);
}
}
void ABR::sendRREP(L3Address destAddr)
{
cMessage *rrep = new cMessage(“RREP”);
rrep->addPar(“destAddr”) = destAddr.str().c_str();
send(rrep, “toMacLayer”);
}
void ABR::processRREP(cMessage *msg)
{
// Implement processing of RREP message
L3Address destAddr = L3AddressResolver().resolve(msg->par(“destAddr”).stringValue());
L3Address nextHop = L3AddressResolver().resolve(msg->par(“nextHop”).stringValue());
routeTable[destAddr] = nextHop;
routeExpiryTable[destAddr] = simTime() + routeLifetime;
delete msg;
}
void ABR::processRERR(cMessage *msg)
{
// Implement processing of RERR message
L3Address destAddr = L3AddressResolver().resolve(msg->par(“destAddr”).stringValue());
routeTable.erase(destAddr);
routeExpiryTable.erase(destAddr);
delete msg;
}
void ABR::updateAssociativityTable(L3Address neighbor)
{
// Update associativity ticks for the neighbor
associativityTable[neighbor]++;
}
void ABR::maintainRoutes()
{
// Implement route maintenance based on associativity ticks and route expiry times
for (auto it = routeExpiryTable.begin(); it != routeExpiryTable.end(); )
{
if (simTime() > it->second)
{
routeTable.erase(it->first);
it = routeExpiryTable.erase(it);
}
else
{
++it;
}
}
}
Step 4: Integrate with Simulation Model
Fit in the ABR module inside the network simulation model.
Network Configuration .ned File
network ABRNetwork
{
submodules:
node1: StandardHost {
parameters:
@display(“p=100,100”);
}
node2: StandardHost {
parameters:
@display(“p=300,100”);
}
// Add more nodes as needed
connections:
node1.pppg++ <–> { @display(“m=100,100”); } <–> node2.pppg++;
}
omnetpp.ini Configuration
network = ABRNetwork
*.node*.pppg[*].queue.typename = “DropTailQueue”
*.node*.ipv4.routingTable = “inet.networklayer.routing.manet.Router”
*.node*.networkLayer.networkProtocol.typename = “IPv4NetworkLayer”
*.node*.transportLayer.tcp.typename = “Tcp”
*.node*.transportLayer.udp.typename = “Udp”
*.node*.application[*].typename = “UdpBasicApp”
*.node*.application[*].destAddresses = “node1” // Set destination as needed
*.node*.application[*].destPort = 2000
*.node*.application[*].startTime = uniform(0s, 10s)
*.node*.application[*].sendInterval = uniform(1s, 2s)
*.node*.application[*].packetLength = 512B
*.node*.app[0].typename = “ABR”
Step 5: Test and Debug
In this script, we overall see the installation of OMNeT++ and INET framework to implement the ABR protocol which is executed in the OMNeT++ environment. Hope, you can understand this procedure however if you have any doubts, we will clarify it.
If you want the best results for implementing and simulating the ABR protocol in OMNeT++, feel free to reach out to our team.