To implement the LAN (Local Area Network) protocols in OMNeT++ contains to making the modules that simulate the activities of common LAN protocols like Spanning Tree Protocol (STP), Ethernet, and Address Resolution Protocol (ARP). The following steps are to implement this protocols by using the INET framework in OMNeT++.
Step-by-Step Implementations:
Step 1: Set Up OMNeT++ and INET Framework
Step 2: Understand LAN Protocols
Ethernet
It is a broadly used LAN protocol that works at the data link layer like Layer 2 of the OSI model. This is define how data is outlined and conducted over the physical medium.
Spanning Tree Protocol (STP)
STP is a network protocol that confirms a loop-free topology used for Ethernet networks.
Address Resolution Protocol (ARP)
It is used to map IP addresses to MAC addresses, permitting communication in the same LAN.
Step 3: Implement Ethernet
Ample implementation of Ethernet, so leverage the remaining implementation provided by INET framework.
Define the Network in .ned File
Produce a .ned file for the Ethernet LAN.
network EthernetLAN
{
parameters:
@display(“bgb=600,400”);
submodules:
host1: StandardHost {
parameters:
@display(“p=100,200”);
}
host2: StandardHost {
parameters:
@display(“p=300,200”);
}
switch: EthernetSwitch {
parameters:
@display(“p=200,100”);
}
connections:
host1.ethg++ <–> Eth10M <–> switch.ethg++;
host2.ethg++ <–> Eth10M <–> switch.ethg++;
}
Step 4: Implement ARP
ARP is also part of the INET framework. We can configure it in the .ini file.
omnetpp.ini Configuration
[General]
network = EthernetLAN
*.host*.eth[*].mac.typename = “EthernetMac”
*.host*.eth[*].mac.promiscuous = true
*.host*.ipv4.arp.typename = “GlobalArp”
*.host*.ipv4.routingTable.netmaskRoutes = “true”
*.switch*.eth[*].mac.typename = “EthernetMac”
*.switch*.eth[*].mac.promiscuous = true
*.switch*.forwardingTable.typename = “MACRelayUnit”
*.host1.ipv4.config = “host1.config”
*.host2.ipv4.config = “host2.config”
Host Configuration
Create configuration files for the hosts.
host1.config
* default
address 192.168.0.1
netmask 255.255.255.0
host2.config
* default
address 192.168.0.2
netmask 255.255.255.0
Step 5: Implement Spanning Tree Protocol (STP)
STP is not comprised in the default INET framework, so we need to make the own module for STP.
Define the STP Module in .ned File
Create a .ned file for the STP module.
simple STP
{
parameters:
@display(“i=block/router”);
gates:
input fromLowerLayer[];
output toLowerLayer[];
}
Implement the STP Module in C++
Create the corresponding .cc and .h files.
STP.h
#ifndef __STP_H_
#define __STP_H_
#include <omnetpp.h>
#include <vector>
#include <map>
#include “inet/common/INETDefs.h”
#include “inet/linklayer/common/MacAddress.h”
using namespace omnetpp;
using namespace inet;
class STP : public cSimpleModule
{
private:
struct PortInfo {
int portNum;
bool isRootPort;
bool isDesignatedPort;
MacAddress designatedBridge;
int designatedPort;
int pathCost;
};
MacAddress bridgeId;
MacAddress rootId;
int rootPathCost;
int helloTime;
int maxAge;
int forwardDelay;
std::map<int, PortInfo> portTable;
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
void sendBPDU();
void processBPDU(cMessage *msg);
public:
STP();
virtual ~STP();
};
#endif
STP.cc
#include “STP.h”
Define_Module(STP);
STP::STP()
{
}
STP::~STP()
{
}
void STP::initialize()
{
bridgeId = MacAddress::generateAutoAddress();
rootId = bridgeId;
rootPathCost = 0;
helloTime = 2;
maxAge = 20;
forwardDelay = 15;
for (int i = 0; i < gateSize(“fromLowerLayer”); ++i) {
PortInfo portInfo = {i, false, true, bridgeId, i, 0};
portTable[i] = portInfo;
}
scheduleAt(simTime() + helloTime, new cMessage(“sendBPDU”));
}
void STP::handleMessage(cMessage *msg)
{
if (msg->isSelfMessage()) {
sendBPDU();
scheduleAt(simTime() + helloTime, msg);
} else {
processBPDU(msg);
}
}
void STP::sendBPDU()
{
for (auto& port : portTable) {
cMessage *bpdu = new cMessage(“BPDU”);
bpdu->addPar(“rootId”) = rootId.str().c_str();
bpdu->addPar(“rootPathCost”) = rootPathCost;
bpdu->addPar(“bridgeId”) = bridgeId.str().c_str();
bpdu->addPar(“portNum”) = port.second.portNum;
send(bpdu, “toLowerLayer”, port.second.portNum);
}
}
void STP::processBPDU(cMessage *msg)
{
MacAddress receivedRootId = MacAddress(msg->par(“rootId”).stringValue());
int receivedRootPathCost = msg->par(“rootPathCost”).intValue();
MacAddress receivedBridgeId = MacAddress(msg->par(“bridgeId”).stringValue());
int receivedPortNum = msg->par(“portNum”).intValue();
if (receivedRootId < rootId ||
(receivedRootId == rootId && receivedRootPathCost + 1 < rootPathCost) ||
(receivedRootId == rootId && receivedRootPathCost + 1 == rootPathCost && receivedBridgeId < bridgeId)) {
rootId = receivedRootId;
rootPathCost = receivedRootPathCost + 1;
for (auto& port : portTable) {
port.second.isRootPort = false;
}
portTable[receivedPortNum].isRootPort = true;
portTable[receivedPortNum].designatedBridge = receivedBridgeId;
portTable[receivedPortNum].designatedPort = receivedPortNum;
portTable[receivedPortNum].pathCost = receivedRootPathCost;
} else if (receivedRootId == rootId && receivedRootPathCost + 1 == rootPathCost && receivedBridgeId == bridgeId) {
portTable[receivedPortNum].isDesignatedPort = false;
}
delete msg;
}
Step 6: Integrate STP with Simulation Model
Integrate the STP module into a network simulation model.
Network Configuration .ned File
Extend the earlier EthernetLAN network definition to include STP.
network EthernetLANWithSTP
{
parameters:
@display(“bgb=600,400”);
submodules:
host1: StandardHost {
parameters:
@display(“p=100,200”);
}
host2: StandardHost {
parameters:
@display(“p=300,200”);
}
switch: EthernetSwitch {
parameters:
@display(“p=200,100”);
}
stp: STP {
parameters:
@display(“p=200,50”);
}
connections:
host1.ethg++ <–> Eth10M <–> switch.ethg++;
host2.ethg++ <–> Eth10M <–> switch.ethg++;
switch.ethg++ <–> Eth10M <–> stp.fromLowerLayer++;
}
Step 7: Test and Debug
Over this page, we are study about Ethernet, implement the STP, and how to execute LAN protocols in OMNeT++ tool using the INET framework. Our team specializes in LAN protocols, including Spanning Tree Protocol (STP), Ethernet, and Address Resolution Protocol (ARP) we have needed resourves to carry out your work. We offer expert implementation of these protocols in OMNeT++, and our developers are here to assist you with innovative topic ideas that are currently trending.