OverSim
BasePastry.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2012 Institute of Telematics, Karlsruhe Institute of Technology (KIT)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef __BASEPASTRY_H_
25 #define __BASEPASTRY_H_
26 
27 #include <vector>
28 #include <map>
29 #include <queue>
30 #include <algorithm>
31 
32 #include <omnetpp.h>
33 #include <IPvXAddress.h>
34 
35 #include <OverlayKey.h>
36 #include <NodeHandle.h>
37 #include <BaseOverlay.h>
38 #include <NeighborCache.h>
39 
40 #include "PastryTypes.h"
41 #include "PastryMessage_m.h"
42 #include "PastryRoutingTable.h"
43 #include "PastryLeafSet.h"
44 #include "PastryNeighborhoodSet.h"
45 
46 class PastryLeafSet;
47 
48 
49 class BasePastry : public BaseOverlay, public ProxListener
50 {
51 public:
52 
53  virtual ~BasePastry();
54 
55  // see BaseOverlay.h
56  int getMaxNumSiblings();
57 
58  // see BaseOverlay.h
60 
66  virtual void handleAppMessage(BaseOverlayMessage* msg);
67 
71  virtual void updateTooltip();
72 
73  // see BaseOverlay.h
74  virtual NodeVector* findNode(const OverlayKey& key,
75  int numRedundantNodes,
76  int numSiblings,
77  BaseOverlayMessage* msg);
78 
84  virtual void handleStateMessage(PastryStateMessage* msg) = 0;
85 
86  // see BaseOverlay.h
87  virtual void finishOverlay();
88 
89  // see BaseOverlay.h
90  virtual bool isSiblingFor(const NodeHandle& node,
91  const OverlayKey& key,
92  int numSiblings,
93  bool* err);
94 
95  // see BaseOverlay.h
97  const BaseOverlayMessage* msg = NULL,
98  const cPacket* dummy = NULL,
99  bool appLookup = false);
100 
101  uint8_t getBitsPerDigit() { return bitsPerDigit; };
102 
103  // statistics
104  int joins;
107  int joinSeen;
111  int joinSent;
130 
139 
148 
149  void proxCallback(const TransportAddress& node, int rpcId,
150  cPolymorphic *contextPointer, Prox prox);
151 
152  // see BaseOverlay.h
154 
155  protected:
156 
162  virtual void changeState(int toState) { };
163 
164  virtual bool handleRpcCall(BaseCallMessage* msg);
165 
166  virtual void handleRpcResponse(BaseResponseMessage* msg,
167  cPolymorphic* context, int rpcId,
168  simtime_t rtt);
169 
170  virtual void handleRpcTimeout(BaseCallMessage* call,
171  const TransportAddress& dest,
172  cPolymorphic* context, int rpcId,
173  const OverlayKey& key);
174 
176 
178 
180 
182 
184  simtime_t timestamp = -1,
185  int16_t row = -1,
186  bool lastHop = false);
187 
188  // parameters
189  uint32_t bitsPerDigit;
190  uint32_t numberOfLeaves;
200 
201  simtime_t nearNodeRtt;
202 
204 
206 
208 
211 
212  simtime_t lastStateChange;
213 
218 
222  std::queue<PastryStateMsgHandle> stateCacheQueue;
223 
228 
233  virtual void checkProxCache(void) = 0;
234 
235  uint32_t joinHopCount;
236  cMessage* readyWait;
237  cMessage* joinUpdateWait;
238 
242 
247  virtual void purgeVectors(void);
248 
252  void baseInit(void);
253 
258  void baseChangeState(int);
259 
260  OverlayKey distance(const OverlayKey& x,
261  const OverlayKey& y,
262  bool useAlternative = false) const;
263 
265  bool incrHopCount) { };
266 
268  {
272  };
273 
274  struct PingContext : public cPolymorphic
275  {
277  : stateObject(stateObject), index(index), nonce(nonce)
278  {};
279  virtual ~PingContext() {};
281  uint32_t index;
282  uint32_t nonce;
283  };
284 
285  enum
286  {
291  };
292 
297  void prePing(const PastryStateMessage* stateMsg);
298 
303  void pingNodes(void);
304 
312  void determineAliveTable(const PastryStateMessage* stateMsg);
313 
317  void newLeafs(void);
318 
319  public:
320  // neighborCache discovery support
321  uint8_t getRTLastRow() const;
322  std::vector<TransportAddress>* getRTRow(uint8_t index) const;
323  std::vector<TransportAddress>* getLeafSet() const;
324 
325  friend class PastryLeafSet;
326 };
327 
332 bool stateMsgIsSmaller(const PastryStateMsgHandle& hnd1,
333  const PastryStateMsgHandle& hnd2);
334 
335 std::ostream& operator<<(std::ostream& os, const PastryStateMsgProximity& pr);
336 
337 #endif
338