Inheritance diagram for Txc10:

The best way is to subclass cMessage and add destination as a data member. Hand-coding the message class is usually tiresome because it contains a lot of boilerplate code, so we let OMNeT++ generate the class for us. The message class specification is in tictoc10.msg -- tictoc10_m.h and .cc will be generated from this file automatically.
To make the model execute longer, after a message arrives to its destination the destination node will generate another message with a random destination address, and so forth.
Protected Member Functions | |
| virtual TicTocMsg10 * | generateMessage () |
| virtual void | forwardMessage (TicTocMsg10 *msg) |
| virtual void | initialize () |
| virtual void | handleMessage (cMessage *msg) |
|
|
00101 {
00102 // Increment hop count.
00103 msg->setHopCount(msg->getHopCount()+1);
00104
00105 // Same routing as before: random gate.
00106 int n = gate("out")->size();
00107 int k = intuniform(0,n-1);
00108
00109 ev << "Forwarding message " << msg << " on port out[" << k << "]\n";
00110 send(msg, "out", k);
00111 }
|
|
|
00083 {
00084 // Produce source and destination addresses.
00085 int src = index(); // our module index
00086 int n = size(); // module vector size
00087 int dest = intuniform(0,n-2);
00088 if (dest>=src) dest++;
00089
00090 char msgname[20];
00091 sprintf(msgname, "tic-%d-to-%d", src, dest);
00092
00093 // Create message object and set source and destination field.
00094 TicTocMsg10 *msg = new TicTocMsg10(msgname);
00095 msg->setSource(src);
00096 msg->setDestination(dest);
00097 return msg;
00098 }
|
|
|
Reimplemented from cSimpleModule. 00059 {
00060 TicTocMsg10 *ttmsg = check_and_cast<TicTocMsg10 *>(msg);
00061
00062 if (ttmsg->getDestination()==index())
00063 {
00064 // Message arrived.
00065 ev << "Message " << ttmsg << " arrived after " << ttmsg->getHopCount() << " hops.\n";
00066 bubble("ARRIVED, starting new one!");
00067 delete ttmsg;
00068
00069 // Generate another one.
00070 ev << "Generating another message: ";
00071 TicTocMsg10 *newmsg = generateMessage();
00072 ev << newmsg << endl;
00073 forwardMessage(newmsg);
00074 }
00075 else
00076 {
00077 // We need to forward the message.
00078 forwardMessage(ttmsg);
00079 }
00080 }
|
|
|
Reimplemented from cModule. 00048 {
00049 // Module 0 sends the first message
00050 if (index()==0)
00051 {
00052 // Boot the process scheduling the initial message as a self-message.
00053 TicTocMsg10 *msg = generateMessage();
00054 scheduleAt(0.0, msg);
00055 }
00056 }
|
1.4.1