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 initialization phase
double initialDeviation
 deviation of update interval during initialization phase
double targetMean
 mean of update interval after initialization 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 (  ) 

00172 {
00173     cancelAndDelete(initFinishedTimer);
00174 }


Member Function Documentation

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

Implements ChurnGenerator.

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

void LifetimeChurn::initializeChurn (  )  [virtual]

Implements ChurnGenerator.

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

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

Implements ChurnGenerator.

00165 {
00166     char buf[80];
00167     sprintf(buf, "lifetime churn");
00168     displayString().setTagArg("t", 0, buf);
00169 }

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

Referenced by handleMessage().

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

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

Referenced by handleMessage().

00122 {
00123     underlayConfigurator->preKillNode(NodeType(), &addr);
00124 
00125     scheduleCreateNodeAt(simulation.simTime() + distributionFunction(),
00126                          distributionFunction());
00127 
00128     RECORD_STATS(globalStatistics->recordOutVector(
00129                  "LifetimeChurn: Time between deletes",
00130                  simulation.simTime() - lastDelete));
00131 
00132     lastDelete = simulation.simTime();
00133 }

double LifetimeChurn::distributionFunction (  )  [protected]

Referenced by deleteNode(), and initializeChurn().

00144 {
00145     double par;
00146 
00147     if (lifetimeDistName == "weibull") {
00148         par = lifetimeMean / tgamma(1 + (1 / lifetimeDistPar1));
00149         return weibull(par, lifetimeDistPar1);
00150     } else if (lifetimeDistName == "pareto_shifted") {
00151         par = lifetimeMean * (lifetimeDistPar1 - 1) / lifetimeDistPar1;
00152         return pareto_shifted(lifetimeDistPar1, par, 0);
00153     } else if (lifetimeDistName == "truncnormal") {
00154         par = lifetimeMean;
00155         return truncnormal(par, par/3.0);
00156     } else {
00157         opp_error("LifetimeChurn::distribution function: Invalid value "
00158             "for parameter lifetimeDistName!");
00159     }
00160 
00161     return 0;
00162 }

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

Referenced by deleteNode(), and initializeChurn().

00136 {
00137     ChurnMessage* churnMsg = new ChurnMessage("CreateNode");
00138     churnMsg->setCreateNode(true);
00139     churnMsg->setLifetime(lifetime);
00140     scheduleAt(creationTime, churnMsg);
00141 }


Member Data Documentation

double LifetimeChurn::initialMean [private]

mean of update interval during initialization phase

Referenced by initializeChurn().

deviation of update interval during initialization phase

Referenced by initializeChurn().

double LifetimeChurn::targetMean [private]

mean of update interval after initialization phase

std::string LifetimeChurn::lifetimeDistName [private]

name of the distribution function

Referenced by distributionFunction(), and initializeChurn().

double LifetimeChurn::lifetimeMean [private]

mean node lifetime

Referenced by distributionFunction(), and initializeChurn().

distribution function parameter

Referenced by distributionFunction(), and initializeChurn().

cMessage* LifetimeChurn::initFinishedTimer [private]

timer to signal end of init phase

Referenced by handleMessage(), initializeChurn(), and ~LifetimeChurn().

double LifetimeChurn::lastCreate [private]

Referenced by createNode(), and initializeChurn().

double LifetimeChurn::lastDelete [private]

Referenced by deleteNode(), and initializeChurn().


The documentation for this class was generated from the following files:

Generated on Fri Sep 19 13:05:07 2008 for ITM OverSim by  doxygen 1.5.5