void tx10::forwardMessage(cMessage *msg)
{
cModule *t = msg->getSenderModule();
int sn = t->getIndex();
EV << "Sender Module Index = " << sn << "\n";
cModule *th = msg->getArrivalModule();
int ar = th->getIndex();
EV << "Arrival Module Index = " << ar << "\n";
int n = gateSize("out");
int k = intuniform(0,n-1);
EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
send (msg , "out" , k);
}
> --
> Sent from the OMNeT++ mailing list. To configure your membership,
> visit http://groups.google.com/group/omnetpp
int a = msg->getArrivalGate()->getIndex();
int n = gateSize("out");
int k = intuniform(0,n-1);
if (k != a)
{
EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
send (msg , "out" , k);
}
but you need to enhance this code for the "else" statement cuz it will
terminate run if "k == a" !!
waiting for your suggestions !!
else
{
k = k + 1;
if (k == n)
{
k = k -1;
send(msg , "out" , k);
}
else
send(msg , "out" , k);
}
the results are impressive , the message you create arrives quickly this time !!
thanks for every reply, however, i am still not able to solve the prob.
i had notice that the getArrivalGate(); function return the value of the gate (port) where the data is comming from (by using getIndex(); ) while getSenderModule(); is returning the node number instead the gate number. right?
and..
i have a another question regarding tutorial 10. what is the usage of ++ sign in this command: tic[0].out++ --> { delay = 100ms; } --> tic[1].in++;
is it to increased the port number (the gart number) after the sending process?
//int arrivalGateIndex = arrivalGate->getIndex(); // null pointer exception runtime error
// because the first message sent by scheduleAt is a self-message