Nice.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2009 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 __NICE_H_
00025 #define __NICE_H_
00026 
00027 namespace oversim
00028 {
00029 
00030 class Nice;
00031 
00032 }
00033 
00034 #include <BaseOverlay.h>
00035 #include "NiceCluster.h"
00036 #include "NiceMessage_m.h"
00037 #include "NicePeerInfo.h"
00038 #include <hashWatch.h>
00039 #include <vector>
00040 #include "combination.h"
00041 #include <algorithm>
00042 
00043 #include <fstream>
00044 
00045 namespace oversim
00046 {
00047 
00048 /* The maximum of supported layers, fix for easier handling of structures */
00049 const short maxLayers = 10;
00050 
00051 /* Define set of TransportAdresses and iterator */
00052 typedef std::set<TransportAddress> TaSet;
00053 typedef std::set<TransportAddress>::iterator TaSetIt;
00054 
00060 static TransportAddress RendevouzPoint = TransportAddress::UNSPECIFIED_NODE;
00061 
00072 class Nice : public BaseOverlay
00073 {
00074 
00075     friend class NicePeerInfo;
00076 
00077 public:
00078 
00079     /* Constructor and Destructor */
00080     Nice();
00081     virtual ~Nice();
00082 
00083     /* See BaseOverlay.h */
00084     virtual void initializeOverlay( int stage );
00085 
00086     virtual void handleTimerEvent(cMessage* msg);
00087 
00088     virtual void handleUDPMessage(BaseOverlayMessage* msg);
00089 
00090     virtual void handleAppMessage(cMessage* msg);
00091 
00092     virtual void finishOverlay();
00093 
00094 
00095 protected:
00096 
00102     virtual void changeState(int toState);
00103 
00104     /* see BaseOverlay.h */
00105     virtual void joinOverlay();
00106 
00107 
00108 private:
00109 
00110     int pimp;
00111 
00112     /* Periodic Self-Messages and their intervals */
00113 
00114     /* Timer for heartbeats by every member node */
00115     cMessage* heartbeatTimer;
00116     simtime_t heartbeatInterval;
00117 
00118     /* Timer structure maintenance */
00119     cMessage* maintenanceTimer;
00120     simtime_t maintenanceInterval;
00121 
00122     /* Timer for query timeouts */
00123     cMessage* queryTimer;
00124     simtime_t queryInterval;
00125 
00126     /* Timer to detect lost connection to nice hierarchy */
00127     cMessage* structureConnectionTimer;
00128     simtime_t structureConnectionInterval;
00129 
00130     /* Timer poll the Rendevouz Point */
00131     cMessage* rpPollTimer;
00132     simtime_t rpPollTimerInterval;
00133 
00134     simtime_t peerTimeoutInterval;
00135 
00136     /* For Visualization only */
00137     cMessage* visualizationTimer;
00138 
00139     void updateVisualization();
00140 
00141     /* Double leader resolution */
00142     simtime_t first_HB;
00143     TransportAddress first_leader;
00144     simtime_t second_HB;
00145     TransportAddress second_leader;
00146 
00147     std::vector<std::pair<TransportAddress, simtime_t> > leaderHeartbeats;
00148 
00149     /* DEBUG */
00150     int clusterrefinement;
00151     int debug_heartbeats;
00152     int debug_visualization;
00153     int debug_join;
00154     int debug_peertimeouts;
00155     int debug_removes;
00156     int debug_queries;
00157 
00158     /* Cluster parameter k */
00159     unsigned short k;
00160 
00161     /* Cluster Information */
00162     NiceCluster clusters[maxLayers];
00163 
00164     /* Holds the current layer we query, if we do */
00165     int evalLayer;
00166     int joinLayer;
00167 
00168     bool isPollingRP;
00169 
00170     /* Holds the query start time for RTT evaluation */
00171     simtime_t query_start;
00172 
00173     /* The current queried node */
00174     TransportAddress tempResolver;
00175 
00176     /* distance to first queried node that answers */
00177     simtime_t query_compare;
00178 
00179     /* Layer intended to join */
00180     short targetLayer;
00181 
00182     /* Map for all peer infos */
00183     std::map<TransportAddress, NicePeerInfo*> peerInfos;
00184 
00185     /* set holding temporary peered joiner nodes */
00186     std::map<TransportAddress, simtime_t> tempPeers;
00187     bool isTempPeered;
00188 
00189     double CLUSTERLEADERBOUND;
00190     double CLUSTERLEADERCOMPAREDIST;
00191     double SC_PROC_DISTANCE;
00192     double SC_MIN_OFFSET;
00193 
00194     /* Makes node Rendevouz Point */
00195     void becomeRendevouzPoint();
00196 
00197     /* Find highest layer in which node is leader */
00198     short getHighestLeaderLayer();
00199 
00200     /* Find highest layer in which node resides */
00201     short getHighestLayer();
00202 
00203     /* Joining the hierarchy from scratch */
00204     void BasicJoinLayer(short layer);
00205 
00206     /* Splits a cluster */
00207     void ClusterSplit(int layer);
00208 
00209     /* Request sublayer information from a cluster leader */
00210     void Query(const TransportAddress& node, short layer);
00211 
00212     /* Handles queries */
00213     void handleQuery(NiceMessage* queryMsg);
00214 
00215     /* Handles query responses */
00216     void handleQueryResponse(NiceMemberMessage* queryRspMsg);
00217 
00218     /* Joins a cluster */
00219     void JoinCluster(const TransportAddress& leader, short layer);
00220 
00221     /* Handles cluster join requests */
00222     void handleJoinCluster(NiceMessage* joinMsg);
00223 
00224     /* Sends heartbeats to all clusters the node resides in */
00225     void sendHeartbeats();
00226 
00227     /* Handles heartbeats */
00228     void handleHeartbeat(NiceMessage* msg);
00229 
00230     /* Periodic maintenance of the protocol hierarchy */
00231     void maintenance();
00232 
00233     /* Determines the max distance of a member in a cluster */
00234     simtime_t getMaxDistance(TransportAddress member, std::set<TransportAddress> neighbors);
00235 
00236     /* Determines the mean distance of a cluster */
00237     simtime_t getMeanDistance(std::set<TransportAddress> neighbors);
00238 
00239     /* Initiates a LeaderTransfer message */
00240     void LeaderTransfer(int layer, TransportAddress leader, TaSet cluster, TransportAddress sc_leader);
00241 
00242     /* Removes node from cluster */
00243     void Remove(int layer);
00244 
00245     /* Sends Heartbeat to specific member */
00246     void sendHeartbeatTo(const TransportAddress& node, int layer);
00247 
00248     /* Merges two clusters */
00249     void ClusterMerge(int layer);
00250 
00251     /* Sends a ClusterMerge request message */
00252     void ClusterMergeRequest(const TransportAddress& node, int layer);
00253 
00254     /* Leaves structure gracefully */
00255     void gracefulLeave(short bottomLayer);
00256 
00257     /* Determines a new appropriate cluster leader */
00258     TransportAddress findClusterLeader(NiceCluster cluster);
00259 
00260     /* Determines the center of a cluster */
00261     std::pair<TransportAddress,simtime_t> findCenter(TaSet cluster, bool allowRandom = false);
00262     std::pair<TransportAddress, simtime_t> findCenter(std::vector<TransportAddress> cluster, bool allowRandom = false);
00263 
00264     void sendDataToOverlay(CbrAppMessage *appMsg);
00265 
00266     void pollRP(int layer);
00267 
00268 };
00269 
00270 }; //namespace
00271 
00272 #endif
00273 

Generated on Tue Sep 8 17:26:53 2009 for OverSim by  doxygen 1.5.8