BaseApp Class Reference

#include <BaseApp.h>

Inheritance diagram for BaseApp:

GIASearchApp KBRTestApp RealWorldTestApp 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 (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.
UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
BootstrapOraclebootstrapOracle
 pointer to BootstrapOracle in this node
GlobalStatisticsglobalStatistics
 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


Constructor & Destructor Documentation

BaseApp::~BaseApp (  )  [virtual]

virtual destructor

00034 {
00035     //...
00036 }


Member Function Documentation

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

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

Parameters:
key destination key
msg delivered message

Reimplemented in KBRTestApp, and RealWorldTestApp.

00154 {
00155     // deliver...
00156 
00157     delete msg;
00158 }

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.

00195 {
00196     // ...
00197 }

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)
00161 {
00162     // forward...
00163 }

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

method to handle non-commonAPI messages from the overlay

Parameters:
msg message to handle

Reimplemented in GIASearchApp.

00171 {
00172     delete msg;
00173 }

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

Parameters:
msg self-message

Reimplemented in GIASearchApp, KBRTestApp, and RealWorldTestApp.

00124 {
00125     // process self-messages
00126 }

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

Reimplemented in RealWorldTestApp.

00166 {
00167     delete msg;
00168 }

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

initializes base class-attributes

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

Parameters:
stage the init stage

Reimplemented in GIASearchApp, KBRTestApp, and RealWorldTestApp.

00074 {
00075     // ...
00076 }

int BaseApp::numInitStages (  )  const [protected]

method to set InitStage

00039 {
00040     return MAX_STAGE_APP + 1;
00041 }

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

sends non-commonAPI message to the overlay

Parameters:
msg message to send
00176 {
00177     numSent++;
00178     bytesSent += msg->byteLength();
00179 
00180     send(msg, "to_overlay");
00181 }


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?

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


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:37:06 2007 for ITM OverSim by  doxygen 1.4.7