#include <BaseApp.h>
Inheritance diagram for BaseApp:
Base class for applications (Tier 1) that use overlay functionality. provides common API for structured overlays (KBR)
Public Member Functions | |
virtual | ~BaseApp () |
virtual destructor | |
Protected Member Functions | |
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 | |
void | finish () |
collects statistical data | |
virtual void | finishApp () |
collects statistical data of derived app | |
void | callRoute (const OverlayKey &key, cMessage *msg, const NodeHandle &hint=NodeHandle::UNSPECIFIED_NODE) |
Common API function: calls route-method in overlay. | |
virtual void | deliver (OverlayKey &key, cMessage *msg) |
Common API function: handles delivered messages from overlay. | |
virtual void | forward (OverlayKey *key, cMessage **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. | |
NodeVector * | callLocalLookup (const OverlayKey &key, int num, bool safe) |
Common API function: produces a list of nodes that can be used as next hops towards key. | |
NodeVector * | callNeighborSet (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 | handleTimerEvent (cMessage *msg) |
processes self-messages | |
virtual void | handleAppMessage (cMessage *msg) |
method to handle non-commonAPI messages from the overlay | |
virtual void | handleUpperMessage (cMessage *msg) |
handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function) | |
void | sendMessageToOverlay (cMessage *msg) |
sends non-commonAPI message to the overlay | |
void | sendRpcMessageToDestination (int destType, const TransportAddress &dest, const OverlayKey &destKey, BaseOverlayMessage *message) |
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 | |
BaseOverlay * | overlay |
pointer to the overlay module of this node | |
bool | debugOutput |
debug output yes/no? | |
bool | onlyCommonAPIMessages |
process/send only commonAPI messages? | |
int | numSent |
number of sent packets | |
int | bytesSent |
number of sent bytes | |
int | numReceived |
number of received packets | |
int | bytesReceived |
number of received bytes | |
simtime_t | creationTime |
simTime when the App has been created | |
Private Member Functions | |
void | forwardResponse (const OverlayKey &key, cMessage *msg, const NodeHandle &nextHopNode) |
sends msg encapsulated in a KBRforward message to the overlay with destination key | |
void | handleCommonAPIMessage (CommonAPIMessage *commonAPIMsg) |
handles CommonAPIMessages |
BaseApp::~BaseApp | ( | ) | [virtual] |
void BaseApp::forwardResponse | ( | const OverlayKey & | key, | |
cMessage * | msg, | |||
const NodeHandle & | nextHopNode | |||
) | [private] |
sends msg encapsulated in a KBRforward message to the overlay with destination key
key | the destination OverlayKey | |
msg | the message to forward | |
nextHopNode | the considered next hop node on the route to the destination |
00172 { 00173 OverlayCtrlInfo* ctrlInfo = 00174 check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo()); 00175 00176 //create forwardResponse message (common API) 00177 KBRforward* forwardMsg = new KBRforward(); 00178 forwardMsg->setDestKey(key); 00179 forwardMsg->setNextHopNode(nextHopNode); 00180 forwardMsg->setControlInfo(ctrlInfo); 00181 forwardMsg->encapsulate(msg); 00182 00183 forwardMsg->setType(KBR_FORWARD_RESPONSE); 00184 00185 send(forwardMsg, "to_lowerTier"); 00186 }
void BaseApp::handleCommonAPIMessage | ( | CommonAPIMessage * | commonAPIMsg | ) | [private] |
handles CommonAPIMessages
This method gets called from BaseApp::handleMessage if message arrived from_lowerTier. It determines type of msg (KBR_DELIVER, KBR_FORWARD, KBR_UPDATE) and calls corresponding methods. All other messages are deleted.
commonAPIMsg | CommonAPIMessage |
00195 { 00196 cMessage* tempMsg = commonAPIMsg->decapsulate(); 00197 00198 // process interface control information 00199 OverlayCtrlInfo* overlayCtrlInfo = 00200 dynamic_cast<OverlayCtrlInfo*>(commonAPIMsg->removeControlInfo()); 00201 if(overlayCtrlInfo != NULL) { 00202 tempMsg->setControlInfo(overlayCtrlInfo); 00203 00204 if(debugOutput) 00205 EV << "(BaseApp) Node " << thisNode.ip << " received message " 00206 << " from node " << overlayCtrlInfo->getSrcNode().ip 00207 << "." << endl; 00208 } 00209 00210 switch (commonAPIMsg->getType()) { 00211 00212 case KBR_DELIVER: 00213 { 00214 KBRdeliver* apiMsg = dynamic_cast<KBRdeliver*>(commonAPIMsg); 00215 OverlayKey key = apiMsg->getDestKey(); 00216 NodeHandle nextHopNode = thisNode; 00217 //first call forward, then deliver 00218 forward(&key, &tempMsg, &nextHopNode); 00219 00220 if(tempMsg != NULL) { 00221 //if key or nextHopNode is changed send msg back to overlay 00222 if(key != apiMsg->getDestKey() || 00223 (!nextHopNode.isUnspecified() && 00224 nextHopNode != thisNode)) { 00225 forwardResponse(key, tempMsg, nextHopNode); 00226 } 00227 else { 00228 RECORD_STATS(numReceived++; bytesReceived += tempMsg->byteLength()); 00229 //handle RPC first 00230 BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(tempMsg); 00231 if (rpcMessage!=NULL) { 00232 internalHandleRpcMessage(rpcMessage); 00233 } 00234 else { 00235 deliver(apiMsg->getDestKey(), tempMsg); 00236 } 00237 } 00238 } 00239 break; 00240 } 00241 00242 case KBR_FORWARD: 00243 { 00244 KBRforward* apiMsg = dynamic_cast<KBRforward*>(commonAPIMsg); 00245 OverlayKey key = apiMsg->getDestKey(); 00246 NodeHandle nextHopNode = apiMsg->getNextHopNode(); 00247 00248 forward(&key, &tempMsg, &nextHopNode); 00249 00250 //if message ist not deleted send it back 00251 if(tempMsg != NULL) { 00252 if(nextHopNode == apiMsg->getNextHopNode()) 00253 //do we need this? 00254 nextHopNode = NodeHandle::UNSPECIFIED_NODE; 00255 forwardResponse(key, tempMsg, nextHopNode); 00256 } 00257 break; 00258 } 00259 00260 case KBR_UPDATE: 00261 { 00262 KBRupdate* apiMsg = dynamic_cast<KBRupdate*>(commonAPIMsg); 00263 if(apiMsg->getJoined() && 00264 ((apiMsg->getNode().ip == thisNode.ip && 00265 (thisNode.port == -1 || apiMsg->getNode().port == thisNode.port)) || 00266 (!thisNode.key.isUnspecified() && apiMsg->getNode().key == thisNode.key))) 00267 thisNode = apiMsg->getNode(); 00268 else 00269 update(apiMsg->getNode(), apiMsg->getJoined()); 00270 00271 break; 00272 } 00273 00274 default: 00275 { 00276 delete tempMsg; 00277 } 00278 } 00279 delete commonAPIMsg; 00280 }
int BaseApp::numInitStages | ( | ) | const [protected] |
method to set InitStage
Reimplemented in DHTTestApp, and DHTXMLRealworldApp.
00041 { 00042 return MAX_STAGE_APP + 1; 00043 }
void BaseApp::initialize | ( | int | stage | ) | [protected] |
initializes base class-attributes
stage | the init stage |
Reimplemented in DHTTestApp, and DHTXMLRealworldApp.
00046 { 00047 if(stage == MIN_STAGE_APP) { 00048 // fetch parameters 00049 debugOutput = par("debugOutput"); 00050 onlyCommonAPIMessages = true; 00051 00052 bootstrapOracle = BootstrapOracleAccess().get(); 00053 underlayConfigurator = UnderlayConfiguratorAccess().get(); 00054 globalStatistics = GlobalStatisticsAccess().get(); 00055 00056 overlay = check_and_cast<BaseOverlay*>(gate("to_lowerTier")->destinationGate()->ownerModule()); 00057 00058 // determine the terminal's transport address 00059 thisNode.ip = IPAddressResolver().addressOf(parentModule()->parentModule()).get4(); 00060 WATCH(thisNode); 00061 //thisNode.key = //solution? 00062 00063 // statistics 00064 numSent = 0; 00065 numReceived = 0; 00066 bytesSent = 0; 00067 bytesReceived = 0; 00068 creationTime = simTime(); 00069 00070 WATCH(numSent); 00071 WATCH(numReceived); 00072 WATCH(bytesSent); 00073 WATCH(bytesReceived); 00074 } 00075 if(stage >= MIN_STAGE_APP && stage <= MAX_STAGE_APP) 00076 initializeApp(stage); 00077 00078 // init rpcs 00079 initRpcs(); 00080 }
void BaseApp::initializeApp | ( | int | stage | ) | [protected, virtual] |
initializes derived class-attributes
stage | the init stage |
Reimplemented in DHT, GIASearchApp, KBRTestApp, RealWorldTestApp, and SimpleClient.
void BaseApp::handleMessage | ( | cMessage * | msg | ) | [protected] |
checks for message type and calls corresponding method
checks for message type (from overlay or selfmessage) and calls corresponding method like deliver(), forward(), and timer()
msg | the handled message |
Reimplemented in DHTXMLRealworldApp.
00089 { 00090 // Process self-messages. 00091 if(msg->isSelfMessage()) { 00092 // process rpc self-messages 00093 BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg); 00094 if (rpcMessage!=NULL) { 00095 internalHandleRpcMessage(rpcMessage); 00096 return; 00097 } 00098 // process all other self-messages 00099 handleTimerEvent(msg); 00100 return; 00101 } 00102 00103 if(msg->arrivedOn("from_lowerTier")) { 00104 BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg); 00105 if (rpcMessage!=NULL) { 00106 internalHandleRpcMessage(rpcMessage); 00107 return; 00108 } 00109 // common API 00110 CommonAPIMessage* commonAPIMsg = dynamic_cast<CommonAPIMessage*>(msg); 00111 if(commonAPIMsg != NULL) 00112 handleCommonAPIMessage(commonAPIMsg); 00113 00114 else if (onlyCommonAPIMessages == false) { 00115 RECORD_STATS(numReceived++; bytesReceived += msg->byteLength()); 00116 handleAppMessage(msg); 00117 } 00118 else 00119 delete msg; 00120 } 00121 else if(msg->arrivedOn("from_upperTier")) { 00122 BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg); 00123 if (rpcMessage!=NULL) { 00124 internalHandleRpcMessage(rpcMessage); 00125 return; 00126 } 00127 handleUpperMessage(msg); 00128 } 00129 }
void BaseApp::finish | ( | ) | [protected] |
collects statistical data
Reimplemented in DHTTestApp.
00300 { 00301 finishRpcs(); 00302 00303 // record scalar data 00304 simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime); 00305 00306 if(time != 0) { 00307 globalStatistics->addStdDev("BaseApp: Sent Messages/s", numSent / time); 00308 globalStatistics->addStdDev("BaseApp: Received Messages/s", numReceived / time); 00309 globalStatistics->addStdDev("BaseApp: Sent Bytes/s", bytesSent / time); 00310 globalStatistics->addStdDev("BaseApp: Received Bytes/s", bytesReceived / time); 00311 } 00312 00313 finishApp(); 00314 }
void BaseApp::finishApp | ( | ) | [protected, virtual] |
collects statistical data of derived app
Reimplemented in DHT, GIASearchApp, KBRTestApp, and RealWorldTestApp.
void BaseApp::callRoute | ( | const OverlayKey & | key, | |
cMessage * | msg, | |||
const NodeHandle & | hint = NodeHandle::UNSPECIFIED_NODE | |||
) | [protected] |
Common API function: calls route-method in overlay.
encapsulates msg into KBRroute message and sends it to the overlay module
key | destination key | |
msg | message to route | |
hint | next hop (usually unused) |
00137 { 00138 // create route-message (common API) 00139 KBRroute* routeMsg = new KBRroute(); 00140 routeMsg->setDestKey(key); 00141 routeMsg->setHint(hint); 00142 routeMsg->encapsulate(msg); 00143 00144 routeMsg->setType(KBR_ROUTE); 00145 00146 send(routeMsg, "to_lowerTier"); 00147 00148 // debug output 00149 if (debugOutput) 00150 EV << "(BaseApp::callRoute()) Node " << thisNode.ip << " sent message " 00151 << id() << "-" << numSent << " to destination key " 00152 << key.toString(16) << "." << endl; 00153 00154 // count 00155 RECORD_STATS(numSent++; bytesSent += msg->byteLength()); 00156 }
void BaseApp::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
key | destination key | |
msg | delivered message |
Reimplemented in KBRTestApp, and RealWorldTestApp.
void BaseApp::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
key | destination key | |
msg | message to forward | |
nextHopNode | next hop |
Reimplemented in KBRTestApp.
void BaseApp::update | ( | const NodeHandle & | node, | |
bool | joined | |||
) | [protected, virtual] |
NodeVector* BaseApp::callLocalLookup | ( | const OverlayKey & | key, | |
int | num, | |||
bool | safe | |||
) | [inline, protected] |
Common API function: produces a list of nodes that can be used as next hops towards key.
key | the destination key | |
num | maximal number of nodes in answer | |
safe | fraction of faulty nodes is not higher than in the overlay? |
00170 { 00171 return overlay->local_lookup(key, num, safe); 00172 };
NodeVector* BaseApp::callNeighborSet | ( | int | num | ) | [inline, protected] |
Common API function: produces a list of neighbor nodes.
num | maximal number of nodes in answer |
00180 { 00181 return overlay->neighborSet(num); 00182 };
bool BaseApp::isSiblingFor | ( | const NodeHandle & | node, | |
const OverlayKey & | key, | |||
int | numSiblings, | |||
bool * | err | |||
) | [inline, protected] |
Query if a node is among the siblings for a given key.
Query if a node is among the siblings for a given key. This means, that the nodeId of this node among the close numSiblings nodes to the key and that by a local findNode() call all other siblings to this key can be retrieved.
node | the NodeHandle | |
key | destination key | |
numSiblings | The nodes knows all numSiblings nodes close to this key | |
err | return false if the range could not be determined |
00201 { 00202 return overlay->isSiblingFor(node, key, numSiblings, err); 00203 };
void BaseApp::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 in DHT, GIASearchApp, KBRTestApp, RealWorldTestApp, SimpleClient, and DHTTestApp.
void BaseApp::handleAppMessage | ( | cMessage * | msg | ) | [protected, virtual] |
method to handle non-commonAPI messages from the overlay
msg | message to handle |
Reimplemented in GIASearchApp, and SimpleClient.
void BaseApp::handleUpperMessage | ( | cMessage * | msg | ) | [protected, virtual] |
handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function)
msg | the message to handle |
Reimplemented in DHT, and RealWorldTestApp.
void BaseApp::sendMessageToOverlay | ( | cMessage * | msg | ) | [protected] |
sends non-commonAPI message to the overlay
msg | message to send |
00293 { 00294 RECORD_STATS(numSent++; bytesSent += msg->byteLength()); 00295 00296 send(msg, "to_lowerTier"); 00297 }
void BaseApp::sendRpcMessageToDestination | ( | int | destType, | |
const TransportAddress & | dest, | |||
const OverlayKey & | destKey, | |||
BaseOverlayMessage * | message | |||
) | [protected, virtual] |
Reimplemented from BaseRpc.
00326 { 00327 switch(destType) { 00328 case RPC_TO_UDP: 00329 callRoute( dynamic_cast<const NodeHandle&>(dest).key, message, dynamic_cast<const NodeHandle&>(dest) ); 00330 break; 00331 case RPC_TO_KEY: 00332 callRoute( destKey, message, dynamic_cast<const NodeHandle&>(dest) ); 00333 break; 00334 case RPC_TO_UPPERTIER: 00335 send( message, "to_upperTier"); 00336 break; 00337 case RPC_TO_LOWERTIER: 00338 send( message, "to_lowerTier"); 00339 break; 00340 } 00341 }
UnderlayConfigurator* BaseApp::underlayConfigurator [protected] |
BootstrapOracle* BaseApp::bootstrapOracle [protected] |
GlobalStatistics* BaseApp::globalStatistics [protected] |
BaseOverlay* BaseApp::overlay [protected] |
bool BaseApp::debugOutput [protected] |
bool BaseApp::onlyCommonAPIMessages [protected] |
process/send only commonAPI messages?
int BaseApp::numSent [protected] |
int BaseApp::bytesSent [protected] |
number of sent bytes
int BaseApp::numReceived [protected] |
number of received packets
int BaseApp::bytesReceived [protected] |
number of received bytes
simtime_t BaseApp::creationTime [protected] |
simTime when the App has been created