OverSim
ChordFingerTable.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
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 __CHORDFINGERTABLE_H_
25 #define __CHORDFINGERTABLE_H_
26 
27 #include <deque>
28 #include <map>
29 
30 #include <omnetpp.h>
31 
32 #include <NodeVector.h>
33 #include <InitStages.h>
34 
35 class BaseOverlay;
36 
37 namespace oversim {
38 
39 typedef std::multimap<simtime_t, NodeHandle> Successors;
40 typedef std::pair<NodeHandle, Successors> FingerEntry;
41 
42 class Chord;
43 
52 class ChordFingerTable : public cSimpleModule
53 {
54  public:
55 
56  virtual int numInitStages() const
57  {
58  return MAX_STAGE_OVERLAY + 1;
59  }
60 
61  virtual void initialize(int stage);
62  virtual void handleMessage(cMessage* msg);
63 
75  virtual void initializeTable(uint32_t size, const NodeHandle& owner,
76  Chord* overlay);
77 
86  virtual void setFinger(uint32_t pos, const NodeHandle& node,
87  Successors const* sucNodes = NULL);
88  virtual void setFinger(uint32_t pos, const Successors& nodes);
89 
90  virtual bool updateFinger(uint32_t pos, const NodeHandle& node, simtime_t rtt);
91 
98  virtual const NodeHandle& getFinger(uint32_t pos);
99 
100  virtual NodeVector* getFinger(uint32_t pos, const OverlayKey& key);
101 
102  bool handleFailedNode(const TransportAddress& failed);
103 
109  void removeFinger(uint32_t pos);
110 
116  virtual uint32_t getSize();
117 
118 private:
119 
120  uint32_t maxSize;
121  std::deque<FingerEntry> fingerTable;
123 };
124 
125 }; //namespace
126 
127 std::ostream& operator<<(std::ostream& os, const oversim::Successors& suc);
128 std::ostream& operator<<(std::ostream& os, const oversim::FingerEntry& entry);
129 
130 #endif