Tictoc Tutorial 10: Exercise

726 views
Skip to first unread message

Mohd Adib Sarijari

unread,
Apr 19, 2012, 9:35:09 AM4/19/12
to omn...@googlegroups.com
Dear all,

In tictoc tutorial 10, there is an exercise given (at the bottom of the tutorial) on editing the code so that the msg will not pass back to the source node. I try to do it with editing the forwardMessege function:

void Txc10::forwardMessage(cMessage *msg)
{   const cGate* p = msg->getArrivalGate();
    const int id = p->getIndex();
    while(k == id)  k = intuniform(0,n-1);
   //and the rest of the code.

}

however, when i run the code (build with no error), the simulator is hang such that it is contained a blocking code. i found out that the one who block the code is const int id = p->getIndex(); ..

does any one know why? i think it is because the getIndex() function? is this a blocking function?

and how to answer the exercise actually?

appreciate any guide.

Adib


nael zuriek

unread,
Apr 19, 2012, 10:15:14 AM4/19/12
to omn...@googlegroups.com
I didn't remember what i did to make that happens (it's just long time
when i started learning Omnet++ ) , but here are the whole
forwardMessage Function :

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

Rudolf Hornig

unread,
Apr 19, 2012, 10:24:04 AM4/19/12
to omn...@googlegroups.com
No, you have obviously written an infinite loop:

while(k == id)  k = intuniform(0,n-1);

you should always avoid such constructs. If id<0 or id>=n this is a guaranteed infinite loop, for other values the runtime is still unlimited.

Mohd Adib Sarijari

unread,
Apr 19, 2012, 10:53:47 AM4/19/12
to omn...@googlegroups.com

Thanks Naeel and Rudolf.

@Naeel
Thanks for the code. however, your code still not solving the prob. as there is no  checking k value on your code. however, it is interesting to see that you are using getSenderModule(); instead getArrivalGate();? what is the different?

i had check that if you do getIndex(); form getSenderModule(); there will be no prob. however, if you use getIndex(); from getArrivalGate(); then your program will hang. any idea why?

@ Rudolf
thanks for the input. yes it will be a blocking instruction and i purposely do this to get the k value different form the id right? so that i will not send to the same port and it will solve the ping pong prob?

if not, do you have suggestion?

appreciate all reply so much. thanks for the effort.

Adib

nael zuriek

unread,
Apr 19, 2012, 7:31:52 PM4/19/12
to omn...@googlegroups.com
try this :

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 !!

nael zuriek

unread,
Apr 19, 2012, 7:48:46 PM4/19/12
to omn...@googlegroups.com
try this very simple "else" code for the last if statement :

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 !!

Mohd Adib Sarijari

unread,
Apr 19, 2012, 10:14:26 PM4/19/12
to omn...@googlegroups.com
Thanks Naeel for the suggestion. its a good alternative. however, this is causing the same prob. as what i have from the start. you can compiled the code without error, however, your simulator will hang when you run it.

this is what i said the problem is. I think the C++ syntax is correct. but, not sure why it caused hang.

your previous code is ok (using getArrivalModule(); instead getArrivalGate(); ) i wonder why is that? what is the different between this two function?any idea?

Mohd Adib Sarijari

unread,
Apr 20, 2012, 4:29:58 AM4/20/12
to omn...@googlegroups.com

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?

Rudolf Hornig

unread,
Apr 20, 2012, 5:14:03 AM4/20/12
to omn...@googlegroups.com


On Friday, April 20, 2012 10:29:58 AM UTC+2, Mohd Adib Sarijari wrote:

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++;

No, not after the sending process. The NED describes the topology of your network. It means connect the next free out gate on tic[0] with the next free in gate on tic[1]
 
is it to increased the port number (the gart number) after the sending process?
Yes it increaes the current (implicit gate number) but NOT after sending, but during the network buildup.

 

Carlo

unread,
Apr 22, 2012, 5:08:31 AM4/22/12
to omn...@googlegroups.com

nael zuriek

unread,
Apr 22, 2012, 10:45:16 AM4/22/12
to omn...@googlegroups.com
yeah , tnx Carlo , it is a very good solution !

Carlo

unread,
Apr 23, 2012, 6:08:35 AM4/23/12
to omn...@googlegroups.com
Message has been deleted

Mohd Adib Sarijari

unread,
Apr 23, 2012, 7:02:33 AM4/23/12
to omn...@googlegroups.com
Dear Carlo,
thank you so much for the link. now, it answer my question on why its hang if i execute the index() instruction.

    //int arrivalGateIndex = arrivalGate->getIndex(); // null pointer exception runtime error
                                          // because the first message sent by scheduleAt is a self-message

and also thanks to all who did response to my question. appreciate it much.

regards.

Carlo

unread,
Apr 23, 2012, 8:24:59 AM4/23/12
to omn...@googlegroups.com
Thank you Mohd :)
Are you able to answer my question?:)
https://groups.google.com/d/topic/omnetpp/njxpTnpoHVM/discussion

Mohd Adib Sarijari

unread,
Apr 23, 2012, 10:12:59 AM4/23/12
to omn...@googlegroups.com, carlo....@gmail.com
do you received my response carlo? i think my post was deleted. hope you did received it in your email.

best regard,
Adib

Message has been deleted

Mohd Adib Sarijari

unread,
Apr 23, 2012, 11:16:53 AM4/23/12
to omn...@googlegroups.com, carlo....@gmail.com
again, my post is being deleted. do anybody know why? admin? am i doing or posting something that is not allowed?

please help me on this.

Adib

Mohd Adib Sarijari

unread,
Apr 23, 2012, 11:21:06 AM4/23/12
to omn...@googlegroups.com, Carlo Liuzza
again it is deleted. luckily i had made a copy.


regarding carlo inquiries:

i think you are referring to the tictoc tutorial 13 c++ file and the code is as follows:

    // Produce source and destination addresses.
    int src = getIndex();   // our module index
    int n = size();      // module vector size
    int dest = intuniform(0,n-2);
    if (dest>=src) dest++;

this is only one of the way to obtain random destination number from the available nodes in the network and avoid choosing the same destination number with the source number.

the code could be explained as below:

int src = getIndex();   // our module index <Is as the comment said, this is to get the node id number>
int n = size();      // module vector size <as everyone know, this is to get the size of the network- how many nodes in the network>

int dest = intuniform(0,n-2);
this is the code that carlo is asking. it minus by 2 because in the next line it will further increased the destination number by one (if dest>=src). its noting fancy abut this, the purpose of this code and the following code is to get a random destination number from the available nodes in the network. with this code, int dest = intuniform(0,n-2); the possible number for dest is = {0,1,2,3 and 4}

if (dest>=src) dest++;
this code is purposely used to avoid the generator to chose the same number for the destination with the source. after this code, the possible number for dest is as follow:

say that there is 6 nodes in the network (id = 0 to 5). and the current node number (src) = 1,

so the dest value after this line is:

if dest = 0 after dest = intuniform(0,n-2);, then dest = 0 after if (dest>=src) dest++;
if dest = 1 after dest = intuniform(0,n-2);, then dest = 2 after if (dest>=src) dest++;
if dest = 2 after dest = intuniform(0,n-2);, then dest = 3 after if (dest>=src) dest++;
if dest = 3 after dest = intuniform(0,n-2);, then dest = 4 after if (dest>=src) dest++;
if dest = 4 after dest = intuniform(0,n-2);, then dest = 5 after if (dest>=src) dest++;

so it does cover all nodes number and also avoid the same destination number as the source. however, this is one of the way of doing it. you could do it as you like as long as it complied to your requirements.

hope this help. good luck.

regards.
Reply all
Reply to author
Forward
0 new messages