To implement the star protocol in OMNeT++ has embraced to generate the network topology and describe the communication pattern for the nodes. A star network topology is one where all nodes are connected to a central hub or switch. We have the necessary resources to carry on your projects so drop us a message we provide you with simulation results.
This procedure will show how to implement the start protocols in OMNeT++ tool:
Step-by-Step Implementation:
Step 1: Set Up OMNeT++ and INET Framework
Step 2: Define the Star Network Topology
Create a .ned file to define the star network topology.
network StarNetwork
{
parameters:
@display(“bgb=600,400”);
submodules:
hub: StandardHost {
parameters:
@display(“p=300,200”);
}
node1: StandardHost {
parameters:
@display(“p=100,100”);
}
node2: StandardHost {
parameters:
@display(“p=100,300”);
}
node3: StandardHost {
parameters:
@display(“p=500,100”);
}
node4: StandardHost {
parameters:
@display(“p=500,300”);
}
connections:
hub.pppg++ <–> Eth10M <–> node1.pppg++;
hub.pppg++ <–> Eth10M <–> node2.pppg++;
hub.pppg++ <–> Eth10M <–> node3.pppg++;
hub.pppg++ <–> Eth10M <–> node4.pppg++;
}
Step 3: Define the Protocol
Create a Simple Communication Protocol
For demonstration purposes, we will generate a basic communication protocol where nodes send messages to the hub, and the hub forwards these messages to a particular node.
Define the Module in .ned File
Create a .ned file for the protocol.
simple StarProtocol
{
parameters:
@display(“i=block/application”);
double sendInterval @unit(s) = default(1s); // Interval for sending messages
string destinationNode = default(“”); // Destination node address
gates:
input fromNetworkLayer;
output toNetworkLayer;
}
Implement the Module in C++
Create the corresponding .cc and .h files.
StarProtocol.h
#ifndef __STARPROTOCOL_H_
#define __STARPROTOCOL_H_
#include <omnetpp.h>
#include “inet/common/INETDefs.h”
#include “inet/networklayer/contract/IInterfaceTable.h”
#include “inet/networklayer/common/L3Address.h”
#include “inet/networklayer/common/L3AddressResolver.h”
#include “inet/applications/base/ApplicationBase.h”
using namespace omnetpp;
using namespace inet;
class StarProtocol : public ApplicationBase
{
private:
cMessage *sendMsgEvent;
double sendInterval;
std::string destinationNode;
L3Address destAddr;
protected:
virtual void initialize(int stage) override;
virtual void handleMessageWhenUp(cMessage *msg) override;
virtual void handleSelfMessage(cMessage *msg);
virtual void sendPacket();
virtual void receivePacket(cMessage *msg);
public:
StarProtocol();
virtual ~StarProtocol();
};
#endif
StarProtocol.cc
#include “StarProtocol.h”
Define_Module(StarProtocol);
StarProtocol::StarProtocol() : sendMsgEvent(nullptr), sendInterval(1.0), destAddr(L3Address::UNSPECIFIED_ADDRESS)
{
}
StarProtocol::~StarProtocol()
{
cancelAndDelete(sendMsgEvent);
}
void StarProtocol::initialize(int stage)
{
ApplicationBase::initialize(stage);
if (stage == INITSTAGE_LOCAL)
{
sendInterval = par(“sendInterval”);
destinationNode = par(“destinationNode”).stdstringValue();
sendMsgEvent = new cMessage(“sendEvent”);
}
else if (stage == INITSTAGE_ROUTING)
{
destAddr = L3AddressResolver().resolve(destinationNode.c_str());
}
if (isNodeUp())
scheduleAt(simTime() + sendInterval, sendMsgEvent);
}
void StarProtocol::handleMessageWhenUp(cMessage *msg)
{
if (msg->isSelfMessage())
{
handleSelfMessage(msg);
}
else
{
receivePacket(msg);
}
}
void StarProtocol::handleSelfMessage(cMessage *msg)
{
sendPacket();
scheduleAt(simTime() + sendInterval, sendMsgEvent);
}
void StarProtocol::sendPacket()
{
if (destAddr.isUnspecified())
return;
auto packet = new cPacket(“DataPacket”);
packet->addPar(“destAddr”) = destAddr.str().c_str();
send(packet, “toNetworkLayer”);
}
void StarProtocol::receivePacket(cMessage *msg)
{
cPacket *packet = check_and_cast<cPacket *>(msg);
L3Address srcAddr = L3AddressResolver().resolve(packet->par(“srcAddr”).stringValue());
EV << “Received packet from ” << srcAddr << endl;
delete packet;
}
Step 4: Integrate the Protocol with the Network
Incorporate StarProtocol module into the network simulation model.
Update the Network Configuration .ned File
Modify the .ned file to use the StarProtocol module.
network StarNetwork
{
parameters:
@display(“bgb=600,400”);
submodules:
hub: StandardHost {
parameters:
@display(“p=300,200”);
@labels(“hub”);
}
node1: StandardHost {
parameters:
@display(“p=100,100”);
@labels(“node”);
}
node2: StandardHost {
parameters:
@display(“p=100,300”);
@labels(“node”);
}
node3: StandardHost {
parameters:
@display(“p=500,100”);
@labels(“node”);
}
node4: StandardHost {
parameters:
@display(“p=500,300”);
@labels(“node”);
}
connections:
hub.pppg++ <–> Eth10M <–> node1.pppg++;
hub.pppg++ <–> Eth10M <–> node2.pppg++;
hub.pppg++ <–> Eth10M <–> node3.pppg++;
hub.pppg++ <–> Eth10M <–> node4.pppg++;
}
Step 5: Configure the Simulation
Configure the simulation parameters in the omnetpp.ini file.
network = StarNetwork
**.hub.numApps = 1
**.hub.app[0].typename = “StarProtocol”
**.hub.app[0].destinationNode = “node1”
**.hub.app[0].sendInterval = 1s
**.node*.numApps = 1
**.node*.app[0].typename = “StarProtocol”
**.node*.app[0].destinationNode = “hub”
**.node*.app[0].sendInterval = 2s
**.pppg[*].queue.typename = “DropTailQueue”
**.ipv4.routingTable = “inet.networklayer.routing.manet.Router”
Step 6: Test and Debug
Here, we clearly demonstrate how to set up a basic star topology and implement a simple protocol for communication between the nodes and the central hub. We plan to provide the additional information on how to implement the start topology in other simulation settings.