📄 congestionwindow.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace Helper.Net.RUDP.BIC
{
//http://www4.ncsu.edu/~rhee/export/bitcp/index.htm
// http://lwn.net/Articles/128627/
sealed internal class CongestionWindow : AbstractWindow
{
#region Variables
double beta;
double Smax;
double Smin;
// if the window size is larger than this threshold, BI-TCP engages; otherwise
// normal TCP increase/decrease.
double low_window;
// default maximum (a large integer)
double default_max_win;
//
double max_win;
//
double min_win;
//
double prev_max;
//
double target_win;
// Boolean indicating whether the protocol is in the slow start. Initially false.
bool is_BITCP_ss;
// a variable to keep track of cwnd increase during the BI-TCP slow start.
double ss_cwnd;
// the value of cwnd after one _rtt in BI-TCP slow start.
double ss_target;
#endregion
#region Constructor
internal CongestionWindow(RUDPSocket rudp)
: base(rudp)
{
_rudp = rudp;
}
#endregion
#region Reset
internal override void Reset()
{
base.Reset();
beta = 0.8;
low_window = 64 * 1024;
Smax = 64 * 1024;
Smin = 1 * 1024;
default_max_win = 256 * 1024;
max_win = default_max_win;
min_win = 16 * 1024;
is_BITCP_ss = false;
}
#endregion
#region OnACK_UpdateWindow
internal override void OnACK_UpdateWindow(RUDPOutgoingPacket packet)
{
if (_cwnd < low_window)
{
_cwnd = _cwnd + _rudp.MTU / _cwnd; // normal TCP = (1 packet/cwnd)
return;
}
if (!is_BITCP_ss)
{
// bin. increase
if ((target_win - _cwnd) < Smax) // bin. search
_cwnd += (target_win - _cwnd) / _cwnd;
else
_cwnd += Smax / _cwnd; // additive incre.
if (max_win > _cwnd)
{
min_win = _cwnd;
target_win = (max_win + min_win) / 2;
}
else
{
is_BITCP_ss = true;
ss_cwnd = 1;
ss_target = _cwnd + 1;
max_win = default_max_win;
}
}
else
{
// slow start
_cwnd = _cwnd + ss_cwnd / _cwnd;
if (_cwnd >= ss_target)
{
ss_cwnd = 2.0 * ss_cwnd;
ss_target = _cwnd + ss_cwnd;
}
if (ss_cwnd >= Smax)
is_BITCP_ss = false;
}
}
#endregion
#region OnResend_UpdateWindow
internal override void OnResend_UpdateWindow()
{
// Enter fast recovery
if (low_window <= _cwnd)
{
prev_max = max_win;
max_win = _cwnd;
_cwnd = _cwnd * (1.0 - beta);
min_win = _cwnd;
if (prev_max > max_win) //Fast. Conv.
max_win = (max_win + min_win) / 2;
target_win = (max_win + min_win) / 2;
}
else
{
_cwnd = _cwnd * 0.5; // normal TCP
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -