#include <DHTTestApp.h>
Inheritance diagram for DHTTestApp:
A simple test application that does random put and get calls on the DHT layer
Public Member Functions | |
virtual | ~DHTTestApp () |
virtual destructor | |
Protected Member Functions | |
int | numInitStages () const |
method to set InitStage | |
void | initialize (int stage) |
initializes base class-attributes | |
OverlayKey | getRandomKey () |
Get a random key of the hashmap. | |
char * | generateRandomValue () |
generate a random char[21] | |
void | finish () |
collects statistical data | |
virtual void | handleGetResponse (DHTgetCAPIResponse *msg) |
processes get responses | |
virtual void | handlePutResponse (DHTputCAPIResponse *msg) |
processes put responses | |
virtual void | handleTimerEvent (cMessage *msg) |
processes self-messages | |
void | handleRpcResponse (BaseResponseMessage *msg, int rpcId, simtime_t rtt) |
This method is called if an RPC response has been received. | |
Protected Attributes | |
UnderlayConfigurator * | underlayConfigurator |
pointer to UnderlayConfigurator in this node | |
BootstrapOracle * | bootstrapOracle |
pointer to BootstrapOracle in this node | |
GlobalStatistics * | globalStatistics |
pointer to GlobalStatistics module in this node | |
bool | debugOutput |
debug output yes/no? | |
double | mean |
mean time interval between sending test messages | |
double | deviation |
deviation of time interval | |
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 |
int DHTTestApp::numInitStages | ( | ) | const [protected] |
void DHTTestApp::initialize | ( | int | stage | ) | [protected] |
initializes base class-attributes
stage | the init stage |
Reimplemented from BaseApp.
00045 { 00046 if(stage == MIN_STAGE_APP) { 00047 // fetch parameters 00048 debugOutput = par("debugOutput"); 00049 activeNetwInitPhase = par("activeNetwInitPhase"); 00050 00051 mean = par("messageDelay"); 00052 deviation = mean / 10; 00053 00054 bootstrapOracle = BootstrapOracleAccess().get(); 00055 underlayConfigurator = UnderlayConfiguratorAccess().get(); 00056 globalStatistics = GlobalStatisticsAccess().get(); 00057 00058 // statistics 00059 numSent = 0; 00060 numGetSent = 0; 00061 numGetError = 0; 00062 numGetSuccess = 0; 00063 numPutSent = 0; 00064 numPutError = 0; 00065 numPutSuccess = 0; 00066 00067 initRpcs(); 00068 WATCH(numSent); 00069 WATCH(numGetSent); 00070 WATCH(numGetError); 00071 WATCH(numGetSuccess); 00072 WATCH(numPutSent); 00073 WATCH(numPutError); 00074 WATCH(numPutSuccess); 00075 00076 // initiate test message emision 00077 cMessage* dhttestput_timer = new cMessage("dhttest_put_timer"); 00078 scheduleAt(simulation.simTime() + truncnormal(mean, deviation), dhttestput_timer); 00079 cMessage* dhttestget_timer = new cMessage("dhttest_get_timer"); 00080 scheduleAt(simulation.simTime() + truncnormal(mean+mean/3, deviation), dhttestget_timer); 00081 cMessage* dhttestmod_timer = new cMessage("dhttest_mod_timer"); 00082 scheduleAt(simulation.simTime() + truncnormal(mean+2*mean/3, deviation), dhttestmod_timer); 00083 } 00084 }
OverlayKey DHTTestApp::getRandomKey | ( | ) | [protected] |
Get a random key of the hashmap.
00217 { 00218 BootstrapOracle::DataMap* dataMap = bootstrapOracle->getDataMap(); 00219 if (dataMap->size() == 0) 00220 return OverlayKey::UNSPECIFIED_KEY; 00221 // return random OverlayKey in O(log n) (taken from BootstrapOracle 00222 std::map<OverlayKey, DHTEntry>::iterator it = dataMap->end(); 00223 DHTEntry tempEntry = {NULL, 0}; 00224 00225 while(it == dataMap->end()) { 00226 OverlayKey randomKey = OverlayKey::random(); 00227 00228 it = dataMap->find(randomKey); 00229 00230 if (it == dataMap->end()) { 00231 it = dataMap->insert(std::make_pair(randomKey,tempEntry)).first; 00232 dataMap->erase(it++); 00233 } 00234 00235 if (it == dataMap->end()) 00236 it = dataMap->begin(); 00237 } 00238 return it->first; 00239 }
char * DHTTestApp::generateRandomValue | ( | ) | [protected] |
generate a random char[21]
00241 { 00242 char * value; 00243 value = (char *)malloc(sizeof(char)*21); 00244 int i, randvalue; 00245 00246 for (i=0; i < 20; i++){ 00247 00248 randvalue = (int)intuniform(0, 25); 00249 value[i] = randvalue+'a'; 00250 } 00251 value[20] = '\0'; 00252 return value; 00253 00254 }
void DHTTestApp::finish | ( | ) | [protected] |
collects statistical data
Reimplemented from BaseApp.
00257 { 00258 // record scalar data 00259 globalStatistics->addStdDev("DHTTest: Sent Messages", numSent); 00260 globalStatistics->addStdDev("DHTTest: Get Messages sent", numGetSent); 00261 globalStatistics->addStdDev("DHTTest: Get Errors", numGetError); 00262 globalStatistics->addStdDev("DHTTest: Get Success", numGetSuccess); 00263 globalStatistics->addStdDev("DHTTest: Put Messages sent", numPutSent); 00264 globalStatistics->addStdDev("DHTTest: Put Errors", numPutError); 00265 globalStatistics->addStdDev("DHTTest: Put Success", numPutSuccess); 00266 }
void DHTTestApp::handleGetResponse | ( | DHTgetCAPIResponse * | msg | ) | [protected, virtual] |
processes get responses
method to handle get responses should be overwritten in derived application if needed
msg | get response message |
00121 { 00122 OverlayKey key = msg->getKey(); 00123 if (!(msg->getIsSuccess())) 00124 { 00125 numGetError++; 00126 return; 00127 } 00128 std::map<OverlayKey, DHTEntry>::iterator it = bootstrapOracle->getDataMap()->find(key); 00129 00130 if (it == bootstrapOracle->getDataMap()->end()) //unexpected key 00131 { 00132 numGetError++; 00133 return; 00134 } 00135 DHTEntry entry = it->second; 00136 if (simulation.simTime() > entry.endtime) 00137 { 00138 if (msg->getValue() != BinaryValue::UNSPECIFIED_VALUE) { 00139 numGetError++; 00140 return; 00141 } 00142 else { 00143 numGetSuccess++; 00144 return; 00145 } 00146 } 00147 else { 00148 if (dynamic_cast< vector<char>& >((msg->getValue())) != dynamic_cast< vector<char>& >(*(entry.value))) { 00149 numGetError++; 00150 return; 00151 } 00152 else { 00153 numGetSuccess++; 00154 return; 00155 } 00156 } 00157 00158 }
void DHTTestApp::handlePutResponse | ( | DHTputCAPIResponse * | msg | ) | [protected, virtual] |
processes put responses
method to handle put responses should be overwritten in derived application if needed
msg | put response message |
00106 { 00107 OverlayKey key = msg->getKey(); 00108 if (!(msg->getIsSuccess())) 00109 { 00110 numPutError++; 00111 return; 00112 } 00113 numPutSuccess++; 00114 DHTEntry entry; 00115 entry.value = new BinaryValue(msg->getValue()); 00116 entry.endtime = simulation.simTime()+300; 00117 bootstrapOracle->getDataMap()->insert(make_pair(msg->getKey(), entry)); 00118 }
void DHTTestApp::handleTimerEvent | ( | cMessage * | msg | ) | [protected, virtual] |
processes self-messages
method to handle self-messages should be overwritten in derived application if needed
msg | self-message |
Reimplemented from BaseApp.
00161 { 00162 if (msg->isName("dhttest_put_timer")) { 00163 // schedule next timer event 00164 scheduleAt(simulation.simTime() + truncnormal(mean, deviation), msg); 00165 00166 // do nothing if the network is still in the initialization phase 00167 if((!activeNetwInitPhase) && (underlayConfigurator->isInit())) 00168 return; 00169 00170 // create a put test message with random destination key 00171 OverlayKey destKey = OverlayKey::random(); 00172 DHTputCAPICall* dhtPutMsg = new DHTputCAPICall(); 00173 char * value = generateRandomValue(); 00174 dhtPutMsg->setKey(destKey); 00175 dhtPutMsg->setValue(value); 00176 dhtPutMsg->setTtl(300); 00177 dhtPutMsg->setIsModifiable(true); 00178 bootstrapOracle->getDataMap()->erase(destKey); 00179 free(value); 00180 00181 numSent++; 00182 numPutSent++; 00183 sendRpcMessage(RPC_TO_LOWERTIER, NodeHandle::UNSPECIFIED_NODE, dhtPutMsg, NULL, OverlayKey::UNSPECIFIED_KEY, -1, 0); 00184 } 00185 if (msg->isName("dhttest_get_timer")) { 00186 scheduleAt(simulation.simTime() + truncnormal(mean, deviation), msg); 00187 OverlayKey key = getRandomKey(); 00188 if (key.isUnspecified()) return; 00189 DHTgetCAPICall* dhtGetMsg = new DHTgetCAPICall(); 00190 dhtGetMsg->setKey(key); 00191 numSent++; 00192 numGetSent++; 00193 sendRpcMessage(RPC_TO_LOWERTIER, NodeHandle::UNSPECIFIED_NODE, dhtGetMsg, NULL, OverlayKey::UNSPECIFIED_KEY, -1, 0); 00194 } 00195 if (msg->isName("dhttest_mod_timer")) { 00196 scheduleAt(simulation.simTime() + truncnormal(mean, deviation), msg); 00197 OverlayKey key = getRandomKey(); 00198 if (key.isUnspecified()) return; 00199 DHTputCAPICall* dhtPutMsg = new DHTputCAPICall(); 00200 char * value = generateRandomValue(); 00201 dhtPutMsg->setKey(key); 00202 dhtPutMsg->setValue(value); 00203 dhtPutMsg->setTtl(300); 00204 dhtPutMsg->setIsModifiable(true); 00205 bootstrapOracle->getDataMap()->erase(key); 00206 DHTEntry entry; 00207 entry.value = new BinaryValue(value); 00208 free(value); 00209 entry.endtime = simulation.simTime()+300; 00210 bootstrapOracle->getDataMap()->insert(make_pair(key, entry)); 00211 numSent++; 00212 numPutSent++; 00213 sendRpcMessage(RPC_TO_LOWERTIER, NodeHandle::UNSPECIFIED_NODE, dhtPutMsg, NULL, OverlayKey::UNSPECIFIED_KEY, -1, 0); 00214 } 00215 }
void DHTTestApp::handleRpcResponse | ( | BaseResponseMessage * | msg, | |
int | rpcId, | |||
simtime_t | rtt | |||
) | [protected, virtual] |
This method is called if an RPC response has been received.
msg | The response message. | |
rpcId | The RPC id. | |
rtt | The Round-Trip-Time of this RPC |
Reimplemented from RpcListener.
00088 { 00089 RPC_SWITCH_START(msg) 00090 RPC_ON_RESPONSE( DHTputCAPI ) { 00091 handlePutResponse(_DHTputCAPIResponse); 00092 EV << "DHT Put RPC Response received: id=" << rpcId 00093 << " msg=" << *_DHTputCAPIResponse << " rtt=" << rtt << endl; 00094 break; 00095 } 00096 RPC_ON_RESPONSE( DHTgetCAPI ) { 00097 handleGetResponse(_DHTgetCAPIResponse); 00098 EV << "DHT Get RPC Response received: id=" << rpcId 00099 << " msg=" << *_DHTgetCAPIResponse << " rtt=" << rtt << endl; 00100 break; 00101 } 00102 RPC_SWITCH_END( ) 00103 }
UnderlayConfigurator* DHTTestApp::underlayConfigurator [protected] |
BootstrapOracle* DHTTestApp::bootstrapOracle [protected] |
GlobalStatistics* DHTTestApp::globalStatistics [protected] |
bool DHTTestApp::debugOutput [protected] |
double DHTTestApp::mean [protected] |
mean time interval between sending test messages
double DHTTestApp::deviation [protected] |
deviation of time interval
bool DHTTestApp::activeNetwInitPhase [protected] |
is app active in network init phase?
int DHTTestApp::numSent [protected] |
int DHTTestApp::numGetSent [protected] |
number of get sent
int DHTTestApp::numGetError [protected] |
number of false get responses
int DHTTestApp::numGetSuccess [protected] |
number of false get responses
int DHTTestApp::numPutSent [protected] |
number of put sent
int DHTTestApp::numPutError [protected] |
number of error in put responses
int DHTTestApp::numPutSuccess [protected] |
number of success in put responses