OverSim
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
NiceCluster.cc
Go to the documentation of this file.
1
//
2
// Copyright (C) 2009 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
25
#include "
NiceCluster.h
"
26
27
// Constructor *****************************************************************
28
NiceCluster::NiceCluster
()
29
{
30
leaderConfirmed
=
false
;
31
setLeader
(
TransportAddress::UNSPECIFIED_NODE
);
32
lastLT
= 0.0;
33
leaderHeartbeatsSent
= 0;
34
35
WATCH_SET(
cluster
);
36
WATCH(
leader
);
37
WATCH(
leaderConfirmed
);
38
39
}
// NICECluster
40
41
// Adds member to cluster ******************************************************
42
void
NiceCluster::add
(
const
TransportAddress
& member )
43
{
44
45
cluster
.insert(member);
46
47
}
// add
48
//
49
// Clears all cluster contents *************************************************
50
void
NiceCluster::clear
()
51
{
52
53
cluster
.clear();
54
setLeader
(
TransportAddress::UNSPECIFIED_NODE
);
55
56
lastLT
= 0.0;
57
58
}
// clear
59
60
// Check if cluster member *****************************************************
61
bool
NiceCluster::contains
(
const
TransportAddress
& member )
62
{
63
if
(member.
isUnspecified
())
64
return
false
;
65
66
return
cluster
.find(member) !=
cluster
.end();
67
}
// contains
68
//
69
// Get cluster size ************************************************************
70
int
NiceCluster::getSize
()
71
{
72
73
return
cluster
.size();
74
75
}
// getSize
76
77
// Get address of specific member **********************************************
78
const
TransportAddress
&
NiceCluster::get
(
int
i )
79
{
80
81
ConstClusterIterator
it =
cluster
.begin();
82
83
for
(
int
j = 0; j < i; j++)
84
it++;
85
86
return
*it;
87
88
}
// get
89
90
void
NiceCluster::remove
(
const
TransportAddress
& member)
91
{
92
93
cluster
.erase(member);
94
if
(!
leader
.
isUnspecified
() && !member.
isUnspecified
() &&
leader
== member) {
95
setLeader
(
TransportAddress::UNSPECIFIED_NODE
);
96
}
97
98
}
// remove
99
100
// set cluster leader **********************************************************
101
void
NiceCluster::setLeader
(
const
TransportAddress
& leader)
102
{
103
104
if
(!leader.
isUnspecified
() && !
contains
(leader)) {
105
throw
cRuntimeError(
"Leader not member of cluster"
);
106
}
107
this->leader =
leader
;
108
109
leaderConfirmed
=
false
;
110
111
// //cout << "Leader set to " << leader << endl;
112
113
}
// setLeader
114
115
// get current cluster leader **************************************************
116
const
TransportAddress
&
NiceCluster::getLeader
()
117
{
118
119
return
leader
;
120
121
}
// getLeader
122
123
std::set<TransportAddress>::const_iterator
NiceCluster::begin
()
const
124
{
125
return
cluster
.begin();
126
}
127
128
std::set<TransportAddress>::const_iterator
NiceCluster::end
()
const
129
{
130
return
cluster
.end();
131
}
132
133
simtime_t
NiceCluster::getLastLT
()
134
{
135
136
return
lastLT
;
137
138
}
139
140
void
NiceCluster::setLastLT
()
141
{
142
143
lastLT
= simTime();
144
145
}
146
147
bool
NiceCluster::isLeaderConfirmed
()
148
{
149
return
leaderConfirmed
;
150
}
151
152
void
NiceCluster::confirmLeader
()
153
{
154
leaderConfirmed
=
true
;
155
}
156
157
int
NiceCluster::getLeaderHeartbeatsSent
()
158
{
159
return
leaderHeartbeatsSent
;
160
}
161
162
void
NiceCluster::setLeaderHeartbeatsSent
(
int
heartbeats)
163
{
164
leaderHeartbeatsSent
= heartbeats;
165
}
166
src
overlay
nice
NiceCluster.cc
Generated on Fri Dec 7 2012 13:37:53 for OverSim by
1.8.1.2