MyOverlay.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00023 #ifndef _MYOVERLAY_
00024 #define _MYOVERLAY_
00025 
00026 #include "BaseOverlay.h"
00027 
00028 class MyOverlay : public BaseOverlay
00029 {
00030 private:
00031     // RPC timer
00032     cMessage *rpcTimer;
00033 
00034     // Routing parameters
00035     int myKey;               // our overlay key
00036     NodeHandle prevNode;     // next node in chain
00037     NodeHandle nextNode;     // previous node in chain
00038 
00039     //module parameters
00040     double dropChance;       // we'll store the "dropChance" parameter here
00041 
00042     // statistics
00043     int numDropped;          // how many packets have we dropped?
00044 
00045     // routine for RPC timer
00046     void handleTimerEvent(cMessage *msg);
00047 
00048     // overlay routines
00049     void initializeOverlay(int stage);                      // called when the overlay is being initialized
00050     void setOwnNodeID();                                    // (optional) called to set the key of this node (random otherwise)
00051     void joinOverlay();                                     // called when the node is ready to join the overlay
00052     void finishOverlay();                                   // called when the module is about to be destroyed
00053 
00054     // obligatory: called when we need the next hop to route a packet to the given key
00055     NodeVector* findNode(const OverlayKey& key,             // key to route to
00056                                  int numRedundantNodes,     // how many candidates for next hop we want (see getMaxNumSiblings)
00057                                  int numSiblings,           // how many siblings we'll return (?) (see getMaxRedundantNodes)
00058                                  BaseOverlayMessage* msg);  // message being routed
00059 
00060     // obligatory: In general, called when we need to know whether node is amongst numSiblings closest nodes to key.
00061     // But normally it is called with node set to thisNode, and asking whether this node is responsible for key.
00062     bool isSiblingFor(const NodeHandle& node,               // which node (usually thisNode) we're referring to
00063                                  const OverlayKey& key,     // key in question
00064                                  int numSiblings,           // how many siblings we're querying about
00065                                  bool* err);                // set to false when we couldn't determine the range
00066 
00067     // obligatory: Set the maximum number of siblings that can be queried about (usually 1)
00068     int getMaxNumSiblings();
00069 
00070     // obligatory: Set the maximum number of redundant nodes that can be queried about (usually 1)
00071     int getMaxNumRedundantNodes();
00072 
00073     // Our RPC interface
00074     // asynchronously request the neighbors of neighborKey
00075     void getNeighbors(const OverlayKey& neighborKey);
00076     // function to call to respond about the queried neighbors
00077     virtual void callbackNeighbors(const NodeHandle& neighborKey,
00078                                    const NodeHandle& prevNeighbor,
00079                                    const NodeHandle& nextNeighbor);
00080     // function to call if the query times out
00081     virtual void callbackTimeout(const OverlayKey &neighborKey);
00082 
00083     // internal handling of RPCs
00084     bool handleRpcCall(BaseCallMessage *msg);                    // called when we receive an RPC from another node
00085     void handleRpcResponse(BaseResponseMessage* msg,         // called when we receive an RPC response from another node
00086                               cPolymorphic* context,
00087                               int rpcId,
00088                               simtime_t rtt);
00089     void handleRpcTimeout(BaseCallMessage* msg,                 // called when an RPC times out
00090                              const TransportAddress& dest,
00091                              cPolymorphic* context, int rpcId,
00092                              const OverlayKey&);
00093 
00094 public:
00095     MyOverlay() { rpcTimer = NULL; };
00096     ~MyOverlay() { cancelAndDelete(rpcTimer); };
00097 };
00098 
00099 #endif
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3