RTP Trace System  1.0
trafficshaper.h
Go to the documentation of this file.
00001 // ##########################################################################
00002 // ####                                                                  ####
00003 // ####                    Master Thesis Implementation                  ####
00004 // ####  Management of Layered Variable Bitrate Multimedia Streams over  ####
00005 // ####                  DiffServ with A Priori Knowledge                ####
00006 // ####                                                                  ####
00007 // #### ================================================================ ####
00008 // ####                                                                  ####
00009 // ####                                                                  ####
00010 // #### Traffic Shaper                                                   ####
00011 // ####                                                                  ####
00012 // #### Version 1.00  --  February 19, 2001                              ####
00013 // ####                                                                  ####
00014 // #### Copyright (C) 2000/2001 Thomas Dreibholz                         ####
00015 // #### University of Bonn, Department of Computer Science IV            ####
00016 // #### EMail: dreibh@iem.uni-due.de                                     ####
00017 // #### WWW:   https://www.uni-due.de/~be0001/diplom/index.html          ####
00018 // ####                                                                  ####
00019 // ##########################################################################
00020 
00021 
00022 #ifndef TRAFFICSHAPER_H
00023 #define TRAFFICSHAPER_H
00024 
00025 
00026 #include "system.h"
00027 #include "socket.h"
00028 #include "internetaddress.h"
00029 #include "timedthread.h"
00030 #include "trafficclassvalues.h"
00031 
00032 
00033 #include <deque.h>
00034 #include <vector.h>
00035 
00036 
00037 namespace Coral {
00038 
00039 
00040 class TrafficShaper;
00041 
00042 
00050 class TrafficShaperSingleton : public TimedThread
00051 {
00052    // ====== Constructor/Destructor =========================================
00053    public:
00057    TrafficShaperSingleton();
00058 
00062    ~TrafficShaperSingleton();
00063 
00064 
00065    // ====== Add/remove traffic shapers =====================================
00071    void addTrafficShaper(TrafficShaper* ts);
00072 
00078    void removeTrafficShaper(TrafficShaper* ts);
00079 
00080 
00081    // ====== Private data ===================================================
00082    private:
00083    void timerEvent();
00084 
00085 
00086    vector<TrafficShaper*> ShaperSet;
00087    cardinal               UserCount;
00088 };
00089 
00090 
00091 
00099 class TrafficShaper : public Synchronizable
00100 {
00101    // ====== Constructor/Destructor =========================================
00102    public:
00106    TrafficShaper();
00107 
00111    TrafficShaper(Socket* socket);
00112 
00116    ~TrafficShaper();
00117 
00118 
00119    // ====== Initialize =====================================================
00125    void init(Socket* socket);
00126 
00127 
00128    // ====== Set sender socket ==============================================
00134    inline void setSocket(Socket* socket);
00135 
00136 
00137    // ====== Settings =======================================================
00143    inline card64 getBandwidth() const;
00144 
00150    inline void setBandwidth(const card64 bandwidth);
00151 
00157    inline double getBufferDelay() const;
00158 
00164    inline void setBufferDelay(const double bufferDelay);
00165 
00166 
00167    // ====== Buffer manipulation ============================================
00171    void flush();
00172 
00180    bool refreshBuffer(const card8 trafficClass,
00181                       const bool doRemapping);
00182 
00188    inline cardinal getLastSeqNum() const;
00189 
00190 
00191    // ====== I/O functions ==================================================
00203     ssize_t sendTo(const void*         buffer,
00204                    const size_t        length,
00205                    const cardinal      seqNum,
00206                    const cardinal      flags,
00207                    const InternetFlow& receiver,
00208                    const card8         trafficClass = 0);
00209 
00223     ssize_t send(const void*    buffer,
00224                  const size_t   length,
00225                  const cardinal seqNum,
00226                  const cardinal flags        = 0,
00227                  const card8    trafficClass = 0);
00228 
00237    ssize_t write(const void*    buffer,
00238                  const size_t   length,
00239                  const cardinal seqNum);
00240 
00241 
00242    // ====== Private data ===================================================
00243    private:
00244    void sendAll();
00245    ssize_t addPacket(const void*    data,
00246                      const cardinal bytes,
00247                      const cardinal seqNum,
00248                      InternetFlow&  destination,
00249                      const cardinal flags,
00250                      const cardinal command);
00251 
00252 
00253    enum TrafficShaperCommand {
00254       TSC_Write  = 0,
00255       TSC_Send   = 1,
00256       TSC_SendTo = 2
00257    };
00258 
00259    struct TrafficShaperPacket {
00260       card64       SendTimeStamp;
00261       cardinal     HeaderSize;
00262       cardinal     PayloadSize;
00263       cardinal     Flags;
00264       cardinal     Command;
00265       InternetFlow Destination;
00266       char*        Data;
00267       cardinal     SeqNum;
00268 
00269       inline int operator<(const TrafficShaperPacket& packet) const {
00270          return(SendTimeStamp < packet.SendTimeStamp);
00271       }
00272    };
00273 
00274    friend class TrafficShaperSingleton;
00275 
00276 
00277    static TrafficShaperSingleton Singleton;
00278    deque<TrafficShaperPacket>    Queue;
00279    Socket*                       SenderSocket;
00280    card64                        SendTimeStamp;
00281    card64                        Bandwidth;
00282    double                        BufferDelay;
00283    integer                       LastError;
00284    cardinal                      LastSeqNum;
00285 };
00286 
00287 
00288 }
00289 
00290 
00291 #include "trafficshaper.icc"
00292 
00293 
00294 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines