BaseOverlay Class Reference

#include <BaseOverlay.h>

Inheritance diagram for BaseOverlay:

RpcListener Broose Chord Gia Pastry Koorde List of all members.

Detailed Description

Base class for overlays.

Base class for overlay modules, with KBR-API, statistics and pointers to the BootstrapOracle and the UnderlayConfigurator. A minimal overlay has to implement numInitStages(), route(), handleUDPMessage() and receiveChangeNotification(). Derived classes must use BaseOverlayMessage as base class for own message types.

Author:
Bernhard Heep (initial)

Sebastian Mies (rpc, lookup)


Public Member Functions

virtual ~BaseOverlay ()
 Virtual destructor.
virtual void setMalicious (bool malicious)
 Sets node to a malicious state.
bool isMalicious ()
 Returns true, if node is malicious.
NodeHandlegetThisNode ()
 Returns the NodeHandle of this node.
virtual NodeVectorlocal_lookup (const OverlayKey &key, int num, bool safe)
virtual NodeVectorneighborSet (int num)
virtual NodeVectorreplicaSet (const OverlayKey &key, int max_rank)
virtual bool range (const NodeHandle &node, int rank, const OverlayKey &lKey, const OverlayKey &rKey)
void sendMessageToUDP (const TransportAddress &dest, BaseOverlayMessage *msg)
 Sends message to underlay.
uint32_t sendRpcMessage (const TransportAddress &dest, BaseCallMessage *msg, RpcListener *rpcListener=NULL, const OverlayKey &destKey=OverlayKey::UNSPECIFIED_KEY, int rpcId=-1, simtime_t timeout=-1, int retries=0)
 Sends a Remote-Procedure-Call message to the underlay.
void cancelRpcMessage (uint32_t nonce)
 Cancels a Remote-Procedure-Call.
void sendToKey (const OverlayKey &key, BaseOverlayMessage *message, uint numNeighbors=0, const TransportAddress &nextHop=TransportAddress::UNSPECIFIED_NODE)
 Sends a message to a overlay node, with the generic routing algorithm.

Protected Types

typedef hash_set< AbstractLookup *,
lookupHashFcn, lookupHashFcn
LookupSet

Protected Member Functions

int numInitStages () const
 Sets init stage.
virtual void initializeOverlay (int stage)
 Initializes derived-class-attributes.
virtual void finishOverlay ()
 collects statistical data in derived class
virtual void route (const OverlayKey &key, cMessage *msg, const NodeHandle &hint=NodeHandle::UNSPECIFIED_NODE)
 Routes message through overlay.
virtual bool isResponsible (const OverlayKey &key)
 Query if the node knowns the k-neighborhood for a key.
void callDeliver (BaseOverlayMessage *msg, const OverlayKey &destKey)
 Calls deliver function in application.
void callForward (const OverlayKey &key, BaseRouteMessage *msg, const NodeHandle &nextHopNode)
 Calls forward function in application.
void callUpdate (const NodeHandle &node, bool joined)
virtual void handleUDPMessage (BaseOverlayMessage *msg)=0
 Processes messages from underlay.
virtual void handleTimerEvent (cMessage *msg)
 Processes "timer" self-messages.
virtual void handleAppMessage (cMessage *msg)
 Processes non-commonAPI messages.
virtual void recordOverlaySentStats (BaseOverlayMessage *msg)
 Collect overlay specific sent messages statistics.
void setReadyIcon (bool ready)
 Colors module-icon blue (ready) or red (not ready).
void showOverlayNeighborArrow (const NodeHandle &neighbor, bool flush=true, char *displayString=NULL)
 Draws an arrow from this node to neighbor.
void deleteOverlayNeighborArrow (const NodeHandle &neighbor)
 Removes an arrow from this node to neighbor.
void sendRpcResponse (BaseCallMessage *call, BaseResponseMessage *response)
 Send Remote-Procedure response message and deletes call message.
virtual void handleRpc (BaseCallMessage *msg)
 Processes Remote-Procedure-Call invokation messages.
virtual AbstractLookupcreateLookup (const BaseRouteMessage *msg=NULL)
 Creates a abstract iterative lookup instance.
virtual void removeLookup (AbstractLookup *lookup)
 Removes the abstract lookup instance.
virtual OverlayKey distance (const OverlayKey &x, const OverlayKey &y) const
 This method should implement the distance between two keys.
virtual NodeVectorfindNode (const OverlayKey &key, BaseOverlayMessage *msg=NULL)
 Implements the find node call.
virtual bool handleFailedNode (const TransportAddress &failed)
 Handles a failed node.
virtual PingResponseping (PingCall *call)
 Implements a ping call.

Protected Attributes

int numForwarded
 number of forwarded packets
int bytesForwarded
 number of forwarded bytes at out-gate
int numSignalingForwarded
 number of forwarded signaling packets
int bytesSignalingForwarded
 number of forwarded signaling bytes at out-gate
int numFindNodeSent
int bytesFindNodeSent
cModule * thisTerminal
 pointer to corresponding node
NodeHandle thisNode
 NodeHandle to 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
UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
bool debugOutput
 debug output ?
bool measureNetwInitPhase
 fetch statistics in init phase ?
bool onlyCommonAPIMessages
 drop non-commonAPIMessages ?
bool useBaseLookup
 use the base lookup class
bool iterativeLookup
 do iterative instead of recursive lookups
bool useCommonAPIforward
 forward messages to applications?
int localPort
 used UDP-port
int hopCountMax
 maximum hop count
int numDropped
 number of dropped packets
int bytesDropped
 number of dropped bytes
bool malicious
 true, if node is malicious
cOutVector delayVector
 statistical output vector for packet-delays
cOutVector hopCountVector
 statistical output vector for hop-counts
BaseLookupConfiguration baseLookupConfig
LookupSet lookups

Private Types

typedef hash_map< int, RpcStateRpcStates
 IN
 OUT
enum  Direction { IN, OUT }

Private Member Functions

void initialize (int stage)
 initializes base-class-attributes
void finish ()
 collects statistical data
void handleMessage (cMessage *msg)
 Checks for message type and calls corresponding method.
void handleBaseOverlayMessage (BaseOverlayMessage *msg, const OverlayKey &destKey=OverlayKey::UNSPECIFIED_KEY)
 Handles a BaseOverlayMessage
.
void compactGateArray (cModule *terminal, enum Direction dir)
 compacts arrow gate-array
void internalHandleRpcMessage (BaseRpcMessage *msg)
 Handles incoming rpc messages and delegates them to the corresponsing listeners or handlers.
bool internalHandleRpc (BaseCallMessage *msg)
 Handles internal rpc requests.
void initRpcs ()
 Initializes Remote-Procedure state.
void finishRpcs ()
 Deinitializes Remote-Procedure state.
void initLookups ()
void finishLookups ()
void internalRoute (const OverlayKey &key, cMessage *msg, const NodeHandle &hint=NodeHandle::UNSPECIFIED_NODE)
virtual void forwardMessageRecursive (const TransportAddress &dest, BaseRouteMessage *msg)
 Hook for forwarded message in recursive lookup mode.
void findNodeRpc (FindNodeCall *call)
void failedNodeRpc (FailedNodeCall *call)
void pingRpc (PingCall *call)

Private Attributes

int numSent
 number of sent packets (incl. forwarded packets)
int bytesSent
 number of sent bytes (incl. forwarded bytes)
int numSignalingSent
 number of sent signaling packets (incl. forwarded packets)
int bytesSignalingSent
 number of sent signaling bytes (incl. forwarded bytes)
int numReceived
 number of received packets (incl. packets to be forwarded )
int bytesReceived
 number of received bytes (incl. bytes to be forwarded)
int numSignalingReceived
 number of received signaling packets (incl. packets to be forwarded)
int bytesSignalingReceived
 number of received signaling bytes (incl. bytes to be forwarded)
cGate * thisOutGateArray
 out-gate array for vis. overlay topology
cGate * thisInGateArray
 in-gate array for vis. overlay topology
bool drawOverlayTopology
 draw overlay topology?
int rpcsPending
RpcListenerdefaultRpcListener
RpcStates rpcStates

Friends

class BaseLookup
class BasePathLookup

Classes

class  lookupHashFcn
class  RpcState


Member Typedef Documentation

typedef hash_set<AbstractLookup*, lookupHashFcn, lookupHashFcn> BaseOverlay::LookupSet [protected]

typedef hash_map<int,RpcState> BaseOverlay::RpcStates [private]


Member Enumeration Documentation

enum BaseOverlay::Direction [private]

Enumerator:
IN 
OUT 
00390 { IN, OUT };


Constructor & Destructor Documentation

BaseOverlay::~BaseOverlay (  )  [virtual]

Virtual destructor.

00048 {
00049     finishLookups();
00050     finishRpcs();
00051 }


Member Function Documentation

void BaseOverlay::callDeliver ( BaseOverlayMessage msg,
const OverlayKey destKey 
) [protected]

Calls deliver function in application.

Encapsulates messages in KBRdeliver messages and sends them to application.

Parameters:
msg delivered message
00237 {
00238     KBRdeliver* deliverMsg = new KBRdeliver();
00239 
00240     OverlayCtrlInfo* overlayCtrlInfo =
00241         check_and_cast<OverlayCtrlInfo*>
00242         (msg->removeControlInfo());
00243 
00244     deliverMsg->setControlInfo(overlayCtrlInfo);
00245     deliverMsg->setDestKey(destKey);
00246 
00247     deliverMsg->encapsulate(msg->decapsulate());
00248 
00249     deliverMsg->setType(KBR_DELIVER);
00250 
00251     send(deliverMsg, "to_app");
00252 
00253     delete msg;
00254 }

void BaseOverlay::callForward ( const OverlayKey key,
BaseRouteMessage msg,
const NodeHandle nextHopNode 
) [protected]

Calls forward function in application.

Encapsulates messages in KBRforward messages and sends them to application.
the message to be sent through the API must be encapsulated in msg.

Parameters:
key destination key
msg message to forward
nextHopNode next hop
00258 {
00259     KBRforward* forwardMsg = new KBRforward();
00260 
00261     forwardMsg->setDestKey(msg->getDestKey());
00262     forwardMsg->setNextHopNode(nextHopNode);
00263     forwardMsg->encapsulate(msg->encapsulatedMsg()->decapsulate());
00264 
00265     OverlayCtrlInfo* overlayCtrlInfo =
00266         new OverlayCtrlInfo();
00267     //overlayCtrlInfo->setThisNode(thisNode);
00268     overlayCtrlInfo->setHopCount(msg->getHopCount());
00269     overlayCtrlInfo->setSrcNode(msg->getSrcNode());
00270 
00271     if(msg->controlInfo() != NULL) {
00272         OverlayCtrlInfo* ctrlInfo =
00273             check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo());
00274         overlayCtrlInfo->setLastHopAddr(ctrlInfo->getLastHopAddr());
00275         overlayCtrlInfo->setLastHopPort(ctrlInfo->getLastHopPort());
00276 
00277         delete ctrlInfo;
00278     }
00279 
00280     forwardMsg->setControlInfo(overlayCtrlInfo);
00281 
00282     forwardMsg->setType(KBR_FORWARD);
00283 
00284     send(forwardMsg, "to_app");
00285 
00286     delete msg;
00287 }

void BaseOverlay::callUpdate ( const NodeHandle node,
bool  joined 
) [protected]

00322 {
00323     KBRupdate* updateMsg = new KBRupdate("UPDATE");
00324 
00325     updateMsg->setNode(node);
00326     updateMsg->setJoined(joined);
00327 
00328     updateMsg->setType(KBR_UPDATE);
00329 
00330     send(updateMsg, "to_app");//"to_upperTier");
00331 }

void BaseOverlay::cancelRpcMessage ( uint32_t  nonce  ) 

Cancels a Remote-Procedure-Call.

Parameters:
nonce The nonce of the RPC
00881 {
00882     if (rpcStates.count(nonce)==0)
00883         return;
00884     RpcState state = rpcStates[nonce];
00885     rpcStates.erase(nonce);
00886     cancelAndDelete(state.callMsg);
00887     cancelAndDelete(state.timeoutMsg);
00888 }

void BaseOverlay::compactGateArray ( cModule *  terminal,
enum Direction  dir 
) [private]

compacts arrow gate-array

Parameters:
terminal node
dir in- or out-array?
00694 {
00695     cGate* gateArray = (dir == OUT ? terminal->gate("overlayNeighborArrowOut")
00696                         : terminal->gate("overlayNeighborArrowIn"));
00697     const char* gateName = (dir == OUT ? "overlayNeighborArrowOut"
00698                             : "overlayNeighborArrowIn");
00699 
00700     for (int j = 0; j < gateArray->size() - 1; j++) {
00701         if (terminal->gate(gateName, j)->isConnectedOutside())
00702             continue;
00703 
00704         cGate* tempGate = NULL;
00705         int k = 1;
00706         while ((tempGate == NULL) && ((j + k) != gateArray->size())) {
00707             tempGate = (dir == OUT ? terminal->gate(gateName, j + k)->toGate()
00708                         : terminal->gate(gateName, j + k)->fromGate());
00709             k++;
00710         }
00711 
00712         if (tempGate == NULL)
00713             break;
00714 
00715         if (dir == OUT) {
00716             terminal->gate(gateName, j + k - 1)->disconnect();
00717             terminal->gate(gateName, j)->connectTo(tempGate);
00718         } else {
00719             tempGate->disconnect();
00720             tempGate->connectTo(terminal->gate(gateName, j));
00721         }
00722     }
00723 
00724     int nullGates = 0;
00725     for (int j = 0; j < gateArray->size(); j++)
00726         if (!terminal->gate(gateName, j)->isConnectedOutside())
00727             nullGates++;
00728 
00729     terminal->setGateSize(gateName, gateArray->size() - nullGates);
00730 }

AbstractLookup * BaseOverlay::createLookup ( const BaseRouteMessage msg = NULL  )  [protected, virtual]

Creates a abstract iterative lookup instance.

Parameters:
msg pointer to the message for which the lookup is created. Derived classes can use it to construct an object with additional info for the lookup class.
Returns:
AbstractLookup* The new lookup instance.

Reimplemented in Pastry.

01222 {
01223     AbstractLookup* newLookup = new BaseLookup( this, baseLookupConfig );
01224     lookups.insert( newLookup );
01225     return newLookup;
01226 }

void BaseOverlay::deleteOverlayNeighborArrow ( const NodeHandle neighbor  )  [protected]

Removes an arrow from this node to neighbor.

Parameters:
neighbor neighbor to remove arrow to
Todo:
add neighbor's kind to distinguish arrows pointing to the same neighbor
00651 {
00652     if (!ev.isGUI() || !drawOverlayTopology)
00653         return;
00654 
00655     //does neighbor module exist anymore?
00656     int neighborModuleId;
00657     if(bootstrapOracle->getPeerInfo(neighbor) == NULL)
00658         return;
00659     else
00660         neighborModuleId = bootstrapOracle->getPeerInfo(neighbor)->getModuleID();
00661 
00662     if (simulation.module(neighborModuleId) == NULL)
00663         return;
00664 
00665     cModule* neighborTerminal
00666     = simulation.module(neighborModuleId)->parentModule();
00667 
00668     //find gate
00669     bool compactOut = false;
00670     bool compactIn = false;
00671     for (int i = 0; i < thisOutGateArray->size(); i++) {
00672         // NULL-Gate?
00673         if (thisTerminal->gate("overlayNeighborArrowOut", i)->toGate() == NULL) {
00674             compactOut = true;
00675             continue;
00676         }
00677 
00678         if (thisTerminal->gate("overlayNeighborArrowOut", i)->toGate()->ownerModule()->id() == neighborTerminal->id()) {
00679             thisTerminal->gate("overlayNeighborArrowOut", i)->disconnect();
00680             compactOut = true;
00681             compactIn = true;
00682         }
00683     }
00684 
00685     //compact OUT-array
00686     if (compactOut)
00687         compactGateArray(thisTerminal, OUT);
00688     //compact IN-array
00689     if (compactIn)
00690         compactGateArray(neighborTerminal, IN);
00691 }

OverlayKey BaseOverlay::distance ( const OverlayKey x,
const OverlayKey y 
) const [protected, virtual]

This method should implement the distance between two keys.

It may be overloaded to implement a new metric. The default implementation uses the standard-metric d = abs(x-y).

Parameters:
x Left-hand-side Key
y Right-hand-side key
Returns:
OverlayKey Distance between x and y
01236 {
01237     return x > y ? x-y : y-x;
01238 }

void BaseOverlay::failedNodeRpc ( FailedNodeCall call  )  [private]

01292 {
01293     FailedNodeResponse* failedNodeResponse =
01294         new FailedNodeResponse("FailedNodeResponse");
01295     failedNodeResponse->setTryAgain(handleFailedNode(call->getFailedNode()));
01296     sendRpcResponse( call, failedNodeResponse );
01297 }

NodeVector * BaseOverlay::findNode ( const OverlayKey key,
BaseOverlayMessage msg = NULL 
) [protected, virtual]

Implements the find node call.

This method simply returns the closest nodes known in the corresponding routing topology. If the node is in the k-neighborhood to key (isResponsible(key) = true), this method returns all k neighbors, with the closest neighbor to the key first.

Parameters:
key The lookup key.
msg A pointer to the BaseRouteMessage or FindNodeCall message of this lookup.
Returns:
NodeVector with closest nodes.

Reimplemented in Broose, Chord, Koorde, and Pastry.

01243 {
01244     opp_error( "findNode: Not implemented!" );
01245     return NULL;
01246 }

void BaseOverlay::findNodeRpc ( FindNodeCall call  )  [private]

01260 {
01261     FindNodeResponse* findNodeResponse =
01262         new FindNodeResponse("FindNodeResponse");
01263 
01264     NodeVector* nextHops = findNode(call->getLookupKey(), call);
01265 
01266     findNodeResponse->setClosestNodesArraySize(nextHops->size());
01267 
01268     for (uint i=0; i < nextHops->size(); i++) {
01269         findNodeResponse->setClosestNodes(i, (*nextHops)[i]);
01270     }
01271 
01272     if (isResponsible(call->getLookupKey()))
01273         findNodeResponse->setNeighbors(true);
01274 
01275     findNodeResponse->setLength(FINDNODERESPONSE_L(findNodeResponse));
01276 
01277     if (call->hasObject("findNodeExt")) {
01278         cMessage* findNodeExt = (cMessage*)call->removeObject("findNodeExt");
01279         findNodeResponse->addObject(findNodeExt);
01280         findNodeResponse->addLength(findNodeExt->length());
01281     }
01282 
01283     RECORD_STATS(numFindNodeSent++; bytesFindNodeSent +=
01284                  findNodeResponse->byteLength());
01285 
01286     delete nextHops;
01287 
01288     sendRpcResponse( call, findNodeResponse );
01289 }

void BaseOverlay::finish (  )  [private]

collects statistical data

00159 {
00160     finishOverlay();
00161     finishLookups();
00162     finishRpcs();
00163 
00164     recordScalar("BaseOverlay: Sent User Messages", numSent);
00165     recordScalar("BaseOverlay: Sent User Bytes", bytesSent);
00166     recordScalar("BaseOverlay: Sent Signaling Messages", numSignalingSent);
00167     recordScalar("BaseOverlay: Sent Signaling Bytes", bytesSignalingSent);
00168     recordScalar("BaseOverlay: Sent Total Messages", numSent + numSignalingSent);
00169     recordScalar("BaseOverlay: Sent Total Bytes", bytesSent + bytesSignalingSent);
00170     recordScalar("BaseOverlay: Sent FindNode Messages", numFindNodeSent);
00171     recordScalar("BaseOverlay: Sent FindNode Bytes", bytesFindNodeSent);
00172 
00173     recordScalar("BaseOverlay: Received User Messages", numReceived);
00174     recordScalar("BaseOverlay: Received User Bytes", bytesReceived);
00175     recordScalar("BaseOverlay: Received Signaling Messages", numSignalingReceived);
00176     recordScalar("BaseOverlay: Received Signaling Bytes", bytesSignalingReceived);
00177     recordScalar("BaseOverlay: Received Total Messages", numReceived
00178                  + numSignalingReceived);
00179     recordScalar("BaseOverlay: Received Total Bytes", bytesReceived
00180                  + bytesSignalingReceived);
00181     recordScalar("BaseOverlay: Forwarded User Messages", numForwarded);
00182     recordScalar("BaseOverlay: Forwarded User Bytes", bytesForwarded);
00183     recordScalar("BaseOverlay: Forwarded Signaling Messages", numSignalingForwarded);
00184     recordScalar("BaseOverlay: Forwarded Signaling Bytes", bytesSignalingForwarded);
00185     recordScalar("BaseOverlay: Forwarded Total Messages", numForwarded
00186                  + numSignalingForwarded);
00187     recordScalar("BaseOverlay: Forwarded Total Bytes", bytesForwarded
00188                  + bytesSignalingForwarded);
00189 
00190     recordScalar("BaseOverlay: Dropped Messages", numDropped);
00191     recordScalar("BaseOverlay: Dropped Bytes", bytesDropped);
00192 
00193 }

void BaseOverlay::finishLookups (  )  [private]

01024 {
01025     while (lookups.size()!=0)
01026         delete *lookups.begin();
01027     lookups.clear();
01028 }

void BaseOverlay::finishOverlay (  )  [protected, virtual]

collects statistical data in derived class

Reimplemented in Broose, Chord, Gia, Koorde, and Pastry.

00196 {
00197     // ...
00198 }

void BaseOverlay::finishRpcs (  )  [private]

Deinitializes Remote-Procedure state.

00803 {
00804     // stop all rpcs
00805     for (RpcStates::iterator i = rpcStates.begin();
00806             i != rpcStates.end(); i++) {
00807         cancelAndDelete(i->second.callMsg);
00808         cancelAndDelete(i->second.timeoutMsg);
00809     }
00810     rpcStates.clear();
00811 
00812     // delete default rpc listener
00813     if (defaultRpcListener!=NULL) {
00814         delete defaultRpcListener;
00815         defaultRpcListener = NULL;
00816     }
00817 }

void BaseOverlay::forwardMessageRecursive ( const TransportAddress dest,
BaseRouteMessage msg 
) [private, virtual]

Hook for forwarded message in recursive lookup mode.

Default implementation just calls sendMessageToUDP(). This hook can for example be used to detect failed nodes and call handleFailedNode() before the actual forwarding takes place.

Parameters:
dest destination node
msg message to send

Reimplemented in Pastry.

01103 {
01104     sendMessageToUDP(dest, msg);
01105 }

NodeHandle & BaseOverlay::getThisNode (  ) 

Returns the NodeHandle of this node.

Returns:
the NodeHandle of this node.
00215 {
00216     return thisNode;
00217 }

void BaseOverlay::handleAppMessage ( cMessage *  msg  )  [protected, virtual]

Processes non-commonAPI messages.


Processes non-commonAPI messages if parameter "onlyCommonAPIMessages" is false.

Parameters:
msg non-commonAPIMessage

Reimplemented in Gia.

00528 {
00529     delete msg;
00530 }

void BaseOverlay::handleBaseOverlayMessage ( BaseOverlayMessage msg,
const OverlayKey destKey = OverlayKey::UNSPECIFIED_KEY 
) [private]

Handles a BaseOverlayMessage
.

Handles BaseOverlayMessages of type OVERLAYSIGNALING, RPC, APPDATA or OVERLAYROUTE.

Parameters:
msg The message to be handled
00446 {
00447     switch(msg->getType()) {
00448     case OVERLAYSIGNALING:
00449         handleUDPMessage(msg);
00450         return;
00451 
00452     case RPC: {
00453             // process rpc-messages
00454             BaseRpcMessage* rpcMessage =
00455                 check_and_cast<BaseRpcMessage*>(msg);
00456             internalHandleRpcMessage(rpcMessage);
00457             return;
00458         }
00459 
00460     case APPDATA: {
00461             BaseAppDataMessage* baseAppDataMsg =
00462                 check_and_cast<BaseAppDataMessage*>(msg);
00463             assert(!destKey.isUnspecified());
00464             callDeliver(baseAppDataMsg, destKey);
00465             return;
00466         }
00467 
00468     case OVERLAYROUTE: {
00469             BaseRouteMessage* baseRouteMsg =
00470                 check_and_cast<BaseRouteMessage*>(msg);
00471 
00472             if (baseRouteMsg->getDestKey().isUnspecified())
00473                 opp_error("BaseOverlay: No destination key in ROUTE msg");
00474 
00475             if (baseRouteMsg->getFinalHop()) {
00476 
00477                 // check if this node is really resposible for this key
00478                 // why do we drop the message here?
00479                 if (!isResponsible(baseRouteMsg->getDestKey())) {
00480                     EV << "BaseOverlay: Received BaseRouteMessage with "
00481                        << "finalHopFlag set, but this node "
00482                        << "is not responsible - dropping message!" << endl;
00483                     RECORD_STATS(numDropped++;
00484                                  bytesDropped += baseRouteMsg->byteLength());
00485                     delete msg;
00486                     return;
00487                 }
00488 
00489                 OverlayCtrlInfo* overlayCtrlInfo =
00490                     check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo());
00491 
00492                 //overlayCtrlInfo->setThisNode(thisNode);
00493                 overlayCtrlInfo->setHopCount(baseRouteMsg->getHopCount());
00494                 overlayCtrlInfo->setSrcNode(baseRouteMsg->getSrcNode());
00495 
00496                 BaseOverlayMessage* tmpMsg
00497                 = check_and_cast<BaseOverlayMessage*>
00498                   (baseRouteMsg->decapsulate());
00499                 tmpMsg->setControlInfo(overlayCtrlInfo);
00500 
00501                 handleBaseOverlayMessage(tmpMsg, baseRouteMsg->getDestKey());//bh
00502                 delete msg;
00503                 return;
00504             } else {
00505                 // forward msg if this node is not responsible for the key
00506                 sendToKey(baseRouteMsg->getDestKey(), baseRouteMsg, 1);
00507                 return;
00508             }
00509             break;
00510         }
00511 
00512     default:
00513         EV << "BaseOverlay::handleMessage(): received unknown message "
00514         << "from UDP of type " << msg->name() << endl;
00515         break;
00516     }
00517 }

bool BaseOverlay::handleFailedNode ( const TransportAddress failed  )  [protected, virtual]

Handles a failed node.

This method is called whenever a node given by findNode() was unreachable. The default implementation does nothing at all.

Parameters:
failed the failed node
Returns:
true if lookup should retry here

Reimplemented in Pastry.

01249 {
01250     return false;
01251 }

void BaseOverlay::handleMessage ( cMessage *  msg  )  [private]

Checks for message type and calls corresponding method.


Checks for message type (from UDP/App or selfmessage) and calls corresponding method like route(), get(), put(), remove(), handleTimerEvent(), handleAppMessage() and handleUDPMessage().

Parameters:
msg The message to be handled
00350 {
00351     // process self-messages
00352     if (msg->isSelfMessage()) {
00353         // process rpc self-messages
00354         BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg);
00355         if (rpcMessage!=NULL) {
00356             internalHandleRpcMessage(rpcMessage);
00357             return;
00358         }
00359         // process all other self-messages
00360         handleTimerEvent(msg);
00361     }
00362 
00363     // process messages from UDP
00364     else if (msg->arrivedOn("from_udp")) {
00365         UDPControlInfo* udpControlInfo =
00366             check_and_cast<UDPControlInfo*>(msg->removeControlInfo());
00367         OverlayCtrlInfo* overlayCtrlInfo = new OverlayCtrlInfo;
00368         overlayCtrlInfo->setLastHopAddr(udpControlInfo->srcAddr());
00369         overlayCtrlInfo->setLastHopPort(udpControlInfo->srcPort());
00370         msg->setControlInfo(overlayCtrlInfo);
00371         delete udpControlInfo;
00372 
00373         BaseOverlayMessage* baseOverlayMsg =
00374             dynamic_cast<BaseOverlayMessage*>(msg);
00375 
00376         if (baseOverlayMsg == NULL) {
00377             delete msg;
00378             return;
00379         }
00380 
00381         // records stats if message is not a UDP "self message"
00382         if (overlayCtrlInfo->getLastHopAddr() != thisNode.ip) {
00383             if (baseOverlayMsg->getSignaling() == false)
00384                 RECORD_STATS(numReceived++; bytesReceived +=
00385                                  baseOverlayMsg->byteLength());
00386             else
00387                 RECORD_STATS(numSignalingReceived++;bytesSignalingReceived
00388                              += baseOverlayMsg->byteLength());
00389         }
00390 
00391         handleBaseOverlayMessage(baseOverlayMsg);
00392     }
00393 
00394     // process CommonAPIMessages from App
00395     else if (dynamic_cast<CommonAPIMessage*>(msg) != NULL) {
00396         if (dynamic_cast<KBRroute*>(msg) != NULL) {
00397             KBRroute* apiMsg = dynamic_cast<KBRroute*>(msg);
00398 
00399             internalRoute(apiMsg->getDestKey(), apiMsg->decapsulate(),
00400                           apiMsg->getHint());
00401         }
00402 
00403         else if (dynamic_cast<KBRforward*>(msg) != NULL) {
00404             KBRforward* apiMsg = dynamic_cast<KBRforward*>(msg);
00405             OverlayCtrlInfo* overlayCtrlInfo =
00406                 check_and_cast<OverlayCtrlInfo*>
00407                 (msg->removeControlInfo());
00408 
00409             BaseAppDataMessage* dataMsg = new BaseAppDataMessage();
00410             dataMsg->setType(APPDATA);
00411             dataMsg->setLength(BASEAPPDATA_L(dataMsg));
00412             dataMsg->encapsulate(msg->decapsulate());
00413             dataMsg->setSignaling(false);
00414 
00415             BaseRouteMessage* routeMsg = new BaseRouteMessage();
00416             routeMsg->setType(OVERLAYROUTE);
00417             routeMsg->setLength(BASEROUTE_L(routeMsg));
00418             routeMsg->encapsulate(dataMsg);
00419 
00420             routeMsg->setSignaling(false);
00421             routeMsg->setDestKey(apiMsg->getDestKey());
00422             routeMsg->setSrcNode(overlayCtrlInfo->getSrcNode());
00423             routeMsg->setHopCount(overlayCtrlInfo->getHopCount());
00424             routeMsg->setControlInfo(overlayCtrlInfo);
00425 
00426             routeMsg->setKind(ALREADY_FORWARDED);
00427 
00428             sendToKey(apiMsg->getDestKey(), routeMsg, 1, apiMsg->getNextHopNode());
00429         }
00430 
00431         delete msg;
00432     }
00433 
00434     // process other messages from App
00435     else if (msg->arrivedOn("from_app") && onlyCommonAPIMessages == false)
00436         handleAppMessage(msg);
00437 
00438     else {
00439         RECORD_STATS(numDropped++; bytesDropped += msg->byteLength());
00440         delete msg;
00441     }
00442 }

void BaseOverlay::handleRpc ( BaseCallMessage msg  )  [protected, virtual]

Processes Remote-Procedure-Call invokation messages.


This method should be overloaded when the overlay provides RPC functionality. One can use

Reimplemented in Broose, Chord, Koorde, and Pastry.

00990 {
00991     opp_error( "handleRpc: Not implemented!" );
00992     delete msg;
00993 }

void BaseOverlay::handleTimerEvent ( cMessage *  msg  )  [protected, virtual]

Processes "timer" self-messages.

Parameters:
msg A self-message

Reimplemented in Broose, Chord, Gia, Koorde, and Pastry.

00522 {
00523     // timer...
00524 }

virtual void BaseOverlay::handleUDPMessage ( BaseOverlayMessage msg  )  [protected, pure virtual]

Processes messages from underlay.

Parameters:
msg Message from UDP

Implemented in Broose, Chord, Gia, Koorde, and Pastry.

void BaseOverlay::initialize ( int  stage  )  [private]

initializes base-class-attributes

Parameters:
stage the init stage
00059 {
00060     if(stage == MIN_STAGE_OVERLAY) {
00061         OverlayKey::setKeyLength(par("keyLength"));
00062 
00063         // fetch some parameters
00064         debugOutput                     = par("debugOutput");
00065         measureNetwInitPhase            = par("measureNetwInitPhase");
00066         localPort                       = par("localPort");
00067         hopCountMax                     = par("hopCountMax");
00068         drawOverlayTopology             = par("drawOverlayTopology");
00069         useBaseLookup                   = par("useBaseLookup");
00070         iterativeLookup                 = par("iterativeLookup");
00071         useCommonAPIforward             = false;
00072         onlyCommonAPIMessages           = true;
00073 
00074         // set base lookup parameters
00075         baseLookupConfig.numNextHops    = par("lookupNumberNextHops");
00076         baseLookupConfig.parallelPaths  = par("lookupParallelPaths");
00077         baseLookupConfig.parallelRpcs   = par("lookupParallelRpcs");
00078         baseLookupConfig.secure         = par("lookupSecure");
00079         baseLookupConfig.merge          = par("lookupMerge");
00080 
00081         // statistics
00082         numSent = 0;
00083         bytesSent = 0;
00084         numSignalingSent = 0;
00085         bytesSignalingSent = 0;
00086         numReceived = 0;
00087         bytesReceived = 0;
00088         numSignalingReceived = 0;
00089         bytesSignalingReceived = 0;
00090         numForwarded = 0;
00091         bytesForwarded = 0;
00092         numSignalingForwarded = 0;
00093         bytesSignalingForwarded = 0;
00094         numDropped = 0;
00095         bytesDropped = 0;
00096         numFindNodeSent = 0;
00097         bytesFindNodeSent = 0;
00098 
00099         WATCH(numSent);
00100         WATCH(bytesSent);
00101         WATCH(numSignalingSent);
00102         WATCH(bytesSignalingSent);
00103         WATCH(numReceived);
00104         WATCH(bytesReceived);
00105         WATCH(numSignalingReceived);
00106         WATCH(bytesSignalingReceived);
00107         WATCH(numForwarded);
00108         WATCH(bytesForwarded);
00109         WATCH(numSignalingForwarded);
00110         WATCH(bytesSignalingForwarded);
00111         WATCH(numDropped);
00112         WATCH(bytesDropped);
00113         WATCH(numFindNodeSent);
00114         WATCH(bytesFindNodeSent);
00115 
00116         // set up UDP
00117         bindToPort(localPort);
00118 
00119         // find friend modules
00120         bootstrapOracle = BootstrapOracleAccess().get();
00121         underlayConfigurator = UnderlayConfiguratorAccess().get();
00122         globalStatistics = GlobalStatisticsAccess().get();
00123         notificationBoard = NotificationBoardAccess().get();
00124 
00125         thisTerminal = parentModule()->parentModule();
00126 
00127         // set up local nodehandle
00128         //thisNode.moduleId = parentModule()->id();
00129         thisNode.ip = IPAddressResolver().
00130                       addressOf(parentModule()->parentModule()).get4();
00131         thisNode.port = localPort;
00132         thisNode.key = OverlayKey::UNSPECIFIED_KEY;
00133 
00134         // set up arrow-gates
00135         thisOutGateArray = thisTerminal->gate("overlayNeighborArrowOut");
00136         thisInGateArray = thisTerminal->gate("overlayNeighborArrowIn");
00137         thisTerminal->setGateSize("overlayNeighborArrowOut" ,1);
00138         thisTerminal->setGateSize("overlayNeighborArrowIn" ,1);
00139 
00140         // subscribe to the notification board
00141         notificationBoard->subscribe( this, NF_HOSTPOSITION_UPDATED);
00142         notificationBoard->subscribe( this, NF_OVERLAY_NODE_LEAVE);
00143 
00144         // init rpcs
00145         initRpcs();
00146         initLookups();
00147     }
00148 
00149     if(stage >= MIN_STAGE_OVERLAY && stage <= MAX_STAGE_OVERLAY)
00150         initializeOverlay(stage);
00151 }

void BaseOverlay::initializeOverlay ( int  stage  )  [protected, virtual]

Initializes derived-class-attributes.


Initializes derived-class-attributes, called by BaseOverlay::initialize(). By default this method is called once. If more stages are needed one can overload numInitStages() and add more stages.

Parameters:
stage the init stage

Reimplemented in Broose, Chord, Gia, Koorde, and Pastry.

00154 {
00155     // ...
00156 }

void BaseOverlay::initLookups (  )  [private]

01019 {
01020     lookups = LookupSet();
01021 }

void BaseOverlay::initRpcs (  )  [private]

Initializes Remote-Procedure state.

00794 {
00795     rpcsPending = 0;
00796     rpcStates.clear();
00797 
00798     defaultRpcListener = new RpcListener();
00799 }

bool BaseOverlay::internalHandleRpc ( BaseCallMessage msg  )  [private]

Handles internal rpc requests.


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

Parameters:
msg The call message
Returns:
bool true, if call has been handled.
00975 {
00976     // call rpc stubs
00977     RPC_SWITCH_START( msg );
00978     RPC_DELEGATE( FindNode, findNodeRpc );
00979         RPC_DELEGATE( FailedNode, failedNodeRpc );
00980     RPC_SWITCH_END( );
00981 
00982     // check if rpc has been handled
00983     IF_RPC_HANDLED return true;
00984     else
00985         return false;
00986 }

void BaseOverlay::internalHandleRpcMessage ( BaseRpcMessage msg  )  [private]

Handles incoming rpc messages and delegates them to the corresponsing listeners or handlers.

Parameters:
msg The message to handle.
00892 {
00893     // check if this is a rpc call message
00894     BaseCallMessage* rpCall = dynamic_cast<BaseCallMessage*>(msg);
00895     if (rpCall != NULL) {
00896         if (!internalHandleRpc(rpCall))
00897             handleRpc(rpCall);
00898         return;
00899     }
00900 
00901     // get nonce
00902     int nonce = msg->getNonce();
00903 
00904     // nonce known? no -> delete message and return
00905     if (rpcStates.count(nonce)==0) {
00906         EV << "RPC: Nonce Unknown!" << endl;
00907         delete msg;
00908         return;
00909     }
00910 
00911     // get state and remove from map
00912     RpcState state = rpcStates[nonce];
00913     rpcStates.erase(nonce);
00914 
00915     // is timeout message?
00916     if ( msg->isSelfMessage() ) { // yes-> inform listener
00917 
00918         // retry?
00919         state.retries--;
00920         simtime_t timeout = simulation.simTime() - state.timeSent;
00921         if (state.retries>=0) {
00922             if (state.destKey.isUnspecified()) {
00923                 sendMessageToUDP( state.dest,
00924                                   dynamic_cast<BaseCallMessage*>
00925                                   (state.callMsg->dup()));
00926             } else {
00927                 // send message to key
00928                 sendToKey( state.destKey,
00929                            dynamic_cast<BaseCallMessage*>
00930                            (state.callMsg->dup()), 1, state.dest );
00931             }
00932             if (timeout!=0)
00933                 scheduleAt( simulation.simTime() + timeout, msg );
00934             rpcStates[nonce] = state;
00935             return;
00936         }
00937 
00938         // inform listener
00939         if ( state.listener != NULL )
00940             state.listener->handleRpcTimeout( state.callMsg, state.dest,
00941                                               state.id );
00942 
00943         // inform overlay
00944         handleRpcTimeout( state.callMsg, state.dest, state.id );
00945 
00946     } else { // no-> handle rpc response
00947 
00948         // get parameters
00949         simtime_t rtt = simulation.simTime() - state.timeSent;
00950         BaseResponseMessage* response
00951         = dynamic_cast<BaseResponseMessage*>(msg);
00952 
00953         // inform listener
00954         if ( state.listener != NULL )
00955             state.listener->handleRpcResponse( response, state.id, rtt );
00956 
00957         // inform overlay
00958         handleRpcResponse( response, state.id, rtt );
00959 
00960         // delete response
00961         delete response;
00962     }
00963 
00964     // delete messages
00965     cancelAndDelete(state.callMsg);
00966     cancelAndDelete(state.timeoutMsg);
00967 
00968     // clean up pointers
00969     state.callMsg = NULL;
00970     state.timeoutMsg = NULL;
00971 }

void BaseOverlay::internalRoute ( const OverlayKey key,
cMessage *  msg,
const NodeHandle hint = NodeHandle::UNSPECIFIED_NODE 
) [private]

01073 {
01074     // check if base lookup should be used
01075     if (!useBaseLookup) {
01076         route(key,msg,hint);
01077         return;
01078     }
01079 
01080     if(key.isUnspecified())
01081         error("route(): key unspecified!");
01082 
01083     // create base route message
01084     BaseAppDataMessage* baseAppDataMsg =
01085         new BaseAppDataMessage("BaseAppDataMessage");
01086     baseAppDataMsg->setType(APPDATA);
01087     baseAppDataMsg->setLength(BASEAPPDATA_L(baseAppDataMsg));
01088     baseAppDataMsg->setSignaling(false);
01089     //baseAppDataMsg->setKind(1);//???
01090     baseAppDataMsg->encapsulate(msg);
01091 
01092     // debug output
01093     if (debugOutput) {
01094         EV << "BaseOverlay: Node " << thisNode.ip << " received message from "
01095         "application." << endl;
01096     }
01097 
01098     sendToKey( key, baseAppDataMsg, 1, hint );
01099 }

bool BaseOverlay::isMalicious (  ) 

Returns true, if node is malicious.

Returns:
true, if node is malicious.
00210 {
00211     return malicious;
00212 }

bool BaseOverlay::isResponsible ( const OverlayKey key  )  [protected, virtual]

Query if the node knowns the k-neighborhood for a key.

Query if the node knowns the complete k-neighborhood for the given key. Usually these are all nodes, that are responsible for the key. If there is no k-neighborhood in a specific overlay protocol, this method simply returns true, if the node is responsible for the key.

Parameters:
key destination key
Returns:
bool true, if the node knows the k-neighborhood for key.

Reimplemented in Broose, Chord, and Pastry.

00229 {
00230     opp_error( "isResponsible: Not implemented!" );
00231     return false;
00232 }

NodeVector * BaseOverlay::local_lookup ( const OverlayKey key,
int  num,
bool  safe 
) [virtual]

00291 {
00292     Enter_Method("local_lookup()");
00293 
00294     NodeVector* nodeVector = findNode(key);
00295 
00296     if(((int)nodeVector->size()) > num)
00297         nodeVector->resize(num);
00298 
00299     return nodeVector;
00300 }

NodeVector * BaseOverlay::neighborSet ( int  num  )  [virtual]

00303 {
00304     //TODO
00305 
00306     Enter_Method("neighborSet()");
00307 
00308     return NULL;
00309 }

int BaseOverlay::numInitStages (  )  const [protected]

Sets init stage.

See also:
InitStages.h

Reimplemented in Broose, and Koorde.

00054 {
00055     return MAX_STAGE_OVERLAY + 1;
00056 }

PingResponse * BaseOverlay::ping ( PingCall call  )  [protected, virtual]

Implements a ping call.


This method implementts a simple ping call.

Parameters:
call The ping message
Returns:
The ping response or NULL if no response should be sent.
01254 {
01255     return new PingResponse();
01256 }

void BaseOverlay::pingRpc ( PingCall call  )  [private]

01301 {
01302     sendRpcResponse( call, ping(call) );
01303 }

bool BaseOverlay::range ( const NodeHandle node,
int  rank,
const OverlayKey lKey,
const OverlayKey rKey 
) [virtual]

00335 {
00336     //TODO
00337 
00338     Enter_Method("range()");
00339 
00340     return false;
00341 }

void BaseOverlay::recordOverlaySentStats ( BaseOverlayMessage msg  )  [protected, virtual]

Collect overlay specific sent messages statistics.

This method is called from BaseOverlay::sendMessageToUDP() for every overlay message that is sent by a node. Use this to collect statistical data for overlay protocol specific message types.

Parameters:
msg The overlay message to be sent to the UDP layer

Reimplemented in Broose, Chord, and Koorde.

00534 {
00535     // collect statistics ...
00536 }

void BaseOverlay::removeLookup ( AbstractLookup lookup  )  [protected, virtual]

Removes the abstract lookup instance.

Parameters:
lookup 
01229 {
01230     lookups.erase(lookup);
01231 }

NodeVector * BaseOverlay::replicaSet ( const OverlayKey key,
int  max_rank 
) [virtual]

00313 {
00314     //TODO
00315 
00316     Enter_Method("replicaSet()");
00317 
00318     return NULL;
00319 }

void BaseOverlay::route ( const OverlayKey key,
cMessage *  msg,
const NodeHandle hint = NodeHandle::UNSPECIFIED_NODE 
) [protected, virtual]

Routes message through overlay.

The default implementation uses FindNode to determine next hops and a generic greedy routing algorithm provides with SendToKey.

Parameters:
key destination key
msg message to route
hint next hop (usually unused)

Reimplemented in Gia.

00226 {}

void BaseOverlay::sendMessageToUDP ( const TransportAddress dest,
BaseOverlayMessage msg 
)

Sends message to underlay.

Parameters:
dest destination node
msg message to send
00738 {
00739     if (!iterativeLookup)
00740     {
00741         // increase HopCount on outgoing RouteMessages in recursive mode
00742         // moved here from sendToKey() so that hopCount is only increased
00743         // when the Overlay decides to actually send the Message in
00744         // forwardMessageRecursive().
00745         BaseRouteMessage* routeMsg = dynamic_cast<BaseRouteMessage*>(msg);
00746         if (routeMsg && (dest != thisNode))
00747         {
00748             routeMsg->setHopCount(routeMsg->getHopCount() + 1);
00749         }
00750     }
00751 
00752     // if there's still a control info attached to the message, remove it
00753     cPolymorphic* ctrlInfo = msg->removeControlInfo();
00754     if (ctrlInfo != NULL)
00755         delete ctrlInfo;
00756 
00757     // debug message
00758     if (debugOutput) {
00759         EV << "BaseOverlay: Node " << thisNode.ip << ": sends "
00760         << msg->name() << " to " << dest.ip << "." << endl;
00761     }
00762 
00763     msg->setKind(UDP_C_DATA);
00764     UDPControlInfo* udpControlInfo = new UDPControlInfo();
00765     udpControlInfo->setSrcAddr(thisNode.ip);
00766     udpControlInfo->setSrcPort(thisNode.port);
00767     udpControlInfo->setDestAddr(dest.ip);
00768     udpControlInfo->setDestPort(dest.port);
00769     msg->setControlInfo(udpControlInfo);
00770 
00771     send(msg, "to_udp");
00772 
00773     if (dest != thisNode) {
00774         // record statistics, if message is not local
00775         if (msg->getSignaling() == false) {
00776             RECORD_STATS(numSent++; bytesSent += msg->byteLength());
00777         } else {
00778             RECORD_STATS(numSignalingSent++; bytesSignalingSent +=
00779                              msg->byteLength());
00780         }
00781         recordOverlaySentStats(msg);
00782         globalStatistics->sentTotalBytes+=msg->byteLength();
00783 
00784     }
00785 }

uint32_t BaseOverlay::sendRpcMessage ( const TransportAddress dest,
BaseCallMessage msg,
RpcListener rpcListener = NULL,
const OverlayKey destKey = OverlayKey::UNSPECIFIED_KEY,
int  rpcId = -1,
simtime_t  timeout = -1,
int  retries = 0 
)

Sends a Remote-Procedure-Call message to the underlay.


If no timeout is provided, a default value of 1.0 for underlay and 5.0 for a overlay rpc is used. After a timeout the message gets retransmitted for at maximum retries times.

The destKey attribute is kept untouched.

Parameters:
dest Destination node handle
msg RPC Call Message
rpcListener RPC Listener
destKey first route the RPC to the node that is responsible for kestkey
rpcId RPC id
timeout RPC timeout
retries How often we try to resent rpc call, if it gets lost
Returns:
The nonce of the RPC
00826 {
00827 
00828     // create nonce, timeout and set default parameters
00829     uint nonce;
00830     do {
00831         nonce = intuniform( 0, 2147483647);
00832     } while (rpcStates.count(nonce) > 0);
00833 
00834 
00835     if (timeout == -1)
00836         timeout = destKey.isUnspecified() ? 1.0 : 5.0;
00837     if (rpcListener == NULL)
00838         rpcListener = defaultRpcListener;
00839 
00840     // create state
00841     RpcState state;
00842     state.id = rpcId;
00843     state.timeSent = simulation.simTime();
00844     state.dest = dest;
00845     state.destKey = destKey;
00846     state.listener = rpcListener;
00847     state.timeoutMsg = new RpcTimeoutMessage();
00848     state.timeoutMsg->setNonce(nonce);
00849     state.retries = retries;
00850 
00851     if (rpcStates.count(nonce) > 0)
00852         error("RPC nonce collision");
00853 
00854     // set message parameters
00855     msg->setNonce( nonce );
00856     msg->setSrcNode( thisNode );
00857     msg->setType(RPC);
00858 
00859     // save copy of call message in RpcState
00860     state.callMsg = dynamic_cast<BaseCallMessage*>(msg->dup());
00861 
00862     // register state
00863     rpcStates[nonce] = state;
00864 
00865     // schedule timeout message
00866     if (timeout!=0)
00867         scheduleAt( simulation.simTime() + timeout, state.timeoutMsg);
00868 
00869     if (destKey.isUnspecified()) {
00870         sendMessageToUDP( dest, msg );
00871     } else {
00872         // send message to key
00873         sendToKey( destKey, msg, 1, dest );
00874     }
00875 
00876     return nonce;
00877 }

void BaseOverlay::sendRpcResponse ( BaseCallMessage call,
BaseResponseMessage response 
) [protected]

Send Remote-Procedure response message and deletes call message.


The destKey attribute is kept untouched. If call or reponse is NULL no reponse will be sent.

Parameters:
call The corresponding call message to the reponse
response The call return value
00998 {
00999     if (call==NULL || response==NULL) {
01000         if ( call!=NULL )
01001             delete call;
01002         return;
01003     }
01004     response->setSrcNode( thisNode );
01005     response->setType( RPC );
01006     response->setNonce( call->getNonce() );
01007     sendMessageToUDP( call->getSrcNode(), response );
01008     delete call;
01009 }

void BaseOverlay::sendToKey ( const OverlayKey key,
BaseOverlayMessage message,
uint  numNeighbors = 0,
const TransportAddress nextHop = TransportAddress::UNSPECIFIED_NODE 
)

Sends a message to a overlay node, with the generic routing algorithm.

Parameters:
key The destination key
message Message to be sent
numNeighbors number of neighbors to send message to (multicast)
nextHop If nextHop is given, the message gets sent to this node before it is routed (nextHop is used as a proxy)
01109 {
01110     BaseRouteMessage* routeMsg = NULL;
01111 
01112     if (key.isUnspecified())
01113         error("BaseOverlay::sendToKey(): unspecified destination key!");
01114 
01115     if (msg->getType() != OVERLAYROUTE) {
01116         routeMsg = new BaseRouteMessage("BaseRouteMessage");
01117         routeMsg->setType(OVERLAYROUTE);
01118         routeMsg->setDestKey(key);
01119         routeMsg->setSrcNode(thisNode);
01120         routeMsg->setSignaling(msg->getSignaling());
01121         //routeMsg->setKind(routeMsg->getSignaling() ? 0 : 1);//???
01122         routeMsg->setKind(NOT_FORWARDED);
01123         // copy the name of the inner message
01124         routeMsg->setName(msg->name());
01125         routeMsg->setLength(BASEROUTE_L(routeMsg));
01126         routeMsg->encapsulate(msg);
01127 
01128         OverlayCtrlInfo* routeCtrlInfo = new OverlayCtrlInfo;
01129         routeCtrlInfo->setLastHopAddr(thisNode.ip);
01130         routeCtrlInfo->setLastHopPort(thisNode.port);
01131 
01132         routeMsg->setControlInfo(routeCtrlInfo);
01133     } else {
01134         routeMsg = check_and_cast<BaseRouteMessage*>(msg);
01135     }
01136 
01137     if (!nextHop.isUnspecified()) {
01138         // send msg to nextHop if specified (used for join rpcs)
01139         sendMessageToUDP(nextHop, routeMsg);
01140         return;
01141     }
01142 
01143     if (iterativeLookup) {
01144         // create lookup and sent to key
01145         AbstractLookup* lookup = createLookup(routeMsg);
01146         lookup->lookup( routeMsg->getDestKey(), numNeighbors, hopCountMax,
01147                         new SendToKeyListener( this, routeMsg ) );
01148     } else  {
01149         // if this node knows the destination node, set the finalHop flag
01150         if(isResponsible(routeMsg->getDestKey())) {
01151             routeMsg->setFinalHop(true);
01152         }
01153 
01154         NodeVector* nextHops = findNode(routeMsg->getDestKey(), routeMsg);
01155 
01156         if (nextHops->size() == 0) {
01157 
01158             EV <<   "BaseOverlay::sendToKey(): findNode() returned NULL "
01159             "- dropping message" << endl;
01160             // statistics
01161             RECORD_STATS(numDropped++; bytesDropped += routeMsg->byteLength());
01162             delete routeMsg;
01163         } else {
01164             // delete message if the hop count maximum is exceeded
01165             if (routeMsg->getHopCount() >= hopCountMax) {
01166                 if (debugOutput) {
01167                     EV << "BaseOverlay: Node " << thisNode.ip << " discards "
01168                     << routeMsg->name() << " from "
01169                     << routeMsg->getSrcNode().ip
01170                     << ". The hop count maximum has been exceeded. ("
01171                     << routeMsg->getHopCount() << ">="
01172                     << hopCountMax << ")" << endl;
01173                     //cout << "HopCount exceeded from " << routeMsg->getSrcNode().ip << endl;
01174                 }
01175 
01176                 // statistics
01177                 RECORD_STATS(numDropped++;
01178                              bytesDropped += routeMsg->byteLength());
01179                 delete routeMsg;
01180                 return;
01181             }
01182 
01183             // callForward to app
01184             if(useCommonAPIforward && !iterativeLookup
01185                && dynamic_cast<BaseAppDataMessage*>(routeMsg->encapsulatedMsg())
01186                && routeMsg->kind() != ALREADY_FORWARDED) {
01187                 //routeMsg->setKind(ALREADY_FORWARDED);
01188                 callForward(routeMsg->getDestKey(), routeMsg, (*nextHops)[0]);
01189                 return;
01190             }
01191             routeMsg->setKind(NOT_FORWARDED);
01192 
01193             // forward msg if this node is not responsible for the key
01194 
01195             if ((*nextHops)[0] != thisNode) {
01196                 OverlayCtrlInfo* overlayCtrlInfo =
01197                     dynamic_cast<OverlayCtrlInfo*>(msg->removeControlInfo());//why msg??? routeMsg???
01198 
01199                 // records statistics, if we forward this message
01200                 if ((overlayCtrlInfo != NULL) &&
01201                         (overlayCtrlInfo->getLastHopAddr() != thisNode.ip)) {
01202                     if (routeMsg->getSignaling() == false) {
01203                         RECORD_STATS(numForwarded++; bytesForwarded +=
01204                                          routeMsg->byteLength());
01205                     } else {
01206                         RECORD_STATS(numSignalingForwarded++;
01207                                      bytesSignalingForwarded +=
01208                                          routeMsg->byteLength());
01209                     }
01210                 }
01211                 if (overlayCtrlInfo != NULL)
01212                     delete overlayCtrlInfo;
01213             }
01214             forwardMessageRecursive((*nextHops)[0], routeMsg);
01215         }
01216         delete nextHops;
01217     }
01218 }

void BaseOverlay::setMalicious ( bool  malicious  )  [virtual]

Sets node to a malicious state.

This method can be overloaded to manage the state change.

Parameters:
malicious true, if node behaves maliciously
00205 {
00206     this->malicious = malicious;
00207 }

void BaseOverlay::setReadyIcon ( bool  ready  )  [protected]

Colors module-icon blue (ready) or red (not ready).

Parameters:
ready state to visualize
00543 {
00544     if (ev.isGUI()) {
00545         if (ready) {
00546             thisTerminal->displayString().setTagArg("i2", 1, "");
00547             displayString().setTagArg("i", 1, "");
00548         } else {
00549             thisTerminal->displayString().setTagArg("i2", 1, "red");
00550             displayString().setTagArg("i", 1, "red");
00551         }
00552     }
00553 }

void BaseOverlay::showOverlayNeighborArrow ( const NodeHandle neighbor,
bool  flush = true,
char *  displayString = NULL 
) [protected]

Draws an arrow from this node to neighbor.

Parameters:
neighbor neighbor to point to
flush delete all previous drawn arrows starting at this node?
displayString display string to define the arrow drawing style
Todo:
add neighbor's kind to distinguish arrows pointing to the same neighbor
00557 {
00558     if (!ev.isGUI() || !drawOverlayTopology)
00559         return;
00560 
00561     char red[] = "o=red,1";
00562     if (displayString == NULL)
00563         displayString = red;
00564 
00565     cModule* neighborTerminal;
00566     cGate* neighborInGateArray;
00567 
00568     // flush
00569     if (flush) {
00570         for (int l = 0; l < thisOutGateArray->size(); l++) {
00571             cGate* tempGate
00572             = thisTerminal->gate("overlayNeighborArrowOut", l)->toGate();
00573             thisTerminal->gate("overlayNeighborArrowOut", l)->disconnect();
00574             if (tempGate != NULL)
00575                 compactGateArray(tempGate->ownerModule(), IN);
00576         }
00577         thisTerminal->setGateSize("overlayNeighborArrowOut" ,0);
00578     }
00579 
00580     int neighborModuleId;
00581     if(bootstrapOracle->getPeerInfo(neighbor) == NULL)
00582         return;
00583     else
00584         neighborModuleId = bootstrapOracle->getPeerInfo(neighbor)->getModuleID();
00585 
00586     if (simulation.module(neighborModuleId) != NULL) {
00587         neighborTerminal
00588         = simulation.module(neighborModuleId)->parentModule();
00589         neighborInGateArray = simulation.module(neighborModuleId)->
00590                               parentModule()->gate("overlayNeighborArrowIn");
00591     } else
00592         return;
00593 
00594     //if (neighborInGateArray == NULL)
00595         //return;
00596 
00597     if (thisTerminal == neighborTerminal)
00598         return;
00599 
00600     //do not draw double
00601     for (int i = 0; i < thisOutGateArray->size(); i++)
00602         if (thisTerminal->gate("overlayNeighborArrowOut", i)->toGate() != NULL
00603                 && neighborTerminal
00604                 == thisTerminal->gate("overlayNeighborArrowOut", i)->
00605                 toGate()->ownerModule())
00606             return;
00607 
00608     // IN
00609     int i = 0;
00610     if (neighborInGateArray->size() == 0) {
00611         neighborTerminal->setGateSize("overlayNeighborArrowIn", 1);
00612         }
00613     else {
00614         for (i = 0; i < neighborInGateArray->size() - 1; i++) {
00615             if (!(neighborTerminal->gate("overlayNeighborArrowIn", i)
00616                     ->isConnectedOutside()))
00617                 break;
00618         }
00619         if (neighborTerminal->gate("overlayNeighborArrowIn", i)
00620                 ->isConnectedOutside()) {
00621             neighborTerminal->setGateSize("overlayNeighborArrowIn", i + 2);
00622             i++;
00623         }
00624     }
00625 
00626     // OUT
00627     int j = 0;
00628     if (thisOutGateArray->size() == 0)
00629         thisTerminal->setGateSize("overlayNeighborArrowOut", 1);
00630     else {
00631         for (j = 0; j < (thisOutGateArray->size() - 1); j++) {
00632             if (!(thisTerminal->gate("overlayNeighborArrowOut", j)
00633                     ->isConnectedOutside()))
00634                 break;
00635         }
00636         if (thisTerminal->gate("overlayNeighborArrowOut", j)
00637                 ->isConnectedOutside()) {
00638             thisTerminal->setGateSize("overlayNeighborArrowOut", j + 2);
00639             j++;
00640         }
00641     }
00642 
00643     thisTerminal->gate("overlayNeighborArrowOut", j)->
00644     connectTo(neighborTerminal->gate("overlayNeighborArrowIn", i));
00645 
00646     thisTerminal->gate("overlayNeighborArrowOut", j)->
00647     setDisplayString(displayString);
00648 }


Friends And Related Function Documentation

friend class BaseLookup [friend]

friend class BasePathLookup [friend]


Member Data Documentation

BaseLookupConfiguration BaseOverlay::baseLookupConfig [protected]

BootstrapOracle* BaseOverlay::bootstrapOracle [protected]

pointer to BootstrapOracle in this node

int BaseOverlay::bytesDropped [protected]

number of dropped bytes

int BaseOverlay::bytesFindNodeSent [protected]

int BaseOverlay::bytesForwarded [protected]

number of forwarded bytes at out-gate

int BaseOverlay::bytesReceived [private]

number of received bytes (incl. bytes to be forwarded)

int BaseOverlay::bytesSent [private]

number of sent bytes (incl. forwarded bytes)

int BaseOverlay::bytesSignalingForwarded [protected]

number of forwarded signaling bytes at out-gate

int BaseOverlay::bytesSignalingReceived [private]

number of received signaling bytes (incl. bytes to be forwarded)

int BaseOverlay::bytesSignalingSent [private]

number of sent signaling bytes (incl. forwarded bytes)

bool BaseOverlay::debugOutput [protected]

debug output ?

RpcListener* BaseOverlay::defaultRpcListener [private]

cOutVector BaseOverlay::delayVector [protected]

statistical output vector for packet-delays

bool BaseOverlay::drawOverlayTopology [private]

draw overlay topology?

GlobalStatistics* BaseOverlay::globalStatistics [protected]

pointer to GlobalStatistics module in this node

int BaseOverlay::hopCountMax [protected]

maximum hop count

cOutVector BaseOverlay::hopCountVector [protected]

statistical output vector for hop-counts

bool BaseOverlay::iterativeLookup [protected]

do iterative instead of recursive lookups

int BaseOverlay::localPort [protected]

used UDP-port

LookupSet BaseOverlay::lookups [protected]

bool BaseOverlay::malicious [protected]

true, if node is malicious

bool BaseOverlay::measureNetwInitPhase [protected]

fetch statistics in init phase ?

NotificationBoard* BaseOverlay::notificationBoard [protected]

pointer to NotificationBoard in this node

int BaseOverlay::numDropped [protected]

number of dropped packets

int BaseOverlay::numFindNodeSent [protected]

int BaseOverlay::numForwarded [protected]

number of forwarded packets

int BaseOverlay::numReceived [private]

number of received packets (incl. packets to be forwarded )

int BaseOverlay::numSent [private]

number of sent packets (incl. forwarded packets)

int BaseOverlay::numSignalingForwarded [protected]

number of forwarded signaling packets

int BaseOverlay::numSignalingReceived [private]

number of received signaling packets (incl. packets to be forwarded)

int BaseOverlay::numSignalingSent [private]

number of sent signaling packets (incl. forwarded packets)

bool BaseOverlay::onlyCommonAPIMessages [protected]

drop non-commonAPIMessages ?

int BaseOverlay::rpcsPending [private]

RpcStates BaseOverlay::rpcStates [private]

cGate* BaseOverlay::thisInGateArray [private]

in-gate array for vis. overlay topology

NodeHandle BaseOverlay::thisNode [protected]

NodeHandle to this node.

Reimplemented in Gia.

cGate* BaseOverlay::thisOutGateArray [private]

out-gate array for vis. overlay topology

cModule* BaseOverlay::thisTerminal [protected]

pointer to corresponding node

UnderlayConfigurator* BaseOverlay::underlayConfigurator [protected]

pointer to UnderlayConfigurator in this node

bool BaseOverlay::useBaseLookup [protected]

use the base lookup class

bool BaseOverlay::useCommonAPIforward [protected]

forward messages to applications?


The documentation for this class was generated from the following files:
Generated on Fri May 11 14:52:39 2007 for ITM OverSim by  doxygen 1.4.7