LifetimeChurn Class Reference

#include <LifetimeChurn.h>

Inheritance diagram for LifetimeChurn:

ChurnGenerator

List of all members.


Detailed Description

Lifetime based churn generating class.

Public Member Functions

void handleMessage (cMessage *msg)
void initializeChurn ()
 ~LifetimeChurn ()

Protected Member Functions

void updateDisplayString ()
void createNode (double lifetime, bool initialize)
void deleteNode (TransportAddress &addr)
double distributionFunction ()
void scheduleCreateNodeAt (double creationTime, double lifetime)

Private Attributes

GlobalStatisticsglobalStatistics
double initialMean
 mean of update interval during initalization phase
double initialDeviation
 deviation of update interval during initalization phase
double targetMean
 mean of update interval after initalization phase
std::string lifetimeDistName
 name of the distribution function
double lifetimeMean
 mean node lifetime
double lifetimeDistPar1
 distribution function parameter
cMessage * initFinishedTimer
 timer to signal end of init phase
double lastCreate
double lastDelete

Constructor & Destructor Documentation

LifetimeChurn::~LifetimeChurn (  ) 

00166 {
00167     cancelAndDelete(initFinishedTimer);
00168 }


Member Function Documentation

void LifetimeChurn::handleMessage ( cMessage *  msg  )  [virtual]

Implements ChurnGenerator.

00074 {
00075     if (!msg->isSelfMessage()) {
00076         delete msg;
00077         return;
00078     }
00079 
00080     // init phase finished
00081     if (msg == initFinishedTimer) {
00082         underlayConfigurator->initFinished();
00083         return;
00084     }
00085 
00086     ChurnMessage* churnMsg = check_and_cast<ChurnMessage*>(msg);
00087     
00088     if (churnMsg->getCreateNode() == true) {
00089         createNode(churnMsg->getLifetime(), false);
00090     } else {
00091         deleteNode(churnMsg->getAddr());
00092     }
00093     
00094     delete msg;
00095 }

void LifetimeChurn::initializeChurn (  )  [virtual]

Implements ChurnGenerator.

00030 {
00031     Enter_Method_Silent();
00032 
00033     initialMean = par("initialMobilityDelay");
00034     initialDeviation = initialMean / 3;
00035     lifetimeMean = par("lifetimeMean");
00036     lifetimeDistName = std::string(par("lifetimeDistName"));
00037     lifetimeDistPar1 = par("lifetimeDistPar1");
00038     
00039     if (lifetimeDistPar1 != 1) {
00040         opp_error("LifetimeChurn currently only works with "
00041           "lifetimeDistPar1=1");
00042     }
00043 
00044     WATCH(lifetimeMean);
00045 
00046     globalStatistics = GlobalStatisticsAccess().get();
00047 
00048     lastCreate = lastDelete = simulation.simTime();
00049 
00050     double initFinishedTime = initialMean * targetOverlayTerminalNum;
00051 
00052 
00053     // create the remaining nodes in bootstrap phase
00054     int targetOverlayTerminalNum = par("targetOverlayTerminalNum");
00055     for (int i = 0; i < targetOverlayTerminalNum; i++) {
00056 
00057         scheduleCreateNodeAt(truncnormal(initialMean*i, initialDeviation),
00058                              initFinishedTime +
00059                              distributionFunction() -
00060                              truncnormal(initialMean*i, initialDeviation));
00061 
00062         // create same number of currently dead nodes
00063         scheduleCreateNodeAt(initFinishedTime +
00064                              distributionFunction(),
00065                              distributionFunction());
00066     }
00067 
00068     initFinishedTimer = new cMessage("initFinishedTimer");
00069 
00070     scheduleAt(initFinishedTime, initFinishedTimer);
00071 }

void LifetimeChurn::updateDisplayString (  )  [protected, virtual]

Implements ChurnGenerator.

00159 {
00160     char buf[80];
00161     sprintf(buf, "lifetime churn");
00162     displayString().setTagArg("t", 0, buf);
00163 }

void LifetimeChurn::createNode ( double  lifetime,
bool  initialize 
) [protected]

00098 {
00099     ChurnMessage* churnMsg = new ChurnMessage("DeleteNode");
00100     TransportAddress* ta = underlayConfigurator->createNode(type, initialize);
00101     churnMsg->setAddr(*ta);
00102     delete ta;
00103     churnMsg->setCreateNode(false);
00104     scheduleAt(max(simulation.simTime(), simulation.simTime()
00105                    + lifetime - underlayConfigurator->getGracefulLeaveDelay()),
00106                    churnMsg);
00107     
00108     RECORD_STATS(globalStatistics->recordOutVector(
00109         "BaseOverlay: Session Time", lifetime));
00110     RECORD_STATS(globalStatistics->recordOutVector(
00111         "BaseOverlay: Time between creates",
00112         simulation.simTime() - lastCreate));
00113 
00114     lastCreate = simulation.simTime();
00115 }

void LifetimeChurn::deleteNode ( TransportAddress addr  )  [protected]

00118 {
00119     underlayConfigurator->preKillNode(NodeType(), &addr);
00120 
00121     scheduleCreateNodeAt(simulation.simTime()
00122                          + distributionFunction(), distributionFunction());
00123     
00124     RECORD_STATS(globalStatistics->recordOutVector(
00125         "BaseOverlay: Time between deletes", 
00126         simulation.simTime() - lastDelete));
00127     
00128     lastDelete = simulation.simTime();
00129 }

double LifetimeChurn::distributionFunction (  )  [protected]

00140 {
00141     double par;
00142 
00143     if (lifetimeDistName == "weibull") {
00144         par = lifetimeMean / tgamma(1 + (1/lifetimeDistPar1));
00145         return weibull(par, lifetimeDistPar1);
00146     } else if (lifetimeDistName == "pareto_shifted") {
00147         par = lifetimeMean * (lifetimeDistPar1-1) / lifetimeDistPar1;
00148         return pareto_shifted(lifetimeDistPar1, par, 0);
00149     } else {
00150         opp_error("LifetimeChurn::distribution function: Invalid value "
00151                   "for parameter lifetimeDistName!");
00152     }
00153     
00154     return 0;
00155 }

void LifetimeChurn::scheduleCreateNodeAt ( double  creationTime,
double  lifetime 
) [protected]

00132 {
00133     ChurnMessage* churnMsg = new ChurnMessage("CreateNode");
00134     churnMsg->setCreateNode(true);
00135     churnMsg->setLifetime(lifetime);
00136     scheduleAt(creationTime, churnMsg);
00137 }


Member Data Documentation

GlobalStatistics* LifetimeChurn::globalStatistics [private]

double LifetimeChurn::initialMean [private]

mean of update interval during initalization phase

double LifetimeChurn::initialDeviation [private]

deviation of update interval during initalization phase

double LifetimeChurn::targetMean [private]

mean of update interval after initalization phase

std::string LifetimeChurn::lifetimeDistName [private]

name of the distribution function

double LifetimeChurn::lifetimeMean [private]

mean node lifetime

double LifetimeChurn::lifetimeDistPar1 [private]

distribution function parameter

cMessage* LifetimeChurn::initFinishedTimer [private]

timer to signal end of init phase

double LifetimeChurn::lastCreate [private]

double LifetimeChurn::lastDelete [private]


The documentation for this class was generated from the following files:
Generated on Thu Apr 17 13:19:29 2008 for ITM OverSim by  doxygen 1.5.3