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 Types

typedef std::vector
< MsgHandle
MsgHandleBuf

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.
bool checkSeen (const OverlayKey &key, int seqNum)
 Checks if a message was already seen before.
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
uint sequenceNumber
int msgHandleBufSize
 how many MsgHandles to store in circular buffer
MsgHandleBuf mhBuf
 circular buffer of MsgHandles
MsgHandleBuf::iterator mhBufBegin
 begin of circular buffer
MsgHandleBuf::iterator mhBufNext
 next element to insert
MsgHandleBuf::iterator mhBufEnd
 end of circular buffer
cOutVector delayVector
 statistical output vector for packet-delays
cOutVector hopCountVector
 statistical output vector for hop-counts

Classes

struct  MsgHandle
 type for storing seen messages in a circular buffer, holds OverlayKey of the sender and SequenceNumber More...


Member Typedef Documentation

typedef std::vector<MsgHandle> KBRTestApp::MsgHandleBuf [protected]


Member Function Documentation

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

initializes derived class-attributes

Parameters:
stage the init stage

Reimplemented from BaseApp.

00033 {
00034     if (stage != MIN_STAGE_APP) {
00035         return;
00036     }
00037 
00038     lookupNodeIds = par("lookupNodeIds");
00039     mean = par("messageDelay");
00040     deviation = mean / 10;
00041     activeNetwInitPhase = par("activeNetwInitPhase");
00042     msgHandleBufSize = par("msgHandleBufSize");
00043 
00044     numDelivered = 0;
00045     bytesDelivered = 0;
00046     WATCH(numDelivered);
00047     WATCH(bytesDelivered);
00048 
00049     sequenceNumber = 0;
00050 
00051     nodeIsLeavingSoon = false;
00052     delayVector.setName("Delay Time");
00053     hopCountVector.setName("Hop Count");
00054 
00055     // initialize circular buffer
00056     if (msgHandleBufSize > 0) {
00057         mhBuf.resize(msgHandleBufSize);
00058         mhBufBegin = mhBuf.begin();
00059         mhBufEnd = mhBuf.end();
00060         mhBufNext = mhBufBegin;
00061     }
00062 
00063     // initiate test message emision
00064     cMessage* test_timer = new cMessage("test_timer");
00065     scheduleAt(simulation.simTime() + truncnormal(mean, deviation), test_timer);
00066 }

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

collects statistical data of derived app

Reimplemented from BaseApp.

00254 {
00255     simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime);
00256 
00257     if (time != 0) {    
00258         globalStatistics->addStdDev("KBRTestApp: Delivered Messages/s",
00259                                     numDelivered / time);
00260         globalStatistics->addStdDev("KBRTestApp: Delivered Bytes/s",
00261                                     bytesDelivered / time);
00262 
00263         if (numSent != 0) {
00264             globalStatistics->addStdDev("KBRTestApp: Delivery Ratio",
00265                                         (float) numDelivered / (float) numSent);
00266         } else {
00267             globalStatistics->addStdDev("KBRTestApp: Delivery Ratio", 0);
00268         }
00269     }
00270 }

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.

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

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.

00155 {
00156     KBRTestMessage* testMsg = check_and_cast<KBRTestMessage*>(msg);
00157     OverlayCtrlInfo* overlayCtrlInfo =
00158         check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo());
00159 
00160     if (thisNode.key.isUnspecified())
00161         error("key");
00162     
00163     // check for duplicate
00164     if ((msgHandleBufSize > 0 )
00165             && checkSeen(overlayCtrlInfo->getSrcNode().key, testMsg->getSeqNum())) {
00166         EV << "KBRTestApp: duplicate dropped." << std::endl;
00167         delete overlayCtrlInfo;
00168         delete testMsg;
00169         return;
00170     }
00171     
00172     // Return statistical data to the sender.
00173     if (cModule* mod = simulation.module(testMsg->getId())) {
00174         if (KBRTestApp* sender = dynamic_cast<KBRTestApp*>(mod)) {
00175             if ((!lookupNodeIds) || (thisNode.key == key)) {
00176                 if (testMsg->getMeasurementPhase() == true) {
00177                         sender->evaluateData((simTime() - testMsg->creationTime()),
00178                                              overlayCtrlInfo->getHopCount(),
00179                                              testMsg->byteLength());
00180                 }
00181             } else if(lookupNodeIds) {
00182                 EV << "[KBRTestApp::deliver() @ " << thisNode.ip
00183                 << " (" << thisNode.key.toString(16) << ")]\n"
00184                 << "    Error: Lookup of NodeIDs and KBRTestMessage"
00185                 << " received with different destKey!"
00186                 << endl;
00187             }
00188         }
00189     }
00190     
00191     EV << "[KBRTestApp::deliver() @ " << thisNode.ip
00192        << " (" << thisNode.key.toString(16) << ")]\n"
00193        << "    Received \"" << testMsg->name() << "(seqNr: "
00194        << testMsg->getSeqNum() << ")\n"
00195        << "    with destination key: " << key.toString(16)
00196        << endl;
00197 
00198     delete overlayCtrlInfo;
00199     delete testMsg;
00200 }

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.

00204 {
00205     KBRTestMessage* tempMsg = check_and_cast<KBRTestMessage*>(*msg);
00206 
00207     tempMsg->setVisitedNodesArraySize(tempMsg->getVisitedNodesArraySize() + 1);
00208     tempMsg->setVisitedNodes(tempMsg->getVisitedNodesArraySize() - 1,
00209                              thisNode.ip);
00210 }

bool KBRTestApp::checkSeen ( const OverlayKey key,
int  seqNum 
) [protected]

Checks if a message was already seen before.

If the sequence number of the message is new for the given sender key, it is stored in a circular buffer and false is returned.

Parameters:
key the OverlayKey of the sender
seqNum sequence number of the message to check
Returns:
true if the message was seen before
00213 {
00214     MsgHandle hdl(key, seqNum);
00215 
00216     for (MsgHandleBuf::iterator it = mhBufBegin; it != mhBufEnd; ++it) {
00217         if (it->key.isUnspecified()) {
00218             continue;
00219         }
00220         
00221         if (*it == hdl) {
00222             return true;
00223         }
00224     }
00225 
00226     *(mhBufNext++) = hdl;
00227     if (mhBufNext == mhBufEnd) {
00228         mhBufNext = mhBufBegin;
00229     }
00230     return false;
00231 }

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
00234 {
00235     // count the number and size of successfully delivered messages
00236     RECORD_STATS(numDelivered++; bytesDelivered += bytes;
00237     globalStatistics->deliveredKBRTestAppMessages++);
00238 
00239     if (numSent < numDelivered) {
00240         error("KBRTestApp::evaluateData(): numSent < numDelivered!");
00241     }
00242 
00243     // record vectorial data
00244     RECORD_STATS(delayVector.record(timeDelay));
00245     RECORD_STATS(hopCountVector.record(hopCount));
00246 
00247     RECORD_STATS(globalStatistics->recordOutVector("KBRTestApp: Global Hop "
00248                                                    "Count", hopCount));
00249     RECORD_STATS(globalStatistics->recordOutVector("KBRTestApp: Global Time "
00250                                                    "Delay", timeDelay));
00251 }

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.

00118 {
00119     RPC_SWITCH_START(msg)
00120     RPC_ON_RESPONSE(Lookup) {
00121         handleLookupResponse(_LookupResponse);
00122         EV << "[KBRTestApp::handleRpcResponse() @ " << thisNode.ip
00123            << " (" << thisNode.key.toString(16) << ")]\n"
00124            << "    Lookup RPC Response received: id=" << rpcId << "\n"
00125            << "    msg=" << *_LookupResponse << " rtt=" << rtt
00126            << endl;
00127         break;
00128     }
00129     RPC_SWITCH_END( )
00130 }

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

00133 {
00134     EV << "[KBRTestApp::handleLookupResponse() @ " << thisNode.ip
00135        << " (" << thisNode.key.toString(16) << ")]\n"
00136        << "    Lookup response for key " << msg->getKey()<< " : ";
00137     if (msg->getIsValid()) {
00138         for (uint i=0; i<msg->getSiblingsArraySize(); i++) {
00139             EV << endl << "    " << msg->getSiblings(i);
00140         }
00141     } else {
00142         EV << "failed";
00143     }
00144     
00145     EV << endl;
00146 }

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

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

Reimplemented from BaseApp.

00149 {
00150     nodeIsLeavingSoon = true;
00151 }


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

uint KBRTestApp::sequenceNumber [protected]

int KBRTestApp::msgHandleBufSize [protected]

how many MsgHandles to store in circular buffer

MsgHandleBuf KBRTestApp::mhBuf [protected]

circular buffer of MsgHandles

MsgHandleBuf::iterator KBRTestApp::mhBufBegin [protected]

begin of circular buffer

MsgHandleBuf::iterator KBRTestApp::mhBufNext [protected]

next element to insert

MsgHandleBuf::iterator KBRTestApp::mhBufEnd [protected]

end of circular buffer

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 Thu Apr 17 13:19:29 2008 for ITM OverSim by  doxygen 1.5.3