OverSim
NTree.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 __NTREE_H_
25 #define __NTREE_H_
26 
27 #include <omnetpp.h>
28 #include <NodeHandle.h>
29 #include <BaseOverlay.h>
30 #include "NTreeHelper.h"
31 #include "NTree_m.h"
32 
45 class NTree : public BaseOverlay
46 {
47  public:
48  // OMNeT++
49  virtual ~NTree();
50  virtual void initializeOverlay(int stage);
51  virtual void finishOverlay();
52  virtual void handleUDPMessage(BaseOverlayMessage* msg);
53  virtual void handleTimerEvent(cMessage* msg);
54  virtual void handleAppMessage(cMessage* msg);
55  virtual bool handleRpcCall(BaseCallMessage* msg);
56  virtual void handleRpcResponse(BaseResponseMessage *msg,
57  cPolymorphic* context,
58  int rpcId, simtime_t rtt);
59  virtual void handleRpcTimeout(BaseCallMessage *msg,
60  const TransportAddress & dest,
61  cPolymorphic* context,
62  int rpcId, const OverlayKey &destKey);
63 
64  protected:
65 
66  void setBootstrapedIcon();
72  void handleMove( GameAPIPositionMessage* posMsg );
78  void handleMoveMessage( NTreeMoveMessage* moveMsg );
84  void handleJoinCall( NTreeJoinCall* joinCall );
90  void handleJoinResponse( NTreeJoinResponse* joinResp );
98  void handleJoinCallTimeout( NTreeJoinCall* joinCall, const TransportAddress& oldNode );
106  void handlePingCall( NTreePingCall* pingCall );
113  void handlePingResponse( NTreePingResponse* pingResp, NTreePingContext* context );
122  void handlePingCallTimeout( NTreePingCall* pingCall, const TransportAddress& oldNode, NTreePingContext* context );
128  void handleDivideCall( NTreeDivideCall* divideCall );
144  void handleDivideCallTimeout( NTreeDivideCall* divideCall, const TransportAddress& oldNode, NTreeGroupDivideContext* context );
150  void handleAddMessage( NTreeGroupAddMessage* addMsg );
156  void handleDeleteMessage( NTreeGroupDeleteMessage* deleteMsg );
162  void handleLeaveMessage( NTreeLeaveMessage* leaveMsg );
168  void handleCollapseMessage( NTreeCollapseMessage* collapseMsg );
174  void handleReplaceMessage( NTreeReplaceNodeMessage* replaceMsg );
181 
183 
190  void divideNode( NTreeGroupDivideContext* context );
197  void collapseTree( std::map<NTreeScope,NTreeNode>::iterator node );
203  void joinGroup( Vector2D position );
204 
211  void leaveGroup( Vector2D position, bool force = false);
212 
216  void pingNodes();
217 
221  void checkParentTimeout();
222 
230  void routeViaNTree( const Vector2D& pos, cPacket* msg, bool forward = false);
231 
239  void sendToGroup( const NTreeGroup& grp, cPacket* msg, bool keepMsg = false);
240 
248  void sendToGroup( const std::set<NodeHandle>& grp, cPacket* msg, bool keepMsg = false);
249 
257  void sendMessage(const TransportAddress& dest, cPacket* msg, bool forward = false);
258 
264  void changeState( int state );
265 
266  unsigned int AOIWidth;
267  unsigned int maxChildren;
271 
272  simtime_t pingInterval;
273 
274  cMessage* joinTimer;
275  cMessage* pingTimer;
276 
277  std::list<NTreeGroup> groups;
278  std::map<NTreeScope,NTreeNode> ntreeNodes;
279 
285  std::list<NTreeGroup>::iterator findGroup(const Vector2D& pos);
293  std::list<NTreeGroup>::iterator findGroup(const Vector2D& pos, double size);
299  std::map<NTreeScope,NTreeNode>::iterator findNTreeNode(const Vector2D& pos);
306  std::map<NTreeScope,NTreeNode>::iterator findNTreeNode(const Vector2D& pos, double size);
307 
313  NodeHandle getRandomNode( std::set<NodeHandle> invalidNodes = std::set<NodeHandle>() );
314 
315  // statistics
316  unsigned int joinsSend;
317  unsigned int joinBytes;
318  unsigned int joinTimeout;
319 
320  unsigned int divideCount;
321  unsigned int collapseCount;
322 
324  unsigned int treeMaintenanceBytes;
325 
326  unsigned int movesSend;
327  unsigned int moveBytes;
328 };
329 
330 #endif