OverSim
PastryRoutingTable.h
Go to the documentation of this file.
1 #ifndef __PASTRYROUTINGTABLE_H_
2 #define __PASTRYROUTINGTABLE_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 
33 #include "PastryStateObject.h"
34 #include "PastryTypes.h"
35 #include "PastryMessage_m.h"
36 
37 
41 typedef std::vector<PastryExtendedNode> PRTRow;
42 
47 {
48  TransportAddress node;//*< the node last asked for repair
49  simtime_t timestamp; //*< the time when it was asked
50  uint32_t failedRow; //*< row of the failed node
51  uint32_t failedCol; //*< col of the failed node
52  uint32_t askedRow; //*< row of the node last asked
53  uint32_t askedCol; //*< col of the node last asked
54 };
55 
65 {
66 
67  public:
75  void initializeTable(uint32_t bitsPerDigit, double repairTimeout,
76  const NodeHandle& owner);
77 
85  const NodeHandle& lookupNextHop(const OverlayKey& destination);
86 
98  virtual const NodeHandle& findCloserNode(const OverlayKey& destination,
99  bool optimize = false);
100 
101  void findCloserNodes(const OverlayKey& destination,
102  NodeVector* nodes);
103 
110  virtual const TransportAddress& failedNode(const TransportAddress& failed);
111 
120  virtual const TransportAddress& repair(const PastryStateMessage* msg,
121  const PastryStateMsgProximity* prox);
122 
128  virtual void dumpToStateMessage(PastryStateMessage* msg) const;
129 
135  virtual void dumpRowToMessage(PastryStateMessage* msg, int row) const;
136 
141  int getLastRow();
142 
143  std::vector<TransportAddress>* getRow(uint8_t row) const;
144 
151  virtual const TransportAddress& getRandomNode(int row);
152 
153 
161  bool mergeNode(const NodeHandle& node, simtime_t prox);
162 
171  bool initStateFromHandleVector(const std::vector<PastryStateMsgHandle>& handles);
172 
180  virtual void dumpToVector(std::vector<TransportAddress>& affected) const;
181 
182  uint32_t nodesPerRow; //TODO getter/setter + private
183 
184  private:
185 
187  std::vector<PRTRow> rows;
188  std::vector<PRTTrackRepair> awaitingRepair;
189 
190  virtual void earlyInit(void);
191 
195  void addRow(void);
196 
204  uint32_t digitAt(uint32_t n, const OverlayKey& key) const;
205 
212  const PastryExtendedNode& nodeAt(uint32_t row, uint32_t col) const;
213 
220  void findNextNodeToAsk(PRTTrackRepair& track) const;
221 
222 };
223 
228 std::ostream& operator<<(std::ostream& os, const PRTRow& row);
229 
230 #endif