#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 (OverlayKey &key, cMessage *msg, NodeHandle *hint=NULL) |
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 | |
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 | |
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 | ( | OverlayKey & | key, | |
cMessage * | msg, | |||
NodeHandle * | hint = NULL | |||
) | [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) |
00124 { 00125 // add some interface control information and send the message 00126 OverlayCtrlInfo* overlayCtrlInfo = new OverlayCtrlInfo(); 00127 overlayCtrlInfo->setDestKey(key); 00128 00129 // create route-message (common API) 00130 KBRroute* routeMsg = new KBRroute(); 00131 routeMsg->setControlInfo(overlayCtrlInfo); 00132 routeMsg->encapsulate(msg); 00133 00134 send(routeMsg, "to_overlay"); 00135 00136 // debug output 00137 if (debugOutput) 00138 EV << "(BaseApp::callRoute()) Node " << thisNode.ip << " sent message " 00139 << id() << "-" << numSent << " to destination key " 00140 << key.toString(16) << "." << endl; 00141 00142 // count 00143 numSent++; 00144 bytesSent += msg->byteLength(); 00145 }
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.
void BaseApp::finish | ( | ) | [protected] |
collects statistical data
00173 { 00174 // record scalar data 00175 recordScalar("BaseApp: Sent Messages", numSent); 00176 recordScalar("BaseApp: Received Messages", numReceived); 00177 recordScalar("BaseApp: Sent Bytes", bytesSent); 00178 recordScalar("BaseApp: Received Bytes", bytesReceived); 00179 00180 finishApp(); 00181 }
void BaseApp::finishApp | ( | ) | [protected, virtual] |
void BaseApp::forward | ( | OverlayKey & | key, | |
cMessage * | msg, | |||
NodeHandle * | hint = NULL | |||
) | [protected, virtual] |
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 | |
hint | next hop (usually unused) |
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 |
00078 { 00079 // Process self-messages. 00080 if(msg->isSelfMessage()) { 00081 handleTimerEvent(msg); 00082 return; 00083 } 00084 00085 // common API 00086 if(dynamic_cast<CommonAPIMessage*>(msg) != NULL) { 00087 cMessage* tempMsg = msg->decapsulate(); 00088 // process interface control information 00089 OverlayCtrlInfo* overlayCtrlInfo = 00090 check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo()); 00091 tempMsg->setControlInfo(overlayCtrlInfo); //bad solution! 00092 00093 if(debugOutput) 00094 EV << "(BaseApp) Node " << thisNode.ip << " received message " 00095 << " (sent to " << overlayCtrlInfo->getDestKey() << ") from node " 00096 << overlayCtrlInfo->getSrcNode().ip << "." << endl; 00097 00098 if(dynamic_cast<KBRdeliver*>(msg) != NULL) { 00099 numReceived++; 00100 bytesReceived += tempMsg->byteLength(); 00101 deliver(overlayCtrlInfo->getDestKey(), tempMsg); 00102 } 00103 else if(dynamic_cast<KBRforward*>(msg) != NULL) 00104 forward(overlayCtrlInfo->getDestKey(), tempMsg, NULL); 00105 00106 else 00107 delete tempMsg; 00108 00109 delete msg; 00110 } else if (onlyCommonAPIMessages == false) { 00111 numReceived++; 00112 bytesReceived += msg->byteLength(); 00113 handleAppMessage(msg); 00114 } else 00115 delete msg; 00116 }
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, and KBRTestApp.
void BaseApp::initialize | ( | int | stage | ) | [protected] |
initializes base class-attributes
stage | the init stage |
00043 { 00044 if(stage == MIN_STAGE_APP) { 00045 // fetch parameters 00046 debugOutput = par("debugOutput"); 00047 onlyCommonAPIMessages = true; 00048 00049 bootstrapOracle = BootstrapOracleAccess().get(); 00050 underlayConfigurator = UnderlayConfiguratorAccess().get(); 00051 00052 // determine the terminal's node handle 00053 thisNode.ip = IPAddressResolver().addressOf(parentModule()).get4(); 00054 //thisNode.key = //solution? 00055 00056 // statistics 00057 numSent = 0; 00058 numReceived = 0; 00059 bytesSent = 0; 00060 bytesReceived = 0; 00061 00062 WATCH(numSent); 00063 WATCH(numReceived); 00064 WATCH(bytesSent); 00065 WATCH(bytesReceived); 00066 } 00067 if(stage >= MIN_STAGE_APP && stage <= MAX_STAGE_APP) 00068 initializeApp(stage); 00069 }
void BaseApp::initializeApp | ( | int | stage | ) | [protected, virtual] |
initializes derived class-attributes
stage | the init stage |
Reimplemented in GIASearchApp, and KBRTestApp.
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?
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