Txc16 Class Reference

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

List of all members.

Protected Member Functions

virtual TicTocMsg16 * generateMessage ()
virtual void forwardMessage (TicTocMsg16 *msg)
virtual void initialize ()
virtual void handleMessage (cMessage *msg)

Private Attributes

simsignal_t arrivalSignal

Detailed Description

The main problem with the previous step is that we must modify the model's code if we want to change what statistics are gathered. Statistic calculation is woven deeply into the model code which is hard to modify and understand.

OMNeT++ 4.1 provides a different mechanism called 'signals' that we can use to gather statistics. First we have to identify the events where the state of the model changes. We can emit signals at these points that carry the value of chosen state variables. This way the C++ code only emits signals, but how those signals are processed are determined only by the listeners that are attached to them.

The signals the model emits and the listeners that process them can be defined in the NED file using the 'signal' and 'statistic' property.

We will gather the same statistics as in the previous step, but notice that we will not need any private member variables to calculate these values. We will use only a single signal that is emitted when a message arrives and carries the hopcount in the message.


Member Function Documentation

void Txc16::forwardMessage ( TicTocMsg16 *  msg  )  [protected, virtual]

Referenced by handleMessage().

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

TicTocMsg16 * Txc16::generateMessage (  )  [protected, virtual]

Referenced by handleMessage(), and initialize().

00091 {
00092     // Produce source and destination addresses.
00093     int src = getIndex();
00094     int n = size();
00095     int dest = intuniform(0,n-2);
00096     if (dest>=src) dest++;
00097 
00098     char msgname[20];
00099     sprintf(msgname, "tic-%d-to-%d", src, dest);
00100 
00101     // Create message object and set source and destination field.
00102     TicTocMsg16 *msg = new TicTocMsg16(msgname);
00103     msg->setSource(src);
00104     msg->setDestination(dest);
00105     return msg;
00106 }

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

Reimplemented from cSimpleModule.

00062 {
00063     TicTocMsg16 *ttmsg = check_and_cast<TicTocMsg16 *>(msg);
00064 
00065     if (ttmsg->getDestination()==getIndex())
00066     {
00067         // Message arrived
00068         int hopcount = ttmsg->getHopCount();
00069         // send a signal
00070         emit(arrivalSignal, hopcount);
00071 
00072         EV << "Message " << ttmsg << " arrived after " << hopcount << " hops.\n";
00073         bubble("ARRIVED, starting new one!");
00074 
00075         delete ttmsg;
00076 
00077         // Generate another one.
00078         EV << "Generating another message: ";
00079         TicTocMsg16 *newmsg = generateMessage();
00080         EV << newmsg << endl;
00081         forwardMessage(newmsg);
00082     }
00083     else
00084     {
00085         // We need to forward the message.
00086         forwardMessage(ttmsg);
00087     }
00088 }

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

Reimplemented from cComponent.

00050 {
00051     arrivalSignal = registerSignal("arrival");
00052     // Module 0 sends the first message
00053     if (getIndex()==0)
00054     {
00055         // Boot the process scheduling the initial message as a self-message.
00056         TicTocMsg16 *msg = generateMessage();
00057         scheduleAt(0.0, msg);
00058     }
00059 }


Member Data Documentation

simsignal_t Txc16::arrivalSignal [private]

Referenced by handleMessage(), and initialize().


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