#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) |
calls route-method in overlay | |
virtual void | deliver (OverlayKey &key, cMessage *msg) |
handles delivered messages from overlay | |
virtual void | forward (OverlayKey &key, cMessage *msg, NodeHandle *hint=NULL) |
handles messages from overlay to be forwarded | |
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 | |
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 |
void BaseApp::callRoute | ( | const OverlayKey & | key, | |
cMessage * | msg, | |||
const NodeHandle & | hint = NodeHandle::UNSPECIFIED_NODE | |||
) | [protected] |
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) |
00129 { 00130 // add some interface control information and send the message 00131 OverlayCtrlInfo* overlayCtrlInfo = new OverlayCtrlInfo(); 00132 overlayCtrlInfo->setDestKey(key); 00133 overlayCtrlInfo->setHint(hint); 00134 00135 // create route-message (common API) 00136 KBRroute* routeMsg = new KBRroute(); 00137 routeMsg->setControlInfo(overlayCtrlInfo); 00138 routeMsg->encapsulate(msg); 00139 00140 send(routeMsg, "to_overlay"); 00141 00142 // debug output 00143 if (debugOutput) 00144 EV << "(BaseApp::callRoute()) Node " << thisNode.ip << " sent message " 00145 << id() << "-" << numSent << " to destination key " 00146 << key.toString(16) << "." << endl; 00147 00148 // count 00149 numSent++; 00150 bytesSent += msg->byteLength(); 00151 }
void BaseApp::deliver | ( | OverlayKey & | key, | |
cMessage * | msg | |||
) | [protected, virtual] |
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
00184 { 00185 // record scalar data 00186 recordScalar("BaseApp: Sent Messages", numSent); 00187 recordScalar("BaseApp: Received Messages", numReceived); 00188 recordScalar("BaseApp: Sent Bytes", bytesSent); 00189 recordScalar("BaseApp: Received Bytes", bytesReceived); 00190 00191 finishApp(); 00192 }
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 * | hint = NULL | |||
) | [protected, virtual] |
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::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 |
00080 { 00081 // Process self-messages. 00082 if(msg->isSelfMessage()) { 00083 handleTimerEvent(msg); 00084 return; 00085 } 00086 00087 if(msg->arrivedOn("from_overlay")) { 00088 // common API 00089 if(dynamic_cast<CommonAPIMessage*>(msg) != NULL) { 00090 cMessage* tempMsg = msg->decapsulate(); 00091 // process interface control information 00092 OverlayCtrlInfo* overlayCtrlInfo = 00093 check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo()); 00094 tempMsg->setControlInfo(overlayCtrlInfo); //bad solution! 00095 00096 if(debugOutput) 00097 EV << "(BaseApp) Node " << thisNode.ip << " received message " 00098 << " (sent to " << overlayCtrlInfo->getDestKey() << ") from node " 00099 << overlayCtrlInfo->getSrcNode().ip << "." << endl; 00100 00101 if(dynamic_cast<KBRdeliver*>(msg) != NULL) { 00102 numReceived++; 00103 bytesReceived += tempMsg->byteLength(); 00104 deliver(overlayCtrlInfo->getDestKey(), tempMsg); 00105 } 00106 else if(dynamic_cast<KBRforward*>(msg) != NULL) 00107 forward(overlayCtrlInfo->getDestKey(), tempMsg, NULL); 00108 00109 else 00110 delete tempMsg; 00111 00112 delete msg; 00113 } else if (onlyCommonAPIMessages == false) { 00114 numReceived++; 00115 bytesReceived += msg->byteLength(); 00116 handleAppMessage(msg); 00117 } 00118 } else if(msg->arrivedOn("from_upperTier")) { 00119 handleUpperMessage(msg); 00120 } 00121 }
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 |
00044 { 00045 if(stage == MIN_STAGE_APP) { 00046 // fetch parameters 00047 debugOutput = par("debugOutput"); 00048 onlyCommonAPIMessages = true; 00049 00050 bootstrapOracle = BootstrapOracleAccess().get(); 00051 underlayConfigurator = UnderlayConfiguratorAccess().get(); 00052 globalStatistics = GlobalStatisticsAccess().get(); 00053 00054 // determine the terminal's node handle 00055 thisNode.ip = IPAddressResolver().addressOf(parentModule()->parentModule()).get4(); 00056 //thisNode.key = //solution? 00057 00058 // statistics 00059 numSent = 0; 00060 numReceived = 0; 00061 bytesSent = 0; 00062 bytesReceived = 0; 00063 00064 WATCH(numSent); 00065 WATCH(numReceived); 00066 WATCH(bytesSent); 00067 WATCH(bytesReceived); 00068 } 00069 if(stage >= MIN_STAGE_APP && stage <= MAX_STAGE_APP) 00070 initializeApp(stage); 00071 }
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] |
void BaseApp::sendMessageToOverlay | ( | cMessage * | msg | ) | [protected] |
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?
NodeHandle BaseApp::thisNode [protected] |
NodeHandle to this node.
UnderlayConfigurator* BaseApp::underlayConfigurator [protected] |
pointer to UnderlayConfigurator in this node