OverSim
PastryLeafSet.h
Go to the documentation of this file.
1 #ifndef __PASTRYLEAFSET_H
2 #define __PASTRYLEAFSET_H
3 
4 //
5 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 //
21 
27 #include <vector>
28 
29 #include <omnetpp.h>
30 
31 #include <NodeHandle.h>
32 #include <NodeVector.h>
33 
34 #include "PastryStateObject.h"
35 #include "PastryTypes.h"
36 #include "PastryMessage_m.h"
37 
38 #include "BasePastry.h"
39 
40 class BasePastry;
41 
46 {
47  simtime_t ts;
48  bool left;
49  PLSRepairData(simtime_t ts = 0, bool left = true) : ts(ts), left(left) {};
50 };
51 
61 {
62  public:
63 
73  void initializeSet(uint32_t numberOfLeaves,
74  uint32_t bitsPerDigit,
75  simtime_t repairTimeout,
76  const NodeHandle& owner,
78 
86  virtual const NodeHandle& getDestinationNode(const OverlayKey& destination);
87 
99  virtual const NodeHandle& findCloserNode(const OverlayKey& destination,
100  bool optimize = false);
101 
102  void findCloserNodes(const OverlayKey& destination,
103  NodeVector* nodes);
110  virtual const TransportAddress& failedNode(const TransportAddress& failed);
111 
120  virtual const TransportAddress& repair(const PastryStateMessage* msg,
121  const PastryStateMsgProximity* prox);
122 
129  bool isClosestNode(const OverlayKey& destination) const;
130 
136  virtual void dumpToStateMessage(PastryStateMessage* msg) const;
137 
143  virtual const TransportAddress& getRandomNode();
144 
152  bool mergeNode(const NodeHandle& node, simtime_t prox);
153 
154  virtual bool mergeState(const PastryStateMessage* msg,
155  const PastryStateMsgProximity* prox);
156 
160  const NodeHandle& getPredecessor(void) const;
161 
165  const NodeHandle& getSuccessor(void) const;
166 
170  bool isValid(void) const;
171 
178  virtual void dumpToVector(std::vector<TransportAddress>& affected) const;
179 
180  NodeVector* createSiblingVector(const OverlayKey& key, int numSiblings) const;
181 
189 
191 
192  private:
193 
194  uint32_t numberOfLeaves;
195  simtime_t repairTimeout;
197  std::vector<NodeHandle> leaves;
198  std::vector<NodeHandle>::iterator smaller;
199  std::vector<NodeHandle>::iterator bigger;
200 
201  std::map<TransportAddress, PLSRepairData> awaitingRepair;
202 
203  bool newLeafs;
204 
205  bool isFull;
206  bool wasFull;
207 
208  virtual void earlyInit(void);
209 
216  const NodeHandle& getBiggestNode(void) const;
217 
224  const OverlayKey& getBiggestKey(void) const;
225 
232  const NodeHandle& getSmallestNode(void) const;
233 
240  const OverlayKey& getSmallestKey(void) const;
241 
249  bool isLeft(const OverlayKey& key) const;
250 
257  void insertLeaf(std::vector<NodeHandle>::iterator& it,
258  const NodeHandle& node);
259 
260  bool balanceLeafSet();
261 };
262 
263 
264 #endif