BaseApp Class Reference

Base class for applications. More...

#include <BaseApp.h>

Inheritance diagram for BaseApp:
BaseRpc RpcListener ALMTest BootstrapList CBRDHT DHT DHTTestApp GIASearchApp I3 KBRTestApp Landmark MyApplication NeighborCache P2pns P2PNSTestApp 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.
void sendReadyMessage (bool ready=true)

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

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

BaseApp::~BaseApp (  )  [virtual]

virtual destructor

Definition at line 48 of file BaseApp.cc.

00049 {
00050     finishRpcs();
00051 }


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

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

00494 {
00495     EV << "[BaseApp::bindToPort() @ " << thisNode.getAddress()
00496        << ":  Binding to UDP port " << port << endl;
00497 
00498     thisNode.setPort(port);
00499 
00500     cMessage *msg = new cMessage("UDP_C_BIND", UDP_C_BIND);
00501     UDPControlInfo *ctrl = new UDPControlInfo();
00502     ctrl->setSrcPort(port);
00503     ctrl->setSockId(UDPSocket::generateSocketId());
00504     msg->setControlInfo(ctrl);
00505     send(msg, "udpOut");
00506 }

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(), MyApplication::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, MyApplication, 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 450 of file BaseApp.cc.

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

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

collects statistical data of derived app

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

Definition at line 488 of file BaseApp.cc.

Referenced by finish().

00489 {
00490     // ...
00491 }

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(), ALMTest::handleReadyMessage(), initialize(), and sendReadyMessage().

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 ALMTest, 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 134 of file BaseApp.cc.

00135 {
00136     if (internalHandleMessage(msg)) {
00137         return;
00138     }
00139 
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 ALMTest, Scribe, SimpleGameClient, NeighborCache, 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, and P2PNSTestApp.

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.

Reimplemented in ALMTest.

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 ALMTest, I3, and MyApplication.

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 ALMTest, 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 58 of file BaseApp.cc.

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

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

initializes derived class-attributes

Parameters:
stage the init stage

Reimplemented in ALMTest, DHT, GIASearchApp, I3, I3TRTServer, KBRTestApp, MyApplication, RealWorldTestApp, Scribe, SimpleGameClient, BootstrapList, CBRDHT, Landmark, NeighborCache, DHTTestApp, P2pns, SimMud, P2PNSTestApp, and XmlRpcInterface.

Definition at line 128 of file BaseApp.cc.

Referenced by initialize().

00129 {
00130     // ...
00131 }

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

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

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

00549 {
00550     // if RPC was handled return true, else tell the parent class to handle it
00551     BaseRpc::internalHandleRpcResponse(msg, context, rpcId, rtt);
00552 }

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

Implements BaseRpc.

Definition at line 554 of file BaseApp.cc.

00558                                                             {
00559     callRoute(destKey, message, sourceRoute, routingType);
00560 }

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

Implements BaseRpc.

Definition at line 562 of file BaseApp.cc.

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

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

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

00054 {
00055     return MAX_STAGE_APP + 1;
00056 }

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

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

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

void BaseApp::sendReadyMessage ( bool  ready = true  )  [protected]

Definition at line 441 of file BaseApp.cc.

Referenced by NeighborCache::handleReadyMessage(), and BootstrapList::initializeApp().

00442 {
00443     CompReadyMessage* msg = new CompReadyMessage();
00444     msg->setReady(ready);
00445     msg->setComp(getThisCompType());
00446 
00447     overlay->sendMessageToAllComp(msg, getThisCompType());
00448 }

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 Wed May 26 16:21:16 2010 for OverSim by  doxygen 1.6.3