OverSim
NicePeerInfo.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 "NicePeerInfo.h"
26 
27 namespace oversim
28 {
29 
31  : parent (_parent)
32 {
33 
35  distance = -1;
36  last_sent_HB = 1;
37  last_recv_HB = 0;
38  backHBPointer = false;
39  last_HB_arrival = 0;
40 
41  activity = simTime().dbl();
42 
44 
45  WATCH_MAP(distanceTable);
46  WATCH(last_sent_HB);
47  WATCH(last_recv_HB);
48  WATCH(last_HB_arrival);
49 
50 } // NicePeerInfo
51 
53 {
54 
55 } // ~NicePeerInfo
56 
58 {
59 
61 
62 } // set_distance_estimation_start
63 
65 {
66 
68 
69 } // getDES
70 
71 void NicePeerInfo::set_distance(double value)
72 {
73 
74  distance = value;
75 
76 } // set_distance
77 
79 {
80 
81  return distance;
82 
83 } // get_distance
84 
86 {
87 
88  return hbTimer;
89 
90 } // startHeartbeatTimeout
91 
92 void NicePeerInfo::updateDistance(TransportAddress member, double distance)
93 {
94  //get member out of map
95  std::map<TransportAddress, double>::iterator it = distanceTable.find(member);
96 
97  if (it != distanceTable.end()) {
98 
99  it->second = distance;
100 
101  } else {
102 
103  distanceTable.insert(std::make_pair(member, distance));
104 
105  }
106 
107 
108 } // updateDistance
109 
111 {
112 
113  //std::cout << "getDistanceTo " << member.getIp() << "..." << endl;
114  //get member out of map
115  std::map<TransportAddress, double>::iterator it = distanceTable.find(member);
116 
117  if (it != distanceTable.end()) {
118 
119  //std::cout << "is in distanceTable" << endl;
120  return it->second;
121 
122  } else {
123 
124  //std::cout << "is NOT in distanceTable" << endl;
125  return -1;
126 
127  }
128 
129 
130 } // getDistanceTo
131 
133 {
134 
135  return last_sent_HB;
136 
137 } // get_last_sent_HB
138 
139 void NicePeerInfo::set_last_sent_HB(unsigned int seqNo)
140 {
141 
142  last_sent_HB = seqNo;
143 
144 } // set_last_sent_HB
145 
147 {
148 
149  return last_recv_HB;
150 
151 } // get_last_recv_HB
152 
153 void NicePeerInfo::set_last_recv_HB(unsigned int seqNo)
154 {
155 
156  last_recv_HB = seqNo;
157 
158 } // set_last_recv_HB
159 
161 {
162 
163  return last_HB_arrival;
164 
165 } // get_last_HB_arrival
166 
167 
169 {
170 
171  last_HB_arrival = arrival;
172 
173 } // set_last_HB_arrival
174 
176 {
177 
178  return backHBPointer;
179 
180 } // get_backHBPointer
181 
182 void NicePeerInfo::set_backHBPointer(bool _backHBPointer)
183 {
184 
185  backHBPointer = _backHBPointer;
186 
187 } // set_backHBPointer
188 
189 void NicePeerInfo::set_backHB(bool backHBPointer, unsigned int seqNo, double time)
190 {
191 
192  backHB[backHBPointer].first = seqNo;
193  backHB[backHBPointer].second = time;
194 
195 } // set_backHB
196 
197 double NicePeerInfo::get_backHB(unsigned int seqNo)
198 {
199 
200  double time = -1;
201 
202  if (backHB[0].first == seqNo)
203  time = backHB[0].second;
204  else if (backHB[1].first == seqNo)
205  time = backHB[1].second;
206 
207  return time;
208 
209 } // get_backHB
210 
211 unsigned int NicePeerInfo::get_backHB_seqNo(bool index)
212 {
213 
214  return backHB[index].first;
215 
216 } // get_backHB_seqNo
217 
218 
220 {
221 
222  activity = simTime().dbl();
223 
224 } // touch
225 
226 
228 {
229 
230  return activity;
231 
232 } // getActivity
233 
234 
235 void NicePeerInfo::setSubClusterMembers( unsigned int members )
236 {
237 
238  subclustermembers = members;
239 
240 }
241 
242 
244 {
245 
246  return subclustermembers;
247 
248 }
249 
250 
251 std::ostream& operator<<(std::ostream& os, NicePeerInfo& pi)
252 {
253  os << "distance: " << pi.distance << endl;
254  os << "des: " << pi.distance_estimation_start << endl;
255  os << "last_rcv: " << pi.get_last_recv_HB() << endl;
256  os << "last_sent: " << pi.get_last_sent_HB() << endl;
257  os << "last_HB: " << pi.get_last_HB_arrival() << endl;
258  os << "backHB[0].seqNo: " << pi.get_backHB_seqNo(0) << endl;
259  os << "backHB[0].time: " << pi.get_backHB(pi.get_backHB_seqNo(0)) << endl;
260  os << "backHB[1].seqNo: " << pi.get_backHB_seqNo(1) << endl;
261  os << "backHB[1].time: " << pi.get_backHB(pi.get_backHB_seqNo(1)) << endl;
262  os << "activity: " << pi.getActivity() << endl;
263 
264  std::map<TransportAddress, double>::iterator it = pi.distanceTable.begin();
265 
266  while (it != pi.distanceTable.end()) {
267  os << it->first << " : " << it->second << endl;
268  it++;
269  }
270 
271  return os;
272 }
273 
274 }; //namespace
275 
276