00001 /***************************************************************************** 00002 Copyright (c) 2001 - 2011, The Board of Trustees of the University of Illinois. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are 00007 met: 00008 00009 * Redistributions of source code must retain the above 00010 copyright notice, this list of conditions and the 00011 following disclaimer. 00012 00013 * Redistributions in binary form must reproduce the 00014 above copyright notice, this list of conditions 00015 and the following disclaimer in the documentation 00016 and/or other materials provided with the distribution. 00017 00018 * Neither the name of the University of Illinois 00019 nor the names of its contributors may be used to 00020 endorse or promote products derived from this 00021 software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00024 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00025 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00026 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00027 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00028 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00029 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00030 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00031 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00032 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 *****************************************************************************/ 00035 00036 /***************************************************************************** 00037 written by 00038 Yunhong Gu, last updated 01/22/2011 00039 *****************************************************************************/ 00040 00041 #ifndef __UDT_WINDOW_H__ 00042 #define __UDT_WINDOW_H__ 00043 00044 00045 #ifndef WIN32 00046 #include <sys/time.h> 00047 #include <time.h> 00048 #endif 00049 #include "udt.h" 00050 00051 00052 class CACKWindow 00053 { 00054 public: 00055 CACKWindow(int size = 1024); 00056 ~CACKWindow(); 00057 00058 // Functionality: 00059 // Write an ACK record into the window. 00060 // Parameters: 00061 // 0) [in] seq: ACK seq. no. 00062 // 1) [in] ack: DATA ACK no. 00063 // Returned value: 00064 // None. 00065 00066 void store(int32_t seq, int32_t ack); 00067 00068 // Functionality: 00069 // Search the ACK-2 "seq" in the window, find out the DATA "ack" and caluclate RTT . 00070 // Parameters: 00071 // 0) [in] seq: ACK-2 seq. no. 00072 // 1) [out] ack: the DATA ACK no. that matches the ACK-2 no. 00073 // Returned value: 00074 // RTT. 00075 00076 int acknowledge(int32_t seq, int32_t& ack); 00077 00078 private: 00079 int32_t* m_piACKSeqNo; // Seq. No. for the ACK packet 00080 int32_t* m_piACK; // Data Seq. No. carried by the ACK packet 00081 uint64_t* m_pTimeStamp; // The timestamp when the ACK was sent 00082 00083 int m_iSize; // Size of the ACK history window 00084 int m_iHead; // Pointer to the lastest ACK record 00085 int m_iTail; // Pointer to the oldest ACK record 00086 00087 private: 00088 CACKWindow(const CACKWindow&); 00089 CACKWindow& operator=(const CACKWindow&); 00090 }; 00091 00093 00094 class CPktTimeWindow 00095 { 00096 public: 00097 CPktTimeWindow(int asize = 16, int psize = 16); 00098 ~CPktTimeWindow(); 00099 00100 // Functionality: 00101 // read the minimum packet sending interval. 00102 // Parameters: 00103 // None. 00104 // Returned value: 00105 // minimum packet sending interval (microseconds). 00106 00107 int getMinPktSndInt() const; 00108 00109 // Functionality: 00110 // Calculate the packes arrival speed. 00111 // Parameters: 00112 // None. 00113 // Returned value: 00114 // Packet arrival speed (packets per second). 00115 00116 int getPktRcvSpeed() const; 00117 00118 // Functionality: 00119 // Estimate the bandwidth. 00120 // Parameters: 00121 // None. 00122 // Returned value: 00123 // Estimated bandwidth (packets per second). 00124 00125 int getBandwidth() const; 00126 00127 // Functionality: 00128 // Record time information of a packet sending. 00129 // Parameters: 00130 // 0) currtime: timestamp of the packet sending. 00131 // Returned value: 00132 // None. 00133 00134 void onPktSent(int currtime); 00135 00136 // Functionality: 00137 // Record time information of an arrived packet. 00138 // Parameters: 00139 // None. 00140 // Returned value: 00141 // None. 00142 00143 void onPktArrival(); 00144 00145 // Functionality: 00146 // Record the arrival time of the first probing packet. 00147 // Parameters: 00148 // None. 00149 // Returned value: 00150 // None. 00151 00152 void probe1Arrival(); 00153 00154 // Functionality: 00155 // Record the arrival time of the second probing packet and the interval between packet pairs. 00156 // Parameters: 00157 // None. 00158 // Returned value: 00159 // None. 00160 00161 void probe2Arrival(); 00162 00163 private: 00164 int m_iAWSize; // size of the packet arrival history window 00165 int* m_piPktWindow; // packet information window 00166 int* m_piPktReplica; 00167 int m_iPktWindowPtr; // position pointer of the packet info. window. 00168 00169 int m_iPWSize; // size of probe history window size 00170 int* m_piProbeWindow; // record inter-packet time for probing packet pairs 00171 int* m_piProbeReplica; 00172 int m_iProbeWindowPtr; // position pointer to the probing window 00173 00174 int m_iLastSentTime; // last packet sending time 00175 int m_iMinPktSndInt; // Minimum packet sending interval 00176 00177 uint64_t m_LastArrTime; // last packet arrival time 00178 uint64_t m_CurrArrTime; // current packet arrival time 00179 uint64_t m_ProbeTime; // arrival time of the first probing packet 00180 00181 private: 00182 CPktTimeWindow(const CPktTimeWindow&); 00183 CPktTimeWindow &operator=(const CPktTimeWindow&); 00184 }; 00185 00186 00187 #endif