To Implement an OSI layer protocol in OMNeT++ has needs to generate modules that emulate the characteristics of protocols at numerous layers of the OSI model from the physical layer to the application layer. The given below is the detailed procedure on how to implement the OSI layer protocol in OMNeT++;
Step-by-Step Implementation:
Step 1: Set Up OMNeT++ and INET Framework
Step 2: Define the OSI Layer Protocol
We need to execute a protocol at the transport layer, same as a simplified version of TCP.
Define the Module in .ned File
Create a .ned file for the transport layer protocol module.
simple TransportLayerProtocol
{
parameters:
@display(“i=block/layer3”);
gates:
input fromNetworkLayer;
output toNetworkLayer;
input fromApplicationLayer;
output toApplicationLayer;
}
Implement the Module in C++
Create the corresponding .cc and .h files.
TransportLayerProtocol.h
#ifndef __TRANSPORTLAYERPROTOCOL_H_
#define __TRANSPORTLAYERPROTOCOL_H_
#include <omnetpp.h>
#include “inet/common/INETDefs.h”
#include “inet/networklayer/contract/INetfilter.h”
#include “inet/networklayer/common/L3Address.h”
#include “inet/networklayer/common/L3AddressResolver.h”
#include “inet/transportlayer/contract/TransportHeader_m.h”
#include <map>
using namespace omnetpp;
using namespace inet;
class TransportLayerProtocol : public cSimpleModule
{
private:
std::map<int, L3Address> connectionTable; // Stores connection info
int nextConnId;
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
void handleAppMessage(cMessage *msg);
void handleNetworkMessage(cMessage *msg);
void sendToNetwork(cPacket *packet, const L3Address &destAddr);
void sendToApp(cPacket *packet, int connId);
public:
TransportLayerProtocol();
virtual ~TransportLayerProtocol();
};
#endif
TransportLayerProtocol.cc
#include “TransportLayerProtocol.h”
Define_Module(TransportLayerProtocol);
TransportLayerProtocol::TransportLayerProtocol() : nextConnId(0)
{
}
TransportLayerProtocol::~TransportLayerProtocol()
{
}
void TransportLayerProtocol::initialize()
{
}
void TransportLayerProtocol::handleMessage(cMessage *msg)
{
if (msg->arrivedOn(“fromApplicationLayer”))
{
handleAppMessage(msg);
}
else if (msg->arrivedOn(“fromNetworkLayer”))
{
handleNetworkMessage(msg);
}
else
{
delete msg;
}
}
void TransportLayerProtocol::handleAppMessage(cMessage *msg)
{
cPacket *packet = check_and_cast<cPacket *>(msg);
int connId = nextConnId++;
L3AddressdestAddr=L3AddressResolver().resolve(packet>par(“destAddr”).stringValue());
connectionTable[connId] = destAddr;
sendToNetwork(packet, destAddr);
}
void TransportLayerProtocol::handleNetworkMessage(cMessage *msg)
{
cPacket *packet = check_and_cast<cPacket *>(msg);
int connId = packet->par(“connId”).intValue();
if (connectionTable.find(connId) != connectionTable.end())
{
sendToApp(packet, connId);
}
else
{
delete packet;
}
}
void TransportLayerProtocol::sendToNetwork(cPacket *packet, const L3Address &destAddr)
{
packet->addPar(“connId”) = nextConnId – 1;
send(packet, “toNetworkLayer”);
}
void TransportLayerProtocol::sendToApp(cPacket *packet, int connId)
{
send(packet, “toApplicationLayer”);
}
Step 3: Integrate with Simulation Model
Incorporate TransportLayerProtocol module inside a network simulation model.
Network Configuration .ned File
Create a .ned file to define the network topology.
network OSIModelNetwork
{
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 4: Configure the Simulation
Configure the simulation parameters in the omnetpp.ini file.
network = OSIModelNetwork
*.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
*.host1.app[0].typename = “TransportLayerProtocol”
*.host2.app[0].typename = “TransportLayerProtocol”
Step 5: Test and Debug
As we discussed earlier about how the OSI layer protocol will perform in OMNeT++ simulator and we help to deliver additional data about how the OSI layer protocol will familiarize in diverse settings. We offer you full support for implementing the OSI layer protocol in the OMNeT++ tool, together with simulation data and the best project performance outcomes.