BaseApp Class Reference

#include <BaseApp.h>

Inheritance diagram for BaseApp:

BaseRpc RpcListener DHT DHTTestApp GIASearchApp I3 KBRTestApp P2pns RealWorldTestApp Scribe SimMud SimpleGameClient 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=NodeHandle::UNSPECIFIED_NODE)
 Common API function: calls route-method in overlay.
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
 __attribute__ ((__deprecated__)) inline void handleAppMessage(cMessage *msg)
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 (TierReadyMessage *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 sendMessageToOverlay (cMessage *msg)
 sends non-commonAPI message to the overlay
CompType getThisCompType ()
 Return the component type of this module.
virtual void sendRpcMessageWithTransport (TransportType transportType, CompType compType, const TransportAddress &dest, const OverlayKey &destKey, BaseRpcMessage *message)
bool internalHandleRpc (BaseCallMessage *msg)
 Handles internal rpc requests.
bool internalHandleRpcResponse (BaseResponseMessage *msg, int rpcId, simtime_t rtt)
 Handles rpc responses internal in base classes
.

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
BaseOverlayoverlay
 pointer to the overlay module of this node
bool debugOutput
 debug output yes/no?
int numSent
 number of sent packets
int bytesSent
 number of sent bytes
int numReceived
 number of received packets
int bytesReceived
 number of received bytes
simtime_t creationTime
 simTime when the App has been created
CompType thisCompType

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

Constructor & Destructor Documentation

BaseApp::BaseApp (  ) 

00039 {
00040     notificationBoard = NULL;
00041 
00042     overlay = NULL;
00043 }

BaseApp::~BaseApp (  )  [virtual]

virtual destructor

00046 {
00047     finishRpcs();
00048 }


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
00267 {
00268     OverlayCtrlInfo* ctrlInfo =
00269         check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo());
00270 
00271         //create forwardResponse message (common API)
00272         KBRforward* forwardMsg = new KBRforward();
00273         forwardMsg->setDestKey(key);
00274         forwardMsg->setNextHopNode(nextHopNode);
00275         forwardMsg->setControlInfo(ctrlInfo);
00276         forwardMsg->encapsulate(msg);
00277 
00278         forwardMsg->setType(KBR_FORWARD_RESPONSE);
00279 
00280         send(forwardMsg, "to_lowerTier");
00281 }

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

int BaseApp::numInitStages (  )  const [protected]

method to set InitStage

Reimplemented in I3.

00051 {
00052     return MAX_STAGE_APP + 1;
00053 }

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

initializes base class-attributes

Parameters:
stage the init stage
00056 {
00057     if(stage == MIN_STAGE_APP) {
00058         // fetch parameters
00059         debugOutput = par("debugOutput");
00060 
00061         bootstrapOracle = BootstrapOracleAccess().get();
00062         underlayConfigurator = UnderlayConfiguratorAccess().get();
00063         globalStatistics = GlobalStatisticsAccess().get();
00064         notificationBoard = NotificationBoardAccess().get();
00065 
00066         // subscribe to the notification board
00067         notificationBoard->subscribe(this, NF_OVERLAY_TRANSPORTADDRESS_CHANGED);
00068         notificationBoard->subscribe(this, NF_OVERLAY_NODE_LEAVE);
00069         notificationBoard->subscribe(this, NF_OVERLAY_NODE_GRACEFUL_LEAVE);
00070 
00071         // set overlay pointer
00072         overlay = OverlayAccess().get(this);
00073 
00074         // determine the terminal's transport address
00075         thisNode.ip = IPAddressResolver().addressOf(
00076                                   parentModule()->parentModule()).get4();
00077         WATCH(thisNode);
00078 
00079         // statistics
00080         numSent = 0;
00081         numReceived = 0;
00082         bytesSent = 0;
00083         bytesReceived = 0;
00084         creationTime = simTime();
00085 
00086         WATCH(numSent);
00087         WATCH(numReceived);
00088         WATCH(bytesSent);
00089         WATCH(bytesReceived);
00090 
00091         // register component
00092         thisCompType = getThisCompType();
00093         overlay->registerComp(thisCompType, this);
00094         
00095         // init rpcs
00096         initRpcs();
00097     }
00098 
00099     if(stage >= MIN_STAGE_APP && stage <= MAX_STAGE_APP)
00100         initializeApp(stage);
00101 }

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

00104 {
00105     // ...
00106 }

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.

00110 {
00111     // Process self-messages.
00112     if(msg->isSelfMessage()) {
00113         // process rpc self-messages
00114         BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg);
00115         if (rpcMessage!=NULL) {
00116             internalHandleRpcMessage(rpcMessage);
00117             return;
00118         }
00119         // process all other self-messages
00120         handleTimerEvent(msg);
00121         return;
00122     }
00123 
00124     // TODO: cleanup code
00125     if (msg->arrivedOn("from_lowerTier") || msg->arrivedOn("direct_in")) {
00126         BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg);
00127         if (rpcMessage!=NULL) {
00128             internalHandleRpcMessage(rpcMessage);
00129             return;
00130         }
00131         TierReadyMessage* readyMsg = dynamic_cast<TierReadyMessage*>(msg);
00132         if (readyMsg != NULL) {
00133             handleReadyMessage(readyMsg);
00134             return;
00135         }
00136         // common API
00137         CommonAPIMessage* commonAPIMsg = dynamic_cast<CommonAPIMessage*>(msg);
00138         if(commonAPIMsg != NULL)
00139             handleCommonAPIMessage(commonAPIMsg);
00140 
00141         else if (msg->arrivedOn("from_lowerTier")) {
00142             RECORD_STATS(numReceived++; bytesReceived += msg->byteLength());
00143             handleLowerMessage(msg);
00144         }
00145         else
00146             delete msg;
00147     } else if(msg->arrivedOn("from_upperTier")) {
00148         BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg);
00149         if (rpcMessage!=NULL) {
00150             internalHandleRpcMessage(rpcMessage);
00151             return;
00152         }
00153         handleUpperMessage(msg);
00154     } else if (msg->arrivedOn("from_udp")) {
00155         handleUDPMessage(msg);
00156     } else if(msg->arrivedOn("trace_in")) {
00157         handleTraceMessage(msg);
00158     } else {
00159         delete msg;
00160     }
00161 
00162 }

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

callback-method for events at the NotificationBoard

Parameters:
category ...
details ...
00200 {
00201     Enter_Method_Silent();
00202     if (category == NF_OVERLAY_TRANSPORTADDRESS_CHANGED) {
00203         handleTransportAddressChangedNotification();
00204     } else if (category == NF_OVERLAY_NODE_LEAVE) {
00205         handleNodeLeaveNotification();
00206     } else if (category == NF_OVERLAY_NODE_GRACEFUL_LEAVE) {
00207         handleNodeGracefulLeaveNotification();
00208     }
00209 }

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

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

00212 {
00213     // ...
00214 }

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

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

Reimplemented in KBRTestApp.

00217 {
00218     // ...
00219 }

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

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

00222 {
00223     // ...
00224 }

void BaseApp::finish (  )  [protected]

collects statistical data

Reimplemented in I3, and I3TRTServer.

00429 {
00430     // record scalar data
00431     simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime);
00432 
00433     if(time != 0) {
00434         globalStatistics->addStdDev("BaseApp: Sent Messages/s", numSent / time);
00435         globalStatistics->addStdDev("BaseApp: Received Messages/s", numReceived / time);
00436         globalStatistics->addStdDev("BaseApp: Sent Bytes/s", bytesSent / time);
00437         globalStatistics->addStdDev("BaseApp: Received Bytes/s", bytesReceived / time);
00438     }
00439 
00440     finishApp();
00441 }

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

collects statistical data of derived app

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

00444 {
00445     // ...
00446 }

void BaseApp::callRoute ( const OverlayKey key,
cMessage *  msg,
const TransportAddress hint = NodeHandle::UNSPECIFIED_NODE 
) [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)
00228 {
00229     // create route-message (common API)
00230     KBRroute* routeMsg = new KBRroute();
00231     routeMsg->setDestKey(key);
00232     routeMsg->setHint(hint);
00233     routeMsg->encapsulate(msg);
00234     routeMsg->setSrcComp(thisCompType);
00235     routeMsg->setDestComp(thisCompType);
00236 
00237     routeMsg->setType(KBR_ROUTE);
00238 
00239     sendDirect(routeMsg, 0, overlay->getCompRpcGate(OVERLAY_COMP));
00240 
00241     // debug output
00242     if (debugOutput)
00243         EV << "[BaseApp::callRoute() @ " << thisNode.ip
00244            << " (" << thisNode.key.toString(16) << ")]\n"
00245            << "    Sent message " << id() << "-" << numSent << "\n"
00246            << "    to destination key " << key.toString(16)
00247            << endl;
00248 
00249     // count
00250     RECORD_STATS(numSent++; bytesSent += msg->byteLength());
00251 }

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.

00254 {
00255     // deliver...
00256 
00257     delete msg;
00258 }

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.

00261 {
00262     // usually do nothing
00263 }

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.

00284 {
00285     if(joined) {
00286         EV << "[BaseApp::update() @ " << thisNode.ip
00287            << " (" << thisNode.key.toString(16) << ")]\n"
00288            << "    (" << node << ", " << joined << ") joined"
00289            << endl;
00290     } else {
00291         EV << "[BaseApp::update() @ " << thisNode.ip
00292            << " (" << thisNode.key.toString(16) << ")]\n"
00293            << "    (" << node << ", " << joined << ") left"
00294            << endl;
00295     }
00296 
00297 }

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?
00220     {
00221         return overlay->local_lookup(key, num, safe);
00222     };

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

Common API function: produces a list of neighbor nodes.

Parameters:
num maximal number of nodes in answer
00230     {
00231         return overlay->neighborSet(num);
00232     };

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.
00251     {
00252         return overlay->isSiblingFor(node, key, numSiblings, err);
00253     };

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

00195 {
00196     // process self-messages
00197 }

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.

00400 {
00401     delete msg;
00402 }

BaseApp::__attribute__ ( (__deprecated__)   )  [inline, protected]

00273     {
00274         handleLowerMessage(msg);
00275     };

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.

00395 {
00396     delete msg;
00397 }

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.

00405 {
00406     delete msg;
00407 }

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

method to handle ready messages from the overlay

Parameters:
msg message to handle

Reimplemented in Scribe, SimpleGameClient, and SimMud.

00410 {
00411     delete msg;
00412 }

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

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

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

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

Sends a packet over UDP.

00499 {
00500     // send message to UDP, with the appropriate control info attached
00501     msg->removeControlInfo();
00502     msg->setKind(UDP_C_DATA);
00503 
00504     UDPControlInfo *ctrl = new UDPControlInfo();
00505     ctrl->setSrcPort(thisNode.port);
00506     ctrl->setSrcAddr(thisNode.ip);
00507     ctrl->setDestAddr(destAddr.ip);
00508     ctrl->setDestPort(destAddr.port);
00509     msg->setControlInfo(ctrl);
00510 
00511     EV << "[BaseApp::sendMessageToUDP() @ " << thisNode.ip
00512        << ":    Sending packet: " << msg
00513        << endl;
00514 
00515     send(msg, "to_udp");
00516 }

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

00313     {
00314         sendMessageToUDP(destAddr, msg);
00315     }

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

Deprecated:
Use sendMessageToUDP instead
00321     {
00322         TransportAddress ta(add, destPort);
00323         sendMessageToUDP(ta, msg);
00324     }

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.

00415 {
00416     throw new cException("This application cannot handle trace data. "
00417                          "You have to overwrite handleTraceMessage() in your application "
00418                          "to make trace files work");
00419 }

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

sends non-commonAPI message to the overlay

Parameters:
msg message to send
00422 {
00423     RECORD_STATS(numSent++; bytesSent += msg->byteLength());
00424 
00425     send(msg, "to_lowerTier");
00426 }

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.

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

void BaseApp::sendRpcMessageWithTransport ( TransportType  transportType,
CompType  compType,
const TransportAddress dest,
const OverlayKey destKey,
BaseRpcMessage *  message 
) [protected, virtual]

Implements BaseRpc.

00454 {
00455     switch (transportType) {
00456     case UDP_TRANSPORT:
00457         sendMessageToUDP( dest, message );
00458         break;
00459     case ROUTE_TRANSPORT:
00460         callRoute(destKey, message, dest);
00461         break;
00462     case INTERNAL_TRANSPORT: {
00463         cGate *destCompGate = overlay->getCompRpcGate(destComp);
00464          if (destCompGate == NULL) {
00465              throw new cException("BaseApp::sendRpcMessageWithTransport():"
00466                                   " INTERNAL_RPC to unknown RpcCompType!");
00467          }
00468          OverlayCtrlInfo *overlayCtrlInfo = new OverlayCtrlInfo();
00469          overlayCtrlInfo->setSrcComp(thisCompType);
00470          overlayCtrlInfo->setDestComp(destComp);
00471          overlayCtrlInfo->setTransportType(INTERNAL_TRANSPORT);
00472          message->setControlInfo(overlayCtrlInfo);
00473          sendDirect( message, 0, destCompGate);
00474          break;
00475     }
00476     default:
00477         opp_error("BaseApp::sendRpcMessageWithTransport: "
00478                   "invalid transportType!");
00479         break;
00480     }
00481 }

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.

00520 {
00521     // if RPC was handled return true, else tell the parent class to handle it
00522     return BaseRpc::internalHandleRpc(msg);
00523 }

bool BaseApp::internalHandleRpcResponse ( BaseResponseMessage *  msg,
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
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.

00526 {
00527     // if RPC was handled return true, else tell the parent class to handle it
00528     return BaseRpc::internalHandleRpcResponse(msg, rpcId, rtt);
00529 }


Member Data Documentation

UnderlayConfigurator* BaseApp::underlayConfigurator [protected]

pointer to UnderlayConfigurator in this node

Reimplemented in DHTTestApp.

BootstrapOracle* BaseApp::bootstrapOracle [protected]

pointer to BootstrapOracle in this node

Reimplemented in DHTTestApp.

GlobalStatistics* BaseApp::globalStatistics [protected]

pointer to GlobalStatistics module in this node

Reimplemented from BaseRpc.

Reimplemented in DHTTestApp.

NotificationBoard* BaseApp::notificationBoard [protected]

pointer to NotificationBoard in this node

BaseOverlay* BaseApp::overlay [protected]

pointer to the overlay module of this node

bool BaseApp::debugOutput [protected]

debug output yes/no?

Reimplemented from BaseRpc.

Reimplemented in DHTTestApp.

int BaseApp::numSent [protected]

number of sent packets

Reimplemented in DHTTestApp.

int BaseApp::bytesSent [protected]

number of sent bytes

int BaseApp::numReceived [protected]

number of received packets

Reimplemented in Scribe.

int BaseApp::bytesReceived [protected]

number of received bytes

simtime_t BaseApp::creationTime [protected]

simTime when the App has been created

CompType BaseApp::thisCompType [protected]


The documentation for this class was generated from the following files:
Generated on Thu Apr 17 13:19:28 2008 for ITM OverSim by  doxygen 1.5.3