- Main Page
- Classes
- Files
- Directories
- Related Pages

- Class List
- Class Hierarchy
- Class Members

# Txc12 Class Reference

Inheritance diagram for Txc12:

List of all members.

## Detailed Description

This model is exciting enough so that we can collect some statistics. We'll record in output vectors the hop count of every message upon arrival. Output vectors are written into the omnetpp.vec file and can be visualized with the Plove program.

We also collect basic statistics (min, max, mean, std.dev.) and histogram about the hop count which we'll print out at the end of the simulation.

## Protected Member Functions
virtual TicTocMsg12 * | generateMessage ()
virtual void | forwardMessage (TicTocMsg12 *msg)
virtual void | initialize ()
virtual void | handleMessage (cMessage *msg)
virtual void | finish ()
## Private Attributes
long | numSent
long | numReceived
cLongHistogram | hopCountStats
cOutVector | hopCountVector

## Member Function Documentation

void Txc12::finish | ( |  | ) | `[protected, virtual]`

| Reimplemented from cModule.
    00131 {
    00132     // This function is called by OMNeT++ at the end of the simulation.
    00133     ev << "Sent:     " << numSent << endl;
    00134     ev << "Received: " << numReceived << endl;
    00135     ev << "Hop count, min:    " << hopCountStats.min() << endl;
    00136     ev << "Hop count, max:    " << hopCountStats.max() << endl;
    00137     ev << "Hop count, mean:   " << hopCountStats.mean() << endl;
    00138     ev << "Hop count, stddev: " << hopCountStats.stddev() << endl;
    00139
    00140     recordScalar("#sent", numSent);
    00141     recordScalar("#received", numReceived);
    00142     hopCountStats.recordScalar("hop count");
    00143 }

void Txc12::forwardMessage | ( | TicTocMsg12 * | msg | ) | `[protected, virtual]`

    00118 {
    00119     // Increment hop count.
    00120     msg->setHopCount(msg->getHopCount()+1);
    00121
    00122     // Same routing as before: random gate.
    00123     int n = gate("out")->size();
    00124     int k = intuniform(0,n-1);
    00125
    00126     ev << "Forwarding message " << msg << " on port out[" << k << "]\n";
    00127     send(msg, "out", k);
    00128 }

TicTocMsg12 * Txc12::generateMessage | ( |  | ) | `[protected, virtual]`

    00100 {
    00101     // Produce source and destination addresses.
    00102     int src = index();
    00103     int n = size();
    00104     int dest = intuniform(0,n-2);
    00105     if (dest>=src) dest++;
    00106
    00107     char msgname[20];
    00108     sprintf(msgname, "tic-%d-to-%d", src, dest);
    00109
    00110     // Create message object and set source and destination field.
    00111     TicTocMsg12 *msg = new TicTocMsg12(msgname);
    00112     msg->setSource(src);
    00113     msg->setDestination(dest);
    00114     return msg;
    00115 }

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

| Reimplemented from cSimpleModule.
    00068 {
    00069     TicTocMsg12 *ttmsg = check_and_cast<TicTocMsg12 *>(msg);
    00070
    00071     if (ttmsg->getDestination()==index())
    00072     {
    00073         // Message arrived
    00074         int hopcount = ttmsg->getHopCount();
    00075         ev << "Message " << ttmsg << " arrived after " << hopcount << " hops.\n";
    00076         bubble("ARRIVED, starting new one!");
    00077
    00078         // update statistics.
    00079         numReceived++;
    00080         hopCountVector.record(hopcount);
    00081         hopCountStats.collect(hopcount);
    00082
    00083         delete ttmsg;
    00084
    00085         // Generate another one.
    00086         ev << "Generating another message: ";
    00087         TicTocMsg12 *newmsg = generateMessage();
    00088         ev << newmsg << endl;
    00089         forwardMessage(newmsg);
    00090         numSent++;
    00091     }
    00092     else
    00093     {
    00094         // We need to forward the message.
    00095         forwardMessage(ttmsg);
    00096     }
    00097 }

void Txc12::initialize | ( |  | ) | `[protected, virtual]`

| Reimplemented from cModule.
    00047 {
    00048     // Initialize variables
    00049     numSent = 0;
    00050     numReceived = 0;
    00051     WATCH(numSent);
    00052     WATCH(numReceived);
    00053
    00054     hopCountStats.setName("hopCountStats");
    00055     hopCountStats.setRangeAutoUpper(0, 10, 1.5);
    00056     hopCountVector.setName("HopCount");
    00057
    00058     // Module 0 sends the first message
    00059     if (index()==0)
    00060     {
    00061         // Boot the process scheduling the initial message as a self-message.
    00062         TicTocMsg12 *msg = generateMessage();
    00063         scheduleAt(0.0, msg);
    00064     }
    00065 }

## Member Data Documentation

cLongHistogram Txc12::hopCountStats`[private]`

cOutVector Txc12::hopCountVector`[private]`

long Txc12::numReceived`[private]`

long Txc12::numSent`[private]`

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

- txc12.cc