Txc13 Class Reference

Inheritance diagram for Txc13:
cSimpleModule cModule cComponent cDefaultList cNoncopyableOwnedObject cOwnedObject noncopyable cNamedObject cObject

List of all members.

Protected Member Functions

virtual TicTocMsg13 * generateMessage ()
virtual void forwardMessage (TicTocMsg13 *msg)
virtual void initialize ()
virtual void handleMessage (cMessage *msg)

Detailed Description

In this step the destination address is no longer node 2 -- we draw a random destination, and we'll add the destination address to the message.

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 tictoc13.msg -- tictoc13_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.


Member Function Documentation

void Txc13::forwardMessage ( TicTocMsg13 *  msg  )  [protected, virtual]

Referenced by handleMessage().

00101 {
00102     // Increment hop count.
00103     msg->setHopCount(msg->getHopCount()+1);
00104 
00105     // Same routing as before: random gate.
00106     int n = gateSize("gate");
00107     int k = intuniform(0,n-1);
00108 
00109     EV << "Forwarding message " << msg << " on gate[" << k << "]\n";
00110     send(msg, "gate$o", k);
00111 }

TicTocMsg13 * Txc13::generateMessage (  )  [protected, virtual]

Referenced by handleMessage(), and initialize().

00083 {
00084     // Produce source and destination addresses.
00085     int src = getIndex();   // 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     TicTocMsg13 *msg = new TicTocMsg13(msgname);
00095     msg->setSource(src);
00096     msg->setDestination(dest);
00097     return msg;
00098 }

void Txc13::handleMessage ( cMessage msg  )  [protected, virtual]

Reimplemented from cSimpleModule.

00059 {
00060     TicTocMsg13 *ttmsg = check_and_cast<TicTocMsg13 *>(msg);
00061 
00062     if (ttmsg->getDestination()==getIndex())
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         TicTocMsg13 *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 }

void Txc13::initialize (  )  [protected, virtual]

Reimplemented from cComponent.

00048 {
00049     // Module 0 sends the first message
00050     if (getIndex()==0)
00051     {
00052         // Boot the process scheduling the initial message as a self-message.
00053         TicTocMsg13 *msg = generateMessage();
00054         scheduleAt(0.0, msg);
00055     }
00056 }


The documentation for this class was generated from the following file:
Generated on Tue Dec 2 11:16:33 2014 for Tictoc Tutorial by  doxygen 1.6.3