00001 // 00002 // Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH) 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 // 00018 00025 #include "NicePeerInfo.h" 00026 00027 namespace oversim 00028 { 00029 00030 NicePeerInfo::NicePeerInfo(Nice* _parent) 00031 : parent (_parent) 00032 { 00033 00034 distance_estimation_start = -1; 00035 distance = -1; 00036 last_sent_HB = 1; 00037 last_recv_HB = 0; 00038 backHBPointer = false; 00039 last_HB_arrival = 0; 00040 00041 activity = simTime().dbl(); 00042 00043 subclustermembers = 0; 00044 00045 WATCH_MAP(distanceTable); 00046 WATCH(last_sent_HB); 00047 WATCH(last_recv_HB); 00048 WATCH(last_HB_arrival); 00049 00050 } // NicePeerInfo 00051 00052 NicePeerInfo::~NicePeerInfo() 00053 { 00054 00055 } // ~NicePeerInfo 00056 00057 void NicePeerInfo::set_distance_estimation_start(double value) 00058 { 00059 00060 distance_estimation_start = value; 00061 00062 } // set_distance_estimation_start 00063 00064 double NicePeerInfo::getDES() 00065 { 00066 00067 return distance_estimation_start; 00068 00069 } // getDES 00070 00071 void NicePeerInfo::set_distance(double value) 00072 { 00073 00074 distance = value; 00075 00076 } // set_distance 00077 00078 double NicePeerInfo::get_distance() 00079 { 00080 00081 return distance; 00082 00083 } // get_distance 00084 00085 cMessage* NicePeerInfo::getHbTimer() 00086 { 00087 00088 return hbTimer; 00089 00090 } // startHeartbeatTimeout 00091 00092 void NicePeerInfo::updateDistance(TransportAddress member, double distance) 00093 { 00094 //get member out of map 00095 std::map<TransportAddress, double>::iterator it = distanceTable.find(member); 00096 00097 if (it != distanceTable.end()) { 00098 00099 it->second = distance; 00100 00101 } else { 00102 00103 distanceTable.insert(std::make_pair(member, distance)); 00104 00105 } 00106 00107 00108 } // updateDistance 00109 00110 double NicePeerInfo::getDistanceTo(TransportAddress member) 00111 { 00112 00113 //std::cout << "getDistanceTo " << member.getAddress() << "..." << endl; 00114 //get member out of map 00115 std::map<TransportAddress, double>::iterator it = distanceTable.find(member); 00116 00117 if (it != distanceTable.end()) { 00118 00119 //std::cout << "is in distanceTable" << endl; 00120 return it->second; 00121 00122 } else { 00123 00124 //std::cout << "is NOT in distanceTable" << endl; 00125 return -1; 00126 00127 } 00128 00129 00130 } // getDistanceTo 00131 00132 unsigned int NicePeerInfo::get_last_sent_HB() 00133 { 00134 00135 return last_sent_HB; 00136 00137 } // get_last_sent_HB 00138 00139 void NicePeerInfo::set_last_sent_HB(unsigned int seqNo) 00140 { 00141 00142 last_sent_HB = seqNo; 00143 00144 } // set_last_sent_HB 00145 00146 unsigned int NicePeerInfo::get_last_recv_HB() 00147 { 00148 00149 return last_recv_HB; 00150 00151 } // get_last_recv_HB 00152 00153 void NicePeerInfo::set_last_recv_HB(unsigned int seqNo) 00154 { 00155 00156 last_recv_HB = seqNo; 00157 00158 } // set_last_recv_HB 00159 00160 double NicePeerInfo::get_last_HB_arrival() 00161 { 00162 00163 return last_HB_arrival; 00164 00165 } // get_last_HB_arrival 00166 00167 00168 void NicePeerInfo::set_last_HB_arrival(double arrival) 00169 { 00170 00171 last_HB_arrival = arrival; 00172 00173 } // set_last_HB_arrival 00174 00175 bool NicePeerInfo::get_backHBPointer() 00176 { 00177 00178 return backHBPointer; 00179 00180 } // get_backHBPointer 00181 00182 void NicePeerInfo::set_backHBPointer(bool _backHBPointer) 00183 { 00184 00185 backHBPointer = _backHBPointer; 00186 00187 } // set_backHBPointer 00188 00189 void NicePeerInfo::set_backHB(bool backHBPointer, unsigned int seqNo, double time) 00190 { 00191 00192 backHB[backHBPointer].first = seqNo; 00193 backHB[backHBPointer].second = time; 00194 00195 } // set_backHB 00196 00197 double NicePeerInfo::get_backHB(unsigned int seqNo) 00198 { 00199 00200 double time = -1; 00201 00202 if (backHB[0].first == seqNo) 00203 time = backHB[0].second; 00204 else if (backHB[1].first == seqNo) 00205 time = backHB[1].second; 00206 00207 return time; 00208 00209 } // get_backHB 00210 00211 unsigned int NicePeerInfo::get_backHB_seqNo(bool index) 00212 { 00213 00214 return backHB[index].first; 00215 00216 } // get_backHB_seqNo 00217 00218 00219 void NicePeerInfo::touch() 00220 { 00221 00222 activity = simTime().dbl(); 00223 00224 } // touch 00225 00226 00227 double NicePeerInfo::getActivity() 00228 { 00229 00230 return activity; 00231 00232 } // getActivity 00233 00234 00235 void NicePeerInfo::setSubClusterMembers( unsigned int members ) 00236 { 00237 00238 subclustermembers = members; 00239 00240 } 00241 00242 00243 unsigned int NicePeerInfo::getSubClusterMembers() 00244 { 00245 00246 return subclustermembers; 00247 00248 } 00249 00250 00251 std::ostream& operator<<(std::ostream& os, NicePeerInfo& pi) 00252 { 00253 os << "distance: " << pi.distance << endl; 00254 os << "des: " << pi.distance_estimation_start << endl; 00255 os << "last_rcv: " << pi.get_last_recv_HB() << endl; 00256 os << "last_sent: " << pi.get_last_sent_HB() << endl; 00257 os << "last_HB: " << pi.get_last_HB_arrival() << endl; 00258 os << "backHB[0].seqNo: " << pi.get_backHB_seqNo(0) << endl; 00259 os << "backHB[0].time: " << pi.get_backHB(pi.get_backHB_seqNo(0)) << endl; 00260 os << "backHB[1].seqNo: " << pi.get_backHB_seqNo(1) << endl; 00261 os << "backHB[1].time: " << pi.get_backHB(pi.get_backHB_seqNo(1)) << endl; 00262 os << "activity: " << pi.getActivity() << endl; 00263 00264 std::map<TransportAddress, double>::iterator it = pi.distanceTable.begin(); 00265 00266 while (it != pi.distanceTable.end()) { 00267 os << it->first << " : " << it->second << endl; 00268 it++; 00269 } 00270 00271 return os; 00272 } 00273 00274 }; //namespace 00275 00276