To implement the IPv4 protocols in OMNeT++ comprises to making a section that manages IP packet progressing, addressing, and routing functionalities. The INET framework in OMNeT++ before now offers wide sustenance for IPv4. To need to extend the new version of an IPv4 protocol, here we give to the step-by-step process.
Step-by-Step Implementations:
Step 1: Set Up OMNeT++ and INET Framework
Step 2: Define the IPv4 Protocol
To build an elementary IPv4 module that handles IP packet forwarding and routing.
Define the Module in .ned File
Generate a .ned file for the IPv4 protocol module.
simple IPv4
{
parameters:
@display(“i=block/layer3”);
gates:
input fromNetworkLayer;
output toNetworkLayer;
input fromMacLayer;
output toMacLayer;
}
Step 3: Implement the IPv4 Protocol in C++
Create the corresponding .cc and .h files.
IPv4.h
#ifndef __IPV4_H_
#define __IPV4_H_
#include <omnetpp.h>
#include “inet/common/INETDefs.h”
#include “inet/networklayer/contract/IRoutingTable.h”
#include “inet/networklayer/contract/IInterfaceTable.h”
#include “inet/networklayer/ipv4/Ipv4Header_m.h”
#include “inet/networklayer/ipv4/Ipv4Route.h”
#include “inet/networklayer/common/L3AddressResolver.h”
#include <map>
using namespace omnetpp;
using namespace inet;
class IPv4 : public cSimpleModule
{
private:
IRoutingTable *routingTable;
IInterfaceTable *interfaceTable;
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
void handleUpperLayerPacket(cPacket *packet);
void handleLowerLayerPacket(cPacket *packet);
void forwardPacket(Ipv4Header *ipHeader, cPacket *packet);
public:
IPv4();
virtual ~IPv4();
};
#endif
IPv4.cc
#include “IPv4.h”
Define_Module(IPv4);
IPv4::IPv4()
{
}
IPv4::~IPv4()
{
}
void IPv4::initialize()
{
routingTable = getModuleFromPar<IRoutingTable>(par(“routingTableModule”), this);
interfaceTable = getModuleFromPar<IInterfaceTable>(par(“interfaceTableModule”), this);
}
void IPv4::handleMessage(cMessage *msg)
{
if (msg->arrivedOn(“fromNetworkLayer”))
{
handleUpperLayerPacket(check_and_cast<cPacket *>(msg));
}
else if (msg->arrivedOn(“fromMacLayer”))
{
handleLowerLayerPacket(check_and_cast<cPacket *>(msg));
}
else
{
delete msg;
}
}
void IPv4::handleUpperLayerPacket(cPacket *packet)
{
Ipv4Header *ipHeader = new Ipv4Header();
ipHeader->setSrcAddress(interfaceTable->getInterface(0)->getIpv4Address());
ipHeader->setDestAddress(packet->par(“destAddr”).stringValue());
packet->insertAtFront(ipHeader);
forwardPacket(ipHeader, packet);
}
void IPv4::handleLowerLayerPacket(cPacket *packet)
{
Ipv4Header *ipHeader = check_and_cast<Ipv4Header *>(packet->removeAtFront<Ipv4Header>());
if (ipHeader->getDestAddress() == interfaceTable->getInterface(0)->getIpv4Address())
{
send(packet, “toNetworkLayer”);
}
else
{
forwardPacket(ipHeader, packet);
}
}
void IPv4::forwardPacket(Ipv4Header *ipHeader, cPacket *packet)
{
Ipv4Route *route = routingTable->findBestMatchingRoute(ipHeader->getDestAddress());
if (route)
{
send(packet, “toMacLayer”);
}
else
{
delete packet;
}
}
Step 4: Integrate with Simulation Model
Integrate the IPv4 module into a network simulation model.
Network Configuration .ned File
Create a .ned file to describe the network topology.
network IPv4Network
{
parameters:
@display(“bgb=600,400”);
submodules:
host1: StandardHost {
parameters:
@display(“p=100,200”);
}
host2: StandardHost {
parameters:
@display(“p=300,200”);
}
router: Router {
parameters:
@display(“p=200,100”);
}
connections:
host1.pppg++ <–> Eth10M <–> router.pppg++;
host2.pppg++ <–> Eth10M <–> router.pppg++;
}
Step 5: Configure the Simulation
Configure the simulation parameters in the omnetpp.ini file.
[General]
network = IPv4Network
*.host*.pppg[*].queue.typename = “DropTailQueue”
*.host*.ipv4.routingTable = “inet.networklayer.routing.manet.Router”
*.host*.networkLayer.networkProtocol.typename = “Ipv4NetworkLayer”
*.host*.transportLayer.tcp.typename = “Tcp”
*.host*.transportLayer.udp.typename = “Udp”
*.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
*.router.app[0].typename = “IPv4”
Step 6: Test and Debug
Finally, we are implemented the IPv4 Protocol by using the tool OMNeT++. Now, we will provide further simulation details about to execute in OMNeT++ tool in your project.