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     // Statistics
00195     int numInconsistencies;
00196 
00197     int numQueryTimeouts;
00198 
00199     int numPeerTimeouts;
00200 
00201     int numTempPeerTimeouts;
00202 
00203     int numStructurePartitions;
00204 
00205     int numOwnMessagesReceived;
00206 
00207     double totalSCMinCompare;
00208 
00209     int numJoins;
00210 
00211     int numForward;
00212 
00213     int totalForwardBytes;
00214 
00215     int numReceived;
00216 
00217     int totalReceivedBytes;
00218 
00219     int numHeartbeat;
00220 
00221     int totalHeartbeatBytes;
00222 
00223     /* Makes node Rendevouz Point */
00224     void becomeRendevouzPoint();
00225 
00226     /* Find highest layer in which node is leader */
00227     short getHighestLeaderLayer();
00228 
00229     /* Find highest layer in which node resides */
00230     short getHighestLayer();
00231 
00232     /* Joining the hierarchy from scratch */
00233     void BasicJoinLayer(short layer);
00234 
00235     /* Splits a cluster */
00236     void ClusterSplit(int layer);
00237 
00238     /* Request sublayer information from a cluster leader */
00239     void Query(const TransportAddress& node, short layer);
00240 
00241     /* NICE message handlers */
00242     void handleNiceClusterMergeRequest(NiceClusterMerge* mergeMsg);
00243 
00244     void handleNiceForceMerge(NiceMessage* msg);
00245 
00246     void handleNiceHeartbeat(NiceMessage* msg);
00247 
00248     void handleNiceJoinCluster(NiceMessage* joinMsg);
00249 
00250     void handleNiceJoineval(NiceMessage* msg);
00251 
00252     void handleNiceJoinevalResponse(NiceMessage* msg);
00253 
00254     void handleNiceLeaderHeartbeatOrTransfer(NiceMessage* msg);
00255 
00256     void handleNiceMulticast(NiceMulticastMessage* multicastMsg);
00257 
00258     void handleNicePeerTemporary(NiceMessage* msg);
00259 
00260     void handleNicePeerTemporaryRelease(NiceMessage* msg);
00261 
00262     void handleNicePingProbe(NiceMessage* msg);
00263 
00264     void handleNicePingProbeResponse(NiceMessage* msg);
00265 
00266     void handleNicePollRp(NiceMessage* msg);
00267 
00268     void handleNicePollRpResponse(NiceMessage* msg);
00269 
00270     void handleNiceQuery(NiceMessage* queryMsg);
00271 
00272     void handleNiceQueryResponse(NiceMemberMessage* queryRspMsg);
00273 
00274     void handleNiceRemove(NiceMessage* msg);
00275 
00276 
00277     /* Joins a cluster */
00278     void JoinCluster(const TransportAddress& leader, short layer);
00279 
00280     /* Sends heartbeats to all clusters the node resides in */
00281     void sendHeartbeats();
00282 
00283     /* Periodic maintenance of the protocol hierarchy */
00284     void maintenance();
00285 
00286     /* Determines the max distance of a member in a cluster */
00287     simtime_t getMaxDistance(TransportAddress member, std::set<TransportAddress> neighbors);
00288 
00289     /* Determines the mean distance of a cluster */
00290     simtime_t getMeanDistance(std::set<TransportAddress> neighbors);
00291 
00292     /* Initiates a LeaderTransfer message */
00293     void LeaderTransfer(int layer, TransportAddress leader, TaSet cluster, TransportAddress sc_leader);
00294 
00295     /* Removes node from cluster */
00296     void Remove(int layer);
00297 
00298     /* Sends Heartbeat to specific member */
00299     void sendHeartbeatTo(const TransportAddress& node, int layer);
00300 
00301     /* Merges two clusters */
00302     void ClusterMerge(int layer);
00303 
00304     /* Sends a ClusterMerge request message */
00305     void ClusterMergeRequest(const TransportAddress& node, int layer);
00306 
00307     /* Leaves structure gracefully */
00308     void gracefulLeave(short bottomLayer);
00309 
00310     /* Determines a new appropriate cluster leader */
00311     TransportAddress findClusterLeader(NiceCluster cluster);
00312 
00313     /* Determines the center of a cluster */
00314     std::pair<TransportAddress,simtime_t> findCenter(TaSet cluster, bool allowRandom = false);
00315     std::pair<TransportAddress, simtime_t> findCenter(std::vector<TransportAddress> cluster, bool allowRandom = false);
00316 
00317     void sendDataToOverlay(NiceMulticastMessage *appMsg);
00318 
00319     void pollRP(int layer);
00320 
00321 };
00322 
00323 }; //namespace
00324 
00325 #endif
00326 
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3