OverSim
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 *****************************************************************
29 {
30  leaderConfirmed = false;
32  lastLT = 0.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 *************************************************
51 {
52 
53  cluster.clear();
55 
56  lastLT = 0.0;
57 
58 } // clear
59 
60 // Check if cluster member *****************************************************
62 {
63  if (member.isUnspecified())
64  return false;
65 
66  return cluster.find(member) != cluster.end();
67 } // contains
68 //
69 // Get cluster size ************************************************************
71 {
72 
73  return cluster.size();
74 
75 } // getSize
76 
77 // Get address of specific member **********************************************
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 
91 {
92 
93  cluster.erase(member);
94  if (!leader.isUnspecified() && !member.isUnspecified() && leader == member) {
96  }
97 
98 } // remove
99 
100 // set cluster 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 **************************************************
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 
134 {
135 
136  return lastLT;
137 
138 }
139 
141 {
142 
143  lastLT = simTime();
144 
145 }
146 
148 {
149  return leaderConfirmed;
150 }
151 
153 {
154  leaderConfirmed = true;
155 }
156 
158 {
159  return leaderHeartbeatsSent;
160 }
161 
163 {
164  leaderHeartbeatsSent = heartbeats;
165 }
166