Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

Txc12 Class Reference

Inheritance diagram for Txc12:

cSimpleModule cModule cDefaultList cObject cPolymorphic 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.


Public Member Functions

 Module_Class_Members (Txc12, cSimpleModule, 0)
virtual TicTocMsg12 * generateMessage ()
virtual void forwardMessage (TicTocMsg12 *msg)
virtual void initialize ()
virtual void handleMessage (cMessage *msg)
virtual void finish ()

Protected Attributes

long numSent
long numReceived
cLongHistogram hopCountStats
cOutVector hopCountVector


Member Function Documentation

void Txc12::finish (   )  [virtual]
 

Reimplemented from cModule.

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

void Txc12::forwardMessage (  TicTocMsg12 *  msg  )  [virtual]
 

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

TicTocMsg12 * Txc12::generateMessage (   )  [virtual]
 

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

void Txc12::handleMessage (  cMessage *  msg  )  [virtual]
 

Reimplemented from cSimpleModule.

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

void Txc12::initialize (   )  [virtual]
 

Reimplemented from cModule.

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

Txc12::Module_Class_Members (  Txc12  ,
cSimpleModule  ,
0 
) 
 


Member Data Documentation

cLongHistogram Txc12::hopCountStats [protected]
 

cOutVector Txc12::hopCountVector [protected]
 

long Txc12::numReceived [protected]
 

long Txc12::numSent [protected]
 


The documentation for this class was generated from the following file:
Generated on Fri Apr 1 12:25:42 2005 for Tictoc Tutorial by  doxygen 1.3.9.1