DHTTestApp Class Reference

#include <DHTTestApp.h>

Inheritance diagram for DHTTestApp:

BaseApp BaseRpc RpcListener List of all members.

Detailed Description

A simple test application for the DHT layer.

A simple test application that does random put and get calls on the DHT layer

Author:
Ingmar Baumgart


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

UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
BootstrapOraclebootstrapOracle
 pointer to BootstrapOracle in this node
GlobalStatisticsglobalStatistics
 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
simtime_t lastPutTime
simtime_t lastGetTime


Constructor & Destructor Documentation

DHTTestApp::~DHTTestApp (  )  [virtual]

virtual destructor

00035 {
00036     //...
00037 }


Member Function Documentation

int DHTTestApp::numInitStages (  )  const [protected]

method to set InitStage

Reimplemented from BaseApp.

00040 {
00041     return MAX_STAGE_APP + 1;
00042 }

void DHTTestApp::initialize ( int  stage  )  [protected]

initializes base class-attributes

Parameters:
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.

00219                                     {
00220     BootstrapOracle::DataMap* dataMap = bootstrapOracle->getDataMap();
00221     if (dataMap->size() == 0)
00222         return OverlayKey::UNSPECIFIED_KEY;
00223     // return random OverlayKey in O(log n) (taken from BootstrapOracle
00224     std::map<OverlayKey, DHTEntry>::iterator it = dataMap->end();
00225     DHTEntry tempEntry = {NULL, 0};
00226 
00227     while(it == dataMap->end()) {
00228         OverlayKey randomKey = OverlayKey::random();
00229 
00230         it = dataMap->find(randomKey);
00231 
00232         if (it == dataMap->end()) {
00233             it = dataMap->insert(std::make_pair(randomKey,tempEntry)).first;
00234             dataMap->erase(it++);
00235         }
00236 
00237         if (it == dataMap->end())
00238             it = dataMap->begin();
00239     }
00240     return it->first;
00241 }

char * DHTTestApp::generateRandomValue (  )  [protected]

generate a random char[21]

00243                                        {
00244     char * value;
00245     value = (char *)malloc(sizeof(char)*21);
00246     int i, randvalue;
00247 
00248     for (i=0; i < 20; i++){
00249       
00250       randvalue = (int)intuniform(0, 25);
00251       value[i] = randvalue+'a';
00252     }
00253     value[20] = '\0';
00254     return value;
00255 
00256 }

void DHTTestApp::finish (  )  [protected]

collects statistical data

Reimplemented from BaseApp.

00259 {
00260     // record scalar data
00261     globalStatistics->addStdDev("DHTTest: Sent Messages", numSent);
00262     globalStatistics->addStdDev("DHTTest: Get Messages sent", numGetSent);
00263     globalStatistics->addStdDev("DHTTest: Get Errors", numGetError);
00264     globalStatistics->addStdDev("DHTTest: Get Success", numGetSuccess);
00265     globalStatistics->addStdDev("DHTTest: Put Messages sent", numPutSent);
00266     globalStatistics->addStdDev("DHTTest: Put Errors", numPutError);
00267     globalStatistics->addStdDev("DHTTest: Put Success", numPutSuccess);
00268 }

void DHTTestApp::handleGetResponse ( DHTgetCAPIResponse *  msg  )  [protected, virtual]

processes get responses

method to handle get responses should be overwritten in derived application if needed

Parameters:
msg get response message
00123 {
00124     OverlayKey key = msg->getKey();
00125     globalStatistics->addStdDev("DHTTest: Get length (s)", simTime() - lastGetTime);
00126     if (!(msg->getIsSuccess()))
00127     {
00128         numGetError++;
00129         return;
00130     }
00131     std::map<OverlayKey, DHTEntry>::iterator it =  bootstrapOracle->getDataMap()->find(key);
00132 
00133     if (it == bootstrapOracle->getDataMap()->end()) //unexpected key
00134     {
00135       numGetError++;
00136       return;
00137     }
00138     DHTEntry entry = it->second;
00139     if (simulation.simTime() > entry.endtime) 
00140     {
00141         //this key doesn't exist anymore in the DHT, delete it in our hashtable
00142         bootstrapOracle->getDataMap()->erase(key);
00143         if (msg->getValue() != BinaryValue::UNSPECIFIED_VALUE) {
00144             numGetError++;
00145             return;
00146         }
00147         else {
00148             numGetSuccess++;
00149             return;
00150         }
00151     }
00152     else {
00153         if (dynamic_cast< vector<char>& >((msg->getValue())) != dynamic_cast< vector<char>& >(*(entry.value))) {
00154             numGetError++;
00155             return;
00156         }
00157         else {
00158             numGetSuccess++;
00159             return;
00160         }
00161     }
00162 
00163 }

void DHTTestApp::handlePutResponse ( DHTputCAPIResponse *  msg  )  [protected, virtual]

processes put responses

method to handle put responses should be overwritten in derived application if needed

Parameters:
msg put response message
00106 {
00107     OverlayKey key = msg->getKey();
00108     globalStatistics->addStdDev("DHTTest: Put length (s)", simTime() - lastPutTime);
00109     if (!(msg->getIsSuccess()))
00110     {
00111         numPutError++;
00112         return;
00113     }
00114     numPutSuccess++;
00115     DHTEntry entry;
00116     entry.value = new BinaryValue(msg->getValue());
00117     entry.endtime = simulation.simTime()+30000;
00118     bootstrapOracle->getDataMap()->erase(msg->getKey());
00119     bootstrapOracle->getDataMap()->insert(make_pair(msg->getKey(), entry));
00120 }

void DHTTestApp::handleTimerEvent ( cMessage *  msg  )  [protected, virtual]

processes self-messages

method to handle self-messages should be overwritten in derived application if needed

Parameters:
msg self-message

Reimplemented from BaseApp.

00166 {
00167     if (msg->isName("dhttest_put_timer")) {
00168         // schedule next timer event
00169         scheduleAt(simulation.simTime() + truncnormal(mean, deviation), msg);
00170 
00171         // do nothing if the network is still in the initialization phase
00172         if((!activeNetwInitPhase) && (underlayConfigurator->isInit()))
00173             return;
00174 
00175         // create a put test message with random destination key
00176         OverlayKey destKey = OverlayKey::random();
00177         DHTputCAPICall* dhtPutMsg = new DHTputCAPICall();
00178         char * value = generateRandomValue();
00179         dhtPutMsg->setKey(destKey);
00180         dhtPutMsg->setValue(value);
00181         dhtPutMsg->setTtl(30000);
00182         dhtPutMsg->setIsModifiable(true);
00183         free(value);
00184         
00185         lastPutTime = simTime();
00186         numSent++;
00187         numPutSent++;
00188         sendRpcMessage(RPC_TO_LOWERTIER, NodeHandle::UNSPECIFIED_NODE, dhtPutMsg, NULL, OverlayKey::UNSPECIFIED_KEY, -1, 0);
00189     }
00190     if (msg->isName("dhttest_get_timer")) {
00191         scheduleAt(simulation.simTime() + truncnormal(mean, deviation), msg);
00192         OverlayKey key =  getRandomKey();
00193         if (key.isUnspecified()) return;
00194         DHTgetCAPICall* dhtGetMsg = new DHTgetCAPICall();
00195         dhtGetMsg->setKey(key);
00196         lastGetTime = simTime();
00197         numSent++;
00198         numGetSent++;
00199         sendRpcMessage(RPC_TO_LOWERTIER, NodeHandle::UNSPECIFIED_NODE, dhtGetMsg, NULL, OverlayKey::UNSPECIFIED_KEY, -1, 0);
00200     }
00201     if (msg->isName("dhttest_mod_timer")) {
00202         scheduleAt(simulation.simTime() + truncnormal(mean, deviation), msg);
00203         OverlayKey key =  getRandomKey();
00204         if (key.isUnspecified()) return;
00205         DHTputCAPICall* dhtPutMsg = new DHTputCAPICall();
00206         char * value = generateRandomValue();
00207         dhtPutMsg->setKey(key);
00208         dhtPutMsg->setValue(value);
00209         dhtPutMsg->setTtl(30000);
00210         dhtPutMsg->setIsModifiable(true);
00211         free(value);
00212         lastPutTime = simTime();
00213         numSent++;
00214         numPutSent++;
00215         sendRpcMessage(RPC_TO_LOWERTIER, NodeHandle::UNSPECIFIED_NODE, dhtPutMsg, NULL, OverlayKey::UNSPECIFIED_KEY, -1, 0);
00216     }
00217 }

void DHTTestApp::handleRpcResponse ( BaseResponseMessage *  msg,
int  rpcId,
simtime_t  rtt 
) [protected, virtual]

This method is called if an RPC response has been received.

Parameters:
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 }


Member Data Documentation

UnderlayConfigurator* DHTTestApp::underlayConfigurator [protected]

pointer to UnderlayConfigurator in this node

Reimplemented from BaseApp.

BootstrapOracle* DHTTestApp::bootstrapOracle [protected]

pointer to BootstrapOracle in this node

Reimplemented from BaseApp.

GlobalStatistics* DHTTestApp::globalStatistics [protected]

pointer to GlobalStatistics module in this node

Reimplemented from BaseApp.

bool DHTTestApp::debugOutput [protected]

debug output yes/no?

Reimplemented from BaseApp.

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]

number of sent packets

Reimplemented from BaseApp.

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

simtime_t DHTTestApp::lastPutTime [protected]

simtime_t DHTTestApp::lastGetTime [protected]


The documentation for this class was generated from the following files:
Generated on Wed Sep 26 12:13:01 2007 for ITM OverSim by  doxygen 1.5.1