
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 TicTocMsg15 * | generateMessage () |
| virtual void | forwardMessage (TicTocMsg15 *msg) |
| virtual void | initialize () |
| virtual void | handleMessage (cMessage *msg) |
| virtual void | finish () |
Private Attributes | |
| long | numSent |
| long | numReceived |
| cLongHistogram | hopCountStats |
| cOutVector | hopCountVector |
| TicTocMsg15 * Txc15::generateMessage | ( | ) | [protected, virtual] |
Referenced by handleMessage(), and initialize().
00100 { 00101 // Produce source and destination addresses. 00102 int src = getIndex(); 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 TicTocMsg15 *msg = new TicTocMsg15(msgname); 00112 msg->setSource(src); 00113 msg->setDestination(dest); 00114 return msg; 00115 }
| void Txc15::forwardMessage | ( | TicTocMsg15 * | msg | ) | [protected, virtual] |
Referenced by handleMessage().
00118 { 00119 // Increment hop count. 00120 msg->setHopCount(msg->getHopCount()+1); 00121 00122 // Same routing as before: random gate. 00123 int n = gateSize("gate"); 00124 int k = intuniform(0,n-1); 00125 00126 EV << "Forwarding message " << msg << " on gate[" << k << "]\n"; 00127 send(msg, "gate$o", k); 00128 }
| void Txc15::initialize | ( | ) | [protected, virtual] |
Reimplemented from cComponent.
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 (getIndex()==0) 00060 { 00061 // Boot the process scheduling the initial message as a self-message. 00062 TicTocMsg15 *msg = generateMessage(); 00063 scheduleAt(0.0, msg); 00064 } 00065 }
| void Txc15::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Reimplemented from cSimpleModule.
00068 { 00069 TicTocMsg15 *ttmsg = check_and_cast<TicTocMsg15 *>(msg); 00070 00071 if (ttmsg->getDestination()==getIndex()) 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 TicTocMsg15 *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 Txc15::finish | ( | ) | [protected, virtual] |
Reimplemented from cComponent.
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.getMin() << endl; 00136 EV << "Hop count, max: " << hopCountStats.getMax() << endl; 00137 EV << "Hop count, mean: " << hopCountStats.getMean() << endl; 00138 EV << "Hop count, stddev: " << hopCountStats.getStddev() << endl; 00139 00140 recordScalar("#sent", numSent); 00141 recordScalar("#received", numReceived); 00142 00143 hopCountStats.recordAs("hop count"); 00144 }
long Txc15::numSent [private] |
Referenced by finish(), handleMessage(), and initialize().
long Txc15::numReceived [private] |
Referenced by finish(), handleMessage(), and initialize().
cLongHistogram Txc15::hopCountStats [private] |
Referenced by finish(), handleMessage(), and initialize().
cOutVector Txc15::hopCountVector [private] |
Referenced by handleMessage(), and initialize().
1.5.5