OverSim
MyOverlay Class Reference

#include <MyOverlay.h>

Inheritance diagram for MyOverlay:
BaseOverlay BaseRpc BaseTcpSupport TopologyVis RpcListener

Public Member Functions

 MyOverlay ()
 ~MyOverlay ()
- Public Member Functions inherited from BaseOverlay
 BaseOverlay ()
virtual ~BaseOverlay ()
 Virtual destructor.
States getState ()
bool isMalicious ()
 Returns true, if node is malicious.
bool isInSimpleMultiOverlayHost ()
 Returns true if overlay is one in an array, inside a SimpleMultiOverlayHost.
const simtime_t & getCreationTime ()
void join (const OverlayKey &nodeID=OverlayKey::UNSPECIFIED_KEY)
 Join the overlay with a given nodeID.
virtual NodeVectorlocal_lookup (const OverlayKey &key, int num, bool safe)
 finds nodes closest to the given OverlayKey
virtual NodeVectorneighborSet (int num)
virtual 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 int getMaxNumSiblings ()
 Query the maximum number of siblings (nodes close to a key) that are maintained by this overlay protocol.
virtual int getMaxNumRedundantNodes ()
 Query the maximum number of redundant next hop nodes that are returned by findNode().
void sendMessageToUDP (const TransportAddress &dest, cPacket *msg, simtime_t delay=SIMTIME_ZERO)
 Sends message to underlay.
void sendToKey (const OverlayKey &key, BaseOverlayMessage *message, int numSiblings=1, const std::vector< TransportAddress > &sourceRoute=TransportAddress::UNSPECIFIED_NODES, RoutingType routingType=DEFAULT_ROUTING)
 Sends a message to an overlay node, with the generic routing algorithm.
virtual OverlayKey distance (const OverlayKey &x, const OverlayKey &y, bool useAlternative=false) const
 This method should implement the distance between two keys.
void registerComp (CompType compType, cModule *module)
cModule * getCompModule (CompType compType)
cGate * getCompRpcGate (CompType compType)
void sendMessageToAllComp (cMessage *msg, CompType srcComp)
bool providesKbr ()
virtual uint8_t getBitsPerDigit ()
bool getMeasureAuthBlock ()
BootstrapListgetBootstrapList () const
virtual OverlayKey estimateMeanDistance ()
 returns mean distance between OverlayKeys in the network
virtual uint32_t estimateOverlaySize ()
 estimates the current number of nodes online
- Public Member Functions inherited from BaseRpc
 BaseRpc ()
const NodeHandlegetThisNode ()
 Returns the NodeHandle of this node.
simtime_t getUdpTimeout ()
- Public Member Functions inherited from RpcListener
virtual ~RpcListener ()
 destructor
- Public Member Functions inherited from BaseTcpSupport
virtual void socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent)
virtual void socketEstablished (int connId, void *yourPtr)
virtual void socketPeerClosed (int connId, void *yourPtr)
virtual void socketFailure (int connId, void *yourPtr, int code)
virtual void socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status)
- Public Member Functions inherited from TopologyVis
 TopologyVis ()
void showOverlayNeighborArrow (const NodeHandle &neighbor, bool flush=true, const char *displayString=NULL)
 Draws an arrow from this node to neighbor.
void deleteOverlayNeighborArrow (const NodeHandle &neighbor)
 Removes an arrow from this node to neighbor.

Private Member Functions

void handleTimerEvent (cMessage *msg)
void initializeOverlay (int stage)
void setOwnNodeID ()
void joinOverlay ()
void finishOverlay ()
NodeVectorfindNode (const OverlayKey &key, int numRedundantNodes, int numSiblings, BaseOverlayMessage *msg)
bool isSiblingFor (const NodeHandle &node, const OverlayKey &key, int numSiblings, bool *err)
int getMaxNumSiblings ()
int getMaxNumRedundantNodes ()
void getNeighbors (const OverlayKey &neighborKey)
virtual void callbackNeighbors (const NodeHandle &neighborKey, const NodeHandle &prevNeighbor, const NodeHandle &nextNeighbor)
virtual void callbackTimeout (const OverlayKey &neighborKey)
bool handleRpcCall (BaseCallMessage *msg)
void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
void handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &)

Private Attributes

cMessage * rpcTimer
int myKey
NodeHandle prevNode
NodeHandle nextNode
double dropChance
int numDropped

Additional Inherited Members

- Public Types inherited from BaseOverlay
enum  States {
  INIT = 0, BOOTSTRAP = 1, DISCOVERY = 2, PREJOIN = 3,
  JOIN = 4, POSTJOIN = 5, READY = 6, REFRESH = 7,
  SHUTDOWN = 8, FAILED = 9, RSET = JOIN, BSET = POSTJOIN
}
- Protected Types inherited from BaseOverlay
typedef UNORDERED_SET
< AbstractLookup
*, lookupHashFcn,
lookupHashFcn
LookupSet
- Protected Member Functions inherited from BaseOverlay
int numInitStages () const
 Sets init stage.
virtual void initializeOverlay (int stage)
 Initializes derived-class-attributes.
virtual void finishOverlay ()
 collects statistical data in derived class
void bindToPort (int port)
 Tells UDP we want to get all packets arriving on the given port.
virtual void route (const OverlayKey &key, CompType destComp, CompType srcComp, cPacket *msg, const std::vector< TransportAddress > &sourceRoute=TransportAddress::UNSPECIFIED_NODES, RoutingType routingType=DEFAULT_ROUTING)
 Routes message through overlay.
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)
 Informs application about state changes of nodes or newly joined nodes.
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

virtual void handleUDPMessage (BaseOverlayMessage *msg)
 Processes messages from underlay.
virtual void handleAppMessage (cMessage *msg)
 Processes "timer" self-messages.
virtual void receiveChangeNotification (int category, const cPolymorphic *details)
 callback-method for events at the NotificationBoard
virtual void handleTransportAddressChangedNotification ()
 This method gets call if the node has a new TransportAddress (IP address) because he changed his access network.
virtual void handleNodeLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed.
virtual void handleNodeGracefulLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed if this node is among the gracefulLeaveProbability nodes.
virtual void recordOverlaySentStats (BaseOverlayMessage *msg)
 Collect overlay specific sent messages statistics.
void setOverlayReady (bool ready)
 Sets the overlay ready icon and register/deregisters the node at the GlobalNodeList.
virtual AbstractLookupcreateLookup (RoutingType routingType=DEFAULT_ROUTING, const BaseOverlayMessage *msg=NULL, const cPacket *findNodeExt=NULL, bool appLookup=false)
 Creates an abstract iterative lookup instance.
virtual void removeLookup (AbstractLookup *lookup)
 Removes the abstract lookup instance.
virtual NodeVectorfindNode (const OverlayKey &key, int numRedundantNodes, int numSiblings, BaseOverlayMessage *msg=NULL)
 Implements the find node call.
virtual void joinOverlay ()
 Join the overlay with a given nodeID in thisNode.key.
virtual void joinForeignPartition (const NodeHandle &node)
 Join another overlay partition with the given node as bootstrap node.
virtual bool handleFailedNode (const TransportAddress &failed)
 Handles a failed node.
virtual void lookupRpc (LookupCall *call)
virtual void nextHopRpc (NextHopCall *call)
void countFindNodeCall (const FindNodeCall *call)
void countFailedNodeCall (const FailedNodeCall *call)
bool internalHandleRpcCall (BaseCallMessage *msg)
 Handles internal rpc requests.
void internalHandleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 Handles rpc responses internal in base classes

void internalHandleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 Handles rpc timeouts internal in base classes

void internalSendRouteRpc (BaseRpcMessage *message, const OverlayKey &destKey, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType)
CompType getThisCompType ()
 Return the component type of this module.
- Protected Attributes inherited from BaseOverlay
int numAppDataForwarded
 number of forwarded app data packets
int bytesAppDataForwarded
 number of forwarded app data bytes at out-gate
int numAppLookupForwarded
 number of forwarded app lookup packets
int bytesAppLookupForwarded
 number of forwarded app lookup bytes at out-gate
int numMaintenanceForwarded
 number of forwarded maintenance packets
int bytesMaintenanceForwarded
 number of forwarded maintenance bytes at out-gate
int numFindNodeSent
int bytesFindNodeSent
int numFindNodeResponseSent
int bytesFindNodeResponseSent
int numFailedNodeSent
int bytesFailedNodeSent
int numFailedNodeResponseSent
int bytesFailedNodeResponseSent
std::vector< HopDelayRecord * > singleHopDelays
simtime_t creationTime
 simtime when the node has been created
GlobalNodeListglobalNodeList
 pointer to GlobalNodeList in this node
NotificationBoard * notificationBoard
 pointer to NotificationBoard in this node
UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
BootstrapListbootstrapList
 pointer to the BootstrapList module
GlobalParametersglobalParameters
 pointer to the GlobalParameters module
uint32_t overlayId
 identifies the overlay this node belongs to (used for multiple overlays)
bool debugOutput
 debug output ?
RoutingType defaultRoutingType
bool useCommonAPIforward
 forward messages to applications?
bool collectPerHopDelay
 collect delay for single hops
bool routeMsgAcks
 send ACK when receiving route message
uint32_t recNumRedundantNodes
 numRedundantNodes for recursive routing
bool recordRoute
 record visited hops on route
bool drawOverlayTopology
bool rejoinOnFailure
bool sendRpcResponseToLastHop
 needed by KBR protocols for NAT support
bool dropFindNodeAttack
 if node is malicious, it tries a findNode attack
bool isSiblingAttack
 if node is malicious, it tries a isSibling attack
bool invalidNodesAttack
 if node is malicious, it tries a invalidNode attack
bool dropRouteMessageAttack
 if node is malicious, it drops all received BaseRouteMessages
int localPort
 used UDP-port
int hopCountMax
 maximum hop count
bool measureAuthBlock
 if true, measure the overhead of signatures in rpc messages
bool restoreContext
 if true, a node rejoins with its old nodeId and malicious state
int numDropped
 number of dropped packets
int bytesDropped
 number of dropped bytes
cOutVector delayVector
 statistical output vector for packet-delays
cOutVector hopCountVector
 statistical output vector for hop-counts
States state
IterativeLookupConfiguration iterativeLookupConfig
RecursiveLookupConfiguration recursiveLookupConfig
LookupSet lookups
bool kbr
 set this to true, if the overlay provides KBR services

Detailed Description

Author
Antonio Zea

Definition at line 28 of file MyOverlay.h.

Constructor & Destructor Documentation

MyOverlay::MyOverlay ( )
inline

Definition at line 95 of file MyOverlay.h.

{ rpcTimer = NULL; };
MyOverlay::~MyOverlay ( )
inline

Definition at line 96 of file MyOverlay.h.

{ cancelAndDelete(rpcTimer); };

Member Function Documentation

void MyOverlay::callbackNeighbors ( const NodeHandle neighborKey,
const NodeHandle prevNeighbor,
const NodeHandle nextNeighbor 
)
privatevirtual

Definition at line 278 of file MyOverlay.cc.

Referenced by handleRpcResponse().

{
EV << thisNode << ": (RPC) Got response from "
<< neighborKey << "\n"
<< thisNode << ": (RPC) Neighbors: "
<< prevNeighbor.getIp() << ", "
<< nextNeighbor.getIp() << std::endl;
}
void MyOverlay::callbackTimeout ( const OverlayKey neighborKey)
privatevirtual

Definition at line 289 of file MyOverlay.cc.

Referenced by handleRpcTimeout().

{
EV << thisNode << ": (RPC) Query to " << neighborKey
<< " timed out!" << std::endl;
}
NodeVector * MyOverlay::findNode ( const OverlayKey key,
int  numRedundantNodes,
int  numSiblings,
BaseOverlayMessage msg 
)
private

Definition at line 121 of file MyOverlay.cc.

{
NodeVector* nextHops;
// do we drop the packet?
if (uniform(0, 1) < dropChance) {
// if yes, return an empty node vector
nextHops = new NodeVector(0);
return nextHops;
}
// else, set the response vector with one node
nextHops = new NodeVector(1);
// are we responsible? next step is this node
if (key == thisNode.getKey()) {
nextHops->add(thisNode);
}
// is the key behind us? next step is the previous node
else if (key < thisNode.getKey()) {
nextHops->add(prevNode);
}
// otherwise, the next step is the next node
else {
nextHops->add(nextNode);
}
return nextHops;
}
void MyOverlay::finishOverlay ( )
private

Definition at line 155 of file MyOverlay.cc.

{
// remove this node from the overlay
// save the statistics (see BaseApp)
globalStatistics->addStdDev("MyOverlay: Dropped packets", numDropped);
}
int MyOverlay::getMaxNumRedundantNodes ( )
private

Definition at line 171 of file MyOverlay.cc.

{
return 1;
}
int MyOverlay::getMaxNumSiblings ( )
private

Definition at line 165 of file MyOverlay.cc.

{
return 1;
}
void MyOverlay::getNeighbors ( const OverlayKey neighborKey)
private

Definition at line 177 of file MyOverlay.cc.

Referenced by handleTimerEvent().

{
msg->setDestinationKey(neighborKey);
// The function we'll be using to send an RPC is sendRouteRpcCall.
// The first value is to which tier we'll be talking. Can be either
// OVERLAY_COMP, TIER1_COMP, TIER2_COMP, and so on.
// The second parameter is the node to which we'll send the message.
// Can be either an OverlayKey or a TransportAddress.
// The third parameter is the message.
EV << thisNode << ": (RPC) Sending query to "
<< neighborKey << "!" << std::endl;
sendRouteRpcCall(OVERLAY_COMP, neighborKey, msg);
}
bool MyOverlay::handleRpcCall ( BaseCallMessage msg)
private

Definition at line 197 of file MyOverlay.cc.

{
// There are many macros to simplify the handling of RPCs. The full list is in <OverSim>/src/common/RpcMacros.h.
// start a switch
// enters the following block if the message is of type MyNeighborCall (note the shortened parameter!)
RPC_ON_CALL(MyNeighbor) {
// get Call message
// create response
// now send the response. sendRpcResponse can automatically tell where
// to send it to. Note that sendRpcResponse will delete mrpc (aka msg)!
sendRpcResponse(mrpc, rrpc);
RPC_HANDLED = true; // set to true, since we did handle this RPC (default is false)
}
// end the switch
// return whether we handled the message or not.
// don't delete unhandled messages!
return RPC_HANDLED;
}
void MyOverlay::handleRpcResponse ( BaseResponseMessage msg,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
)
private

Definition at line 255 of file MyOverlay.cc.

{
// The macros are here similar. Just use RPC_ON_RESPONSE instead of RPC_ON_CALL.
// start a switch
// enters the following block if the message is of type MyNeighborCall (note the shortened parameter!)
RPC_ON_RESPONSE(MyNeighbor) {
// get Response message
// call our interface function
mrpc->getPrevNeighbor(),
mrpc->getNextNeighbor());
}
// end the switch
}
void MyOverlay::handleRpcTimeout ( BaseCallMessage msg,
const TransportAddress dest,
cPolymorphic *  context,
int  rpcId,
const OverlayKey  
)
private

Definition at line 233 of file MyOverlay.cc.

{
// Same macros as in handleRpc
// start a switch
// enters the following block if the message is of type MyNeighborCall (note the shortened parameter!)
RPC_ON_CALL(MyNeighbor) {
MyNeighborCall *mrpc = (MyNeighborCall*)msg; // get Call message
callbackTimeout(mrpc->getDestinationKey()); // call interface function
}
// end the switch
}
void MyOverlay::handleTimerEvent ( cMessage *  msg)
private

Definition at line 86 of file MyOverlay.cc.

{
if (msg == rpcTimer) {
// reschedule the timer
scheduleAt(simTime() + 5, rpcTimer);
// if the simulator is still busy creating the network, let's wait a bit longer
// pick either or next neighbor, or our previous neighbor, and request their neighbors
int neighborToAsk = intuniform(0, 1);
if (neighborToAsk == 0) key = prevNode.getKey();
else key = nextNode.getKey();
}
}
void MyOverlay::initializeOverlay ( int  stage)
private

Definition at line 41 of file MyOverlay.cc.

{
// see BaseApp.cc
if (stage != MIN_STAGE_OVERLAY) return;
// get our key from our IP address
myKey = thisNode.getIp().get4().getInt() & ~BIGBIT;
// initialize the rest of variables
if (!(par("enableDrops"))) {
} else {
dropChance = par("dropChance");
}
rpcTimer = new cMessage("RPC timer");
scheduleAt(simTime() + 5, rpcTimer);
}
bool MyOverlay::isSiblingFor ( const NodeHandle node,
const OverlayKey key,
int  numSiblings,
bool *  err 
)
private

Definition at line 107 of file MyOverlay.cc.

{
// is it our node and our key?
if (node == thisNode && key == thisNode.getKey()) {
return true;
}
// we don't know otherwise
return false;
}
void MyOverlay::joinOverlay ( )
private

Definition at line 70 of file MyOverlay.cc.

{
// Set the information of the previous step in the chain
prevNode.setIp(IPAddress(BIGBIT | (myKey - 1)));
// Set the information of the next step in the chain
nextNode.setIp(IPAddress(BIGBIT | (myKey + 1)));
// tell the simulator that we're ready
}
void MyOverlay::setOwnNodeID ( )
private

Definition at line 62 of file MyOverlay.cc.

{
// create the corresponding overlay key
}

Member Data Documentation

double MyOverlay::dropChance
private

Definition at line 40 of file MyOverlay.h.

Referenced by findNode(), and initializeOverlay().

int MyOverlay::myKey
private

Definition at line 35 of file MyOverlay.h.

Referenced by initializeOverlay(), joinOverlay(), and setOwnNodeID().

NodeHandle MyOverlay::nextNode
private

Definition at line 37 of file MyOverlay.h.

Referenced by findNode(), handleRpcCall(), handleTimerEvent(), and joinOverlay().

int MyOverlay::numDropped
private

Definition at line 43 of file MyOverlay.h.

Referenced by findNode(), finishOverlay(), and initializeOverlay().

NodeHandle MyOverlay::prevNode
private

Definition at line 36 of file MyOverlay.h.

Referenced by findNode(), handleRpcCall(), handleTimerEvent(), and joinOverlay().

cMessage* MyOverlay::rpcTimer
private

Definition at line 32 of file MyOverlay.h.

Referenced by handleTimerEvent(), initializeOverlay(), MyOverlay(), and ~MyOverlay().


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