Txc14 Class Reference

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

List of all members.

Protected Member Functions

virtual TicTocMsg14 * generateMessage ()
virtual void forwardMessage (TicTocMsg14 *msg)
virtual void updateDisplay ()
virtual void initialize ()
virtual void handleMessage (cMessage *msg)

Private Attributes

long numSent
long numReceived

Detailed Description

In this step we keep track of how many messages we send and received, and display it above the icon.


Member Function Documentation

void Txc14::forwardMessage ( TicTocMsg14 *  msg  )  [protected, virtual]

Referenced by handleMessage().

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

TicTocMsg14 * Txc14::generateMessage (  )  [protected, virtual]

Referenced by handleMessage(), and initialize().

00086 {
00087     // Produce source and destination addresses.
00088     int src = getIndex();   // our module index
00089     int n = size();      // module vector size
00090     int dest = intuniform(0,n-2);
00091     if (dest>=src) dest++;
00092 
00093     char msgname[20];
00094     sprintf(msgname, "tic-%d-to-%d", src, dest);
00095 
00096     // Create message object and set source and destination field.
00097     TicTocMsg14 *msg = new TicTocMsg14(msgname);
00098     msg->setSource(src);
00099     msg->setDestination(dest);
00100     return msg;
00101 }

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

Reimplemented from cSimpleModule.

00056 {
00057     TicTocMsg14 *ttmsg = check_and_cast<TicTocMsg14 *>(msg);
00058 
00059     if (ttmsg->getDestination()==getIndex())
00060     {
00061         // Message arrived
00062         int hopcount = ttmsg->getHopCount();
00063         EV << "Message " << ttmsg << " arrived after " << hopcount << " hops.\n";
00064         numReceived++;
00065         delete ttmsg;
00066         bubble("ARRIVED, starting new one!");
00067 
00068         // Generate another one.
00069         EV << "Generating another message: ";
00070         TicTocMsg14 *newmsg = generateMessage();
00071         EV << newmsg << endl;
00072         forwardMessage(newmsg);
00073         numSent++;
00074 
00075         if (ev.isGUI())
00076             updateDisplay();
00077     }
00078     else
00079     {
00080         // We need to forward the message.
00081         forwardMessage(ttmsg);
00082     }
00083 }

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

Reimplemented from cComponent.

00039 {
00040     // Initialize variables
00041     numSent = 0;
00042     numReceived = 0;
00043     WATCH(numSent);
00044     WATCH(numReceived);
00045 
00046     // Module 0 sends the first message
00047     if (getIndex()==0)
00048     {
00049         // Boot the process scheduling the initial message as a self-message.
00050         TicTocMsg14 *msg = generateMessage();
00051         scheduleAt(0.0, msg);
00052     }
00053 }

void Txc14::updateDisplay (  )  [protected, virtual]

Referenced by handleMessage().

00117 {
00118     char buf[40];
00119     sprintf(buf, "rcvd: %ld sent: %ld", numReceived, numSent);
00120     getDisplayString().setTagArg("t",0,buf);
00121 }


Member Data Documentation

long Txc14::numReceived [private]
long Txc14::numSent [private]

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