RTP Audio System  2.0.0
bandwidthmanager.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 // #### Bandwidth Manager                                                ####
00011 // ####                                                                  ####
00012 // ####           Copyright (C) 1999-2012 by Thomas Dreibholz            ####
00013 // ####                                                                  ####
00014 // #### Contact:                                                         ####
00015 // ####    EMail: dreibh@iem.uni-due.de                                  ####
00016 // ####    WWW:   https://www.nntb.no/~dreibh/rtpaudio                ####
00017 // ####                                                                  ####
00018 // #### ---------------------------------------------------------------- ####
00019 // ####                                                                  ####
00020 // #### This program is free software: you can redistribute it and/or    ####
00021 // #### modify it under the terms of the GNU General Public License as   ####
00022 // #### published by the Free Software Foundation, either version 3 of   ####
00023 // #### the License, or (at your option) any later version.              ####
00024 // ####                                                                  ####
00025 // #### This program is distributed in the hope that it will be useful,  ####
00026 // #### but WITHOUT ANY WARRANTY; without even the implied warranty of   ####
00027 // #### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    ####
00028 // #### GNU General Public License for more details.                     ####
00029 // ####                                                                  ####
00030 // #### You should have received a copy of the GNU General Public        ####
00031 // #### License along with this program.  If not, see                    ####
00032 // #### <http://www.gnu.org/licenses/>.                                  ####
00033 // ####                                                                  ####
00034 // ##########################################################################
00035 // $Id: bandwidthmanager.h 1307 2011-12-22 07:36:29Z dreibh $
00036 
00037 
00038 #ifndef BANDWIDTHMANAGER_H
00039 #define BANDWIDTHMANAGER_H
00040 
00041 
00042 #include "tdsystem.h"
00043 #include "qosmanagerinterface.h"
00044 #include "abstractqosdescription.h"
00045 #include "timedthread.h"
00046 #include "servicelevelagreement.h"
00047 #include "streamdescription.h"
00048 #include "sessiondescription.h"
00049 #include "roundtriptimepinger.h"
00050 #include "rtcppacket.h"
00051 
00052 
00053 #include <map>
00054 #include <algorithm>
00055 
00056 
00065 struct ResourceUtilizationSimplePoint
00066 {
00067    // ====== Stream and point identification ================================
00071    StreamDescription* Stream;
00072 
00076    cardinal Point;
00077 
00081    double StreamPriorityFactor;
00082 
00083 
00084    // ====== Point data =====================================================
00088    card64 Bandwidth;
00089 
00093    double BandwidthCost;
00094 
00098    double Utilization;
00099 
00103    double SortingValue;
00104 };
00105 
00109 std::ostream& operator<<(std::ostream& os, const ResourceUtilizationSimplePoint& srup);
00110 
00111 
00112 
00121 struct ResourceUtilizationMultiPoint
00122 {
00123    // ====== Comparision operators ==========================================
00127    inline int operator<(const ResourceUtilizationMultiPoint& srup) const;
00128 
00132    inline int operator>(const ResourceUtilizationMultiPoint& srup) const;
00133 
00134 
00135    // ====== Session identification =========================================
00139    SessionDescription* Session;
00140 
00144    double SessionPriorityFactor;
00145 
00146 
00147    // ====== Streams and points identification ==============================
00151    static const cardinal MaxStreamsPerSession = 128;
00152 
00156    cardinal Streams;
00157 
00161    StreamDescription* Stream[MaxStreamsPerSession];
00162 
00166    cardinal Point[MaxStreamsPerSession];
00167 
00168 
00169    // ====== Point data =====================================================
00173    card64 Bandwidth;
00174 
00178    double BandwidthCost;
00179 
00183    double Utilization;
00184 
00188    double SortingValue;
00189 
00190 
00191    // ====== Miscellaneous ==================================================
00196    bool AlreadyAllocated;
00197 };
00198 
00199 
00203 std::ostream& operator<<(std::ostream& os, const ResourceUtilizationMultiPoint& srup);
00204 
00205 
00206 
00214 class BandwidthManager : virtual public QoSManagerInterface,
00215                          public TimedThread
00216 {
00217    // ====== Constructor/Destructor =========================================
00218    public:
00225    BandwidthManager(ServiceLevelAgreement* sla,
00226                     RoundTripTimePinger*   rttp);
00227 
00231    ~BandwidthManager();
00232 
00233 
00234    // ====== Stream management ==============================================
00242    void addStream(ManagedStreamInterface* stream,
00243                   const cardinal          sessionID = 0,
00244                   const char*             name      = NULL);
00245 
00251    void removeStream(ManagedStreamInterface* stream);
00252 
00258    void updateStream(ManagedStreamInterface* stream);
00259 
00263    inline void forceCompleteRemapping();
00264 
00265    // ====== Events =========================================================
00274    void intervalChangeEvent(ManagedStreamInterface* stream,
00275                             const bool              isNew,
00276                             const card64            when,
00277                             const bool              newRUList);
00278 
00286    void reportEvent(ManagedStreamInterface*         stream,
00287                     const RTCPReceptionReportBlock* report,
00288                     const cardinal                  layer);
00289 
00295    void bufferFlushEvent(ManagedStreamInterface* stream,
00296                          const cardinal          layer);
00297 
00303    void timerEvent();
00304 
00305 
00306    // ====== Settings =======================================================
00312    void setLogStream(std::ostream* logStream);
00313 
00322    inline void getPartialRemapping(bool&   enabled,
00323                                    double& reservedPortion,
00324                                    double& utilizationTolerance,
00325                                    double& maxRemappingInterval) const;
00326 
00327 
00336    inline void setPartialRemapping(const bool   enabled,
00337                                    const double reservedPortion,
00338                                    const double utilizationTolerance,
00339                                    const double maxRemappingInterval);
00340 
00347    inline void getFairness(double& fairnessSession,
00348                            double& fairnessStream) const;
00349 
00356    inline void setFairness(const double fairnessSession,
00357                            const double fairnessStream);
00358 
00367    inline void getQoSOptimizationParameters(
00368                   cardinal& maxRUPoints,
00369                   double&   utilizationThreshold,
00370                   card64&   bandwidthThreshold,
00371                   double&   systemDelayTolerance,
00372                   bool&     unlayeredAllocation) const;
00373 
00382    inline void setQoSOptimizationParameters(
00383                   const cardinal maxRUPoints,
00384                   const double   utilizationThreshold,
00385                   const card64   bandwidthThreshold,
00386                   const double   systemDelayTolerance,
00387                   const bool     unlayeredAllocation);
00388 
00389 
00390    // ====== Bandwidth variables ============================================
00391    card64 TotalAvailableBandwidth;
00392    card64 ClassAvailableBandwidthArray[TrafficClassValues::MaxValues];
00393    card64 TotalBandwidth;
00394    card64 ClassBandwidthArray[TrafficClassValues::MaxValues];
00395    int64  SLAUpdateRecommendation[TrafficClassValues::MaxValues];
00396 
00397 
00398    // ====== Information about remappings ===================================
00399    card64   StreamIDGenerator;
00400    card64   LastCompleteRemapping;
00401    card64   LastCompleteRemappingDuration;
00402    cardinal CompleteRemappings;
00403    cardinal PartialRemappings;
00404    cardinal TotalBufferFlushes;
00405 
00406 
00407    // ====== Simulator variables ============================================
00408    static card64 SimulatorTime;
00409 
00410 
00411    // ====== Stream and session management ==================================
00412    std::multimap<ManagedStreamInterface*,StreamDescription*> StreamSet;
00413    std::multimap<cardinal,SessionDescription*>               SessionSet;
00414    ServiceLevelAgreement*                                    SLA;
00415    cardinal                                                  Streams;
00416    cardinal                                                  Sessions;
00417 
00418 
00419    // ====== Constants ======================================================
00420    cardinal MaxRUPoints;
00421    double   UtilizationThreshold;
00422    card64   BandwidthThreshold;
00423    double   SystemDelayTolerance;
00424    double   FairnessSession;
00425    double   FairnessStream;
00426    double   AlphaLossRate;
00427    double   AlphaJitter;
00428    double   PartialRemappingPortion;
00429    double   PartialRemappingUtilizationTolerance;
00430    card64   MaxRemappingInterval;
00431    bool     EnablePartialRemappings;
00432    bool     UnlayeredAllocation;
00433 
00434 
00435    // ====== Private data ===================================================
00436    private:
00437    cardinal calculateSessionMultiPoints(
00438                SessionDescription*       session,
00439                const cardinal            offset,
00440                const cardinal            lastPoint,
00441                ResourceUtilizationMultiPoint* rumpList);
00442    void getRoundTripTimes(StreamDescription* sd);
00443 
00444    inline double getPriorityFactor(const int8 streamPriority) const;
00445    inline double getResourcePart(const ResourceUtilizationSimplePoint& rup) const;
00446    inline double getResourcePart(const ResourceUtilizationMultiPoint& rump) const;
00447    inline double getStreamSortingValue(const ResourceUtilizationSimplePoint& rup) const;
00448    inline double getSessionSortingValue(const ResourceUtilizationMultiPoint& rump) const;
00449 
00450    static inline void smoothedUpdate(double& value, const double measured, const double alpha);
00451 
00452    public:
00453    void updateReservation(StreamDescription* streamDescription);
00454    private:
00455 
00456    bool tryAllocation(
00457            ResourceUtilizationMultiPoint& rump,
00458            const card64                   bandwidthLimit = (card64)-1);
00459 
00460    void doAllocationTrials(
00461            ResourceUtilizationMultiPoint* rumpList,
00462            const cardinal                 points,
00463            const card64                   bandwidthLimit = (card64)-1);
00464 
00465    bool doPartialRemapping(StreamDescription* streamDescription);
00466    void doCompleteRemapping();
00467 
00468 
00469    RoundTripTimePinger* RTTP;
00470    std::ostream*        Log;
00471    card64               LogStartupTimeStamp;
00472    bool                 Changed;
00473 };
00474 
00475 
00476 #include "bandwidthmanager.icc"
00477 
00478 
00479 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines