Skip to content

Commit

Permalink
monkey patched SCTP congestion avoidance
Browse files Browse the repository at this point in the history
some of the fixes are probably legit, but I believe the T3-rtx timer is not implemented correctly

kinda works around sipsorcery-org#1088
  • Loading branch information
lostmsu committed Mar 20, 2024
1 parent 5ae95a1 commit b050051
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/net/SCTP/SctpDataSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ private void ProcessGapReports(ReadOnlySpan<byte> sackGapBlocks, uint maxTSNDist
logger.LogTrace($"SCTP sender entering fast recovery mode due to missing TSN {missingTSN}. Fast recovery exit point {_fastRecoveryExitPoint}.");
// RFC4960 7.2.3
_slowStartThreshold = (uint)Math.Max(_congestionWindow / 2, 4 * _defaultMTU);
_congestionWindow = _defaultMTU;
_congestionWindow = _slowStartThreshold;
}
}
}
Expand Down Expand Up @@ -644,12 +644,13 @@ private void DoSend(object state)
if (!_inRetransmitMode)
{
logger.LogTrace("SCTP sender entering retransmit mode.");
_inRetransmitMode = true;

// When the T3-rtx timer expires on an address, SCTP should perform slow start.
// RFC4960 7.2.3
_slowStartThreshold = (uint)Math.Max(_congestionWindow / 2, 4 * _defaultMTU);
_congestionWindow = _defaultMTU;
// did not clarify, but I believe entering retransmit mode is NOT the same
// as T3-rtx timer expiring. Will just use regular halving formula here.
_congestionWindow = _slowStartThreshold;

// For the destination address for which the timer expires, set RTO <- RTO * 2("back off the timer")
// RFC4960 6.3.3 E2
Expand All @@ -664,7 +665,7 @@ private void DoSend(object state)
// if it has cwnd or more bytes of data outstanding to that transport address.

// Send any new data chunks that have not yet been sent.
if (chunksSent < burstSize && _sendQueue.Count > 0 && _congestionWindow > outstandingBytes)
if (chunksSent < burstSize && !_sendQueue.IsEmpty && _congestionWindow > outstandingBytes)
{
while (chunksSent < burstSize && _sendQueue.TryDequeue(out var dataChunk))
{
Expand Down Expand Up @@ -789,11 +790,11 @@ private uint CalculateReceiverWindow(uint advertisedReceiveWindow, uint outstand
/// <returns>A congestion window value.</returns>
private uint CalculateCongestionWindow(int lastAckDataChunkSize, uint outstandingBytes)
{
if (_congestionWindow < _slowStartThreshold)
if (_congestionWindow <= _slowStartThreshold)
{
// In Slow-Start mode, see RFC4960 7.2.1.

if (_congestionWindow < outstandingBytes)
// Updated to RFC9260 7.2.1
if (_congestionWindow <= outstandingBytes && !_inFastRecoveryMode)
{
// When cwnd is less than or equal to ssthresh, an SCTP endpoint MUST
// use the slow - start algorithm to increase cwnd only if the current
Expand All @@ -814,7 +815,7 @@ private uint CalculateCongestionWindow(int lastAckDataChunkSize, uint outstandin
{
// In Congestion Avoidance mode, see RFC4960 7.2.2.

if (_congestionWindow < outstandingBytes)
if (_congestionWindow <= outstandingBytes)
{
logger.LogTrace("SCTP sender congestion window in congestion avoidance increased from {Original} to {Increased}.",
_congestionWindow, _congestionWindow + _defaultMTU);
Expand Down

0 comments on commit b050051

Please sign in to comment.