BaseApp Class Reference

Base class for applications. More...

#include <BaseApp.h>

Inheritance diagram for BaseApp:

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

List of all members.

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.
NodeVectorcallLocalLookup (const OverlayKey &key, int num, bool safe)
 Common API function: produces a list of nodes that can be used as next hops towards key.
NodeVectorcallNeighborSet (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 handleLowerMessage (cMessage *msg)
 processes self-messages
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 internalHandleRpcCall (BaseCallMessage *msg)
 Handles internal rpc requests.
void 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

UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
GlobalNodeListglobalNodeList
 pointer to GlobalNodeList in this node
GlobalStatisticsglobalStatistics
 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)


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.


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::bindToPort ( int  port  )  [protected, virtual]

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

Definition at line 485 of file BaseApp.cc.

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

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

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

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

Definition at line 236 of file BaseApp.cc.

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

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(), I3::sendPacket(), and P2pns::sendTunnelMessage().

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

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, Scribe, and P2pns.

Definition at line 278 of file BaseApp.cc.

Referenced by handleCommonAPIMessage().

00279 {
00280     // deliver...
00281 
00282     delete msg;
00283 }

void BaseApp::finish (  )  [protected]

collects statistical data

Reimplemented in I3, and I3TRTServer.

Definition at line 442 of file BaseApp.cc.

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

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

collects statistical data of derived app

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

Definition at line 480 of file BaseApp.cc.

Referenced by finish().

00481 {
00482     // ...
00483 }

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 285 of file BaseApp.cc.

Referenced by handleCommonAPIMessage().

00286 {
00287     // usually do nothing
00288 }

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 290 of file BaseApp.cc.

Referenced by handleCommonAPIMessage().

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

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, and NeighborCache.

Definition at line 181 of file BaseApp.cc.

Referenced by forwardResponse(), SimpleGameClient::handleReadyMessage(), SimMud::handleReadyMessage(), Scribe::handleReadyMessage(), and initialize().

00182 {
00183     std::string name(this->getName());
00184 
00185     if (name == std::string("tier1")) {
00186         return TIER1_COMP;
00187     } else if (name == std::string("tier2")) {
00188         return TIER2_COMP;
00189     } else if (name == std::string("tier3")) {
00190         return TIER3_COMP;
00191     }
00192 
00193     std::string parentName(this->getParentModule()->getName());
00194 
00195     if (parentName == std::string("tier1")) {
00196         return TIER1_COMP;
00197     } else if (parentName == std::string("tier2")) {
00198         return TIER2_COMP;
00199     } else if (parentName == std::string("tier3")) {
00200         return TIER3_COMP;
00201     } else {
00202         throw cRuntimeError("BaseApp::getThisCompType(): "
00203                              "Unknown module type!");
00204     }
00205 
00206     return INVALID_COMP;
00207 }

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 316 of file BaseApp.cc.

Referenced by handleMessage().

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

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

processes self-messages

method to handle self-messages should be overwritten in derived application if needed

Parameters:
msg self-message method to handle non-commonAPI messages from the overlay
msg message to handle

Reimplemented in GIASearchApp, SimpleGameClient, and SimMud.

Definition at line 413 of file BaseApp.cc.

Referenced by handleMessage().

00414 {
00415     delete msg;
00416 }

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 128 of file BaseApp.cc.

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

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 231 of file BaseApp.cc.

Referenced by receiveChangeNotification().

00232 {
00233     // ...
00234 }

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

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

Reimplemented in KBRTestApp, and DHTTestApp.

Definition at line 226 of file BaseApp.cc.

Referenced by receiveChangeNotification().

00227 {
00228     // ...
00229 }

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

method to handle ready messages from the overlay

Parameters:
msg message to handle

Reimplemented in Scribe, SimpleGameClient, P2pns, SimMud, and XmlRpcInterface.

Definition at line 423 of file BaseApp.cc.

Referenced by handleMessage().

00424 {
00425     delete msg;
00426 }

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 428 of file BaseApp.cc.

Referenced by handleMessage().

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

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 221 of file BaseApp.cc.

Referenced by receiveChangeNotification().

00222 {
00223     // ...
00224 }

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 418 of file BaseApp.cc.

Referenced by handleMessage().

00419 {
00420     delete msg;
00421 }

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 RealWorldTestApp, Scribe, CBRDHT, and SimMud.

Definition at line 408 of file BaseApp.cc.

Referenced by handleMessage().

00409 {
00410     delete msg;
00411 }

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

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, CBRDHT, Landmark, NeighborCache, DHTTestApp, P2pns, SimMud, and XmlRpcInterface.

Definition at line 122 of file BaseApp.cc.

Referenced by initialize().

00123 {
00124     // ...
00125 }

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

Handles internal rpc requests.


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

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

Reimplemented from BaseRpc.

Definition at line 532 of file BaseApp.cc.

00533 {
00534     // if RPC was handled return true, else tell the parent class to handle it
00535     return BaseRpc::internalHandleRpcCall(msg);
00536 }

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

Reimplemented from BaseRpc.

Definition at line 538 of file BaseApp.cc.

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

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

Implements BaseRpc.

Definition at line 546 of file BaseApp.cc.

00550                                                             {
00551     callRoute(destKey, message, sourceRoute, routingType);
00552 }

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

Implements BaseRpc.

Definition at line 554 of file BaseApp.cc.

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

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

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::receiveChangeNotification ( int  category,
const cPolymorphic *  details 
) [protected, virtual]

callback-method for events at the NotificationBoard

Parameters:
category ...
details ...

Definition at line 209 of file BaseApp.cc.

00210 {
00211     Enter_Method_Silent();
00212     if (category == NF_OVERLAY_TRANSPORTADDRESS_CHANGED) {
00213         handleTransportAddressChangedNotification();
00214     } else if (category == NF_OVERLAY_NODE_LEAVE) {
00215         handleNodeLeaveNotification();
00216     } else if (category == NF_OVERLAY_NODE_GRACEFUL_LEAVE) {
00217         handleNodeGracefulLeaveNotification();
00218     }
00219 }

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

sends non-commonAPI message to the lower tier

Parameters:
msg message to send

Definition at line 435 of file BaseApp.cc.

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

00436 {
00437     RECORD_STATS(numOverlaySent++; bytesOverlaySent += msg->getByteLength());
00438 
00439     send(msg, "to_lowerTier");
00440 }

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

Sends a packet over UDP.

Reimplemented from BaseRpc.

Definition at line 500 of file BaseApp.cc.

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

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

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, Scribe, and CBRDHT.

Definition at line 312 of file BaseApp.cc.

Referenced by handleCommonAPIMessage().

00313 {
00314 }


Member Data Documentation

number of received bytes from overlay

Definition at line 353 of file BaseApp.h.

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

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::bytesUdpReceived [protected]

number of received bytes from UDP

Definition at line 357 of file BaseApp.h.

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

int BaseApp::bytesUdpSent [protected]

number of sent bytes to UDP

Definition at line 355 of file BaseApp.h.

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

simtime_t BaseApp::creationTime [protected]

bool BaseApp::debugOutput [protected]

NotificationBoard* BaseApp::notificationBoard [protected]

pointer to NotificationBoard in this node

Definition at line 343 of file BaseApp.h.

Referenced by BaseApp(), and initialize().

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

int BaseApp::numOverlaySent [protected]

number of sent packets to overlay

Definition at line 350 of file BaseApp.h.

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

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::numUdpSent [protected]

number of sent packets to UDP

Definition at line 354 of file BaseApp.h.

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


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

Generated on Tue Sep 8 17:26:56 2009 for OverSim by  doxygen 1.5.8