Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

Nodes sending messages to Hub

I would like to write an OMNET++ program where there are 5 nodes connected to a hub. The requirements are each node will send 10 messages per second to the hub. Upon received of the message, the hub will forward the message to all nodes except the sender. I have written Hub.cc. The content of Hub.cc is as below:

#include<omnetpp.h>
class Hub:public cSimpleModule
{
protected:
virtual void initialize();
virtual void
handleMessage(cMessage *msg);
virtual void finish();
};
Define_Module(Hub); 

void Hub::handleMessage(cMessage *msg)
{
cGate *g= msg->getArrivalGate();
int i;
for(i=0;i<g->size();i++)
{
if(i!=g->getIndex())
send(msg->dup(),"out",i);
}
}

And I have created the Hub.ned file with the content as below:

Simple Hub
{
     gates:
           input  in[];
           output out[];

}

I have created Net2.ned with contents as below:

network Net2
{ parameters:
int n_nodes;
submodules:
hub: Hub;
node[n_nodes]: Node ;
connections:
for i=0..n_nodes-1
{
node[i].out --> hub.in++;
hub.out++ --> node[i].in;
}
}

I have created omnetpp2.ini and added the following code to this file:

**.n_nodes = 5

I need help on writing code for the nodes to send messages to hub.

question from:https://stackoverflow.com/questions/65829418/nodes-sending-messages-to-hub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...