RTP Audio System
2.0.0
|
00001 // ########################################################################## 00002 // #### #### 00003 // #### RTP Audio Server Project #### 00004 // #### ============================ #### 00005 // #### #### 00006 // #### Round Trip Time Pinger #### 00007 // #### #### 00008 // #### Copyright (C) 1999-2012 by Thomas Dreibholz #### 00009 // #### #### 00010 // #### Contact: #### 00011 // #### EMail: dreibh@iem.uni-due.de #### 00012 // #### WWW: https://www.nntb.no/~dreibh/rtpaudio #### 00013 // #### #### 00014 // #### ---------------------------------------------------------------- #### 00015 // #### #### 00016 // #### This program is free software: you can redistribute it and/or #### 00017 // #### modify it under the terms of the GNU General Public License as #### 00018 // #### published by the Free Software Foundation, either version 3 of #### 00019 // #### the License, or (at your option) any later version. #### 00020 // #### #### 00021 // #### This program is distributed in the hope that it will be useful, #### 00022 // #### but WITHOUT ANY WARRANTY; without even the implied warranty of #### 00023 // #### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #### 00024 // #### GNU General Public License for more details. #### 00025 // #### #### 00026 // #### You should have received a copy of the GNU General Public #### 00027 // #### License along with this program. If not, see #### 00028 // #### <http://www.gnu.org/licenses/>. #### 00029 // #### #### 00030 // ########################################################################## 00031 // $Id: roundtriptimepinger.h 1316 2011-12-23 11:36:11Z dreibh $ 00032 00033 00034 #ifndef ROUNDTRIPTIMEPINGER_H 00035 #define ROUNDTRIPTIMEPINGER_H 00036 00037 00038 #include "tdsystem.h" 00039 #include "tdsocket.h" 00040 #include "internetaddress.h" 00041 #include "timedthread.h" 00042 #include "rtppacket.h" 00043 #include "pingerhost.h" 00044 #include "randomizer.h" 00045 00046 00047 #include <set> 00048 #include <algorithm> 00049 #include <fstream> 00050 00051 #include <netinet/ip.h> 00052 #include <netinet/ip_icmp.h> 00053 #include <netinet/icmp6.h> 00054 #include <sys/time.h> 00055 00056 00064 class RoundTripTimePinger : public TimedThread 00065 { 00066 // ====== Constructor =================================================== 00067 public: 00075 RoundTripTimePinger(Socket* ping4socket, 00076 Socket* ping6socket, 00077 const card64 delay = 1000000); 00078 00082 ~RoundTripTimePinger(); 00083 00084 00085 // ====== Status functions =============================================== 00091 inline bool ready() const; 00092 00098 inline cardinal getHosts(); 00099 00100 00106 inline double getAlpha(); 00107 00113 inline void setAlpha(const double alpha); 00114 00115 00121 inline card64 getMaxPingDelay(); 00122 00128 inline void setMaxPingDelay(const card64 delay); 00129 00130 00137 cardinal getRoundTripTime(const InternetAddress& address, 00138 const card8 trafficClass = 0x00); 00139 00140 00141 // ====== Adding/removing hosts ========================================== 00149 bool addHost(const InternetAddress& address, 00150 const card8 trafficClass = 0x00); 00151 00158 void removeHost(const InternetAddress& address, 00159 const card8 trafficClass = 0x00); 00160 00161 // ====== GNUplot output generator ======================================= 00170 void activateLogger(std::ostream* scriptStream, 00171 std::ostream* dataStream, 00172 const char* dataName); 00173 00177 void deactivateLogger(); 00178 00182 inline bool isLogging() const; 00183 00192 void writeGPHeader(std::ostream& os, 00193 const char* dataName, 00194 const cardinal lineStyle = 1); 00195 00201 void writeGPData(std::ostream& os); 00202 00203 00204 // ====== Output operator ================================================ 00208 friend std::ostream& operator<<(std::ostream& os, RoundTripTimePinger& pinger); 00209 00210 00211 // ====== Constants ====================================================== 00215 static const cardinal MaxRoundTripTime = 180000000; 00216 00223 static const double UnreachableFactor = 2.0; 00224 00231 static const card64 MinUnreachableAsumption = 2500000; 00232 00233 00234 // ====== Private data =================================================== 00235 private: 00236 void timerEvent(); 00237 void calculateRoundTripTime(const InternetAddress& address, 00238 const card8 trafficClass, 00239 const card64 sendTime, 00240 const card64 arrivalTime); 00241 card16 calculateChecksum(const card16* addr, 00242 const cardinal length, 00243 card16 csum); 00244 card64 sendPing4(const InternetAddress& destination, 00245 const card8 trafficClass, 00246 const card16 sequenceNumber); 00247 card64 sendPing6(const InternetAddress& destination, 00248 const card8 trafficClass, 00249 const card16 sequenceNumber); 00250 bool receiveEcho4(); 00251 bool receiveEcho6(); 00252 void checkUnreachable(PingerHost& host); 00253 00254 00255 struct Ping4Packet 00256 { 00257 icmp Header; 00258 card64 TimeStamp; 00259 }; 00260 00261 struct Ping6Packet 00262 { 00263 icmp6_hdr Header; 00264 card64 TimeStamp; 00265 }; 00266 00267 00268 Socket* Ping4Socket; 00269 Socket* Ping6Socket; 00270 double RoundTripTimeAlpha; 00271 std::multiset<PingerHost> HostSet; 00272 card64 GPHeaderTimeStamp; 00273 bool Ready; 00274 bool Logger; 00275 std::ostream* LoggerScriptStream; 00276 std::ostream* LoggerDataStream; 00277 card64 MaxPingDelay; 00278 Randomizer Random; 00279 }; 00280 00281 00282 #include "roundtriptimepinger.icc" 00283 00284 00285 #endif