BaseApp Class Reference

#include <BaseApp.h>

Inheritance diagram for BaseApp:

GIASearchApp KBRTestApp List of all members.

Detailed Description

Base class for applications (Tier 1).

Base class for applications (Tier 1) that use overlay functionality. provides common API for structured overlays (KBR)

See also:
KBRTestApp
Author:
Bernhard Heep


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.
UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
BootstrapOraclebootstrapOracle
 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


Constructor & Destructor Documentation

BaseApp::~BaseApp (  )  [virtual]

virtual destructor

00033 {
00034     //...
00035 }


Member Function Documentation

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

Parameters:
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

Parameters:
key destination key
msg delivered message

Reimplemented in KBRTestApp.

00148 {
00149     // deliver...
00150 
00151     delete msg;
00152 }

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]

collects statistical data of derived app

Reimplemented in GIASearchApp, and KBRTestApp.

00184 {
00185     // ...
00186 }

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

Parameters:
key destination key
msg message to forward
hint next hop (usually unused)
00155 {
00156     // forward...
00157 }

void BaseApp::handleAppMessage ( cMessage *  msg  )  [protected, virtual]

method to handle non-commonAPI messages from the overlay

Parameters:
msg message to handle

Reimplemented in GIASearchApp.

00160 {
00161     delete msg;
00162 }

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()

Parameters:
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

Parameters:
msg self-message

Reimplemented in GIASearchApp, and KBRTestApp.

00119 {
00120     // process self-messages
00121 }

void BaseApp::initialize ( int  stage  )  [protected]

initializes base class-attributes

Parameters:
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

Parameters:
stage the init stage

Reimplemented in GIASearchApp, and KBRTestApp.

00072 {
00073     // ...
00074 }

int BaseApp::numInitStages (  )  const [protected]

method to set InitStage

00038 {
00039     return MAX_STAGE_APP + 1;
00040 }

void BaseApp::sendMessageToOverlay ( cMessage *  msg  )  [protected]

sends non-commonAPI message to the overlay

Parameters:
msg message to send
00165 {
00166     numSent++;
00167     bytesSent += msg->byteLength();
00168 
00169     send(msg, "to_overlay");
00170 }


Member Data Documentation

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


The documentation for this class was generated from the following files:
Generated on Fri Dec 15 17:50:30 2006 for ITM OverSim by  doxygen 1.4.7