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

Txc10 Class Reference

Inheritance diagram for Txc10:

cSimpleModule cModule cDefaultList cObject cPolymorphic List of all members.

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 tictoc10.msg -- tictoc10_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.


Private Member Functions

 Module_Class_Members (Txc10, cSimpleModule, 0)
virtual TicTocMsg10 * generateMessage ()
virtual void forwardMessage (TicTocMsg10 *msg)
virtual void initialize ()
virtual void handleMessage (cMessage *msg)


Member Function Documentation

void Txc10::forwardMessage (  TicTocMsg10 *  msg  )  [private, virtual]
 

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

TicTocMsg10 * Txc10::generateMessage (   )  [private, virtual]
 

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

void Txc10::handleMessage (  cMessage *  msg  )  [private, virtual]
 

Reimplemented from cSimpleModule.

00060 {
00061     TicTocMsg10 *ttmsg = check_and_cast<TicTocMsg10 *>(msg);
00062 
00063     if (ttmsg->getDestination()==index())
00064     {
00065         // Message arrived.
00066         ev << "Message " << ttmsg << " arrived after " << ttmsg->getHopCount() << " hops.\n";
00067         bubble("ARRIVED, starting new one!");
00068         delete ttmsg;
00069 
00070         // Generate another one.
00071         ev << "Generating another message: ";
00072         TicTocMsg10 *newmsg = generateMessage();
00073         ev << newmsg << endl;
00074         forwardMessage(newmsg);
00075     }
00076     else
00077     {
00078         // We need to forward the message.
00079         forwardMessage(ttmsg);
00080     }
00081 }

void Txc10::initialize (   )  [private, virtual]
 

Reimplemented from cModule.

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

Txc10::Module_Class_Members (  Txc10  ,
cSimpleModule  ,
0 
)  [private]
 


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