NTree.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00024 #ifndef __NTREE_H_
00025 #define __NTREE_H_
00026 
00027 #include <omnetpp.h>
00028 #include <NodeHandle.h>
00029 #include <BaseOverlay.h>
00030 #include "NTreeHelper.h"
00031 #include "NTree_m.h"
00032 
00045 class NTree : public BaseOverlay
00046 {
00047     public:
00048         // OMNeT++
00049         virtual ~NTree();
00050         virtual void initializeOverlay(int stage);
00051         virtual void finishOverlay();
00052         virtual void handleUDPMessage(BaseOverlayMessage* msg);
00053         virtual void handleTimerEvent(cMessage* msg);
00054         virtual void handleAppMessage(cMessage* msg);
00055         virtual bool handleRpcCall(BaseCallMessage* msg);
00056         virtual void handleRpcResponse(BaseResponseMessage *msg,
00057                                        cPolymorphic* context,
00058                                        int rpcId, simtime_t rtt);
00059         virtual void handleRpcTimeout(BaseCallMessage *msg,
00060                                       const TransportAddress & dest,
00061                                       cPolymorphic* context,
00062                                       int rpcId, const OverlayKey &destKey);
00063 
00064     protected:
00065 
00066         void setBootstrapedIcon();
00072         void handleMove( GameAPIPositionMessage* posMsg );
00078         void handleMoveMessage( NTreeMoveMessage* moveMsg );
00084         void handleJoinCall( NTreeJoinCall* joinCall );
00090         void handleJoinResponse( NTreeJoinResponse* joinResp );
00098         void handleJoinCallTimeout( NTreeJoinCall* joinCall, const TransportAddress& oldNode );
00106         void handlePingCall( NTreePingCall* pingCall );
00113         void handlePingResponse( NTreePingResponse* pingResp, NTreePingContext* context );
00122         void handlePingCallTimeout( NTreePingCall* pingCall, const TransportAddress& oldNode, NTreePingContext* context );
00128         void handleDivideCall( NTreeDivideCall* divideCall );
00135         void handleDivideResponse( NTreeDivideResponse* divideResp, NTreeGroupDivideContext* context );
00144         void handleDivideCallTimeout( NTreeDivideCall* divideCall, const TransportAddress& oldNode, NTreeGroupDivideContext* context );
00150         void handleAddMessage( NTreeGroupAddMessage* addMsg );
00156         void handleDeleteMessage( NTreeGroupDeleteMessage* deleteMsg );
00162         void handleLeaveMessage( NTreeLeaveMessage* leaveMsg );
00168         void handleCollapseMessage( NTreeCollapseMessage* collapseMsg );
00174         void handleReplaceMessage( NTreeReplaceNodeMessage* replaceMsg );
00180         void handleTakeOverMessage( NTreeTakeOverMessage* takeMsg );
00181 
00182         void handleNodeGracefulLeaveNotification();
00183 
00190         void divideNode( NTreeGroupDivideContext* context );
00197         void collapseTree( std::map<NTreeScope,NTreeNode>::iterator node );
00203         void joinGroup( Vector2D position );
00204 
00211         void leaveGroup( Vector2D position, bool force = false);
00212 
00216         void pingNodes();
00217 
00221         void checkParentTimeout();
00222 
00230         void routeViaNTree( const Vector2D& pos, cPacket* msg, bool forward = false);
00231 
00239         void sendToGroup( const NTreeGroup& grp, cPacket* msg, bool keepMsg = false);
00240 
00248         void sendToGroup( const std::set<NodeHandle>& grp, cPacket* msg, bool keepMsg = false);
00249 
00257         void sendMessage(const TransportAddress& dest, cPacket* msg, bool forward = false);
00258 
00264         void changeState( int state );
00265 
00266         unsigned int AOIWidth;
00267         unsigned int maxChildren;
00268         double areaDimension;
00269         Vector2D position;
00270         NTreeGroup* currentGroup;
00271 
00272         simtime_t pingInterval;
00273 
00274         cMessage* joinTimer;
00275         cMessage* pingTimer;
00276 
00277         std::list<NTreeGroup> groups;
00278         std::map<NTreeScope,NTreeNode> ntreeNodes;
00279 
00285         std::list<NTreeGroup>::iterator findGroup(const Vector2D& pos);
00293         std::list<NTreeGroup>::iterator findGroup(const Vector2D& pos, double size);
00299         std::map<NTreeScope,NTreeNode>::iterator findNTreeNode(const Vector2D& pos);
00306         std::map<NTreeScope,NTreeNode>::iterator findNTreeNode(const Vector2D& pos, double size);
00307 
00313         NodeHandle getRandomNode( std::set<NodeHandle> invalidNodes = std::set<NodeHandle>() );
00314 
00315         // statistics
00316         unsigned int joinsSend;
00317         unsigned int joinBytes;
00318         unsigned int joinTimeout;
00319 
00320         unsigned int divideCount;
00321         unsigned int collapseCount;
00322 
00323         unsigned int treeMaintenanceMessages;
00324         unsigned int treeMaintenanceBytes;
00325 
00326         unsigned int movesSend;
00327         unsigned int moveBytes;
00328 };
00329 
00330 #endif