Reputation: 152
Below is the C++ and .ned file code. I have 3 modules tic,tac and toc. I want the message to traverse each module only once, but after few events the program becomes unresponsive? Specifically, When the message reaches toc after few iterations! If there any other workaround please let me know. Sorry for me being a newbie.
void Txc1::handleMessage(cMessage *msg)
{
counter++;
int n= gateSize("out");
int k = intuniform(0,gateSize("out")-1);
cGate *arrivalGate = msg->getArrivalGate();
cGate *depGate = msg ->getSenderGate();
if(arrivalGate != NULL)
{
int gate = arrivalGate->getIndex();
int gate_out = depGate ->getIndex();
EV<<"Arrival Gate: "<<gate<<endl;
EV<<"Departure Gate: "<<gate_out<<endl;
if(n >= 2)
{
while(gate==k){
k = gate_out;
}
}
}
else
EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
send(msg, "out", k);
}
-----.NED-------
simple Txc1
{
gates:
input in[];
output out[];
}
network Tictoc1
{
submodules:
tic: Txc1;
toc: Txc1;
tac: Txc1;
connections:
tic.out++ --> { delay = 100ms; } --> toc.in++;
tic.in++ <-- { delay = 100ms; } <-- toc.out++;
toc.out++ --> { delay = 100ms; } --> tac.in++;
tac.in++ <-- { delay = 100ms; } <-- toc.out++;
tac.out++ --> { delay = 100ms; } --> toc.in++;
}
Upvotes: 0
Views: 404
Reputation: 26
It looks like tic and toc will just talk to each other forever:
tic.out++ --> { delay = 100ms; } --> toc.in++;
tic.in++ <-- { delay = 100ms; } <-- toc.out++;
As the tic "out" gate messages the toc "in" gate and also the toc "out" gate messages the toc "in" gate so it will just go around in circles.
I don't understand what you're trying to do exactly in the module source code. I'd go back to the Example TicToc project which comes with latest OMNeT++ versions and look closely at how the connections talk to eachother. This is more what you would want for connections:
tic.out++ --> { delay = 100ms; } --> toc.in++;
tac.in++ <-- { delay = 100ms; } <-- toc.out++;
tac.out++ --> { delay = 100ms; } --> tic.in++;
So it goes tic - toc - tac.
Upvotes: 1