#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. | |
NodeVector * | callReplicaSet (const OverlayKey &key, int max_rank) |
Common API function: produces a ordered list of neighbor nodes on which replicas of key can be stored. | |
bool | range (const NodeHandle &node, int rank, const OverlayKey &lKey, const OverlayKey &rKey) |
Common API function: Information about the ranges of keys. | |
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) |
void | sendMessageToOverlay (cMessage *msg) |
sends non-commonAPI message to the overlay | |
Protected Attributes | |
NodeHandle | thisNode |
NodeHandle to this node. | |
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 | |
Private Member Functions | |
void | forwardResponse (const OverlayKey &key, cMessage *msg, const NodeHandle &nextHopNode) |
void | handleCommonAPIMessage (CommonAPIMessage *commonAPIMsg) |
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? |
00151 { 00152 return overlay->local_lookup(key, num, safe); 00153 };
NodeVector* BaseApp::callNeighborSet | ( | int | num | ) | [inline, protected] |
Common API function: produces a list of neighbor nodes.
num | maximal number of nodes in answer |
00161 { 00162 return overlay->neighborSet(num); 00163 };
NodeVector* BaseApp::callReplicaSet | ( | const OverlayKey & | key, | |
int | max_rank | |||
) | [inline, protected] |
Common API function: produces a ordered list of neighbor nodes on which replicas of key can be stored.
key | ID of the object | |
max_rank | TODO |
00173 { 00174 return overlay->replicaSet(key, max_rank); 00175 };
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) |
00113 { 00114 // create route-message (common API) 00115 KBRroute* routeMsg = new KBRroute(); 00116 routeMsg->setDestKey(key); 00117 routeMsg->setHint(hint); 00118 routeMsg->encapsulate(msg); 00119 00120 routeMsg->setType(KBR_ROUTE); 00121 00122 send(routeMsg, "to_lowerTier"); 00123 00124 // debug output 00125 if (debugOutput) 00126 EV << "(BaseApp::callRoute()) Node " << thisNode.ip << " sent message " 00127 << id() << "-" << numSent << " to destination key " 00128 << key.toString(16) << "." << endl; 00129 00130 // count 00131 numSent++; 00132 bytesSent += msg->byteLength(); 00133 }
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::finish | ( | ) | [protected] |
collects statistical data
00271 { 00272 // record scalar data 00273 recordScalar("BaseApp: Sent Messages", numSent); 00274 recordScalar("BaseApp: Received Messages", numReceived); 00275 recordScalar("BaseApp: Sent Bytes", bytesSent); 00276 recordScalar("BaseApp: Received Bytes", bytesReceived); 00277 00278 finishApp(); 00279 }
void BaseApp::finishApp | ( | ) | [protected, virtual] |
collects statistical data of derived app
Reimplemented in GIASearchApp, 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::forwardResponse | ( | const OverlayKey & | key, | |
cMessage * | msg, | |||
const NodeHandle & | nextHopNode | |||
) | [private] |
00149 { 00150 OverlayCtrlInfo* ctrlInfo = 00151 check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo()); 00152 00153 //create forwardResponse message (common API) 00154 KBRforward* forwardMsg = new KBRforward(); 00155 forwardMsg->setDestKey(key); 00156 forwardMsg->setNextHopNode(nextHopNode); 00157 forwardMsg->setControlInfo(ctrlInfo); 00158 forwardMsg->encapsulate(msg); 00159 00160 forwardMsg->setType(KBR_FORWARD_RESPONSE); 00161 00162 send(forwardMsg, "to_lowerTier"); 00163 }
void BaseApp::handleAppMessage | ( | cMessage * | msg | ) | [protected, virtual] |
method to handle non-commonAPI messages from the overlay
msg | message to handle |
Reimplemented in GIASearchApp.
void BaseApp::handleCommonAPIMessage | ( | CommonAPIMessage * | commonAPIMsg | ) | [private] |
00171 { 00172 cMessage* tempMsg = commonAPIMsg->decapsulate(); 00173 00174 // process interface control information 00175 OverlayCtrlInfo* overlayCtrlInfo = 00176 dynamic_cast<OverlayCtrlInfo*>(commonAPIMsg->removeControlInfo()); 00177 if(overlayCtrlInfo != NULL) { 00178 tempMsg->setControlInfo(overlayCtrlInfo); 00179 00180 if(debugOutput) 00181 EV << "(BaseApp) Node " << thisNode.ip << " received message " 00182 << " from node " << overlayCtrlInfo->getSrcNode().ip 00183 << "." << endl; 00184 } 00185 00186 switch (commonAPIMsg->getType()) { 00187 00188 case KBR_DELIVER: 00189 { 00190 KBRdeliver* apiMsg = dynamic_cast<KBRdeliver*>(commonAPIMsg); 00191 OverlayKey key = apiMsg->getDestKey(); 00192 NodeHandle nextHopNode = thisNode; 00193 //first call forward, then deliver 00194 forward(&key, tempMsg, &nextHopNode); 00195 00196 if(tempMsg != NULL) { 00197 //if key or nextHopNode is changed send msg back to overlay 00198 if(key != apiMsg->getDestKey() || 00199 (!nextHopNode.isUnspecified() && 00200 nextHopNode != thisNode)) { 00201 forwardResponse(key, tempMsg, nextHopNode); 00202 } 00203 else { 00204 numReceived++; 00205 bytesReceived += tempMsg->byteLength(); 00206 deliver(apiMsg->getDestKey(), tempMsg); 00207 } 00208 } 00209 break; 00210 } 00211 00212 case KBR_FORWARD: 00213 { 00214 KBRforward* apiMsg = dynamic_cast<KBRforward*>(commonAPIMsg); 00215 OverlayKey key = apiMsg->getDestKey(); 00216 NodeHandle nextHopNode = apiMsg->getNextHopNode(); 00217 00218 forward(&key, tempMsg, &nextHopNode); 00219 00220 //if message ist not deleted send it back 00221 if(tempMsg != NULL) { 00222 if(nextHopNode == apiMsg->getNextHopNode()) 00223 //do we need this? 00224 nextHopNode = NodeHandle::UNSPECIFIED_NODE; 00225 forwardResponse(key, tempMsg, nextHopNode); 00226 } 00227 break; 00228 } 00229 00230 case KBR_UPDATE: 00231 { 00232 KBRupdate* apiMsg = dynamic_cast<KBRupdate*>(commonAPIMsg); 00233 if(apiMsg->getJoined() && 00234 ((apiMsg->getNode().ip == thisNode.ip && 00235 thisNode.port == -1 || apiMsg->getNode().port == thisNode.port) || 00236 apiMsg->getNode().key == thisNode.key)) 00237 thisNode = apiMsg->getNode(); 00238 else 00239 update(apiMsg->getNode(), apiMsg->getJoined()); 00240 00241 break; 00242 } 00243 00244 default: 00245 { 00246 delete tempMsg; 00247 } 00248 } 00249 delete commonAPIMsg; 00250 }
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 |
00084 { 00085 // Process self-messages. 00086 if(msg->isSelfMessage()) { 00087 handleTimerEvent(msg); 00088 return; 00089 } 00090 00091 if(msg->arrivedOn("from_lowerTier")) { 00092 // common API 00093 CommonAPIMessage* commonAPIMsg = dynamic_cast<CommonAPIMessage*>(msg); 00094 if(commonAPIMsg != NULL) 00095 handleCommonAPIMessage(commonAPIMsg); 00096 00097 else if (onlyCommonAPIMessages == false) { 00098 numReceived++; 00099 bytesReceived += msg->byteLength(); 00100 handleAppMessage(msg); 00101 } 00102 } 00103 else if(msg->arrivedOn("from_upperTier")) 00104 handleUpperMessage(msg); 00105 }
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 GIASearchApp, KBRTestApp, and RealWorldTestApp.
void BaseApp::handleUpperMessage | ( | cMessage * | msg | ) | [protected, virtual] |
void BaseApp::initialize | ( | int | stage | ) | [protected] |
initializes base class-attributes
stage | the init stage |
00045 { 00046 if(stage == MIN_STAGE_APP) { 00047 // fetch parameters 00048 debugOutput = par("debugOutput"); 00049 onlyCommonAPIMessages = true; 00050 00051 bootstrapOracle = BootstrapOracleAccess().get(); 00052 underlayConfigurator = UnderlayConfiguratorAccess().get(); 00053 globalStatistics = GlobalStatisticsAccess().get(); 00054 00055 overlay = check_and_cast<BaseOverlay*>(gate("to_lowerTier")->destinationGate()->ownerModule()); 00056 00057 // determine the terminal's transport address 00058 thisNode.ip = IPAddressResolver().addressOf(parentModule()->parentModule()).get4(); 00059 WATCH(thisNode); 00060 //thisNode.key = //solution? 00061 00062 // statistics 00063 numSent = 0; 00064 numReceived = 0; 00065 bytesSent = 0; 00066 bytesReceived = 0; 00067 00068 WATCH(numSent); 00069 WATCH(numReceived); 00070 WATCH(bytesSent); 00071 WATCH(bytesReceived); 00072 } 00073 if(stage >= MIN_STAGE_APP && stage <= MAX_STAGE_APP) 00074 initializeApp(stage); 00075 }
void BaseApp::initializeApp | ( | int | stage | ) | [protected, virtual] |
initializes derived class-attributes
stage | the init stage |
Reimplemented in GIASearchApp, KBRTestApp, and RealWorldTestApp.
int BaseApp::numInitStages | ( | ) | const [protected] |
bool BaseApp::range | ( | const NodeHandle & | node, | |
int | rank, | |||
const OverlayKey & | lKey, | |||
const OverlayKey & | rKey | |||
) | [inline, protected] |
void BaseApp::sendMessageToOverlay | ( | cMessage * | msg | ) | [protected] |
void BaseApp::update | ( | const NodeHandle & | node, | |
bool | joined | |||
) | [protected, virtual] |
BootstrapOracle* BaseApp::bootstrapOracle [protected] |
pointer to BootstrapOracle in this node
int BaseApp::bytesReceived [protected] |
number of received bytes
int BaseApp::bytesSent [protected] |
number of sent bytes
bool BaseApp::debugOutput [protected] |
debug output yes/no?
GlobalStatistics* BaseApp::globalStatistics [protected] |
pointer to GlobalStatistics module in this node
int BaseApp::numReceived [protected] |
number of received packets
int BaseApp::numSent [protected] |
number of sent packets
bool BaseApp::onlyCommonAPIMessages [protected] |
process/send only commonAPI messages?
BaseOverlay* BaseApp::overlay [protected] |
pointer to the overlay module of this node
NodeHandle BaseApp::thisNode [protected] |
NodeHandle to this node.
UnderlayConfigurator* BaseApp::underlayConfigurator [protected] |
pointer to UnderlayConfigurator in this node