OverSim
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
RandomChurn.cc
Go to the documentation of this file.
1
//
2
// Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3
//
4
// This program is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU General Public License
6
// as published by the Free Software Foundation; either version 2
7
// of the License, or (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
//
18
24
#include <assert.h>
25
26
#include <
TransportAddress.h
>
27
#include <
GlobalStatistics.h
>
28
#include <
GlobalStatisticsAccess.h
>
29
#include <
UnderlayConfigurator.h
>
30
31
#include "
RandomChurn.h
"
32
33
Define_Module
(
RandomChurn
);
34
35
void
RandomChurn::initializeChurn
()
36
{
37
Enter_Method_Silent();
38
39
creationProbability
= par(
"creationProbability"
);
40
migrationProbability
= par(
"migrationProbability"
);
41
removalProbability
= par(
"removalProbability"
);
42
initialMean
= par(
"initPhaseCreationInterval"
);
43
initialDeviation
=
initialMean
/ 3;
44
targetMean
= par(
"targetMobilityDelay"
);
45
targetOverlayTerminalNum
= par(
"targetOverlayTerminalNum"
);
46
WATCH(
targetMean
);
47
48
churnTimer
= NULL;
49
churnIntervalChanged
=
false
;
50
churnChangeInterval
= par(
"churnChangeInterval"
);
51
initAddMoreTerminals
=
true
;
52
53
globalStatistics
=
GlobalStatisticsAccess
().
get
();
54
55
// initialize simulation
56
mobilityTimer
= NULL;
57
mobilityTimer
=
new
cMessage(
"mobilityTimer"
);
58
scheduleAt(simTime(),
mobilityTimer
);
59
60
if
(
churnChangeInterval
> 0) {
61
churnTimer
=
new
cMessage(
"churnTimer"
);
62
scheduleAt(simTime() +
churnChangeInterval
,
churnTimer
);
63
}
64
}
65
66
void
RandomChurn::handleMessage
(cMessage* msg)
67
{
68
if
(!msg->isSelfMessage()) {
69
delete
msg;
70
return
;
71
}
72
73
if
(msg ==
churnTimer
) {
74
cancelEvent(
churnTimer
);
75
scheduleAt(simTime() +
churnChangeInterval
,
churnTimer
);
76
if
(
churnIntervalChanged
) {
77
targetMean
= par(
"targetMobilityDelay"
);
78
churnIntervalChanged
=
false
;
79
}
80
else
{
81
targetMean
= par(
"targetMobilityDelay2"
);
82
churnIntervalChanged
=
true
;
83
}
84
std::stringstream temp;
85
temp <<
"Churn-rate changed to "
<<
targetMean
;
86
bubble(temp.str().c_str());
87
}
else
if
(msg ==
mobilityTimer
) {
88
if
(
initAddMoreTerminals
) {
89
// increase the number of nodes steadily during setup
90
if
(
terminalCount
<
targetOverlayTerminalNum
) {
91
TransportAddress
* ta =
underlayConfigurator
->
createNode
(
type
);
92
delete
ta;
// Address not needed in this churn model
93
}
94
95
if
(
terminalCount
>=
targetOverlayTerminalNum
) {
96
initAddMoreTerminals
=
false
;
97
underlayConfigurator
->
initFinished
();
98
}
99
scheduleAt(simTime()
100
+ truncnormal(
initialMean
,
initialDeviation
), msg);
101
}
102
else
{
103
double
random = uniform(0, 1);
104
105
// modify the number of nodes according to user parameters
106
if
(random <
creationProbability
) {
107
TransportAddress
* ta =
underlayConfigurator
->
createNode
(
type
);
108
delete
ta;
// Address not needed in this churn model
109
}
else
if
(
creationProbability
<= random &&
110
random <
creationProbability
+
removalProbability
&&
111
terminalCount
> 1) {
112
int
oldTerminalCount =
terminalCount
;
113
underlayConfigurator
->
preKillNode
(
type
);
114
assert ((oldTerminalCount - 1) ==
terminalCount
);
115
}
else
if
(
creationProbability
+
removalProbability
<= random &&
116
random <
creationProbability
+
removalProbability
117
+
migrationProbability
&&
terminalCount
> 1) {
118
underlayConfigurator
->
migrateNode
(
type
);
119
}
120
scheduleAt(simTime()
121
+ truncnormal(
targetMean
,
targetMean
/ 3), msg);
122
}
123
}
124
}
125
126
void
RandomChurn::updateDisplayString
()
127
{
128
char
buf[80];
129
sprintf(buf,
"random churn"
);
130
getDisplayString().setTagArg(
"t"
, 0, buf);
131
}
132
133
RandomChurn::~RandomChurn
() {
134
// destroy self timer messages
135
cancelAndDelete(
churnTimer
);
136
cancelAndDelete(
mobilityTimer
);
137
}
138
src
common
RandomChurn.cc
Generated on Fri Dec 7 2012 13:37:53 for OverSim by
1.8.1.2