OverSim
TreeManagement.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2010 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 
25 #ifndef TREEMANAGEMENT_H_
26 #define TREEMANAGEMENT_H_
27 
28 #define MAXTREELEVEL 25 // 20 levels = 1 000 000 Nodes
29 
30 #include <map>
31 #include <oversim_mapset.h>
32 
33 #include <NodeHandle.h>
34 #include <GlobalNodeList.h>
35 #include <OverlayKey.h>
36 #include <NeighborCache.h>
38 
39 class GlobalNodeList;
40 class TransportAddress;
41 class BaseOverlay;
42 class NodeHandle;
44 
45 struct treeNodeEntry {
47  simtime_t lastTouch;
48 };
49 
50 typedef std::pair<TransportAddress, treeNodeEntry> treeNodePair;
51 typedef UNORDERED_MAP<TransportAddress, treeNodeEntry, TransportAddress::hashFcn> treeNodeMap;
52 
53 
54 class TreeManagement: public RpcListener //, public TopologyVis
55 {
56 
57 private:
58 
64 
66 
67  cMessage* treeBuildTimer;
68 
70  double deviation;
72 
73  //typedef std::pair<const char*, RpcListener*> msgClientPair;
74  //typedef UNORDERED_MAP<const char*, RpcListener*> msgClientMap;
75 
76  typedef std::pair<const char*, AbstractTreeMsgClient*> msgClientPair;
77  typedef UNORDERED_MAP<const char*, AbstractTreeMsgClient*> msgClientMap;
78 
80 
81 public:
82 
84 
85  /*
86  * Inject the Neighbour Cache Object
87  * @param Pointer to NeighborCache
88  */
90 
91  virtual ~TreeManagement();
92 
93  void handleTimerEvent(cMessage* msg);
94 
95  virtual bool handleRpcCall(BaseCallMessage* msg);
96 
98  const TransportAddress& dest,
99  cPolymorphic* context, int rpcId,
100  const OverlayKey& destKey);
101 
107 
108  /*
109  * send a message to all children
110  * @praram msg BaseCallMessage
111  */
113 
114  /*
115  * start the process an schedule it
116  */
117  void startTreeBuilding();
118 
119  /*
120  * return a node haNodeHandlendle to the current parent map
121  * @returns NodeHandle parent node
122  */
123  const NodeHandle& getParentNode();
124 
125  /*
126  * Check if the node is root (parent points to self)
127  * @returns boolean
128  */
129  bool isRoot();
130 
131  bool isChild(TransportAddress& node);
132 
133  bool isParent(TransportAddress& node);
134 
135 
139  int getCurrentTreeLevel();
140 
141  /*
142  * return the child nodes in an unorderd map
143  * @returns treeNodeMap
144  */
145  const treeNodeMap& getChildNodes();
146 
147  void addMsgClient(const char* identifier, AbstractTreeMsgClient* msgClient);
148 
149  void removeMsgClient(const char* identifier);
150 
152 
154  cPolymorphic* context,
155  int rpcId, simtime_t rtt);
156 
157  //void pingTimeout(PingCall* call, const TransportAddress& dest,
158  // cPolymorphic* context, int rpcId);
159 
163  void finishTreeManagement();
164 
165 protected:
166 
171 
176 
177  simtime_t creationTime;
178 
182  void connectToParent();
183 
184  /*
185  * Remove an existing but not longer valid connection
186  */
187  void removeParentConnection();
188 
189  /*
190  * Check if the parent is valid
191  * @returns boolean false if no connection or a connection to a not responsible parent exists - true otherwise
192  */
193  bool checkParentValid();
194 
195  /*
196  * Search for the parents domain of the actual node and send a parent request
197  */
198  bool registerAtParent();
199 
200  /*
201  * Check if the the current saved treeDomainKey is still valid
202  * @returns boolean
203  */
204  bool isTreeDomainKeyValid();
205 
206 
212 
215  cPolymorphic* context, int rpcId, simtime_t rtt);
216 
218 
219  /*
220  * Draw a line from the curent node to the given node
221  * @param treeNode Nodehandle to draw the line to
222  * @return void
223  */
224  void visualizeTreeLinkToNode(const NodeHandle& treeNode);
225 
226  void addChildNode(NodeHandle& childNode);
227 
228  virtual void handleRpcResponse(BaseResponseMessage* msg,
229  cPolymorphic* context,
230  int rpcId, simtime_t rtt);
231 
235  void sendChildReleaseCall();
236 
240  void checkTreeChildNodes();
241 
246  void removeTreeChild(const TransportAddress& childToRemove);
247 
248  void debugChildren();
249 
250  void cleanup();
251 };
252 
253 #endif /* TREEMANAGEMENT_H_ */