KBRTestApp Class Reference

#include <KBRTestApp.h>

Inheritance diagram for KBRTestApp:

BaseApp BaseRpc RpcListener List of all members.

Detailed Description

Test application for KBR interface.

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.


Protected 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, cMessage **msg, NodeHandle *nextHopNode)
 Common API function: handles messages from overlay to be forwarded.
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, int rpcId, simtime_t rtt)
 This method is called if an RPC response has been received.
void handleLookupResponse (LookupResponse *msg)
virtual void handleNodeLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed.

Protected 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
cOutVector delayVector
 statistical output vector for packet-delays
cOutVector hopCountVector
 statistical output vector for hop-counts


Member Function Documentation

void KBRTestApp::initializeApp ( int  stage  )  [protected, virtual]

initializes derived class-attributes

Parameters:
stage the init stage

Reimplemented from BaseApp.

00034 {
00035     if(stage != MIN_STAGE_APP)
00036         return;
00037 
00038     lookupNodeIds = par("lookupNodeIds");
00039     mean = par("messageDelay");
00040     deviation = mean / 10;
00041     activeNetwInitPhase = par("activeNetwInitPhase");
00042 
00043     numDelivered = 0;
00044     bytesDelivered = 0;
00045     WATCH(numDelivered);
00046     WATCH(bytesDelivered);
00047 
00048     nodeIsLeavingSoon = false;
00049     delayVector.setName("Delay Time");
00050     hopCountVector.setName("Hop Count");
00051 
00052     // initiate test message emision
00053     cMessage* test_timer = new cMessage("test_timer");
00054     scheduleAt(simulation.simTime() + truncnormal(mean, deviation), test_timer);
00055 }

void KBRTestApp::finishApp (  )  [protected, virtual]

collects statistical data of derived app

Reimplemented from BaseApp.

00205 {
00206     simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime);
00207     
00208     if(time != 0) {    
00209         globalStatistics->addStdDev("KBRTestApp: Delivered Messages/s",
00210                                     numDelivered / time);
00211         globalStatistics->addStdDev("KBRTestApp: Delivered Bytes/s",
00212                                     bytesDelivered / time);
00213     
00214         if (numSent != 0)
00215             globalStatistics->addStdDev("KBRTestApp: Delivery Ratio",
00216                                         (float) numDelivered / (float) numSent);
00217         else
00218             globalStatistics->addStdDev("KBRTestApp: Delivery Ratio", 0);
00219     }
00220 }

void KBRTestApp::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.

00058 {
00059     if (msg->isName("test_timer")) {
00060         // schedule next timer event
00061         scheduleAt(simulation.simTime() + truncnormal(mean, deviation), msg);
00062 
00063         // do nothing if the network is still in the initialization phase
00064         if ((!activeNetwInitPhase && underlayConfigurator->isInit())
00065             || underlayConfigurator->isSimulationEndingSoon()
00066             || nodeIsLeavingSoon) {
00067 
00068             return;
00069         }
00070 
00071         OverlayKey destKey;
00072         if (lookupNodeIds) {
00073             destKey = bootstrapOracle->getBootstrapNode().key;
00074             // do nothing if there are currently no nodes in the network
00075             if (destKey.isUnspecified())
00076                 return;
00077         } else {
00078             // generate random destination key
00079             destKey = OverlayKey::random();
00080         }
00081 
00082         // create a 100 byte test message
00083         KBRTestMessage* testMsg = new KBRTestMessage("KBRTestMessage");
00084         testMsg->setId(id());
00085         testMsg->setSeqNum(numSent);
00086         testMsg->setByteLength(100);
00087         testMsg->setMeasurementPhase(globalStatistics->isMeasuring());
00088 
00089         RECORD_STATS(globalStatistics->sentKBRTestAppMessages++);
00090 
00091         callRoute(destKey, testMsg);
00092 /*
00093         LookupCall* call = new LookupCall();
00094         call->setLength(0);
00095         call->setKey(destKey);
00096         call->setNumSiblings(overlay->getMaxNumSiblings());
00097         sendRpcMessage(RPC_TO_LOWERTIER, NodeHandle::UNSPECIFIED_NODE,
00098                        call, NULL, OverlayKey::UNSPECIFIED_KEY, -1, 0);
00099 */
00100 
00101     }
00102 }

void KBRTestApp::deliver ( OverlayKey key,
cMessage *  msg 
) [protected, virtual]

Common API function: handles delivered messages from overlay.

method to handle decapsulated KBRdeliver messages from overlay module, should be overwritten in derived application

Parameters:
key destination key
msg delivered message

Reimplemented from BaseApp.

00142 {
00143     KBRTestMessage* testMsg = check_and_cast<KBRTestMessage*>(msg);
00144     OverlayCtrlInfo* overlayCtrlInfo =
00145         check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo());
00146 
00147     if (thisNode.key.isUnspecified())
00148         error("key");
00149 
00150     // Return statistical data to the sender.
00151     if(cModule* mod = simulation.module(testMsg->getId())) {
00152         if(KBRTestApp* sender = dynamic_cast<KBRTestApp*>(mod)) {
00153             if((!lookupNodeIds) || (thisNode.key ==
00154                                     key /*overlayCtrlInfo->getDestKey()*/))
00155             {
00156                 if (testMsg->getMeasurementPhase() == true) {
00157                     sender->evaluateData((simTime() - testMsg->creationTime()),
00158                                          overlayCtrlInfo->getHopCount(),
00159                                          testMsg->byteLength());
00160                 }
00161             }
00162         }
00163     }
00164 
00165     EV << "[KBRTestApp::deliver() @ " << thisNode.ip
00166        << " (" << thisNode.key.toString(16) << ")]\n"
00167        << "    Received \"" << testMsg->name() << "(seqNr: " << testMsg->getSeqNum() << ")\n"
00168        << "    with destination key: " << key.toString(16)
00169        << endl;
00170 
00171     delete overlayCtrlInfo;
00172     delete testMsg;
00173 }

void KBRTestApp::forward ( OverlayKey key,
cMessage **  msg,
NodeHandle nextHopNode 
) [protected, 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

Parameters:
key destination key
msg message to forward
nextHopNode next hop

Reimplemented from BaseApp.

00177 {
00178     KBRTestMessage* tempMsg = check_and_cast<KBRTestMessage*>(*msg);
00179 
00180     tempMsg->setVisitedNodesArraySize(tempMsg->getVisitedNodesArraySize() + 1);
00181     tempMsg->setVisitedNodes(tempMsg->getVisitedNodesArraySize() - 1,
00182                              thisNode.ip);
00183 }

void KBRTestApp::evaluateData ( simtime_t  timeDelay,
int  hopCount,
long int  bytes 
) [protected]

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.

Parameters:
timeDelay packet-delay
hopCount packet hop-count
bytes packet size in bytes
00186 {
00187     // count the number and size of successfully delivered messages
00188     RECORD_STATS(numDelivered++; bytesDelivered += bytes; globalStatistics->deliveredKBRTestAppMessages++);
00189 
00190     if (numSent < numDelivered)
00191         error("KBRTestApp::evaluateData(): numSent < numDelivered!");
00192 
00193 
00194     // record vectorial data
00195     RECORD_STATS(delayVector.record(timeDelay));
00196     RECORD_STATS(hopCountVector.record(hopCount));
00197 
00198     RECORD_STATS(globalStatistics->recordOutVector("KBRTestApp: Global Hop "
00199                                                    "Count", hopCount));
00200     RECORD_STATS(globalStatistics->recordOutVector("KBRTestApp: Global Time "
00201                                                    "Delay", timeDelay));
00202 }

void KBRTestApp::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.

00106 {
00107     RPC_SWITCH_START(msg)
00108     RPC_ON_RESPONSE(Lookup) {
00109     handleLookupResponse(_LookupResponse);
00110     EV << "[KBRTestApp::handleRpcResponse() @ " << thisNode.ip
00111        << " (" << thisNode.key.toString(16) << ")]\n"
00112        << "    Lookup RPC Response received: id=" << rpcId << "\n"
00113        << "    msg=" << *_LookupResponse << " rtt=" << rtt
00114        << endl;
00115     break;
00116     }
00117     RPC_SWITCH_END( )
00118 }

void KBRTestApp::handleLookupResponse ( LookupResponse *  msg  )  [protected]

00121 {
00122     EV << "[KBRTestApp::handleLookupResponse() @ " << thisNode.ip
00123        << " (" << thisNode.key.toString(16) << ")]\n"
00124        << "    Lookup response for key " << msg->getKey()<< " : ";
00125     if (msg->getIsValid()) {
00126         for (uint i=0; i<msg->getSiblingsArraySize(); i++) {
00127             EV << endl << "    " << msg->getSiblings(i);
00128         }
00129     } else {
00130         EV << "failed";
00131     }
00132     EV << endl;
00133 }

void KBRTestApp::handleNodeLeaveNotification (  )  [protected, virtual]

This method gets call **.gracefulLeaveDelay seconds before it is killed.

Reimplemented from BaseApp.

00136 {
00137     nodeIsLeavingSoon = true;
00138 }


Member Data Documentation

double KBRTestApp::mean [protected]

mean time interval between sending test messages

double KBRTestApp::deviation [protected]

deviation of time interval

bool KBRTestApp::activeNetwInitPhase [protected]

is app active in network init phase?

bool KBRTestApp::lookupNodeIds [protected]

lookup only existing nodeIDs

bool KBRTestApp::nodeIsLeavingSoon [protected]

true if the node is going to be killed shortly

int KBRTestApp::numDelivered [protected]

number of delivered packets

int KBRTestApp::bytesDelivered [protected]

number of delivered bytes

cOutVector KBRTestApp::delayVector [protected]

statistical output vector for packet-delays

cOutVector KBRTestApp::hopCountVector [protected]

statistical output vector for hop-counts


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