UnderlayConfigurator.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 _UNDERLAYCONFIGURATOR_H_
00025 #define _UNDERLAYCONFIGURATOR_H_
00026 
00027 #include <omnetpp.h>
00028 
00029 class PeerInfo;
00030 class ChurnGenerator;
00031 class NodeType;
00032 class TransportAddress;
00033 class GlobalNodeList;
00034 class GlobalStatistics;
00035 
00036 #ifndef timersub
00037 # define timersub(a, b, result)                                               \
00038 do {                                                                        \
00039     (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                             \
00040     (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                          \
00041     if ((result)->tv_usec < 0) {                                              \
00042         --(result)->tv_sec;                                                     \
00043        (result)->tv_usec += 1000000;                                           \
00044     }                                                                         \
00045 } while (0)
00046 #endif
00047 
00053 class UnderlayConfigurator : public cSimpleModule
00054 {
00055 public:
00056 
00057     UnderlayConfigurator();
00058     virtual ~UnderlayConfigurator();
00059 
00063     bool isInInitPhase() { return init; };
00064 
00068     bool isSimulationEndingSoon() { return simulationEndingSoon; };
00069 
00073     simtime_t getGracefulLeaveDelay() { return gracefulLeaveDelay; };
00074 
00075 
00076     bool isTransitionTimeFinished() { return transitionTimeFinished; };
00077 
00084     virtual TransportAddress* createNode(NodeType type, bool initialize=false) = 0;
00085 
00092     virtual void preKillNode(NodeType type, TransportAddress* addr=NULL) = 0;
00093 
00100     virtual void migrateNode(NodeType type, TransportAddress* addr=NULL) = 0;
00101 
00102     void initFinished();
00103 
00104     ChurnGenerator* getChurnGenerator(int typeID);
00105 
00106     uint8_t getChurnGeneratorNum();
00107 
00108 protected:
00109 
00113     int numInitStages() const;
00114 
00118     virtual void initialize(int stage);
00119 
00123     virtual void initializeUnderlay(int stage) = 0;
00124 
00125     virtual void handleTimerEvent(cMessage* msg);
00126 
00130     void finish();
00131 
00135     virtual void finishUnderlay();
00136 
00140     virtual void setDisplayString() = 0;
00141 
00147     void handleMessage(cMessage* msg);
00148 
00149     int overlayTerminalCount; 
00150     int firstNodeId; 
00151     simtime_t gracefulLeaveDelay; 
00152     double gracefulLeaveProbability; 
00153 
00154     GlobalNodeList* globalNodeList; 
00155     GlobalStatistics* globalStatistics; 
00156     std::vector<ChurnGenerator*> churnGenerator; 
00157 
00158     cMessage* endSimulationTimer; 
00159     cMessage* endSimulationNotificationTimer; 
00160     cMessage* endTransitionTimer; 
00161 
00162     struct timeval initFinishedTime; 
00163     struct timeval initStartTime; 
00164 
00165     simtime_t transitionTime; 
00166     simtime_t measurementTime; 
00167 
00168     static const unsigned int NUM_COLORS;
00169     static const char* colorNames[];
00170 
00171 private:
00172     bool init;
00173     bool simulationEndingSoon;
00174     bool transitionTimeFinished;
00175     unsigned int initCounter;
00176 
00177     void consoleOut(const std::string& text);
00178 };
00179 
00180 #endif
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3