RTP Trace System  1.0
roundtriptimepinger.h
Go to the documentation of this file.
00001 // ##########################################################################
00002 // ####                                                                  ####
00003 // ####                      RTP Audio Server Project                    ####
00004 // ####                    ============================                  ####
00005 // ####                                                                  ####
00006 // #### Round Trip Time Pinger                                           ####
00007 // ####                                                                  ####
00008 // #### Version 1.00  --  February 16, 2001                              ####
00009 // ####                                                                  ####
00010 // #### Copyright (C) 1999  Thomas Dreibholz                             ####
00011 // ####               2000  Universität Bonn, Abt. IV                    ####
00012 // ####               2001  EMail: dreibh@iem.uni-due.de                 ####
00013 // ####                     WWW:   https://www.uni-due.de/~be0001        ####
00014 // ####                                                                  ####
00015 // ##########################################################################
00016 
00017 
00018 #ifndef ROUNDTRIPTIMEPINGER_H
00019 #define ROUNDTRIPTIMEPINGER_H
00020 
00021 
00022 #include "system.h"
00023 #include "socket.h"
00024 #include "internetaddress.h"
00025 #include "timedthread.h"
00026 #include "rtppacket.h"
00027 #include "pingerhost.h"
00028 #include "randomizer.h"
00029 
00030 
00031 #include <multiset.h>
00032 #include <algo.h>
00033 #include <netinet/ip.h>
00034 #include <netinet/ip_icmp.h>
00035 #include <netinet/icmp6.h>
00036 #include <sys/time.h>
00037 #include <fstream.h>
00038 
00039 
00040 namespace Coral {
00041 
00042 
00050 class RoundTripTimePinger : public TimedThread
00051 {
00052    // ====== Constructor ===================================================
00053    public:
00061    RoundTripTimePinger(Socket*      ping4socket,
00062                        Socket*      ping6socket,
00063                        const card64 delay = 1000000);
00064 
00068    ~RoundTripTimePinger();
00069 
00070 
00071    // ====== Status functions ===============================================
00077    inline bool ready() const;
00078 
00084    inline cardinal getHosts();
00085 
00086 
00092    inline double getAlpha();
00093 
00099    inline void setAlpha(const double alpha);
00100 
00101 
00107    inline card64 getMaxPingDelay();
00108 
00114    inline void setMaxPingDelay(const card64 delay);
00115 
00116 
00123    cardinal getRoundTripTime(const InternetAddress& address,
00124                              const card8            trafficClass = 0x00);
00125 
00126 
00127    // ====== Adding/removing hosts ==========================================
00135    bool addHost(const InternetAddress& address,
00136                 const card8            trafficClass = 0x00);
00137 
00144    void removeHost(const InternetAddress& address,
00145                    const card8            trafficClass = 0x00);
00146 
00147    // ====== GNUplot output generator =======================================
00156    void activateLogger(ostream*    scriptStream,
00157                        ostream*    dataStream,
00158                        const char* dataName);
00159 
00163    void deactivateLogger();
00164 
00168    inline bool isLogging() const;
00169 
00178    void writeGPHeader(ostream&       os,
00179                       const char*    dataName,
00180                       const cardinal lineStyle = 1);
00181 
00187    void writeGPData(ostream& os);
00188 
00189 
00190    // ====== Output operator ================================================
00194    friend ostream& operator<<(ostream& os, RoundTripTimePinger& pinger);
00195 
00196 
00197    // ====== Constants ======================================================
00201    static const cardinal MaxRoundTripTime = 180000000;
00202 
00209    static const double UnreachableFactor = 2.0;
00210 
00217    static const card64 MinUnreachableAsumption = 2500000;
00218 
00219 
00220    // ====== Private data ===================================================
00221    private:
00222    void timerEvent();
00223    void calculateRoundTripTime(const InternetAddress& address,
00224                                const card8            trafficClass,
00225                                const card64           sendTime,
00226                                const card64           arrivalTime);
00227    card16 RoundTripTimePinger::calculateChecksum(const card16*  addr,
00228                                                  const cardinal length,
00229                                                  card16         csum);
00230    card64 RoundTripTimePinger::sendPing4(const InternetAddress& destination,
00231                                          const card8            trafficClass,
00232                                          const card16           sequenceNumber);
00233    card64 RoundTripTimePinger::sendPing6(const InternetAddress& destination,
00234                                          const card8            trafficClass,
00235                                          const card16           sequenceNumber);
00236    bool receiveEcho4();
00237    bool receiveEcho6();
00238    void checkUnreachable(PingerHost& host);
00239 
00240 
00241    struct Ping4Packet
00242    {
00243       icmphdr Header;
00244       card64  TimeStamp;
00245    };
00246 
00247    struct Ping6Packet
00248    {
00249       icmp6_hdr Header;
00250       card64    TimeStamp;
00251    };
00252 
00253 
00254    Socket*              Ping4Socket;
00255    Socket*              Ping6Socket;
00256    double               RoundTripTimeAlpha;
00257    multiset<PingerHost> HostSet;
00258    card64               GPHeaderTimeStamp;
00259    bool                 Ready;
00260    bool                 Logger;
00261    ostream*             LoggerScriptStream;
00262    ostream*             LoggerDataStream;
00263    card64               MaxPingDelay;
00264    Randomizer           Random;
00265 };
00266 
00267 
00268 }
00269 
00270 
00271 #include "roundtriptimepinger.icc"
00272 
00273 
00274 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines