#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) |
Processes Remote-Procedure-Call invocation messages. | |
void | handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt) |
This method is called if an RPC response has been received. | |
void | handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &) |
This method is called if an RPC timeout has been reached. | |
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.
00095 { rpcTimer = NULL; };
MyOverlay::~MyOverlay | ( | ) | [inline] |
Definition at line 96 of file MyOverlay.h.
00096 { 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().
00281 { 00282 EV << thisNode << ": (RPC) Got response from " 00283 << neighborKey << "\n" 00284 << thisNode << ": (RPC) Neighbors: " 00285 << prevNeighbor.getAddress() << ", " 00286 << nextNeighbor.getAddress() << std::endl; 00287 }
void MyOverlay::callbackTimeout | ( | const OverlayKey & | neighborKey | ) | [private, virtual] |
Definition at line 289 of file MyOverlay.cc.
Referenced by handleRpcTimeout().
00290 { 00291 EV << thisNode << ": (RPC) Query to " << neighborKey 00292 << " timed out!" << std::endl; 00293 }
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.
00125 { 00126 NodeVector* nextHops; 00127 00128 // do we drop the packet? 00129 if (uniform(0, 1) < dropChance) { 00130 // if yes, return an empty node vector 00131 nextHops = new NodeVector(0); 00132 numDropped++; 00133 return nextHops; 00134 } 00135 00136 // else, set the response vector with one node 00137 nextHops = new NodeVector(1); 00138 00139 // are we responsible? next step is this node 00140 if (key == thisNode.getKey()) { 00141 nextHops->add(thisNode); 00142 } 00143 // is the key behind us? next step is the previous node 00144 else if (key < thisNode.getKey()) { 00145 nextHops->add(prevNode); 00146 } 00147 // otherwise, the next step is the next node 00148 else { 00149 nextHops->add(nextNode); 00150 } 00151 return nextHops; 00152 }
void MyOverlay::finishOverlay | ( | ) | [private, virtual] |
collects statistical data in derived class
Reimplemented from BaseOverlay.
Definition at line 155 of file MyOverlay.cc.
00156 { 00157 // remove this node from the overlay 00158 setOverlayReady(false); 00159 00160 // save the statistics (see BaseApp) 00161 globalStatistics->addStdDev("MyOverlay: Dropped packets", numDropped); 00162 }
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.
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.
void MyOverlay::getNeighbors | ( | const OverlayKey & | neighborKey | ) | [private] |
Definition at line 177 of file MyOverlay.cc.
Referenced by handleTimerEvent().
00178 { 00179 MyNeighborCall *msg = new MyNeighborCall(); 00180 msg->setDestinationKey(neighborKey); 00181 00182 // The function we'll be using to send an RPC is sendRouteRpcCall. 00183 // The first value is to which tier we'll be talking. Can be either 00184 // OVERLAY_COMP, TIER1_COMP, TIER2_COMP, and so on. 00185 // The second parameter is the node to which we'll send the message. 00186 // Can be either an OverlayKey or a TransportAddress. 00187 // The third parameter is the message. 00188 00189 EV << thisNode << ": (RPC) Sending query to " 00190 << neighborKey << "!" << std::endl; 00191 00192 sendRouteRpcCall(OVERLAY_COMP, neighborKey, msg); 00193 }
bool MyOverlay::handleRpcCall | ( | BaseCallMessage * | msg | ) | [private, virtual] |
Processes Remote-Procedure-Call invocation messages.
This method should be overloaded when the overlay provides RPC functionality.
Reimplemented from BaseRpc.
Definition at line 197 of file MyOverlay.cc.
00198 { 00199 // There are many macros to simplify the handling of RPCs. The full list is in <OverSim>/src/common/RpcMacros.h. 00200 00201 // start a switch 00202 RPC_SWITCH_START(msg); 00203 00204 // enters the following block if the message is of type MyNeighborCall (note the shortened parameter!) 00205 RPC_ON_CALL(MyNeighbor) { 00206 // get Call message 00207 MyNeighborCall *mrpc = (MyNeighborCall*)msg; 00208 00209 // create response 00210 MyNeighborResponse *rrpc = new MyNeighborResponse(); 00211 rrpc->setRespondingNode(thisNode); 00212 rrpc->setPrevNeighbor(prevNode); 00213 rrpc->setNextNeighbor(nextNode); 00214 00215 // now send the response. sendRpcResponse can automatically tell where 00216 // to send it to. Note that sendRpcResponse will delete mrpc (aka msg)! 00217 sendRpcResponse(mrpc, rrpc); 00218 00219 RPC_HANDLED = true; // set to true, since we did handle this RPC (default is false) 00220 } 00221 00222 // end the switch 00223 RPC_SWITCH_END(); 00224 00225 // return whether we handled the message or not. 00226 // don't delete unhandled messages! 00227 return RPC_HANDLED; 00228 }
void MyOverlay::handleRpcResponse | ( | BaseResponseMessage * | msg, | |
cPolymorphic * | context, | |||
int | rpcId, | |||
simtime_t | rtt | |||
) | [private, virtual] |
This method is called if an RPC response has been received.
msg | The response message. | |
context | Pointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code | |
rpcId | The RPC id. | |
rtt | The Round-Trip-Time of this RPC |
Reimplemented from RpcListener.
Definition at line 255 of file MyOverlay.cc.
00259 { 00260 // The macros are here similar. Just use RPC_ON_RESPONSE instead of RPC_ON_CALL. 00261 00262 // start a switch 00263 RPC_SWITCH_START(msg); 00264 00265 // enters the following block if the message is of type MyNeighborCall (note the shortened parameter!) 00266 RPC_ON_RESPONSE(MyNeighbor) { 00267 // get Response message 00268 MyNeighborResponse *mrpc = (MyNeighborResponse*)msg; 00269 // call our interface function 00270 callbackNeighbors(mrpc->getRespondingNode(), 00271 mrpc->getPrevNeighbor(), 00272 mrpc->getNextNeighbor()); 00273 } 00274 // end the switch 00275 RPC_SWITCH_END(); 00276 }
void MyOverlay::handleRpcTimeout | ( | BaseCallMessage * | msg, | |
const TransportAddress & | dest, | |||
cPolymorphic * | context, | |||
int | rpcId, | |||
const OverlayKey & | destKey | |||
) | [private, virtual] |
This method is called if an RPC timeout has been reached.
msg | The original RPC message. | |
dest | The destination node | |
context | Pointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code | |
rpcId | The RPC id. | |
destKey | the destination OverlayKey |
Reimplemented from RpcListener.
Definition at line 233 of file MyOverlay.cc.
00237 { 00238 // Same macros as in handleRpc 00239 00240 // start a switch 00241 RPC_SWITCH_START(msg); 00242 00243 // enters the following block if the message is of type MyNeighborCall (note the shortened parameter!) 00244 RPC_ON_CALL(MyNeighbor) { 00245 MyNeighborCall *mrpc = (MyNeighborCall*)msg; // get Call message 00246 callbackTimeout(mrpc->getDestinationKey()); // call interface function 00247 } 00248 // end the switch 00249 RPC_SWITCH_END(); 00250 }
void MyOverlay::handleTimerEvent | ( | cMessage * | msg | ) | [private, virtual] |
Reimplemented from BaseRpc.
Definition at line 86 of file MyOverlay.cc.
00087 { 00088 if (msg == rpcTimer) { 00089 // reschedule the timer 00090 scheduleAt(simTime() + 5, rpcTimer); 00091 00092 // if the simulator is still busy creating the network, let's wait a bit longer 00093 if (underlayConfigurator->isInInitPhase()) return; 00094 00095 // pick either or next neighbor, or our previous neighbor, and request their neighbors 00096 OverlayKey key; 00097 int neighborToAsk = intuniform(0, 1); 00098 00099 if (neighborToAsk == 0) key = prevNode.getKey(); 00100 else key = nextNode.getKey(); 00101 00102 getNeighbors(key); 00103 } 00104 }
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.
00042 { 00043 // see BaseApp.cc 00044 if (stage != MIN_STAGE_OVERLAY) return; 00045 00046 // get our key from our IP address 00047 myKey = thisNode.getAddress().get4().getInt() & ~BIGBIT; 00048 00049 // initialize the rest of variables 00050 numDropped = 0; 00051 if (!(par("enableDrops"))) { 00052 dropChance = 0; 00053 } else { 00054 dropChance = par("dropChance"); 00055 } 00056 00057 rpcTimer = new cMessage("RPC timer"); 00058 scheduleAt(simTime() + 5, rpcTimer); 00059 }
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.
00071 { 00072 // Set the information of the previous step in the chain 00073 prevNode.setAddress(IPAddress(BIGBIT | (myKey - 1))); 00074 prevNode.setPort(thisNode.getPort()); 00075 prevNode.setKey(OverlayKey(myKey - 1)); 00076 00077 // Set the information of the next step in the chain 00078 nextNode.setAddress(IPAddress(BIGBIT | (myKey + 1))); 00079 nextNode.setPort(thisNode.getPort()); 00080 nextNode.setKey(OverlayKey(myKey + 1)); 00081 00082 // tell the simulator that we're ready 00083 setOverlayReady(true); 00084 }
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.
00063 { 00064 // create the corresponding overlay key 00065 thisNode.setKey(OverlayKey(myKey)); 00066 }
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().