⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccc.cpp.svn-base

📁 UDT 4.0 based on the UDP.
💻 SVN-BASE
字号:
/*****************************************************************************Copyright (c) 2001 - 2008, The Board of Trustees of the University of Illinois.All rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions aremet:* Redistributions of source code must retain the above  copyright notice, this list of conditions and the  following disclaimer.* Redistributions in binary form must reproduce the  above copyright notice, this list of conditions  and the following disclaimer in the documentation  and/or other materials provided with the distribution.* Neither the name of the University of Illinois  nor the names of its contributors may be used to  endorse or promote products derived from this  software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "ASIS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER ORCONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDINGNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*****************************************************************************//*****************************************************************************written by   Yunhong Gu, last updated 11/07/2008*****************************************************************************/#include "core.h"#include "ccc.h"#include <cmath>CCC::CCC():m_iSYNInterval(CUDT::m_iSYNInterval),m_dPktSndPeriod(1.0),m_dCWndSize(16.0),m_iACKPeriod(0),m_iACKInterval(0),m_bUserDefinedRTO(false),m_iRTO(-1){}void CCC::setACKTimer(const int msINT){   m_iACKPeriod = msINT;   if (m_iACKPeriod > m_iSYNInterval)      m_iACKPeriod = m_iSYNInterval;}void CCC::setACKInterval(const int pktINT){   m_iACKInterval = pktINT;}void CCC::setRTO(const int usRTO){   m_bUserDefinedRTO = true;   m_iRTO = usRTO;}void CCC::sendCustomMsg(CPacket& pkt) const{   CUDT* u = CUDT::getUDTHandle(m_UDT);   if (NULL != u)      u->m_pSndQueue->sendto(u->m_pPeerAddr, pkt);}const CPerfMon* CCC::getPerfInfo(){   CUDT* u = CUDT::getUDTHandle(m_UDT);   if (NULL != u)      u->sample(&m_PerfInfo, false);   return &m_PerfInfo;}void CCC::setMSS(const int mss){   m_iMSS = mss;}void CCC::setBandwidth(const int bw){   m_iBandwidth = bw;}void CCC::setSndCurrSeqNo(const int32_t seqno){   m_iSndCurrSeqNo = seqno;}void CCC::setRcvRate(const int rcvrate){   m_iRcvRate = rcvrate;}void CCC::setMaxCWndSize(const int cwnd){   m_dMaxCWndSize = cwnd;}void CCC::setRTT(const int rtt){   m_iRTT = rtt;}//bool CUDTCC::construct() throw(){   return true;}void CUDTCC::init(){   m_iRCInterval = m_iSYNInterval;   m_LastRCTime = CTimer::getTime();   setACKTimer(m_iRCInterval);   m_bSlowStart = true;   m_iLastAck = m_iSndCurrSeqNo;   m_bLoss = false;   m_iLastDecSeq = CSeqNo::decseq(m_iLastAck);   m_dLastDecPeriod = 1;   m_iAvgNAKNum = 0;   m_iNAKCount = 0;   m_iDecCount = 0;   m_iDecRandom = 1;   m_dCWndSize = 1;   m_dPktSndPeriod = 60000;  // 60 milisecond, which means that the initial speed is 1500*8/0.06 = 200Kbps. the other reason is that the initial recv rate is 16 packets/sec   m_dMaxCWndSize = 4096;}void CUDTCC::onACK(const int32_t ack){   if (m_bSlowStart)   {      m_dCWndSize += CSeqNo::seqlen(m_iLastAck, ack);      m_iLastAck = ack;      if (m_dCWndSize > m_dMaxCWndSize)      {         m_bSlowStart = false;         if (m_iRcvRate > 0)            m_dPktSndPeriod = 1000000.0 / m_iRcvRate;         else            m_dPktSndPeriod = m_dCWndSize / (m_iRTT + m_iRCInterval);      }      else	  m_dPktSndPeriod = m_dPktSndPeriod * 0.9375; // 15/16      return;   }   uint64_t currtime = CTimer::getTime();   if (currtime - m_LastRCTime < (uint64_t)m_iRCInterval)      return;   m_LastRCTime = currtime;   // Note: m_iRcvRate may vary a lot because sending rate is tuned due to   // network change, packet loss and timeout   double delta = m_iRcvRate / 1000000.0 * (m_iRTT + m_iRCInterval) - m_dCWndSize;   m_dCWndSize = m_dCWndSize + 1 + delta / 2;   if (m_bLoss)   {      m_bLoss = false;      return;   }   int64_t B = (int64_t)(m_iBandwidth - 1000000.0 / m_dPktSndPeriod);   if ((m_dPktSndPeriod > m_dLastDecPeriod) && ((m_iBandwidth / 9) < B))      B = m_iBandwidth / 9;   double inc;   if (B <= 0)      inc = 1.0 / m_iMSS;   else   {      // inc = max(10 ^ ceil(log10( B * MSS * 8 ) * Beta / MSS, 1/MSS)      // Beta = 1.5 * 10^(-6)      inc = pow(10.0, ceil(log10(B * m_iMSS * 8.0))) * 0.0000015 / m_iMSS;      if (inc < 1.0/m_iMSS)         inc = 1.0/m_iMSS;   }   m_dPktSndPeriod = m_dPktSndPeriod * m_iRCInterval / (m_dPktSndPeriod * inc + m_iRCInterval);}void CUDTCC::onLoss(const int32_t* losslist, const int){   //Slow Start stopped, if it hasn't yet   if (m_bSlowStart)   {      m_bSlowStart = false;      if (m_iRcvRate > 0)      {	  double period = 1000000.0 / m_iRcvRate; // 1sec/rate	  if (period > m_dPktSndPeriod)	      m_dPktSndPeriod = period;	  else	      m_dPktSndPeriod = m_dPktSndPeriod * 1.125;      }      else         m_dPktSndPeriod = m_dCWndSize / (m_iRTT + m_iRCInterval);   }   m_bLoss = true;   if (CSeqNo::seqcmp(losslist[0] & 0x7FFFFFFF, m_iLastDecSeq) > 0)   {      m_dLastDecPeriod = m_dPktSndPeriod;      m_dPktSndPeriod = ceil(m_dPktSndPeriod * 1.125);      m_iAvgNAKNum = (int)ceil(m_iAvgNAKNum * 0.875 + m_iNAKCount * 0.125);      m_iNAKCount = 1;      m_iDecCount = 1;      m_iLastDecSeq = m_iSndCurrSeqNo;      // remove global synchronization using randomization      // srand(m_iLastDecSeq);   // need to do this?      m_iDecRandom = (int)ceil(rand() * double(m_iAvgNAKNum) / (RAND_MAX + 1.0));      if (m_iDecRandom < 1)         m_iDecRandom = 1;   }   else if ((m_iDecCount ++ < 10) && (0 == (++ m_iNAKCount % m_iDecRandom)))   {      // 1.0625^10 = 1.834, rate should not be decreased by more than half within a congestion period      m_dPktSndPeriod = ceil(m_dPktSndPeriod * 1.0625);      m_iLastDecSeq = m_iSndCurrSeqNo;   }}void CUDTCC::onTimeout(){   if (m_bSlowStart)   {      m_bSlowStart = false;      // cut the congestion window a half when timeout occurs during slow start      m_dCWndSize = m_dCWndSize * 0.5;      if (m_dCWndSize < 2)	  m_dCWndSize = 2;      if (m_iRcvRate > 0)      {	  double period = 1000000.0 / m_iRcvRate; // 1sec/rate	  if (period > m_dPktSndPeriod)	      m_dPktSndPeriod = period;	  else	      m_dPktSndPeriod = m_dPktSndPeriod * 1.125;      }      else         m_dPktSndPeriod = m_dCWndSize / (m_iRTT + m_iRCInterval);   }   if (m_iDecCount ++ < 10)   {      m_dPktSndPeriod = ceil(m_dPktSndPeriod * 1.0625);      m_iLastDecSeq = m_iSndCurrSeqNo;   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -