# Txc11 Class Reference

Inheritance diagram for Txc11:

List of all members.

## Detailed Description

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

## Protected Member Functions

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

## Private Attributes

long | numSent
long | numReceived

## Member Function Documentation

void Txc11::forwardMessage | ( | TicTocMsg11 * | msg | ) | `[protected, virtual]`

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

TicTocMsg11 * Txc11::generateMessage | ( |  | ) | `[protected, virtual]`

    00086 {
    00087     // Produce source and destination addresses.
    00088     int src = index();   // 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     TicTocMsg11 *msg = new TicTocMsg11(msgname);
    00098     msg->setSource(src);
    00099     msg->setDestination(dest);
    00100     return msg;
    00101 }

void Txc11::handleMessage | ( | cMessage * | msg | ) | `[protected, virtual]`

Reimplemented from cSimpleModule.

    00056 {
    00057     TicTocMsg11 *ttmsg = check_and_cast<TicTocMsg11 *>(msg);
    00058
    00059     if (ttmsg->getDestination()==index())
    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         TicTocMsg11 *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 Txc11::initialize | ( |  | ) | `[protected, virtual]`

Reimplemented from cModule.

    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 (index()==0)
    00048     {
    00049         // Boot the process scheduling the initial message as a self-message.
    00050         TicTocMsg11 *msg = generateMessage();
    00051         scheduleAt(0.0, msg);
    00052     }
    00053 }

void Txc11::updateDisplay | ( |  | ) | `[protected, virtual]`

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

## Member Data Documentation

long Txc11::numReceived`[private]`

long Txc11::numSent`[private]`

The documentation for this class was generated from the following file:

- txc11.cc