BaseApp Class Reference

#include <BaseApp.h>

Inheritance diagram for BaseApp:

BaseRpc RpcListener BootstrapList DHT DHTTestApp GIASearchApp I3 KBRTestApp P2pns RealWorldTestApp Scribe SimMud SimpleGameClient TierDummy XmlRpcInterface

List of all members.


Detailed Description

Base class for applications.

Base class for applications (Tier 1-3) that use overlay functionality. provides common API for structured overlays (KBR), RPC and UDP

BaseApp provides the following API calls for derived classes:

Method nameCall directionavailable on Tierimplemented as
Modified CommonAPI for structured P2P overlays:
callRoute()CALL1OMNeT++ messages
deliver()CALLBACK1OMNeT++ messages
forward()CALLBACK1OMNeT++ messages
update()CALLBACK1OMNeT++ messages
callLocalLookup()CALL1-3direct C++-method calls
callNeighborSet()CALL1-3direct C++-method calls
isSiblingFor()CALL1-3direct C++-method calls
Remote Procedure Call API (RPC):
sendUdpRpcCall()CALL1-3*OMNeT++ messages
sendRouteRpcCall()CALL1-3*OMNeT++ messages
sendInternalRpcCall()CALL1-3*OMNeT++ messages
UDP API:
handleUDPMessage()CALLBACK1-3OMNeT++ messages
sendMessageToUDP()CALL1-3OMNeT++ messages
bindToPort()CALL1-3OMNeT++ messages

Callback functions have to be implemented in derived classes!

See also:
KBRTestApp
Author:
Bernhard Heep

Definition at line 75 of file BaseApp.h.


Public Member Functions

 BaseApp ()
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
virtual void receiveChangeNotification (int category, const cPolymorphic *details)
 callback-method for events at the NotificationBoard
virtual void handleTransportAddressChangedNotification ()
 This method gets call if the node has a new TransportAddress (IP address) because he changed his access network.
virtual void handleNodeLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed.
virtual void handleNodeGracefulLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed if this node is among the gracefulLeaveProbability nodes.
void finish ()
 collects statistical data
virtual void finishApp ()
 collects statistical data of derived app
void callRoute (const OverlayKey &key, cPacket *msg, const TransportAddress &hint=TransportAddress::UNSPECIFIED_NODE, RoutingType routingType=DEFAULT_ROUTING)
 Common API function: calls route-method in overlay.
void callRoute (const OverlayKey &key, cPacket *msg, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType=DEFAULT_ROUTING)
virtual void deliver (OverlayKey &key, cMessage *msg)
 Common API function: handles delivered messages from overlay.
virtual void forward (OverlayKey *key, cPacket **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.
bool isSiblingFor (const NodeHandle &node, const OverlayKey &key, int numSiblings, bool *err)
 Query if a node is among the siblings for a given key.
virtual void handleTimerEvent (cMessage *msg)
 processes self-messages
virtual void handleLowerMessage (cMessage *msg)
 method to handle non-commonAPI messages from the overlay
virtual void handleUpperMessage (cMessage *msg)
 handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function)
virtual void handleUDPMessage (cMessage *msg)
 method to handle messages that come directly from the UDP gate
virtual void handleReadyMessage (CompReadyMessage *msg)
 method to handle ready messages from the overlay
virtual void bindToPort (int port)
 Tells UDP we want to get all packets arriving on the given port.
virtual void sendMessageToUDP (const TransportAddress &destAddr, cPacket *msg)
 Sends a packet over UDP.
virtual void handleTraceMessage (cMessage *msg)
 handleTraceMessage gets called of handleMessage(cMessage* msg) if a message arrives at trace_in.
void sendMessageToLowerTier (cPacket *msg)
 sends non-commonAPI message to the lower tier
bool internalHandleRpc (BaseCallMessage *msg)
 Handles internal rpc requests.
bool internalHandleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 Handles rpc responses internal in base classes
.
void internalSendRouteRpc (BaseRpcMessage *message, const OverlayKey &destKey, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType)
virtual CompType getThisCompType ()
 Return the component type of this module.

Protected Attributes

UnderlayConfigurator * underlayConfigurator
 pointer to UnderlayConfigurator in this node
GlobalNodeList * globalNodeList
 pointer to GlobalNodeList in this node
GlobalStatistics * globalStatistics
 pointer to GlobalStatistics module in this node
NotificationBoard * notificationBoard
 pointer to NotificationBoard in this node
bool debugOutput
 debug output yes/no?
int numOverlaySent
 number of sent packets to overlay
int bytesOverlaySent
 number of sent bytes to overlay
int numOverlayReceived
 number of received packets from overlay
int bytesOverlayReceived
 number of received bytes from overlay
int numUdpSent
 number of sent packets to UDP
int bytesUdpSent
 number of sent bytes to UDP
int numUdpReceived
 number of received packets from UDP
int bytesUdpReceived
 number of received bytes from UDP
simtime_t creationTime
 simTime when the App has been created

Private Member Functions

void forwardResponse (const OverlayKey &key, cPacket *msg, const NodeHandle &nextHopNode)
 sends msg encapsulated in a KBRforward message to the overlay with destination key
void handleCommonAPIMessage (CommonAPIMessage *commonAPIMsg)
 handles CommonAPIMessages
void internalSendRpcResponse (BaseCallMessage *call, BaseResponseMessage *response)

Constructor & Destructor Documentation

BaseApp::BaseApp (  ) 

Definition at line 40 of file BaseApp.cc.

00041 {
00042     notificationBoard = NULL;
00043 
00044     overlay = NULL;
00045 }

BaseApp::~BaseApp (  )  [virtual]

virtual destructor

Definition at line 47 of file BaseApp.cc.

00048 {
00049     finishRpcs();
00050 }


Member Function Documentation

void BaseApp::forwardResponse ( const OverlayKey &  key,
cPacket *  msg,
const NodeHandle &  nextHopNode 
) [private]

sends msg encapsulated in a KBRforward message to the overlay with destination key

Parameters:
key the destination OverlayKey
msg the message to forward
nextHopNode the considered next hop node on the route to the destination

Definition at line 287 of file BaseApp.cc.

Referenced by handleCommonAPIMessage().

00289 {
00290     OverlayCtrlInfo* ctrlInfo =
00291         check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo());
00292 
00293     //create forwardResponse message (common API)
00294     KBRforward* forwardMsg = new KBRforward();
00295     forwardMsg->setDestKey(key);
00296     forwardMsg->setNextHopNode(nextHopNode);
00297     forwardMsg->setControlInfo(ctrlInfo);
00298     forwardMsg->encapsulate(msg);
00299 
00300     forwardMsg->setType(KBR_FORWARD_RESPONSE);
00301 
00302     if (getThisCompType() == TIER1_COMP) {
00303         send(forwardMsg, "to_lowerTier");
00304     } else {
00305         sendDirect(forwardMsg, overlay->getCompRpcGate(OVERLAY_COMP));
00306     }
00307 }

void BaseApp::handleCommonAPIMessage ( CommonAPIMessage *  commonAPIMsg  )  [private]

handles CommonAPIMessages

This method gets called from BaseApp::handleMessage if message arrived from_lowerTier. It determines type of msg (KBR_DELIVER, KBR_FORWARD, KBR_UPDATE) and calls corresponding methods. All other messages are deleted.

Parameters:
commonAPIMsg CommonAPIMessage

Definition at line 313 of file BaseApp.cc.

Referenced by handleMessage().

00314 {
00315     cPacket* tempMsg = commonAPIMsg->decapsulate();
00316 
00317     // process interface control information
00318     OverlayCtrlInfo* overlayCtrlInfo =
00319         dynamic_cast<OverlayCtrlInfo*>(commonAPIMsg->removeControlInfo());
00320 
00321     if (overlayCtrlInfo != NULL) {
00322         tempMsg->setControlInfo(overlayCtrlInfo);
00323     }
00324 
00325     switch (commonAPIMsg->getType()) {
00326         case KBR_DELIVER:
00327         {
00328             KBRdeliver* apiMsg = dynamic_cast<KBRdeliver*>(commonAPIMsg);
00329             OverlayKey key = apiMsg->getDestKey();
00330             NodeHandle nextHopNode = overlay->getThisNode();
00331 
00332             //first call forward, then deliver
00333             forward(&key, &tempMsg, &nextHopNode);
00334 
00335             if(tempMsg != NULL) {
00336                 //if key or nextHopNode is changed send msg back to overlay
00337                 if ((!key.isUnspecified() && key != apiMsg->getDestKey()) ||
00338                     (!nextHopNode.isUnspecified()
00339                             && nextHopNode != overlay->getThisNode())) {
00340                     forwardResponse(key, tempMsg, nextHopNode);
00341                 }
00342                 else {
00343                     RECORD_STATS(numOverlayReceived++;
00344                                  bytesOverlayReceived += tempMsg->getByteLength());
00345 
00346                     assert(overlayCtrlInfo->getTransportType()
00347                            == ROUTE_TRANSPORT);
00348 
00349                     // debug message
00350                     if (debugOutput) {
00351                         EV << "[BaseApp:handleCommonAPIMessage() @ "
00352                         << thisNode.ip << " ("
00353                         << overlay->getThisNode().key.toString(16) << ")]\n"
00354                         << "    Received " << *tempMsg << " from "
00355                         << overlayCtrlInfo->getSrcNode() << endl;
00356                     }
00357 
00358                     //handle RPC first
00359                     BaseRpcMessage* rpcMessage
00360                         = dynamic_cast<BaseRpcMessage*>(tempMsg);
00361                     if (rpcMessage!=NULL) {
00362                         internalHandleRpcMessage(rpcMessage);
00363                     } else {
00364                         deliver(apiMsg->getDestKey(), tempMsg);
00365                     }
00366                 }
00367             }
00368             break;
00369         }
00370 
00371         case KBR_FORWARD:
00372         {
00373             KBRforward* apiMsg = dynamic_cast<KBRforward*>(commonAPIMsg);
00374             OverlayKey key = apiMsg->getDestKey();
00375             NodeHandle nextHopNode = apiMsg->getNextHopNode();
00376 
00377             forward(&key, &tempMsg, &nextHopNode);
00378 
00379             //if message ist not deleted send it back
00380             if(tempMsg != NULL) {
00381                 if(nextHopNode == apiMsg->getNextHopNode())
00382                     //do we need this?
00383                     nextHopNode = NodeHandle::UNSPECIFIED_NODE;
00384                 forwardResponse(key, tempMsg, nextHopNode);
00385             }
00386             break;
00387         }
00388 
00389         case KBR_UPDATE:
00390         {
00391             KBRupdate* apiMsg = dynamic_cast<KBRupdate*>(commonAPIMsg);
00392             update(apiMsg->getNode(), apiMsg->getJoined());
00393 
00394             break;
00395         }
00396 
00397         default:
00398         {
00399             delete tempMsg;
00400         }
00401     }
00402     delete commonAPIMsg;
00403 }

int BaseApp::numInitStages (  )  const [protected]

method to set InitStage

Reimplemented in I3.

Definition at line 52 of file BaseApp.cc.

Referenced by SimMud::initializeApp(), and Scribe::initializeApp().

00053 {
00054     return MAX_STAGE_APP + 1;
00055 }

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

initializes base class-attributes

Parameters:
stage the init stage

Definition at line 57 of file BaseApp.cc.

00058 {
00059     if (stage == MIN_STAGE_APP) {
00060         // fetch parameters
00061         debugOutput = par("debugOutput");
00062 
00063         globalNodeList = GlobalNodeListAccess().get();
00064         underlayConfigurator = UnderlayConfiguratorAccess().get();
00065         globalStatistics = GlobalStatisticsAccess().get();
00066         notificationBoard = NotificationBoardAccess().get();
00067 
00068         // subscribe to the notification board
00069         notificationBoard->subscribe(this, NF_OVERLAY_TRANSPORTADDRESS_CHANGED);
00070         notificationBoard->subscribe(this, NF_OVERLAY_NODE_LEAVE);
00071         notificationBoard->subscribe(this, NF_OVERLAY_NODE_GRACEFUL_LEAVE);
00072 
00073         // determine the terminal's transport address
00074         if (getParentModule()->getSubmodule("interfaceTable", 0) != NULL) {
00075             thisNode.ip = IPAddressResolver()
00076                           .addressOf(getParentModule()).get4();
00077         } else {
00078             thisNode.ip = IPAddressResolver()
00079                           .addressOf(getParentModule()->getParentModule()).get4();
00080         }
00081 
00082         thisNode.port = -1;
00083 
00084         WATCH(thisNode);
00085 
00086         // statistics
00087         numOverlaySent = 0;
00088         numOverlayReceived = 0;
00089         bytesOverlaySent = 0;
00090         bytesOverlayReceived = 0;
00091         numUdpSent = 0;
00092         numUdpReceived = 0;
00093         bytesUdpSent = 0;
00094         bytesUdpReceived = 0;
00095 
00096         creationTime = simTime();
00097 
00098         WATCH(numOverlaySent);
00099         WATCH(numOverlayReceived);
00100         WATCH(bytesOverlaySent);
00101         WATCH(bytesOverlayReceived);
00102         WATCH(numUdpSent);
00103         WATCH(numUdpReceived);
00104         WATCH(bytesUdpSent);
00105         WATCH(bytesUdpReceived);
00106 
00107         // init rpcs
00108         initRpcs();
00109     }
00110 
00111     if (stage >= MIN_STAGE_APP && stage <= MAX_STAGE_APP)
00112         initializeApp(stage);
00113 }

void BaseApp::initializeApp ( int  stage  )  [protected, virtual]

initializes derived class-attributes

Parameters:
stage the init stage

Reimplemented in DHT, GIASearchApp, I3, I3TRTServer, KBRTestApp, RealWorldTestApp, Scribe, SimpleGameClient, BootstrapList, DHTTestApp, P2pns, SimMud, and XmlRpcInterface.

Definition at line 115 of file BaseApp.cc.

Referenced by initialize().

00116 {
00117     // ...
00118 }

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

Reimplemented in XmlRpcInterface.

Definition at line 121 of file BaseApp.cc.

00122 {
00123     BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg);
00124 
00125     if (rpcMessage!=NULL) {
00126         // process rpc messages
00127         internalHandleRpcMessage(rpcMessage);
00128     } else if (msg->isSelfMessage()) {
00129         // Process self-messages.
00130         handleTimerEvent(msg);
00131     } else if (msg->arrivedOn("from_lowerTier") ||
00132                msg->arrivedOn("direct_in")) {
00133         CompReadyMessage* readyMsg = dynamic_cast<CompReadyMessage*>(msg);
00134         if (readyMsg != NULL) {
00135             handleReadyMessage(readyMsg);
00136             return;
00137         }
00138         // common API
00139         CommonAPIMessage* commonAPIMsg = dynamic_cast<CommonAPIMessage*>(msg);
00140         if (commonAPIMsg != NULL) {
00141             handleCommonAPIMessage(commonAPIMsg);
00142         } else if (msg->arrivedOn("from_lowerTier")) {
00143             // TODO: What kind of messages to we want to measure here?
00144                 cPacket* packet = check_and_cast<cPacket*>(msg);
00145             RECORD_STATS(numOverlayReceived++;
00146                          bytesOverlayReceived += packet->getByteLength());
00147             handleLowerMessage(msg);
00148         }
00149         else delete msg;
00150     } else if (msg->arrivedOn("from_upperTier")) {
00151         handleUpperMessage(msg);
00152     } else if (msg->arrivedOn("udpIn")) {
00153         cPacket* packet = check_and_cast<cPacket*>(msg);
00154         RECORD_STATS(numUdpReceived++; bytesUdpReceived += packet->getByteLength());
00155         // debug message
00156         if (debugOutput && !ev.isDisabled()) {
00157             UDPControlInfo* udpControlInfo =
00158                 check_and_cast<UDPControlInfo*>(msg->getControlInfo());
00159             EV << "[BaseApp:handleMessage() @ " << thisNode.ip
00160             << " (" << overlay->getThisNode().key.toString(16) << ")]\n"
00161             << "    Received " << *msg << " from "
00162             << udpControlInfo->getSrcAddr() << endl;
00163         }
00164         handleUDPMessage(msg);
00165     } else if (msg->arrivedOn("trace_in")) {
00166         handleTraceMessage(msg);
00167     } else {
00168         delete msg;
00169     }
00170 }

void BaseApp::receiveChangeNotification ( int  category,
const cPolymorphic *  details 
) [protected, virtual]

callback-method for events at the NotificationBoard

Parameters:
category ...
details ...

Definition at line 206 of file BaseApp.cc.

00207 {
00208     Enter_Method_Silent();
00209     if (category == NF_OVERLAY_TRANSPORTADDRESS_CHANGED) {
00210         handleTransportAddressChangedNotification();
00211     } else if (category == NF_OVERLAY_NODE_LEAVE) {
00212         handleNodeLeaveNotification();
00213     } else if (category == NF_OVERLAY_NODE_GRACEFUL_LEAVE) {
00214         handleNodeGracefulLeaveNotification();
00215     }
00216 }

void BaseApp::handleTransportAddressChangedNotification (  )  [protected, virtual]

This method gets call if the node has a new TransportAddress (IP address) because he changed his access network.

Definition at line 218 of file BaseApp.cc.

Referenced by receiveChangeNotification().

00219 {
00220     // ...
00221 }

void BaseApp::handleNodeLeaveNotification (  )  [protected, virtual]

This method gets call **.gracefulLeaveDelay seconds before it is killed.

Reimplemented in KBRTestApp, and DHTTestApp.

Definition at line 223 of file BaseApp.cc.

Referenced by receiveChangeNotification().

00224 {
00225     // ...
00226 }

void BaseApp::handleNodeGracefulLeaveNotification (  )  [protected, virtual]

This method gets call **.gracefulLeaveDelay seconds before it is killed if this node is among the gracefulLeaveProbability nodes.

Definition at line 228 of file BaseApp.cc.

Referenced by receiveChangeNotification().

00229 {
00230     // ...
00231 }

void BaseApp::finish (  )  [protected]

collects statistical data

Reimplemented in I3, and I3TRTServer.

Definition at line 439 of file BaseApp.cc.

00440 {
00441     // record scalar data
00442     simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime);
00443 
00444     string baseAppName = string("BaseApp (") += string(this->getName())
00445                          += string("): ");
00446 
00447     if (time != 0) {
00448         globalStatistics->addStdDev(baseAppName + string("Sent Messages/s to "
00449                                                          "Overlay"),
00450                                     numOverlaySent / time);
00451         globalStatistics->addStdDev(baseAppName +
00452                                     string("Received Messages/s from Overlay"),
00453                                     numOverlayReceived / time);
00454         globalStatistics->addStdDev(baseAppName + string("Sent Bytes/s to "
00455                                                          "Overlay"),
00456                                     bytesOverlaySent / time);
00457         globalStatistics->addStdDev(baseAppName + string("Received Bytes/s "
00458                                                          "from Overlay"),
00459                                     bytesOverlayReceived / time);
00460         globalStatistics->addStdDev(baseAppName + string("Sent Messages/s to "
00461                                                          "UDP"),
00462                                     numUdpSent / time);
00463         globalStatistics->addStdDev(baseAppName +
00464                                     string("Received Messages/s from UDP"),
00465                                     numUdpReceived / time);
00466         globalStatistics->addStdDev(baseAppName + string("Sent Bytes/s to UDP"),
00467                                     bytesUdpSent / time);
00468         globalStatistics->addStdDev(baseAppName + string("Received Bytes/s "
00469                                                          "from UDP"),
00470                                     bytesUdpReceived / time);
00471 
00472     }
00473 
00474     finishApp();
00475 }

void BaseApp::finishApp (  )  [protected, virtual]

collects statistical data of derived app

Reimplemented in DHT, GIASearchApp, KBRTestApp, RealWorldTestApp, Scribe, BootstrapList, DHTTestApp, P2pns, and SimMud.

Definition at line 477 of file BaseApp.cc.

Referenced by finish().

00478 {
00479     // ...
00480 }

void BaseApp::callRoute ( const OverlayKey &  key,
cPacket *  msg,
const TransportAddress &  hint = TransportAddress::UNSPECIFIED_NODE,
RoutingType  routingType = DEFAULT_ROUTING 
) [inline, protected]

Common API function: 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)
routingType specifies the routing mode (ITERATIVE_ROUTING, ...)

Definition at line 180 of file BaseApp.h.

Referenced by Scribe::checkGroupEmpty(), RealWorldTestApp::deliver(), Scribe::deliverALMDataToGroup(), Scribe::handleTimerEvent(), KBRTestApp::handleTimerEvent(), I3::handleUDPMessage(), RealWorldTestApp::handleUpperMessage(), internalSendRouteRpc(), and I3::sendPacket().

00184     {
00185         std::vector<TransportAddress> sourceRoute;
00186         sourceRoute.push_back(hint);
00187         callRoute(key, msg, sourceRoute, routingType);
00188     }

void BaseApp::callRoute ( const OverlayKey &  key,
cPacket *  msg,
const std::vector< TransportAddress > &  sourceRoute,
RoutingType  routingType = DEFAULT_ROUTING 
) [protected]

Definition at line 233 of file BaseApp.cc.

00236 {
00237     // create route-message (common API)
00238     KBRroute* routeMsg = new KBRroute();
00239     routeMsg->setDestKey(key);
00240 
00241     if (!(sourceRoute.size() == 1 && sourceRoute[0].isUnspecified())) {
00242         routeMsg->setSourceRouteArraySize(sourceRoute.size());
00243         for (uint32_t i = 0; i < sourceRoute.size(); ++i) {
00244             routeMsg->setSourceRoute(i, sourceRoute[i]);
00245         }
00246     }
00247     routeMsg->encapsulate(msg);
00248     routeMsg->setSrcComp(thisCompType);
00249     routeMsg->setDestComp(thisCompType);
00250     routeMsg->setRoutingType(routingType);
00251 
00252     routeMsg->setType(KBR_ROUTE);
00253 
00254     sendDirect(routeMsg, overlay->getCompRpcGate(OVERLAY_COMP));
00255 
00256     // debug message
00257     if (debugOutput && !ev.isDisabled()) {
00258         EV << "[BaseApp::callRoute() @ " << thisNode.ip
00259         << " (" << overlay->getThisNode().key.toString(16) << ")]\n"
00260         << "    Sending " << *msg
00261         << " to destination key " << key
00262         << " with source route ";
00263 
00264         for (uint32_t i = 0; i < sourceRoute.size(); ++i) {
00265             EV << sourceRoute[i] << " ";
00266         }
00267 
00268         EV << endl;
00269     }
00270 
00271     // count
00272     RECORD_STATS(numOverlaySent++; bytesOverlaySent += msg->getByteLength());
00273 }

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

Parameters:
key destination key
msg delivered message

Reimplemented in I3, I3TRTServer, KBRTestApp, RealWorldTestApp, and Scribe.

Definition at line 275 of file BaseApp.cc.

Referenced by handleCommonAPIMessage().

00276 {
00277     // deliver...
00278 
00279     delete msg;
00280 }

void BaseApp::forward ( OverlayKey *  key,
cPacket **  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

Parameters:
key destination key
msg message to forward
nextHopNode next hop

Reimplemented in I3, KBRTestApp, and Scribe.

Definition at line 282 of file BaseApp.cc.

Referenced by I3::forward(), and handleCommonAPIMessage().

00283 {
00284     // usually do nothing
00285 }

void BaseApp::update ( const NodeHandle &  node,
bool  joined 
) [protected, virtual]

Common API function: informs application about neighbors and own nodeID.

Parameters:
node new or lost neighbor
joined new or lost?

Reimplemented in DHT, and Scribe.

Definition at line 309 of file BaseApp.cc.

Referenced by handleCommonAPIMessage().

00310 {
00311 }

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.

Parameters:
key the destination key
num maximal number of nodes in answer
safe fraction of faulty nodes is not higher than in the overlay?

Definition at line 232 of file BaseApp.h.

00234     {
00235         return overlay->local_lookup(key, num, safe);
00236     };

NodeVector* BaseApp::callNeighborSet ( int  num  )  [inline, protected]

Common API function: produces a list of neighbor nodes.

Parameters:
num maximal number of nodes in answer

Definition at line 243 of file BaseApp.h.

00244     {
00245         return overlay->neighborSet(num);
00246     };

bool BaseApp::isSiblingFor ( const NodeHandle &  node,
const OverlayKey &  key,
int  numSiblings,
bool *  err 
) [inline, protected]

Query if a node is among the siblings for a given key.

Query if a node is among the siblings for a given key. This means, that the nodeId of this node among the close numSiblings nodes to the key and that by a local findNode() call all other siblings to this key can be retrieved.

Parameters:
node the NodeHandle
key destination key
numSiblings The nodes knows all numSiblings nodes close to this key
err return false if the range could not be determined
Returns:
bool true, if the node is responsible for the key.

Definition at line 263 of file BaseApp.h.

00265     {
00266         return overlay->isSiblingFor(node, key, numSiblings, err);
00267     };

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 DHT, GIASearchApp, I3, KBRTestApp, RealWorldTestApp, Scribe, SimpleGameClient, BootstrapList, DHTTestApp, P2pns, and SimMud.

Definition at line 201 of file BaseApp.cc.

Referenced by handleMessage().

00202 {
00203     // process self-messages
00204 }

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

method to handle non-commonAPI messages from the overlay

Parameters:
msg message to handle

Reimplemented in GIASearchApp, SimpleGameClient, and SimMud.

Definition at line 410 of file BaseApp.cc.

Referenced by handleMessage().

00411 {
00412     delete msg;
00413 }

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

handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function)

Parameters:
msg the message to handle

Reimplemented in DHT, RealWorldTestApp, Scribe, and SimMud.

Definition at line 405 of file BaseApp.cc.

Referenced by handleMessage().

00406 {
00407     delete msg;
00408 }

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

method to handle messages that come directly from the UDP gate

Parameters:
msg message to handle

Reimplemented in I3.

Definition at line 415 of file BaseApp.cc.

Referenced by handleMessage().

00416 {
00417     delete msg;
00418 }

void BaseApp::handleReadyMessage ( CompReadyMessage *  msg  )  [protected, virtual]

method to handle ready messages from the overlay

Parameters:
msg message to handle

Reimplemented in Scribe, SimpleGameClient, and SimMud.

Definition at line 420 of file BaseApp.cc.

Referenced by handleMessage().

00421 {
00422     delete msg;
00423 }

void BaseApp::bindToPort ( int  port  )  [protected, virtual]

Tells UDP we want to get all packets arriving on the given port.

Definition at line 482 of file BaseApp.cc.

Referenced by KBRTestApp::initializeApp(), and I3::initializeApp().

00483 {
00484     EV << "[BaseApp::bindToPort() @ " << thisNode.ip
00485        << ":  Binding to UDP port " << port << endl;
00486 
00487     thisNode.port = port;
00488 
00489     cMessage *msg = new cMessage("UDP_C_BIND", UDP_C_BIND);
00490     UDPControlInfo *ctrl = new UDPControlInfo();
00491     ctrl->setSrcPort(port);
00492     ctrl->setSockId(UDPSocket::generateSocketId());
00493     msg->setControlInfo(ctrl);
00494     send(msg, "udpOut");
00495 }

void BaseApp::sendMessageToUDP ( const TransportAddress &  destAddr,
cPacket *  msg 
) [protected, virtual]

Sends a packet over UDP.

Reimplemented from BaseRpc.

Definition at line 497 of file BaseApp.cc.

Referenced by I3::sendQueryReply(), and I3::sendToNode().

00498 {
00499     // send message to UDP, with the appropriate control info attached
00500     msg->removeControlInfo();
00501     msg->setKind(UDP_C_DATA);
00502 
00503     UDPControlInfo *ctrl = new UDPControlInfo();
00504     ctrl->setSrcPort(thisNode.port);
00505     ctrl->setSrcAddr(thisNode.ip);
00506     ctrl->setDestAddr(destAddr.ip);
00507     ctrl->setDestPort(destAddr.port);
00508     msg->setControlInfo(ctrl);
00509 
00510     if (ev.isGUI()) {
00511         BaseRpcMessage* rpc = dynamic_cast<BaseRpcMessage*>(msg);
00512         if (rpc) rpc->setStatType(APP_DATA_STAT);
00513     }
00514 
00515     // debug message
00516     if (debugOutput) {
00517         EV << "[BaseApp::sendMessageToUDP() @ " << thisNode.ip
00518         << " (" << overlay->getThisNode().key.toString(16) << ")]\n"
00519         << "    Sending " << *msg << " to " << destAddr.ip
00520         << endl;
00521     }
00522 
00523 
00524     RECORD_STATS(numUdpSent++; bytesUdpSent += msg->getByteLength());
00525     send(msg, "udpOut");
00526 }

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

handleTraceMessage gets called of handleMessage(cMessage* msg) if a message arrives at trace_in.

The command included in this message should be parsed and handled.

Parameters:
msg the command message to handle

Reimplemented in DHTTestApp.

Definition at line 425 of file BaseApp.cc.

Referenced by handleMessage().

00426 {
00427     throw cRuntimeError("This application cannot handle trace data. "
00428                          "You have to overwrite handleTraceMessage() in your "
00429                          "application to make trace files work");
00430 }

void BaseApp::sendMessageToLowerTier ( cPacket *  msg  )  [protected]

sends non-commonAPI message to the lower tier

Parameters:
msg message to send

Definition at line 432 of file BaseApp.cc.

Referenced by SimpleGameClient::handleRealworldPacket(), SimpleGameClient::handleTimerEvent(), GIASearchApp::handleTimerEvent(), and SimpleGameClient::updatePosition().

00433 {
00434     RECORD_STATS(numOverlaySent++; bytesOverlaySent += msg->getByteLength());
00435 
00436     send(msg, "to_lowerTier");
00437 }

bool BaseApp::internalHandleRpc ( BaseCallMessage *  msg  )  [protected, virtual]

Handles internal rpc requests.


This method is used to implement basic functionionality in the BaseRpc.

Parameters:
msg The call message
Returns:
bool true, if call has been handled.

Reimplemented from BaseRpc.

Definition at line 529 of file BaseApp.cc.

00530 {
00531     // if RPC was handled return true, else tell the parent class to handle it
00532     return BaseRpc::internalHandleRpc(msg);
00533 }

bool BaseApp::internalHandleRpcResponse ( BaseResponseMessage *  msg,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
) [protected, virtual]

Handles rpc responses internal in base classes
.

This method is used to implement basic functionionality in the BaseRpc.

Parameters:
msg The call message
context Pointer to an optional state object. The object has to be handled/deleted by the internalHandleRpcResponse() code
rpcId The ID of the call
rtt the time between sending the call and receiving the response
Returns:
bool true, if call has been handled.

Reimplemented from BaseRpc.

Definition at line 535 of file BaseApp.cc.

00538 {
00539     // if RPC was handled return true, else tell the parent class to handle it
00540     return BaseRpc::internalHandleRpcResponse(msg, context, rpcId, rtt);
00541 }

void BaseApp::internalSendRouteRpc ( BaseRpcMessage *  message,
const OverlayKey &  destKey,
const std::vector< TransportAddress > &  sourceRoute,
RoutingType  routingType 
) [protected, virtual]

Implements BaseRpc.

Definition at line 543 of file BaseApp.cc.

00547                                                             {
00548     callRoute(destKey, message, sourceRoute, routingType);
00549 }

CompType BaseApp::getThisCompType (  )  [protected, virtual]

Return the component type of this module.

This method is overloaded by BaseOverlay/BaseApp and returns the appropriate component type of this module.

Returns:
the component type of this module

Implements BaseRpc.

Reimplemented in BootstrapList.

Definition at line 172 of file BaseApp.cc.

Referenced by forwardResponse().

00173 {
00174     std::string name(this->getName());
00175 
00176     if (name == std::string("tier1")) {
00177         return TIER1_COMP;
00178     } else if (name == std::string("tier2")) {
00179         return TIER2_COMP;
00180     } else if (name == std::string("tier3")) {
00181         return TIER3_COMP;
00182     }
00183 
00184     std::string parentName(this->getParentModule()->getName());
00185 
00186     if (parentName == std::string("tier1")) {
00187         return TIER1_COMP;
00188     } else if (parentName == std::string("tier2")) {
00189         return TIER2_COMP;
00190     } else if (parentName == std::string("tier3")) {
00191         return TIER3_COMP;
00192     } else {
00193         throw cRuntimeError("BaseApp::getThisCompType(): "
00194                              "Unknown module type!");
00195     }
00196 
00197     return INVALID_COMP;
00198 }

void BaseApp::internalSendRpcResponse ( BaseCallMessage *  call,
BaseResponseMessage *  response 
) [private, virtual]

Implements BaseRpc.

Definition at line 551 of file BaseApp.cc.

00553 {
00554     // default values for UDP transport
00555     TransportType transportType = UDP_TRANSPORT;
00556     CompType compType = INVALID_COMP;
00557     const TransportAddress* destNode = &TransportAddress::UNSPECIFIED_NODE;//&(call->getSrcNode());
00558     const OverlayKey* destKey = &OverlayKey::UNSPECIFIED_KEY;
00559 
00560     TransportAddress tempNode;
00561 
00562     OverlayCtrlInfo* overlayCtrlInfo =
00563         dynamic_cast<OverlayCtrlInfo*>(call->getControlInfo());
00564 
00565     if (overlayCtrlInfo &&
00566         overlayCtrlInfo->getTransportType() == ROUTE_TRANSPORT) {
00567         //destNode = &(overlayCtrlInfo->getSrcNode());
00568         if (overlayCtrlInfo->getSrcNode().isUnspecified())
00569             destNode = &(overlayCtrlInfo->getLastHop());
00570         else
00571             destNode = &(overlayCtrlInfo->getSrcNode());
00572         transportType = ROUTE_TRANSPORT;
00573         compType = static_cast<CompType>(overlayCtrlInfo->getSrcComp());
00574         if (static_cast<RoutingType>(overlayCtrlInfo->getRoutingType())
00575                 == FULL_RECURSIVE_ROUTING) {
00576             destKey = &(overlayCtrlInfo->getSrcNode().key);//&(call->getSrcNode().key);
00577             destNode = &NodeHandle::UNSPECIFIED_NODE;
00578         }
00579     } else {
00580         UDPControlInfo* udpCtrlInfo =
00581             check_and_cast<UDPControlInfo*>(call->getControlInfo());
00582 
00583         tempNode = TransportAddress(udpCtrlInfo->getSrcAddr(), udpCtrlInfo->getSrcPort());
00584         destNode = &tempNode;
00585 
00586     }
00587 
00588     sendRpcResponse(transportType, compType,
00589                     *destNode, *destKey, call, response);
00590 }


Member Data Documentation

pointer to UnderlayConfigurator in this node

Reimplemented in DHTTestApp.

Definition at line 334 of file BaseApp.h.

Referenced by KBRTestApp::handleTimerEvent(), GIASearchApp::handleTimerEvent(), and initialize().

pointer to GlobalNodeList in this node

Reimplemented in DHTTestApp.

Definition at line 337 of file BaseApp.h.

Referenced by KBRTestApp::handleTimerEvent(), GIASearchApp::handleTimerEvent(), initialize(), and BootstrapList::registerBootstrapNode().

NotificationBoard* BaseApp::notificationBoard [protected]

pointer to NotificationBoard in this node

Definition at line 343 of file BaseApp.h.

Referenced by BaseApp(), and initialize().

bool BaseApp::debugOutput [protected]

int BaseApp::numOverlaySent [protected]

number of sent packets to overlay

Definition at line 350 of file BaseApp.h.

Referenced by callRoute(), KBRTestApp::evaluateData(), finish(), KBRTestApp::finishApp(), initialize(), and sendMessageToLowerTier().

int BaseApp::bytesOverlaySent [protected]

number of sent bytes to overlay

Definition at line 351 of file BaseApp.h.

Referenced by callRoute(), finish(), initialize(), and sendMessageToLowerTier().

int BaseApp::numOverlayReceived [protected]

number of received packets from overlay

Definition at line 352 of file BaseApp.h.

Referenced by finish(), handleCommonAPIMessage(), handleMessage(), and initialize().

number of received bytes from overlay

Definition at line 353 of file BaseApp.h.

Referenced by finish(), handleCommonAPIMessage(), handleMessage(), and initialize().

int BaseApp::numUdpSent [protected]

number of sent packets to UDP

Definition at line 354 of file BaseApp.h.

Referenced by finish(), initialize(), and sendMessageToUDP().

int BaseApp::bytesUdpSent [protected]

number of sent bytes to UDP

Definition at line 355 of file BaseApp.h.

Referenced by finish(), initialize(), and sendMessageToUDP().

int BaseApp::numUdpReceived [protected]

number of received packets from UDP

Definition at line 356 of file BaseApp.h.

Referenced by finish(), handleMessage(), and initialize().

int BaseApp::bytesUdpReceived [protected]

number of received bytes from UDP

Definition at line 357 of file BaseApp.h.

Referenced by finish(), handleMessage(), and initialize().

simtime_t BaseApp::creationTime [protected]

simTime when the App has been created

Definition at line 359 of file BaseApp.h.

Referenced by finish(), SimMud::finishApp(), Scribe::finishApp(), KBRTestApp::finishApp(), DHTTestApp::finishApp(), DHT::finishApp(), and initialize().


The documentation for this class was generated from the following files:

Generated on Wed Mar 25 16:32:51 2009 for OverSim by  doxygen 1.5.5