#include <KBRTestApp.h>

Test application for KBR interface that sends periodically test messages to random keys or existing nodeIDs. The receiver does not send back any answer, but sender::evaluateDate() is called.
Definition at line 42 of file KBRTestApp.h.
Public Member Functions | |
| KBRTestApp () | |
| ~KBRTestApp () | |
Private Types | |
| typedef std::vector< MsgHandle > | MsgHandleBuf |
Private Member Functions | |
| void | initializeApp (int stage) |
| initializes derived class-attributes | |
| void | finishApp () |
| collects statistical data of derived app | |
| void | handleTimerEvent (cMessage *msg) |
| processes self-messages | |
| void | deliver (OverlayKey &key, cMessage *msg) |
| Common API function: handles delivered messages from overlay. | |
| void | forward (OverlayKey *key, cPacket **msg, NodeHandle *nextHopNode) |
| Common API function: handles messages from overlay to be forwarded. | |
| bool | checkSeen (const OverlayKey &key, int seqNum) |
| Checks if a message was already seen before. | |
| void | evaluateData (simtime_t timeDelay, int hopCount, long int bytes) |
| Analyses and records measuring data handed over from nodes that previously had been the destination for a test message from this module, called by receiver::handleMessage() at sendermodule. | |
| void | handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt) |
| This method is called if an RPC response has been received. | |
| void | handleLookupResponse (LookupResponse *msg) |
| void | pingResponse (PingResponse *response, cPolymorphic *context, int rpcId, simtime_t rtt) |
| virtual void | handleNodeLeaveNotification () |
| This method gets call **.gracefulLeaveDelay seconds before it is killed. | |
Private Attributes | |
| double | mean |
| mean time interval between sending test messages | |
| double | deviation |
| deviation of time interval | |
| bool | activeNetwInitPhase |
| is app active in network init phase? | |
| bool | lookupNodeIds |
| lookup only existing nodeIDs | |
| bool | nodeIsLeavingSoon |
| true if the node is going to be killed shortly | |
| int | numDelivered |
| number of delivered packets | |
| int | bytesDelivered |
| number of delivered bytes | |
| int | numDropped |
| int | bytesDropped |
| cMessage * | testTimer |
| uint32_t | sequenceNumber |
| int | msgHandleBufSize |
| how many MsgHandles to store in circular buffer | |
| MsgHandleBuf | mhBuf |
| circular buffer of MsgHandles | |
| MsgHandleBuf::iterator | mhBufBegin |
| begin of circular buffer | |
| MsgHandleBuf::iterator | mhBufNext |
| next element to insert | |
| MsgHandleBuf::iterator | mhBufEnd |
| end of circular buffer | |
Classes | |
| struct | MsgHandle |
| type for storing seen messages in a circular buffer, holds OverlayKey of the sender and SequenceNumber More... | |
typedef std::vector<MsgHandle> KBRTestApp::MsgHandleBuf [private] |
Definition at line 72 of file KBRTestApp.h.
| KBRTestApp::KBRTestApp | ( | ) |
| KBRTestApp::~KBRTestApp | ( | ) |
| void KBRTestApp::initializeApp | ( | int | stage | ) | [private, virtual] |
initializes derived class-attributes
| stage | the init stage |
Reimplemented from BaseApp.
Definition at line 45 of file KBRTestApp.cc.
00046 { 00047 if (stage != MIN_STAGE_APP) { 00048 return; 00049 } 00050 00051 lookupNodeIds = par("lookupNodeIds"); 00052 mean = par("testMsgInterval"); 00053 deviation = mean / 10; 00054 activeNetwInitPhase = par("activeNetwInitPhase"); 00055 msgHandleBufSize = par("msgHandleBufSize"); 00056 00057 numDelivered = 0; 00058 bytesDelivered = 0; 00059 WATCH(numDelivered); 00060 WATCH(bytesDelivered); 00061 00062 numDropped = 0; 00063 bytesDropped = 0; 00064 WATCH(numDropped); 00065 WATCH(bytesDropped); 00066 00067 sequenceNumber = 0; 00068 00069 nodeIsLeavingSoon = false; 00070 00071 // initialize circular buffer 00072 if (msgHandleBufSize > 0) { 00073 mhBuf.resize(msgHandleBufSize); 00074 mhBufBegin = mhBuf.begin(); 00075 mhBufEnd = mhBuf.end(); 00076 mhBufNext = mhBufBegin; 00077 } 00078 00079 #if 0 00080 bindToPort(1025); 00081 thisNode.port = 1025; 00082 #endif 00083 00084 // start periodic timer 00085 testTimer = new cMessage("KBRTestApp Timer"); 00086 scheduleAt(simTime() + truncnormal(mean, deviation), testTimer); 00087 }
| void KBRTestApp::finishApp | ( | ) | [private, virtual] |
collects statistical data of derived app
Reimplemented from BaseApp.
Definition at line 285 of file KBRTestApp.cc.
00286 { 00287 simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime); 00288 00289 if (time != 0) { 00290 globalStatistics->addStdDev("KBRTestApp: Delivered Messages/s", 00291 numDelivered / time); 00292 globalStatistics->addStdDev("KBRTestApp: Delivered Bytes/s", 00293 bytesDelivered / time); 00294 globalStatistics->addStdDev("KBRTestApp: Dropped Messages/s", 00295 numDropped / time); 00296 globalStatistics->addStdDev("KBRTestApp: Dropped Bytes/s", 00297 bytesDropped / time); 00298 if (numOverlaySent != 0) { 00299 globalStatistics->addStdDev("KBRTestApp: KBR Delivery Ratio", 00300 (float)numDelivered / 00301 (float)numOverlaySent); 00302 } else { 00303 globalStatistics->addStdDev("KBRTestApp: KBR Delivery Ratio", 0); 00304 } 00305 } 00306 }
| void KBRTestApp::handleTimerEvent | ( | cMessage * | msg | ) | [private, virtual] |
processes self-messages
method to handle self-messages should be overwritten in derived application if needed
| msg | self-message |
Reimplemented from BaseApp.
Definition at line 89 of file KBRTestApp.cc.
00090 { 00091 if (msg == testTimer) { 00092 // schedule next timer event 00093 scheduleAt(simTime() + truncnormal(mean, deviation), msg); 00094 00095 // do nothing if the network is still in the initialization phase 00096 if ((!activeNetwInitPhase && underlayConfigurator->isInInitPhase()) 00097 || underlayConfigurator->isSimulationEndingSoon() 00098 || nodeIsLeavingSoon) { 00099 00100 return; 00101 } 00102 00103 OverlayKey destKey; 00104 if (lookupNodeIds) { 00105 destKey = globalNodeList->getBootstrapNode().key; 00106 // do nothing if there are currently no nodes in the network 00107 if (destKey.isUnspecified()) 00108 return; 00109 } else { 00110 // generate random destination key 00111 destKey = OverlayKey::random(); 00112 } 00113 00114 // create a 100 byte test message 00115 KBRTestMessage* testMsg = new KBRTestMessage("KBRTestMessage"); 00116 testMsg->setId(getId()); 00117 testMsg->setSeqNum(sequenceNumber++); 00118 testMsg->setByteLength(100); 00119 testMsg->setMeasurementPhase(globalStatistics->isMeasuring()); 00120 00121 RECORD_STATS(globalStatistics->sentKBRTestAppMessages++); 00122 00123 callRoute(destKey, testMsg); 00124 00125 #if 0 00126 thisNode.port = 1025; 00127 NodeHandle handle = globalNodeList->getBootstrapNode(); 00128 handle.port = 1025; 00129 pingNode(handle, -1, -1, NULL, "TestPING", NULL, -1, UDP_TRANSPORT); 00130 00131 LookupCall* call = new LookupCall(); 00132 call->setBitLength(0); 00133 call->setKey(destKey); 00134 call->setNumSiblings(overlay->getMaxNumSiblings()); 00135 sendInternalRpcCall(OVERLAY_COMP, call); 00136 #endif 00137 00138 } 00139 }
| void KBRTestApp::deliver | ( | OverlayKey & | key, | |
| cMessage * | msg | |||
| ) | [private, virtual] |
Common API function: handles delivered messages from overlay.
method to handle decapsulated KBRdeliver messages from overlay module, should be overwritten in derived application
| key | destination key | |
| msg | delivered message |
Reimplemented from BaseApp.
Definition at line 185 of file KBRTestApp.cc.
00186 { 00187 KBRTestMessage* testMsg = check_and_cast<KBRTestMessage*>(msg); 00188 OverlayCtrlInfo* overlayCtrlInfo = 00189 check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo()); 00190 00191 if (overlay->getThisNode().key.isUnspecified()) 00192 error("key"); 00193 00194 // check for duplicate 00195 if ((msgHandleBufSize > 0 ) 00196 && checkSeen(overlayCtrlInfo->getSrcNode().key, testMsg->getSeqNum())) { 00197 EV << "[KBRTestApp::deliver() @ " << overlay->getThisNode().ip 00198 << " (" << overlay->getThisNode().key.toString(16) << ")]\n" 00199 << " Duplicate dropped." 00200 << endl; 00201 delete overlayCtrlInfo; 00202 delete testMsg; 00203 return; 00204 } 00205 00206 // Return statistical data to the sender. 00207 if (cModule* mod = simulation.getModule(testMsg->getId())) { 00208 if (KBRTestApp* sender = dynamic_cast<KBRTestApp*>(mod)) { 00209 if ((!lookupNodeIds) || (overlay->getThisNode().key == key)) { 00210 if (testMsg->getMeasurementPhase() == true) { 00211 sender->evaluateData((simTime() - testMsg->getCreationTime()), 00212 overlayCtrlInfo->getHopCount(), 00213 testMsg->getByteLength()); 00214 } 00215 } else if(lookupNodeIds) { 00216 RECORD_STATS(numDropped++; 00217 bytesDropped += testMsg->getByteLength()); 00218 EV << "[KBRTestApp::deliver() @ " << overlay->getThisNode().ip 00219 << " (" << overlay->getThisNode().key.toString(16) << ")]\n" 00220 << " Error: Lookup of NodeIDs and KBRTestMessage" 00221 << " received with different destKey!" 00222 << endl; 00223 } 00224 } 00225 } 00226 00227 EV << "[KBRTestApp::deliver() @ " << overlay->getThisNode().ip 00228 << " (" << overlay->getThisNode().key.toString(16) << ")]\n" 00229 << " Received \"" << testMsg->getName() << "(seqNr: " 00230 << testMsg->getSeqNum() << ")\n" 00231 << " with destination key: " << key.toString(16) 00232 << endl; 00233 00234 delete overlayCtrlInfo; 00235 delete testMsg; 00236 }
| void KBRTestApp::forward | ( | OverlayKey * | key, | |
| cPacket ** | msg, | |||
| NodeHandle * | nextHopNode | |||
| ) | [private, virtual] |
Common API function: handles messages from overlay to be forwarded.
method to handle decapsulated KBRdeliver messages from overlay module, should be overwritten in derived application if needed
| key | destination key | |
| msg | message to forward | |
| nextHopNode | next hop |
Reimplemented from BaseApp.
Definition at line 238 of file KBRTestApp.cc.
00240 { 00241 KBRTestMessage* tempMsg = check_and_cast<KBRTestMessage*>(*msg); 00242 00243 tempMsg->setVisitedNodesArraySize(tempMsg->getVisitedNodesArraySize() + 1); 00244 tempMsg->setVisitedNodes(tempMsg->getVisitedNodesArraySize() - 1, 00245 overlay->getThisNode().ip); 00246 }
| bool KBRTestApp::checkSeen | ( | const OverlayKey & | key, | |
| int | seqNum | |||
| ) | [private] |
Checks if a message was already seen before.
If the sequence number of the message is new for the given sender key, it is stored in a circular buffer and false is returned.
| key | the OverlayKey of the sender | |
| seqNum | sequence number of the message to check |
Definition at line 248 of file KBRTestApp.cc.
Referenced by deliver().
00249 { 00250 MsgHandle hdl(key, seqNum); 00251 00252 for (MsgHandleBuf::iterator it = mhBufBegin; it != mhBufEnd; ++it) { 00253 if (it->key.isUnspecified()) { 00254 continue; 00255 } 00256 00257 if (*it == hdl) { 00258 return true; 00259 } 00260 } 00261 00262 *(mhBufNext++) = hdl; 00263 if (mhBufNext == mhBufEnd) { 00264 mhBufNext = mhBufBegin; 00265 } 00266 return false; 00267 }
| void KBRTestApp::evaluateData | ( | simtime_t | timeDelay, | |
| int | hopCount, | |||
| long int | bytes | |||
| ) | [private] |
Analyses and records measuring data handed over from nodes that previously had been the destination for a test message from this module, called by receiver::handleMessage() at sendermodule.
| timeDelay | packet-delay | |
| hopCount | packet hop-count | |
| bytes | packet size in bytes |
Definition at line 269 of file KBRTestApp.cc.
00270 { 00271 // count the number and size of successfully delivered messages 00272 RECORD_STATS(numDelivered++; bytesDelivered += bytes; 00273 globalStatistics->deliveredKBRTestAppMessages++); 00274 00275 if (numOverlaySent < numDelivered) { 00276 error("KBRTestApp::evaluateData(): numSent < numDelivered!"); 00277 } 00278 00279 RECORD_STATS(globalStatistics->recordOutVector("KBRTestApp: KBR Hop " 00280 "Count", hopCount)); 00281 RECORD_STATS(globalStatistics->recordOutVector("KBRTestApp: KBR Latency", 00282 SIMTIME_DBL(latency))); 00283 }
| void KBRTestApp::handleRpcResponse | ( | BaseResponseMessage * | msg, | |
| cPolymorphic * | context, | |||
| int | rpcId, | |||
| simtime_t | rtt | |||
| ) | [private, virtual] |
This method is called if an RPC response has been received.
| msg | The response message. | |
| context | Pointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code | |
| rpcId | The RPC id. | |
| rtt | The Round-Trip-Time of this RPC |
Reimplemented from RpcListener.
Definition at line 146 of file KBRTestApp.cc.
00149 { 00150 RPC_SWITCH_START(msg) 00151 RPC_ON_RESPONSE(Lookup) { 00152 handleLookupResponse(_LookupResponse); 00153 EV << "[KBRTestApp::handleRpcResponse() @ " << overlay->getThisNode().ip 00154 << " (" << overlay->getThisNode().key.toString(16) << ")]\n" 00155 << " Lookup RPC Response received: id=" << rpcId << "\n" 00156 << " msg=" << *_LookupResponse << " rtt=" << rtt 00157 << endl; 00158 break; 00159 } 00160 RPC_SWITCH_END( ) 00161 }
| void KBRTestApp::handleLookupResponse | ( | LookupResponse * | msg | ) | [private] |
Definition at line 163 of file KBRTestApp.cc.
Referenced by handleRpcResponse().
00164 { 00165 EV << "[KBRTestApp::handleLookupResponse() @ " << overlay->getThisNode().ip 00166 << " (" << overlay->getThisNode().key.toString(16) << ")]\n" 00167 << " Lookup response for key " << msg->getKey()<< " : "; 00168 if (msg->getIsValid()) { 00169 for (uint32_t i=0; i<msg->getSiblingsArraySize(); i++) { 00170 EV << endl << " " << msg->getSiblings(i); 00171 } 00172 } else { 00173 EV << "failed"; 00174 } 00175 00176 EV << endl; 00177 }
| void KBRTestApp::pingResponse | ( | PingResponse * | response, | |
| cPolymorphic * | context, | |||
| int | rpcId, | |||
| simtime_t | rtt | |||
| ) | [private, virtual] |
| void KBRTestApp::handleNodeLeaveNotification | ( | ) | [private, virtual] |
This method gets call **.gracefulLeaveDelay seconds before it is killed.
Reimplemented from BaseApp.
Definition at line 179 of file KBRTestApp.cc.
00180 { 00181 nodeIsLeavingSoon = true; 00182 }
double KBRTestApp::mean [private] |
mean time interval between sending test messages
Definition at line 116 of file KBRTestApp.h.
Referenced by handleTimerEvent(), and initializeApp().
double KBRTestApp::deviation [private] |
deviation of time interval
Definition at line 117 of file KBRTestApp.h.
Referenced by handleTimerEvent(), and initializeApp().
bool KBRTestApp::activeNetwInitPhase [private] |
is app active in network init phase?
Definition at line 118 of file KBRTestApp.h.
Referenced by handleTimerEvent(), and initializeApp().
bool KBRTestApp::lookupNodeIds [private] |
lookup only existing nodeIDs
Definition at line 119 of file KBRTestApp.h.
Referenced by deliver(), handleTimerEvent(), and initializeApp().
bool KBRTestApp::nodeIsLeavingSoon [private] |
true if the node is going to be killed shortly
Definition at line 120 of file KBRTestApp.h.
Referenced by handleNodeLeaveNotification(), handleTimerEvent(), and initializeApp().
int KBRTestApp::numDelivered [private] |
number of delivered packets
Definition at line 122 of file KBRTestApp.h.
Referenced by evaluateData(), finishApp(), and initializeApp().
int KBRTestApp::bytesDelivered [private] |
number of delivered bytes
Definition at line 123 of file KBRTestApp.h.
Referenced by evaluateData(), finishApp(), and initializeApp().
int KBRTestApp::numDropped [private] |
Definition at line 124 of file KBRTestApp.h.
Referenced by deliver(), finishApp(), and initializeApp().
int KBRTestApp::bytesDropped [private] |
Definition at line 125 of file KBRTestApp.h.
Referenced by deliver(), finishApp(), and initializeApp().
cMessage* KBRTestApp::testTimer [private] |
Definition at line 127 of file KBRTestApp.h.
Referenced by handleTimerEvent(), initializeApp(), KBRTestApp(), and ~KBRTestApp().
uint32_t KBRTestApp::sequenceNumber [private] |
int KBRTestApp::msgHandleBufSize [private] |
how many MsgHandles to store in circular buffer
Definition at line 129 of file KBRTestApp.h.
Referenced by deliver(), and initializeApp().
MsgHandleBuf KBRTestApp::mhBuf [private] |
circular buffer of MsgHandles
Definition at line 130 of file KBRTestApp.h.
Referenced by initializeApp().
MsgHandleBuf::iterator KBRTestApp::mhBufBegin [private] |
begin of circular buffer
Definition at line 131 of file KBRTestApp.h.
Referenced by checkSeen(), and initializeApp().
MsgHandleBuf::iterator KBRTestApp::mhBufNext [private] |
next element to insert
Definition at line 132 of file KBRTestApp.h.
Referenced by checkSeen(), and initializeApp().
MsgHandleBuf::iterator KBRTestApp::mhBufEnd [private] |
end of circular buffer
Definition at line 133 of file KBRTestApp.h.
Referenced by checkSeen(), and initializeApp().
1.5.5