OverSim
LifetimeChurn Class Reference

Lifetime based churn generating class. More...

#include <LifetimeChurn.h>

Inheritance diagram for LifetimeChurn:
ChurnGenerator

Public Member Functions

void handleMessage (cMessage *msg)
void initializeChurn ()
 LifetimeChurn ()
 ~LifetimeChurn ()
- Public Member Functions inherited from ChurnGenerator
virtual int numInitStages () const
virtual void initialize (int stage)
void setNodeType (const NodeType &t)
const NodeTypegetNodeType ()

Protected Member Functions

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

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
std::vector< cObject * > contextVector
 context pointer vector
simtime_t lastCreate
simtime_t lastDelete

Additional Inherited Members

- Public Attributes inherited from ChurnGenerator
bool init
 still in initialization phase?
int terminalCount
 current number of overlay terminals
- Protected Attributes inherited from ChurnGenerator
UnderlayConfiguratorunderlayConfigurator
int targetOverlayTerminalNum
 final number of overlay terminals
NodeType type
 the nodeType this generator is responsible for

Detailed Description

Lifetime based churn generating class.

Definition at line 36 of file LifetimeChurn.h.

Constructor & Destructor Documentation

LifetimeChurn::LifetimeChurn ( )
inline

Definition at line 41 of file LifetimeChurn.h.

{ initFinishedTimer = NULL; };
LifetimeChurn::~LifetimeChurn ( )

Definition at line 176 of file LifetimeChurn.cc.

{
cancelAndDelete(initFinishedTimer);
for (std::vector<cObject*>::iterator it = contextVector.begin();
it != contextVector.end(); it++) {
if (*it) {
delete *it;
}
}
}

Member Function Documentation

void LifetimeChurn::createNode ( simtime_t  lifetime,
bool  initialize,
int  contextPos 
)
protected

Definition at line 100 of file LifetimeChurn.cc.

Referenced by handleMessage().

{
ChurnMessage* churnMsg = new ChurnMessage("DeleteNode");
NodeType createType = type;
createType.context = &(contextVector[contextPos]);
churnMsg->setAddr(*ta);
churnMsg->setContextPos(contextPos);
delete ta;
churnMsg->setCreateNode(false);
scheduleAt(std::max(simTime(), simTime() + lifetime
"LifetimeChurn: Session Time", SIMTIME_DBL(lifetime)));
"LifetimeChurn: Time between creates",
SIMTIME_DBL(simTime() - lastCreate)));
lastCreate = simTime();
}
void LifetimeChurn::deleteNode ( TransportAddress addr,
int  contextPos 
)
protected

Definition at line 124 of file LifetimeChurn.cc.

Referenced by handleMessage().

{
distributionFunction(), contextPos);
"LifetimeChurn: Time between deletes",
SIMTIME_DBL(simTime() - lastDelete)));
lastDelete = simTime();
}
double LifetimeChurn::distributionFunction ( )
protected

Definition at line 148 of file LifetimeChurn.cc.

Referenced by deleteNode(), and initializeChurn().

{
double par;
if (lifetimeDistName == "weibull") {
par = lifetimeMean / tgamma(1 + (1 / lifetimeDistPar1));
return weibull(par, lifetimeDistPar1);
} else if (lifetimeDistName == "pareto_shifted") {
return pareto_shifted(lifetimeDistPar1, par, 0);
} else if (lifetimeDistName == "truncnormal") {
par = lifetimeMean;
return truncnormal(par, par/3.0);
} else {
opp_error("LifetimeChurn::distribution function: Invalid value "
"for parameter lifetimeDistName!");
}
return 0;
}
void LifetimeChurn::handleMessage ( cMessage *  msg)
virtual

Implements ChurnGenerator.

Definition at line 73 of file LifetimeChurn.cc.

{
if (!msg->isSelfMessage()) {
delete msg;
return;
}
// init phase finished
if (msg == initFinishedTimer) {
cancelEvent(initFinishedTimer);
return;
}
ChurnMessage* churnMsg = check_and_cast<ChurnMessage*> (msg);
if (churnMsg->getCreateNode() == true) {
createNode(churnMsg->getLifetime(), false, churnMsg->getContextPos());
} else {
deleteNode(churnMsg->getAddr(), churnMsg->getContextPos());
}
delete msg;
}
void LifetimeChurn::initializeChurn ( )
virtual

Implements ChurnGenerator.

Definition at line 34 of file LifetimeChurn.cc.

{
Enter_Method_Silent();
initialMean = par("initPhaseCreationInterval");
lifetimeMean = par("lifetimeMean");
lifetimeDistName = par("lifetimeDistName").stdstringValue();
lifetimeDistPar1 = par("lifetimeDistPar1");
WATCH(lifetimeMean);
lastCreate = lastDelete = simTime();
simtime_t initFinishedTime = initialMean * targetOverlayTerminalNum;
// create the remaining nodes in bootstrap phase
int targetOverlayTerminalNum = par("targetOverlayTerminalNum");
contextVector.assign(2*targetOverlayTerminalNum, (cObject*)NULL);
for (int i = 0; i < targetOverlayTerminalNum; i++) {
initFinishedTime + distributionFunction()
- truncnormal(initialMean * i,
// create same number of currently dead nodes
distributionFunction(), targetOverlayTerminalNum + i);
}
initFinishedTimer = new cMessage("initFinishedTimer");
scheduleAt(initFinishedTime, initFinishedTimer);
}
void LifetimeChurn::scheduleCreateNodeAt ( simtime_t  creationTime,
simtime_t  lifetime,
int  contextPos 
)
protected

Definition at line 138 of file LifetimeChurn.cc.

Referenced by deleteNode(), and initializeChurn().

{
ChurnMessage* churnMsg = new ChurnMessage("CreateNode");
churnMsg->setCreateNode(true);
churnMsg->setLifetime(SIMTIME_DBL(lifetime));
churnMsg->setContextPos(contextPos);
scheduleAt(creationTime, churnMsg);
}
void LifetimeChurn::updateDisplayString ( )
protectedvirtual

Implements ChurnGenerator.

Definition at line 169 of file LifetimeChurn.cc.

{
char buf[80];
sprintf(buf, "lifetime churn");
getDisplayString().setTagArg("t", 0, buf);
}

Member Data Documentation

std::vector<cObject*> LifetimeChurn::contextVector
private

context pointer vector

Definition at line 64 of file LifetimeChurn.h.

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

GlobalStatistics* LifetimeChurn::globalStatistics
private

Definition at line 53 of file LifetimeChurn.h.

Referenced by createNode(), deleteNode(), and initializeChurn().

cMessage* LifetimeChurn::initFinishedTimer
private

timer to signal end of init phase

Definition at line 62 of file LifetimeChurn.h.

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

double LifetimeChurn::initialDeviation
private

deviation of update interval during initialization phase

Definition at line 56 of file LifetimeChurn.h.

Referenced by initializeChurn().

double LifetimeChurn::initialMean
private

mean of update interval during initialization phase

Definition at line 55 of file LifetimeChurn.h.

Referenced by initializeChurn().

simtime_t LifetimeChurn::lastCreate
private

Definition at line 66 of file LifetimeChurn.h.

Referenced by createNode(), and initializeChurn().

simtime_t LifetimeChurn::lastDelete
private

Definition at line 67 of file LifetimeChurn.h.

Referenced by deleteNode(), and initializeChurn().

std::string LifetimeChurn::lifetimeDistName
private

name of the distribution function

Definition at line 58 of file LifetimeChurn.h.

Referenced by distributionFunction(), and initializeChurn().

double LifetimeChurn::lifetimeDistPar1
private

distribution function parameter

Definition at line 60 of file LifetimeChurn.h.

Referenced by distributionFunction(), and initializeChurn().

double LifetimeChurn::lifetimeMean
private

mean node lifetime

Definition at line 59 of file LifetimeChurn.h.

Referenced by distributionFunction(), and initializeChurn().

double LifetimeChurn::targetMean
private

mean of update interval after initialization phase

Definition at line 57 of file LifetimeChurn.h.


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