#include <MyOverlay.h>
Public Member Functions | |
MyOverlay () | |
~MyOverlay () | |
Private Member Functions | |
void | handleTimerEvent (cMessage *msg) |
void | initializeOverlay (int stage) |
Initializes derived-class-attributes. | |
void | setOwnNodeID () |
Overlay implementations can overwrite this virtual method to set a specific nodeID. | |
void | joinOverlay () |
Join the overlay with a given nodeID in thisNode.key. | |
void | finishOverlay () |
collects statistical data in derived class | |
NodeVector * | findNode (const OverlayKey &key, int numRedundantNodes, int numSiblings, BaseOverlayMessage *msg) |
Implements the find node call. | |
bool | isSiblingFor (const NodeHandle &node, const OverlayKey &key, int numSiblings, bool *err) |
Query if a node is among the siblings for a given key. | |
int | getMaxNumSiblings () |
Query the maximum number of siblings (nodes close to a key) that are maintained by this overlay protocol. | |
int | getMaxNumRedundantNodes () |
Query the maximum number of redundant next hop nodes that are returned by findNode(). | |
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 |
number of dropped packets |
Definition at line 28 of file MyOverlay.h.
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); };
void MyOverlay::callbackNeighbors | ( | const NodeHandle & | neighborKey, | |
const NodeHandle & | prevNeighbor, | |||
const NodeHandle & | nextNeighbor | |||
) | [private, virtual] |
Definition at line 278 of file MyOverlay.cc.
Referenced by handleRpcResponse().
void MyOverlay::callbackTimeout | ( | const OverlayKey & | neighborKey | ) | [private, virtual] |
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, virtual] |
Implements the find node call.
This method simply returns the closest nodes known in the corresponding routing topology. If the node is a sibling for this key (isSiblingFor(key) = true), this method returns all numSiblings siblings, with the closest neighbor to the key first.
key | The lookup key. | |
numRedundantNodes | Maximum number of next hop nodes to return. | |
numSiblings | number of siblings to return | |
msg | A pointer to the BaseRouteMessage or FindNodeCall message of this lookup. |
Reimplemented from BaseOverlay.
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); numDropped++; 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, virtual] |
collects statistical data in derived class
Reimplemented from BaseOverlay.
Definition at line 155 of file MyOverlay.cc.
{ // remove this node from the overlay setOverlayReady(false); // save the statistics (see BaseApp) globalStatistics->addStdDev("MyOverlay: Dropped packets", numDropped); }
int MyOverlay::getMaxNumRedundantNodes | ( | ) | [private, virtual] |
Query the maximum number of redundant next hop nodes that are returned by findNode().
Reimplemented from BaseOverlay.
Definition at line 171 of file MyOverlay.cc.
{
return 1;
}
int MyOverlay::getMaxNumSiblings | ( | ) | [private, virtual] |
Query the maximum number of siblings (nodes close to a key) that are maintained by this overlay protocol.
Reimplemented from BaseOverlay.
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().
{ MyNeighborCall *msg = new MyNeighborCall(); 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 RPC_SWITCH_START(msg); // enters the following block if the message is of type MyNeighborCall (note the shortened parameter!) RPC_ON_CALL(MyNeighbor) { // get Call message MyNeighborCall *mrpc = (MyNeighborCall*)msg; // create response MyNeighborResponse *rrpc = new MyNeighborResponse(); rrpc->setRespondingNode(thisNode); rrpc->setPrevNeighbor(prevNode); rrpc->setNextNeighbor(nextNode); // 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 RPC_SWITCH_END(); // 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 RPC_SWITCH_START(msg); // enters the following block if the message is of type MyNeighborCall (note the shortened parameter!) RPC_ON_RESPONSE(MyNeighbor) { // get Response message MyNeighborResponse *mrpc = (MyNeighborResponse*)msg; // call our interface function callbackNeighbors(mrpc->getRespondingNode(), mrpc->getPrevNeighbor(), mrpc->getNextNeighbor()); } // end the switch RPC_SWITCH_END(); }
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 RPC_SWITCH_START(msg); // 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 RPC_SWITCH_END(); }
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 if (underlayConfigurator->isInInitPhase()) return; // pick either or next neighbor, or our previous neighbor, and request their neighbors OverlayKey key; int neighborToAsk = intuniform(0, 1); if (neighborToAsk == 0) key = prevNode.getKey(); else key = nextNode.getKey(); getNeighbors(key); } }
void MyOverlay::initializeOverlay | ( | int | stage | ) | [private, 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.
stage | the init stage |
Reimplemented from BaseOverlay.
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 numDropped = 0; if (!(par("enableDrops"))) { dropChance = 0; } 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, virtual] |
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 is among the closest numSiblings nodes to the key and that by a local findNode() call all other siblings to this key can be retrieved.
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 |
Reimplemented from BaseOverlay.
Definition at line 107 of file MyOverlay.cc.
void MyOverlay::joinOverlay | ( | ) | [private, virtual] |
Join the overlay with a given nodeID in thisNode.key.
Join the overlay with a given nodeID in thisNode.key. This method may be called by an application to join the overlay with a specific nodeID. It is also called if the node's IP address changes.
Reimplemented from BaseOverlay.
Definition at line 70 of file MyOverlay.cc.
{ // Set the information of the previous step in the chain prevNode.setIp(IPAddress(BIGBIT | (myKey - 1))); prevNode.setPort(thisNode.getPort()); prevNode.setKey(OverlayKey(myKey - 1)); // Set the information of the next step in the chain nextNode.setIp(IPAddress(BIGBIT | (myKey + 1))); nextNode.setPort(thisNode.getPort()); nextNode.setKey(OverlayKey(myKey + 1)); // tell the simulator that we're ready setOverlayReady(true); }
void MyOverlay::setOwnNodeID | ( | ) | [private, virtual] |
Overlay implementations can overwrite this virtual method to set a specific nodeID.
The default implementation sets a random nodeID.
Reimplemented from BaseOverlay.
Definition at line 62 of file MyOverlay.cc.
{ // create the corresponding overlay key thisNode.setKey(OverlayKey(myKey)); }
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] |
number of dropped packets
Reimplemented from BaseOverlay.
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().