OverSim
DHTTestApp Class Reference

A simple test application for the DHT layer. More...

#include <DHTTestApp.h>

Inheritance diagram for DHTTestApp:
BaseApp BaseRpc BaseTcpSupport RpcListener

Classes

class  DHTStatsContext
 A container used by the DHTTestApp to store context information for statistics. More...

Public Member Functions

 DHTTestApp ()
virtual ~DHTTestApp ()
 virtual destructor
- Public Member Functions inherited from BaseApp
 BaseApp ()
virtual ~BaseApp ()
 virtual destructor
- Public Member Functions inherited from BaseRpc
 BaseRpc ()
const NodeHandlegetThisNode ()
 Returns the NodeHandle of this node.
simtime_t getUdpTimeout ()
- Public Member Functions inherited from RpcListener
virtual ~RpcListener ()
 destructor
- Public Member Functions inherited from BaseTcpSupport
virtual void socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent)
virtual void socketEstablished (int connId, void *yourPtr)
virtual void socketPeerClosed (int connId, void *yourPtr)
virtual void socketFailure (int connId, void *yourPtr, int code)
virtual void socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status)

Private Member Functions

void initializeApp (int stage)
OverlayKey getRandomKey ()
 Get a random key of the hashmap.
BinaryValue generateRandomValue ()
 generate a random human readable binary value
void finishApp ()
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 ()
void handleRpcResponse (BaseResponseMessage *msg, const RpcState &state, simtime_t rtt)

Private Attributes

UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
GlobalNodeListglobalNodeList
 pointer to GlobalNodeList in this node
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
GlobalDhtTestMapglobalDhtTestMap
 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 p2pnsTraffic
 model p2pns application traffic */
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

Additional Inherited Members

- Public Types inherited from BaseTcpSupport
enum  EvCode {
  NO_EST_CONNECTION, PEER_CLOSED, PEER_TIMEDOUT, PEER_REFUSED,
  CONNECTION_RESET, CONNECTION_SUCC_ClOSED
}
- Protected Member Functions inherited from BaseApp
int numInitStages () const
 method to set InitStage
void initialize (int stage)
 initializes base class-attributes
virtual void initializeApp (int stage)
 initializes derived class-attributes
void handleMessage (cMessage *msg)
 checks for message type and calls corresponding method
virtual void receiveChangeNotification (int category, const cPolymorphic *details)
 callback-method for events at the NotificationBoard
virtual void handleTransportAddressChangedNotification ()
 This method gets call if the node has a new TransportAddress (IP address) because he changed his access network.
virtual void handleNodeLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed.
virtual void handleNodeGracefulLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed if this node is among the gracefulLeaveProbability nodes.
void finish ()
 collects statistical data
virtual void finishApp ()
 collects statistical data of derived app
void callRoute (const OverlayKey &key, cPacket *msg, const TransportAddress &hint=TransportAddress::UNSPECIFIED_NODE, RoutingType routingType=DEFAULT_ROUTING)
 Common API function: calls route-method in overlay.
void callRoute (const OverlayKey &key, cPacket *msg, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType=DEFAULT_ROUTING)
virtual void deliver (OverlayKey &key, cMessage *msg)
 Common API function: handles delivered messages from overlay.
virtual void forward (OverlayKey *key, cPacket **msg, NodeHandle *nextHopNode)
 Common API function: handles messages from overlay to be forwarded.
virtual void update (const NodeHandle &node, bool joined)
 Common API function: informs application about neighbors and own nodeID.
NodeVectorcallLocalLookup (const OverlayKey &key, int num, bool safe)
 Common API function: produces a list of nodes that can be used as next hops towards key.
NodeVectorcallNeighborSet (int num)
 Common API function: produces a list of neighbor nodes.
bool isSiblingFor (const NodeHandle &node, const OverlayKey &key, int numSiblings, bool *err)
 Query if a node is among the siblings for a given key.
virtual void handleLowerMessage (cMessage *msg)
 processes self-messages
virtual void handleUpperMessage (cMessage *msg)
 handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function)
virtual void handleUDPMessage (cMessage *msg)
 method to handle messages that come directly from the UDP gate
virtual void handleReadyMessage (CompReadyMessage *msg)
 method to handle ready messages from the overlay
virtual void bindToPort (int port)
 Tells UDP we want to get all packets arriving on the given port.
virtual void sendMessageToUDP (const TransportAddress &destAddr, cPacket *msg, simtime_t delay=SIMTIME_ZERO)
 Sends a packet over UDP.
virtual void handleTraceMessage (cMessage *msg)
 handleTraceMessage gets called of handleMessage(cMessage* msg) if a message arrives at trace_in.
void sendMessageToLowerTier (cPacket *msg)
 sends non-commonAPI message to the lower tier
bool internalHandleRpcCall (BaseCallMessage *msg)
 Handles internal rpc requests.
void internalHandleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 Handles rpc responses internal in base classes

void internalSendRouteRpc (BaseRpcMessage *message, const OverlayKey &destKey, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType)
virtual CompType getThisCompType ()
 Return the component type of this module.
void sendReadyMessage (bool ready=true, const OverlayKey &nodeId=OverlayKey::UNSPECIFIED_KEY)
- Protected Attributes inherited from BaseApp
UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
GlobalNodeListglobalNodeList
 pointer to GlobalNodeList in this node
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
NotificationBoard * notificationBoard
 pointer to NotificationBoard in this node
bool debugOutput
 debug output yes/no?
int numOverlaySent
 number of sent packets to overlay
int bytesOverlaySent
 number of sent bytes to overlay
int numOverlayReceived
 number of received packets from overlay
int bytesOverlayReceived
 number of received bytes from overlay
int numUdpSent
 number of sent packets to UDP
int bytesUdpSent
 number of sent bytes to UDP
int numUdpReceived
 number of received packets from UDP
int bytesUdpReceived
 number of received bytes from UDP
simtime_t creationTime
 simTime when the App has been created

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

Definition at line 50 of file DHTTestApp.h.

Constructor & Destructor Documentation

DHTTestApp::DHTTestApp ( )

Definition at line 46 of file DHTTestApp.cc.

DHTTestApp::~DHTTestApp ( )
virtual

virtual destructor

Definition at line 39 of file DHTTestApp.cc.

{
cancelAndDelete(dhttestput_timer);
cancelAndDelete(dhttestget_timer);
cancelAndDelete(dhttestmod_timer);
}

Member Function Documentation

void DHTTestApp::finishApp ( )
private

Definition at line 450 of file DHTTestApp.cc.

{
// record scalar data
globalStatistics->addStdDev("DHTTestApp: Sent Total Messages/s",
numSent / time);
globalStatistics->addStdDev("DHTTestApp: Sent GET Messages/s",
numGetSent / time);
globalStatistics->addStdDev("DHTTestApp: Failed GET Requests/s",
numGetError / time);
globalStatistics->addStdDev("DHTTestApp: Successful GET Requests/s",
numGetSuccess / time);
globalStatistics->addStdDev("DHTTestApp: Sent PUT Messages/s",
numPutSent / time);
globalStatistics->addStdDev("DHTTestApp: Failed PUT Requests/s",
numPutError / time);
globalStatistics->addStdDev("DHTTestApp: Successful PUT Requests/s",
numPutSuccess / time);
if ((numGetSuccess + numGetError) > 0) {
globalStatistics->addStdDev("DHTTestApp: GET Success Ratio",
(double) numGetSuccess
/ (double) (numGetSuccess + numGetError));
}
}
}
BinaryValue DHTTestApp::generateRandomValue ( )
private

generate a random human readable binary value

Definition at line 433 of file DHTTestApp.cc.

{
char value[DHTTESTAPP_VALUE_LEN + 1];
for (int i = 0; i < DHTTESTAPP_VALUE_LEN; i++) {
value[i] = intuniform(0, 25) + 'a';
}
value[DHTTESTAPP_VALUE_LEN] = '\0';
return BinaryValue(value);
}
OverlayKey DHTTestApp::getRandomKey ( )
private

Get a random key of the hashmap.

void DHTTestApp::handleGetResponse ( DHTgetCAPIResponse msg,
DHTStatsContext context 
)
privatevirtual

processes get responses

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

Parameters
msgget response message
contextcontext object used for collecting statistics

Definition at line 173 of file DHTTestApp.cc.

{
if (context->measurementPhase == false) {
// don't count response, if the request was not sent
// in the measurement phase
delete context;
return;
}
RECORD_STATS(globalStatistics->addStdDev("DHTTestApp: GET Latency (s)",
SIMTIME_DBL(simTime() - context->requestTime)));
if (!(msg->getIsSuccess())) {
//cout << "DHTTestApp: success == false" << endl;
delete context;
return;
}
const DHTEntry* entry = globalDhtTestMap->findEntry(context->key);
if (entry == NULL) {
//unexpected key
//cout << "DHTTestApp: unexpected key" << endl;
delete context;
return;
}
if (simTime() > entry->endtime) {
//this key doesn't exist anymore in the DHT, delete it in our hashtable
globalDhtTestMap->eraseEntry(context->key);
delete context;
if (msg->getResultArraySize() > 0) {
//cout << "DHTTestApp: deleted key still available" << endl;
return;
} else {
//cout << "DHTTestApp: success (1)" << endl;
return;
}
} else {
delete context;
if ((msg->getResultArraySize() > 0) &&
(msg->getResult(0).getValue() == entry->value)) {
//cout << "DHTTestApp: success (2)" << endl;
return;
} else {
#if 0
if (msg->getResultArraySize()) {
cout << "DHTTestApp: wrong value: " << msg->getResult(0).getValue() << endl;
} else {
cout << "DHTTestApp: no value" << endl;
}
#endif
return;
}
}
}
void DHTTestApp::handleNodeLeaveNotification ( )
privatevirtual

Definition at line 445 of file DHTTestApp.cc.

{
}
void DHTTestApp::handlePutResponse ( DHTputCAPIResponse msg,
DHTStatsContext context 
)
privatevirtual

processes put responses

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

Parameters
msgput response message
contextcontext object used for collecting statistics

Definition at line 147 of file DHTTestApp.cc.

{
DHTEntry entry = {context->value, simTime() + ttl, simTime()};
globalDhtTestMap->insertEntry(context->key, entry);
if (context->measurementPhase == false) {
// don't count response, if the request was not sent
// in the measurement phase
delete context;
return;
}
if (msg->getIsSuccess()) {
RECORD_STATS(globalStatistics->addStdDev("DHTTestApp: PUT Latency (s)",
SIMTIME_DBL(simTime() - context->requestTime)));
} else {
//cout << "DHTTestApp: PUT failed" << endl;
}
delete context;
}
void DHTTestApp::handleRpcResponse ( BaseResponseMessage msg,
const RpcState state,
simtime_t  rtt 
)
private

Definition at line 121 of file DHTTestApp.cc.

{
RPC_ON_RESPONSE( DHTputCAPI ) {
handlePutResponse(_DHTputCAPIResponse,
check_and_cast<DHTStatsContext*>(state.getContext()));
EV << "[DHTTestApp::handleRpcResponse()]\n"
<< " DHT Put RPC Response received: id=" << state.getId()
<< " msg=" << *_DHTputCAPIResponse << " rtt=" << rtt
<< endl;
break;
}
RPC_ON_RESPONSE(DHTgetCAPI)
{
handleGetResponse(_DHTgetCAPIResponse,
check_and_cast<DHTStatsContext*>(state.getContext()));
EV << "[DHTTestApp::handleRpcResponse()]\n"
<< " DHT Get RPC Response received: id=" << state.getId()
<< " msg=" << *_DHTgetCAPIResponse << " rtt=" << rtt
<< endl;
break;
}
}
void DHTTestApp::handleTimerEvent ( cMessage *  msg)
privatevirtual

processes self-messages

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

Parameters
msgself-message

Definition at line 298 of file DHTTestApp.cc.

{
if (msg->isName("dhttest_put_timer")) {
// schedule next timer event
scheduleAt(simTime() + truncnormal(mean, deviation), msg);
// do nothing if the network is still in the initialization phase
return;
if (p2pnsTraffic) {
for (int i = 0; i < 4; i++) {
// create a put test message with random destination key
DHTputCAPICall* dhtPutMsg = new DHTputCAPICall();
dhtPutMsg->setKey(destKey);
dhtPutMsg->setTtl(ttl);
dhtPutMsg->setIsModifiable(true);
new DHTStatsContext(globalStatistics->isMeasuring(),
simTime(), destKey, dhtPutMsg->getValue()));
}
}
cancelEvent(msg);
return;
}
// create a put test message with random destination key
DHTputCAPICall* dhtPutMsg = new DHTputCAPICall();
dhtPutMsg->setKey(destKey);
dhtPutMsg->setTtl(ttl);
dhtPutMsg->setIsModifiable(true);
new DHTStatsContext(globalStatistics->isMeasuring(),
simTime(), destKey, dhtPutMsg->getValue()));
} else if (msg->isName("dhttest_get_timer")) {
scheduleAt(simTime() + truncnormal(mean, deviation), msg);
// do nothing if the network is still in the initialization phase
return;
}
if (p2pnsTraffic && (uniform(0, 1) > ((double)mean/1800.0))) {
return;
}
if (key.isUnspecified()) {
EV << "[DHTTestApp::handleTimerEvent() @ " << thisNode.getIp()
<< " (" << thisNode.getKey().toString(16) << ")]\n"
<< " Error: No key available in global DHT test map!"
<< endl;
return;
}
DHTgetCAPICall* dhtGetMsg = new DHTgetCAPICall();
dhtGetMsg->setKey(key);
new DHTStatsContext(globalStatistics->isMeasuring(),
simTime(), key));
} else if (msg->isName("dhttest_mod_timer")) {
scheduleAt(simTime() + truncnormal(mean, deviation), msg);
// do nothing if the network is still in the initialization phase
return;
}
if (p2pnsTraffic) {
if (key.isUnspecified())
return;
DHTputCAPICall* dhtPutMsg = new DHTputCAPICall();
dhtPutMsg->setKey(key);
dhtPutMsg->setTtl(ttl);
dhtPutMsg->setIsModifiable(true);
new DHTStatsContext(globalStatistics->isMeasuring(),
simTime(), key, dhtPutMsg->getValue()));
}
cancelEvent(msg);
return;
}
if (key.isUnspecified())
return;
#if 0
const DHTEntry* entry = globalDhtTestMap->findEntry(key);
if (entry->insertiontime + 10.0 > simTime()) {
std::cout << "avoided early get" << std::endl;
return;
}
#endif
DHTputCAPICall* dhtPutMsg = new DHTputCAPICall();
dhtPutMsg->setKey(key);
dhtPutMsg->setTtl(ttl);
dhtPutMsg->setIsModifiable(true);
new DHTStatsContext(globalStatistics->isMeasuring(),
simTime(), key, dhtPutMsg->getValue()));
}
}
void DHTTestApp::handleTraceMessage ( cMessage *  msg)
privatevirtual

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.

Parameters
msgthe command message to handle

Definition at line 240 of file DHTTestApp.cc.

{
char* cmd = new char[strlen(msg->getName()) + 1];
strcpy(cmd, msg->getName());
if (strlen(msg->getName()) < 5) {
delete[] cmd;
delete msg;
return;
}
if (strncmp(cmd, "PUT ", 4) == 0) {
// Generate key
char* buf = cmd + 4;
while (!isspace(buf[0])) {
if (buf[0] == '\0')
throw cRuntimeError("Error parsing PUT command");
buf++;
}
buf[0] = '\0';
BinaryValue b(cmd + 4);
// get value
buf++;
// build putMsg
DHTputCAPICall* dhtPutMsg = new DHTputCAPICall();
dhtPutMsg->setKey(destKey);
dhtPutMsg->setValue(buf);
dhtPutMsg->setTtl(ttl);
dhtPutMsg->setIsModifiable(true);
new DHTStatsContext(globalStatistics->isMeasuring(),
simTime(), destKey, buf));
} else if (strncmp(cmd, "GET ", 4) == 0) {
// Get key
BinaryValue b(cmd + 4);
DHTgetCAPICall* dhtGetMsg = new DHTgetCAPICall();
dhtGetMsg->setKey(key);
new DHTStatsContext(globalStatistics->isMeasuring(),
simTime(), key));
} else {
throw cRuntimeError("Unknown trace command; "
"only GET and PUT are allowed");
}
delete[] cmd;
delete msg;
}
void DHTTestApp::initializeApp ( int  stage)
private

Definition at line 53 of file DHTTestApp.cc.

{
if (stage != MIN_STAGE_APP)
return;
// fetch parameters
debugOutput = par("debugOutput");
activeNetwInitPhase = par("activeNetwInitPhase");
mean = par("testInterval");
p2pnsTraffic = par("p2pnsTraffic");
deviation = mean / 10;
if (p2pnsTraffic) {
ttl = 3600*24*365;
} else {
ttl = par("testTtl");
}
globalDhtTestMap = dynamic_cast<GlobalDhtTestMap*>(simulation.getModuleByPath(
"globalObserver.globalFunctions[0].function"));
if (globalDhtTestMap == NULL) {
throw cRuntimeError("DHTTestApp::initializeApp(): "
"GlobalDhtTestMap module not found!");
}
// statistics
numSent = 0;
//initRpcs();
WATCH(numSent);
WATCH(numGetSent);
WATCH(numGetError);
WATCH(numGetSuccess);
WATCH(numPutSent);
WATCH(numPutError);
WATCH(numPutSuccess);
// initiate test message transmission
dhttestput_timer = new cMessage("dhttest_put_timer");
dhttestget_timer = new cMessage("dhttest_get_timer");
dhttestmod_timer = new cMessage("dhttest_mod_timer");
if (mean > 0) {
scheduleAt(simTime() + truncnormal(mean, deviation),
scheduleAt(simTime() + truncnormal(mean + mean / 3,
scheduleAt(simTime() + truncnormal(mean + 2 * mean / 3,
}
}

Member Data Documentation

bool DHTTestApp::activeNetwInitPhase
private

is app active in network init phase?

Definition at line 148 of file DHTTestApp.h.

bool DHTTestApp::debugOutput
private

debug output yes/no?

Definition at line 143 of file DHTTestApp.h.

double DHTTestApp::deviation
private

deviation of time interval

Definition at line 145 of file DHTTestApp.h.

const int DHTTestApp::DHTTESTAPP_VALUE_LEN = 20
staticprivate

Definition at line 162 of file DHTTestApp.h.

cMessage * DHTTestApp::dhttestget_timer
private

Definition at line 159 of file DHTTestApp.h.

cMessage * DHTTestApp::dhttestmod_timer
private

Definition at line 159 of file DHTTestApp.h.

cMessage* DHTTestApp::dhttestput_timer
private

Definition at line 159 of file DHTTestApp.h.

GlobalDhtTestMap* DHTTestApp::globalDhtTestMap
private

pointer to the GlobalDhtTestMap module

Definition at line 140 of file DHTTestApp.h.

GlobalNodeList* DHTTestApp::globalNodeList
private

pointer to GlobalNodeList in this node

Definition at line 137 of file DHTTestApp.h.

GlobalStatistics* DHTTestApp::globalStatistics
private

pointer to GlobalStatistics module in this node

Definition at line 139 of file DHTTestApp.h.

double DHTTestApp::mean
private

mean time interval between sending test messages

Definition at line 144 of file DHTTestApp.h.

bool DHTTestApp::nodeIsLeavingSoon
private

true if the node is going to be killed shortly

Definition at line 160 of file DHTTestApp.h.

int DHTTestApp::numGetError
private

number of false get responses

Definition at line 153 of file DHTTestApp.h.

int DHTTestApp::numGetSent
private

number of get sent

Definition at line 152 of file DHTTestApp.h.

int DHTTestApp::numGetSuccess
private

number of false get responses

Definition at line 154 of file DHTTestApp.h.

int DHTTestApp::numPutError
private

number of error in put responses

Definition at line 156 of file DHTTestApp.h.

int DHTTestApp::numPutSent
private

number of put sent

Definition at line 155 of file DHTTestApp.h.

int DHTTestApp::numPutSuccess
private

number of success in put responses

Definition at line 157 of file DHTTestApp.h.

int DHTTestApp::numSent
private

number of sent packets

Definition at line 151 of file DHTTestApp.h.

bool DHTTestApp::p2pnsTraffic
private

model p2pns application traffic */

Definition at line 147 of file DHTTestApp.h.

int DHTTestApp::ttl
private

ttl for stored DHT records

Definition at line 146 of file DHTTestApp.h.

UnderlayConfigurator* DHTTestApp::underlayConfigurator
private

pointer to UnderlayConfigurator in this node

Definition at line 135 of file DHTTestApp.h.


The documentation for this class was generated from the following files: