#include <DHTTestApp.h>

A simple test application that does random put and get calls on the DHT layer
Definition at line 50 of file DHTTestApp.h.
Public Member Functions | |
| DHTTestApp () | |
| virtual | ~DHTTestApp () |
| virtual destructor | |
Private Member Functions | |
| void | initializeApp (int stage) |
| initializes derived class-attributes | |
| OverlayKey | getRandomKey () |
| Get a random key of the hashmap. | |
| BinaryValue | generateRandomValue () |
| generate a random human readable binary value | |
| void | finishApp () |
| collects statistical data of derived app | |
| virtual void | handleGetResponse (DHTgetCAPIResponse *msg, DHTStatsContext *context) |
| processes get responses | |
| virtual void | handlePutResponse (DHTputCAPIResponse *msg, DHTStatsContext *context) |
| processes put responses | |
| virtual void | handleTimerEvent (cMessage *msg) |
| processes self-messages | |
| virtual void | handleTraceMessage (cMessage *msg) |
| handleTraceMessage gets called of handleMessage(cMessage* msg) if a message arrives at trace_in. | |
| virtual void | handleNodeLeaveNotification () |
| This method gets call **.gracefulLeaveDelay seconds before it is killed. | |
| void | handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt) |
| This method is called if an RPC response has been received. | |
Private Attributes | |
| UnderlayConfigurator * | underlayConfigurator |
| pointer to UnderlayConfigurator in this node | |
| GlobalNodeList * | globalNodeList |
| pointer to GlobalNodeList in this node | |
| GlobalStatistics * | globalStatistics |
| pointer to GlobalStatistics module in this node | |
| GlobalDhtTestMap * | globalDhtTestMap |
| pointer to the GlobalDhtTestMap module | |
| bool | debugOutput |
| debug output yes/no? | |
| double | mean |
| mean time interval between sending test messages | |
| double | deviation |
| deviation of time interval | |
| int | ttl |
| ttl for stored DHT records | |
| bool | activeNetwInitPhase |
| is app active in network init phase? | |
| int | numSent |
| number of sent packets | |
| int | numGetSent |
| number of get sent | |
| int | numGetError |
| number of false get responses | |
| int | numGetSuccess |
| number of false get responses | |
| int | numPutSent |
| number of put sent | |
| int | numPutError |
| number of error in put responses | |
| int | numPutSuccess |
| number of success in put responses | |
| cMessage * | dhttestput_timer |
| cMessage * | dhttestget_timer |
| cMessage * | dhttestmod_timer |
| bool | nodeIsLeavingSoon |
| true if the node is going to be killed shortly | |
Static Private Attributes | |
| static const int | DHTTESTAPP_VALUE_LEN = 20 |
Classes | |
| class | DHTStatsContext |
| A container used by the DHTTestApp to store context information for statistics. More... | |
| DHTTestApp::DHTTestApp | ( | ) |
Definition at line 46 of file DHTTestApp.cc.
00047 { 00048 dhttestput_timer = NULL; 00049 dhttestget_timer = NULL; 00050 dhttestmod_timer = NULL; 00051 }
| DHTTestApp::~DHTTestApp | ( | ) | [virtual] |
virtual destructor
Definition at line 39 of file DHTTestApp.cc.
00040 { 00041 cancelAndDelete(dhttestput_timer); 00042 cancelAndDelete(dhttestget_timer); 00043 cancelAndDelete(dhttestmod_timer); 00044 }
| void DHTTestApp::initializeApp | ( | int | stage | ) | [private, virtual] |
initializes derived class-attributes
| stage | the init stage |
Reimplemented from BaseApp.
Definition at line 53 of file DHTTestApp.cc.
00054 { 00055 if (stage != MIN_STAGE_APP) 00056 return; 00057 00058 // fetch parameters 00059 debugOutput = par("debugOutput"); 00060 activeNetwInitPhase = par("activeNetwInitPhase"); 00061 00062 mean = par("testInterval"); 00063 deviation = mean / 10; 00064 00065 ttl = par("testTtl"); 00066 00067 globalNodeList = GlobalNodeListAccess().get(); 00068 underlayConfigurator = UnderlayConfiguratorAccess().get(); 00069 globalStatistics = GlobalStatisticsAccess().get(); 00070 00071 globalDhtTestMap = dynamic_cast<GlobalDhtTestMap*>(simulation.getModuleByPath( 00072 "globalObserver.globalFunctions[0]")); 00073 00074 if (globalDhtTestMap == NULL) { 00075 throw cRuntimeError("DHTTestApp::initializeApp(): " 00076 "GlobalDhtTestMap module not found!"); 00077 } 00078 00079 // statistics 00080 numSent = 0; 00081 numGetSent = 0; 00082 numGetError = 0; 00083 numGetSuccess = 0; 00084 numPutSent = 0; 00085 numPutError = 0; 00086 numPutSuccess = 0; 00087 00088 initRpcs(); 00089 WATCH(numSent); 00090 WATCH(numGetSent); 00091 WATCH(numGetError); 00092 WATCH(numGetSuccess); 00093 WATCH(numPutSent); 00094 WATCH(numPutError); 00095 WATCH(numPutSuccess); 00096 00097 nodeIsLeavingSoon = false; 00098 00099 // initiate test message transmission 00100 dhttestput_timer = new cMessage("dhttest_put_timer"); 00101 dhttestget_timer = new cMessage("dhttest_get_timer"); 00102 dhttestmod_timer = new cMessage("dhttest_mod_timer"); 00103 00104 if (mean > 0) { 00105 scheduleAt(simTime() + truncnormal(mean, deviation), 00106 dhttestput_timer); 00107 scheduleAt(simTime() + truncnormal(mean + mean / 3, 00108 deviation), 00109 dhttestget_timer); 00110 scheduleAt(simTime() + truncnormal(mean + 2 * mean / 3, 00111 deviation), 00112 dhttestmod_timer); 00113 } 00114 }
| OverlayKey DHTTestApp::getRandomKey | ( | ) | [private] |
Get a random key of the hashmap.
| BinaryValue DHTTestApp::generateRandomValue | ( | ) | [private] |
generate a random human readable binary value
Definition at line 360 of file DHTTestApp.cc.
Referenced by handleTimerEvent().
00361 { 00362 char value[DHTTESTAPP_VALUE_LEN + 1]; 00363 00364 for (int i = 0; i < DHTTESTAPP_VALUE_LEN; i++) { 00365 value[i] = intuniform(0, 25) + 'a'; 00366 } 00367 00368 value[DHTTESTAPP_VALUE_LEN] = '\0'; 00369 return BinaryValue(value); 00370 }
| void DHTTestApp::finishApp | ( | ) | [private, virtual] |
collects statistical data of derived app
Reimplemented from BaseApp.
Definition at line 377 of file DHTTestApp.cc.
00378 { 00379 simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime); 00380 00381 // record scalar data 00382 globalStatistics->addStdDev("DHTTestApp: Sent Total Messages/s", 00383 numSent / time); 00384 globalStatistics->addStdDev("DHTTestApp: Sent GET Messages/s", 00385 numGetSent / time); 00386 globalStatistics->addStdDev("DHTTestApp: Failed GET Requests/s", 00387 numGetError / time); 00388 globalStatistics->addStdDev("DHTTestApp: Successful GET Requests/s", 00389 numGetSuccess / time); 00390 00391 globalStatistics->addStdDev("DHTTestApp: Sent PUT Messages/s", 00392 numPutSent / time); 00393 globalStatistics->addStdDev("DHTTestApp: Failed PUT Requests/s", 00394 numPutError / time); 00395 globalStatistics->addStdDev("DHTTestApp: Successful PUT Requests/s", 00396 numPutSuccess / time); 00397 00398 if (numGetSent > 0) { 00399 globalStatistics->addStdDev("DHTTestApp: GET Success Ratio", 00400 (double) numGetSuccess 00401 / (double) numGetSent); 00402 } 00403 }
| void DHTTestApp::handleGetResponse | ( | DHTgetCAPIResponse * | msg, | |
| DHTStatsContext * | context | |||
| ) | [private, virtual] |
processes get responses
method to handle get responses should be overwritten in derived application if needed
| msg | get response message | |
| context | context object used for collecting statistics |
Definition at line 173 of file DHTTestApp.cc.
Referenced by handleRpcResponse().
00175 { 00176 if (context->measurementPhase == false) { 00177 // don't count response, if the request was not sent 00178 // in the measurement phase 00179 return; 00180 } 00181 00182 RECORD_STATS(globalStatistics->addStdDev("DHTTestApp: GET delay (s)", 00183 SIMTIME_DBL(simTime() - context->requestTime))); 00184 00185 if (!(msg->getIsSuccess())) { 00186 //cout << "DHTTestApp: success == false" << endl; 00187 RECORD_STATS(numGetError++); 00188 return; 00189 } 00190 00191 const DHTEntry* entry = globalDhtTestMap->findEntry(msg->getKey()); 00192 00193 if (entry == NULL) { 00194 //unexpected key 00195 RECORD_STATS(numGetError++); 00196 //cout << "DHTTestApp: unexpected key" << endl; 00197 return; 00198 } 00199 00200 if (simTime() > entry->endtime) { 00201 //this key doesn't exist anymore in the DHT, delete it in our hashtable 00202 00203 globalDhtTestMap->eraseEntry(msg->getKey()); 00204 00205 if (!(msg->getValue().isUnspecified())) { 00206 RECORD_STATS(numGetError++); 00207 //cout << "DHTTestApp: deleted key still available" << endl; 00208 return; 00209 } else { 00210 RECORD_STATS(numGetSuccess++); 00211 return; 00212 } 00213 } else { 00214 if (msg->getValue() != entry->value) { 00215 RECORD_STATS(numGetError++); 00216 //cout << "DHTTestApp: wrong value" << endl; 00217 //cout << "size: " << msg->getValue().size() << endl; 00218 return; 00219 } else { 00220 RECORD_STATS(numGetSuccess++); 00221 return; 00222 } 00223 } 00224 00225 }
| void DHTTestApp::handlePutResponse | ( | DHTputCAPIResponse * | msg, | |
| DHTStatsContext * | context | |||
| ) | [private, virtual] |
processes put responses
method to handle put responses should be overwritten in derived application if needed
| msg | put response message | |
| context | context object used for collecting statistics |
Definition at line 143 of file DHTTestApp.cc.
Referenced by handleRpcResponse().
00145 { 00146 if (!(msg->getIsSuccess())) { 00147 if (context->measurementPhase == false) { 00148 // don't count response, if the request was not sent 00149 // in the measurement phase 00150 RECORD_STATS(numPutError++); 00151 } 00152 return; 00153 } 00154 00155 OverlayKey key = msg->getKey(); 00156 DHTEntry entry = {BinaryValue(msg->getValue()), 00157 simTime() + ttl}; 00158 00159 globalDhtTestMap->insertEntry(msg->getKey(), entry); 00160 00161 if (context->measurementPhase == false) { 00162 // don't count response, if the request was not sent 00163 // in the measurement phase 00164 return; 00165 } 00166 00167 RECORD_STATS(numPutSuccess++); 00168 00169 RECORD_STATS(globalStatistics->addStdDev("DHTTestApp: PUT delay (s)", 00170 SIMTIME_DBL(simTime() - context->requestTime))); 00171 }
| void DHTTestApp::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 285 of file DHTTestApp.cc.
00286 { 00287 if (msg->isName("dhttest_put_timer")) { 00288 // schedule next timer event 00289 scheduleAt(simTime() + truncnormal(mean, deviation), msg); 00290 00291 // do nothing if the network is still in the initialization phase 00292 if ((!activeNetwInitPhase) && (underlayConfigurator->isInInitPhase()) 00293 || underlayConfigurator->isSimulationEndingSoon() 00294 || nodeIsLeavingSoon) 00295 return; 00296 00297 // create a put test message with random destination key 00298 OverlayKey destKey = OverlayKey::random(); 00299 DHTputCAPICall* dhtPutMsg = new DHTputCAPICall(); 00300 dhtPutMsg->setKey(destKey); 00301 dhtPutMsg->setValue(generateRandomValue()); 00302 dhtPutMsg->setTtl(ttl); 00303 dhtPutMsg->setIsModifiable(true); 00304 00305 RECORD_STATS(numSent++; numPutSent++); 00306 sendInternalRpcCall(TIER1_COMP, dhtPutMsg, 00307 new DHTStatsContext(globalStatistics->isMeasuring(), 00308 simTime())); 00309 } else if (msg->isName("dhttest_get_timer")) { 00310 scheduleAt(simTime() + truncnormal(mean, deviation), msg); 00311 00312 // do nothing if the network is still in the initialization phase 00313 if ((!activeNetwInitPhase) && (underlayConfigurator->isInInitPhase()) 00314 || underlayConfigurator->isSimulationEndingSoon() 00315 || nodeIsLeavingSoon) { 00316 return; 00317 } 00318 00319 const OverlayKey& key = globalDhtTestMap->getRandomKey(); 00320 00321 if (key.isUnspecified()) 00322 return; 00323 00324 DHTgetCAPICall* dhtGetMsg = new DHTgetCAPICall(); 00325 dhtGetMsg->setKey(key); 00326 RECORD_STATS(numSent++; numGetSent++); 00327 00328 sendInternalRpcCall(TIER1_COMP, dhtGetMsg, 00329 new DHTStatsContext(globalStatistics->isMeasuring(), 00330 simTime())); 00331 } else if (msg->isName("dhttest_mod_timer")) { 00332 scheduleAt(simTime() + truncnormal(mean, deviation), msg); 00333 00334 // do nothing if the network is still in the initialization phase 00335 if ((!activeNetwInitPhase) && (underlayConfigurator->isInInitPhase()) 00336 || underlayConfigurator->isSimulationEndingSoon() 00337 || nodeIsLeavingSoon) { 00338 return; 00339 } 00340 00341 const OverlayKey& key = globalDhtTestMap->getRandomKey(); 00342 00343 if (key.isUnspecified()) 00344 return; 00345 00346 DHTputCAPICall* dhtPutMsg = new DHTputCAPICall(); 00347 dhtPutMsg->setKey(key); 00348 dhtPutMsg->setValue(generateRandomValue()); 00349 dhtPutMsg->setTtl(ttl); 00350 dhtPutMsg->setIsModifiable(true); 00351 00352 RECORD_STATS(numSent++; numPutSent++); 00353 sendInternalRpcCall(TIER1_COMP, dhtPutMsg, 00354 new DHTStatsContext(globalStatistics->isMeasuring(), 00355 simTime())); 00356 } 00357 }
| void DHTTestApp::handleTraceMessage | ( | cMessage * | msg | ) | [private, virtual] |
handleTraceMessage gets called of handleMessage(cMessage* msg) if a message arrives at trace_in.
The command included in this message should be parsed and handled.
| msg | the command message to handle |
Reimplemented from BaseApp.
Definition at line 227 of file DHTTestApp.cc.
00228 { 00229 char* cmd = new char[strlen(msg->getName()) + 1]; 00230 strcpy(cmd, msg->getName()); 00231 00232 if (strlen(msg->getName()) < 5) { 00233 delete[] cmd; 00234 delete msg; 00235 return; 00236 } 00237 00238 if (strncmp(cmd, "PUT ", 4) == 0) { 00239 // Generate key 00240 char* buf = cmd + 4; 00241 00242 while (!isspace(buf[0])) { 00243 if (buf[0] == '\0') 00244 throw cRuntimeError("Error parsing PUT command"); 00245 buf++; 00246 } 00247 00248 buf[0] = '\0'; 00249 BinaryValue b(cmd + 4); 00250 OverlayKey destKey(OverlayKey::sha1(b)); 00251 00252 // get value 00253 buf++; 00254 00255 // build putMsg 00256 DHTputCAPICall* dhtPutMsg = new DHTputCAPICall(); 00257 dhtPutMsg->setKey(destKey); 00258 dhtPutMsg->setValue(buf); 00259 dhtPutMsg->setTtl(ttl); 00260 dhtPutMsg->setIsModifiable(true); 00261 RECORD_STATS(numSent++; numPutSent++); 00262 sendInternalRpcCall(TIER1_COMP, dhtPutMsg, 00263 new DHTStatsContext(globalStatistics->isMeasuring(), 00264 simTime())); 00265 } else if (strncmp(cmd, "GET ", 4) == 0) { 00266 // Get key 00267 BinaryValue b(cmd + 4); 00268 OverlayKey key(OverlayKey::sha1(b)); 00269 00270 DHTgetCAPICall* dhtGetMsg = new DHTgetCAPICall(); 00271 dhtGetMsg->setKey(key); 00272 RECORD_STATS(numSent++; numGetSent++); 00273 sendInternalRpcCall(TIER1_COMP, dhtGetMsg, 00274 new DHTStatsContext(globalStatistics->isMeasuring(), 00275 simTime())); 00276 } else { 00277 throw cRuntimeError("Unknown trace command; " 00278 "only GET and PUT are allowed"); 00279 } 00280 00281 delete[] cmd; 00282 delete msg; 00283 }
| void DHTTestApp::handleNodeLeaveNotification | ( | ) | [private, virtual] |
This method gets call **.gracefulLeaveDelay seconds before it is killed.
Reimplemented from BaseApp.
Definition at line 372 of file DHTTestApp.cc.
00373 { 00374 nodeIsLeavingSoon = true; 00375 }
| void DHTTestApp::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 116 of file DHTTestApp.cc.
00119 { 00120 RPC_SWITCH_START(msg) 00121 RPC_ON_RESPONSE( DHTputCAPI ) { 00122 handlePutResponse(_DHTputCAPIResponse, 00123 check_and_cast<DHTStatsContext*>(context)); 00124 EV << "[DHTTestApp::handleRpcResponse()]\n" 00125 << " DHT Put RPC Response received: id=" << rpcId 00126 << " msg=" << *_DHTputCAPIResponse << " rtt=" << rtt 00127 << endl; 00128 break; 00129 } 00130 RPC_ON_RESPONSE(DHTgetCAPI) 00131 { 00132 handleGetResponse(_DHTgetCAPIResponse, 00133 check_and_cast<DHTStatsContext*>(context)); 00134 EV << "[DHTTestApp::handleRpcResponse()]\n" 00135 << " DHT Get RPC Response received: id=" << rpcId 00136 << " msg=" << *_DHTgetCAPIResponse << " rtt=" << rtt 00137 << endl; 00138 break; 00139 } 00140 RPC_SWITCH_END() 00141 }
pointer to UnderlayConfigurator in this node
Reimplemented from BaseApp.
Definition at line 131 of file DHTTestApp.h.
Referenced by handleTimerEvent(), and initializeApp().
GlobalNodeList* DHTTestApp::globalNodeList [private] |
pointer to GlobalNodeList in this node
Reimplemented from BaseApp.
Definition at line 133 of file DHTTestApp.h.
Referenced by initializeApp().
GlobalStatistics* DHTTestApp::globalStatistics [private] |
pointer to GlobalStatistics module in this node
Reimplemented from BaseApp.
Definition at line 135 of file DHTTestApp.h.
Referenced by finishApp(), handleGetResponse(), handlePutResponse(), handleTimerEvent(), handleTraceMessage(), and initializeApp().
GlobalDhtTestMap* DHTTestApp::globalDhtTestMap [private] |
pointer to the GlobalDhtTestMap module
Definition at line 136 of file DHTTestApp.h.
Referenced by handleGetResponse(), handlePutResponse(), handleTimerEvent(), and initializeApp().
bool DHTTestApp::debugOutput [private] |
debug output yes/no?
Reimplemented from BaseApp.
Definition at line 139 of file DHTTestApp.h.
Referenced by initializeApp().
double DHTTestApp::mean [private] |
mean time interval between sending test messages
Definition at line 140 of file DHTTestApp.h.
Referenced by handleTimerEvent(), and initializeApp().
double DHTTestApp::deviation [private] |
deviation of time interval
Definition at line 141 of file DHTTestApp.h.
Referenced by handleTimerEvent(), and initializeApp().
int DHTTestApp::ttl [private] |
ttl for stored DHT records
Definition at line 142 of file DHTTestApp.h.
Referenced by handlePutResponse(), handleTimerEvent(), handleTraceMessage(), and initializeApp().
bool DHTTestApp::activeNetwInitPhase [private] |
is app active in network init phase?
Definition at line 143 of file DHTTestApp.h.
Referenced by handleTimerEvent(), and initializeApp().
int DHTTestApp::numSent [private] |
number of sent packets
Definition at line 146 of file DHTTestApp.h.
Referenced by finishApp(), handleTimerEvent(), handleTraceMessage(), and initializeApp().
int DHTTestApp::numGetSent [private] |
number of get sent
Definition at line 147 of file DHTTestApp.h.
Referenced by finishApp(), handleTimerEvent(), handleTraceMessage(), and initializeApp().
int DHTTestApp::numGetError [private] |
number of false get responses
Definition at line 148 of file DHTTestApp.h.
Referenced by finishApp(), handleGetResponse(), and initializeApp().
int DHTTestApp::numGetSuccess [private] |
number of false get responses
Definition at line 149 of file DHTTestApp.h.
Referenced by finishApp(), handleGetResponse(), and initializeApp().
int DHTTestApp::numPutSent [private] |
number of put sent
Definition at line 150 of file DHTTestApp.h.
Referenced by finishApp(), handleTimerEvent(), handleTraceMessage(), and initializeApp().
int DHTTestApp::numPutError [private] |
number of error in put responses
Definition at line 151 of file DHTTestApp.h.
Referenced by finishApp(), handlePutResponse(), and initializeApp().
int DHTTestApp::numPutSuccess [private] |
number of success in put responses
Definition at line 152 of file DHTTestApp.h.
Referenced by finishApp(), handlePutResponse(), and initializeApp().
cMessage* DHTTestApp::dhttestput_timer [private] |
Definition at line 154 of file DHTTestApp.h.
Referenced by DHTTestApp(), initializeApp(), and ~DHTTestApp().
cMessage * DHTTestApp::dhttestget_timer [private] |
Definition at line 154 of file DHTTestApp.h.
Referenced by DHTTestApp(), initializeApp(), and ~DHTTestApp().
cMessage * DHTTestApp::dhttestmod_timer [private] |
Definition at line 154 of file DHTTestApp.h.
Referenced by DHTTestApp(), initializeApp(), and ~DHTTestApp().
bool DHTTestApp::nodeIsLeavingSoon [private] |
true if the node is going to be killed shortly
Definition at line 155 of file DHTTestApp.h.
Referenced by handleNodeLeaveNotification(), handleTimerEvent(), and initializeApp().
const int DHTTestApp::DHTTESTAPP_VALUE_LEN = 20 [static, private] |
1.5.5