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

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, 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, cMessage *msg, const TransportAddress &hint=TransportAddress::UNSPECIFIED_NODE, RoutingType routingType=DEFAULT_ROUTING)
 Common API function: calls route-method in overlay.
void callRoute (const OverlayKey &key, cMessage *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, cMessage **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 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, cMessage *msg)
 Sends a packet over UDP.
virtual void sendMessageToUDP (cMessage *msg, const TransportAddress &destAddr) __attribute__((deprecated))
virtual void sendToUDP (cMessage *msg, int destPort, IPvXAddress add, int srcPort) __attribute__((deprecated))
virtual void handleTraceMessage (cMessage *msg)
 handleTraceMessage gets called of handleMessage(cMessage* msg) if a message arrives at trace_in.
void sendMessageToLowerTier (cMessage *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

UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
BootstrapOraclebootstrapOracle
 pointer to BootstrapOracle 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, cMessage *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 (  ) 

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

BaseApp::~BaseApp (  )  [virtual]

virtual destructor

00048 {
00049     finishRpcs();
00050 }


Member Function Documentation

void BaseApp::forwardResponse ( const OverlayKey key,
cMessage *  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

Referenced by handleCommonAPIMessage().

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

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

Referenced by handleMessage().

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

int BaseApp::numInitStages (  )  const [protected]

method to set InitStage

Reimplemented in I3.

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
00058 {
00059     if (stage == MIN_STAGE_APP) {
00060         // fetch parameters
00061         debugOutput = par("debugOutput");
00062 
00063         bootstrapOracle = BootstrapOracleAccess().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 (parentModule()->submodule("interfaceTable", 0) != NULL) {
00075             thisNode.ip = IPAddressResolver()
00076                           .addressOf(parentModule()).get4();
00077         } else {
00078             thisNode.ip = IPAddressResolver()
00079                           .addressOf(parentModule()->parentModule()).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.

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.

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             RECORD_STATS(numOverlayReceived++;
00145                          bytesOverlayReceived += msg->byteLength());
00146             handleLowerMessage(msg);
00147         }
00148         else delete msg;
00149     } else if (msg->arrivedOn("from_upperTier")) {
00150         handleUpperMessage(msg);
00151     } else if (msg->arrivedOn("from_udp")) {
00152         RECORD_STATS(numUdpReceived++; bytesUdpReceived += msg->byteLength());
00153         // debug message
00154         if (debugOutput && !ev.disabled()) {
00155             UDPControlInfo* udpControlInfo =
00156                 check_and_cast<UDPControlInfo*>(msg->controlInfo());
00157             EV << "[BaseApp:handleMessage() @ " << thisNode.ip
00158             << " (" << overlay->getThisNode().key.toString(16) << ")]\n"
00159             << "    Received " << *msg << " from "
00160             << udpControlInfo->srcAddr() << endl;
00161         }
00162         handleUDPMessage(msg);
00163     } else if (msg->arrivedOn("trace_in")) {
00164         handleTraceMessage(msg);
00165     } else {
00166         delete msg;
00167     }
00168 }

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

callback-method for events at the NotificationBoard

Parameters:
category ...
details ...
00205 {
00206     Enter_Method_Silent();
00207     if (category == NF_OVERLAY_TRANSPORTADDRESS_CHANGED) {
00208         handleTransportAddressChangedNotification();
00209     } else if (category == NF_OVERLAY_NODE_LEAVE) {
00210         handleNodeLeaveNotification();
00211     } else if (category == NF_OVERLAY_NODE_GRACEFUL_LEAVE) {
00212         handleNodeGracefulLeaveNotification();
00213     }
00214 }

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

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

Referenced by receiveChangeNotification().

00217 {
00218     // ...
00219 }

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

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

Reimplemented in KBRTestApp, and DHTTestApp.

Referenced by receiveChangeNotification().

00222 {
00223     // ...
00224 }

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

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

Referenced by receiveChangeNotification().

00227 {
00228     // ...
00229 }

void BaseApp::finish (  )  [protected]

collects statistical data

Reimplemented in I3, and I3TRTServer.

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

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

collects statistical data of derived app

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

Referenced by finish().

00476 {
00477     // ...
00478 }

void BaseApp::callRoute ( const OverlayKey key,
cMessage *  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, ...)

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,
cMessage *  msg,
const std::vector< TransportAddress > &  sourceRoute,
RoutingType  routingType = DEFAULT_ROUTING 
) [protected]

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

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.

Referenced by handleCommonAPIMessage().

00274 {
00275     // deliver...
00276 
00277     delete msg;
00278 }

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

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

00281 {
00282     // usually do nothing
00283 }

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.

Referenced by handleCommonAPIMessage().

00308 {
00309 }

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

Referenced by handleMessage().

00200 {
00201     // process self-messages
00202 }

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.

Referenced by handleMessage().

00409 {
00410     delete msg;
00411 }

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.

Referenced by handleMessage().

00404 {
00405     delete msg;
00406 }

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.

Referenced by handleMessage().

00414 {
00415     delete msg;
00416 }

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.

Referenced by handleMessage().

00419 {
00420     delete msg;
00421 }

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

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

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

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

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

Sends a packet over UDP.

Reimplemented from BaseRpc.

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

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

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

00321     {
00322         sendMessageToUDP(destAddr, msg);
00323     }

virtual void BaseApp::sendToUDP ( cMessage *  msg,
int  destPort,
IPvXAddress  add,
int  srcPort 
) [inline, protected, virtual]

Deprecated:
Use sendMessageToUDP instead
00329     {
00330         TransportAddress ta(add, destPort);
00331         sendMessageToUDP(ta, msg);
00332     }

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.

Referenced by handleMessage().

00424 {
00425     throw new cException("This application cannot handle trace data. "
00426                          "You have to overwrite handleTraceMessage() in your "
00427                          "application to make trace files work");
00428 }

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

sends non-commonAPI message to the lower tier

Parameters:
msg message to send

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

00431 {
00432     RECORD_STATS(numOverlaySent++; bytesOverlaySent += msg->byteLength());
00433 
00434     send(msg, "to_lowerTier");
00435 }

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.

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

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.

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

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

Implements BaseRpc.

00545                                                             {
00546     callRoute(destKey, message, sourceRoute, routingType);
00547 }

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.

Referenced by forwardResponse().

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

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

Implements BaseRpc.

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


Member Data Documentation

NotificationBoard* BaseApp::notificationBoard [protected]

pointer to NotificationBoard in this node

Referenced by BaseApp(), and initialize().

bool BaseApp::debugOutput [protected]

int BaseApp::numOverlaySent [protected]

int BaseApp::bytesOverlaySent [protected]

number of sent bytes to overlay

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

int BaseApp::numOverlayReceived [protected]

number of received packets from overlay

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

number of received bytes from overlay

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

int BaseApp::numUdpSent [protected]

number of sent packets to UDP

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

int BaseApp::bytesUdpSent [protected]

number of sent bytes to UDP

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

int BaseApp::numUdpReceived [protected]

number of received packets from UDP

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

int BaseApp::bytesUdpReceived [protected]

number of received bytes from UDP

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

simtime_t BaseApp::creationTime [protected]


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

Generated on Fri Sep 19 13:05:05 2008 for ITM OverSim by  doxygen 1.5.5