Bug 1565 - Silly window syndrome avoidance
Silly window syndrome avoidance
Status: RESOLVED INVALID
Product: ns-3
Classification: Unclassified
Component: tcp
ns-3.16
All All
: P5 normal
Assigned To: Adrian S.-W. Tam
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-01-10 16:24 EST by Florian Tschorsch
Modified: 2015-10-27 05:56 EDT (History)
5 users (show)

See Also:


Attachments
Silly window syndrome test script (2.32 KB, text/x-c++src)
2013-01-10 16:24 EST, Florian Tschorsch
Details
SWS patch (1.97 KB, patch)
2013-01-11 07:19 EST, Florian Tschorsch
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Tschorsch 2013-01-10 16:24:03 EST
Created attachment 1494 [details]
Silly window syndrome test script

I recognized an incomplete implementation of silly window syndrome (SWS) avoidance in ns-3. As far as I understand SWS there are two avoidance methods:

First, on the sending side. Here, you try to always send a full MSS. Thus you minimize the relation between payload and header overhead. This is called clumping. In ns-3 this feature is implemented in TcpSocketBase::SendPendingData (lines 1931ff.). 

Second, on the receiving side. Here, you try to avoid advertising tiny TCP flow control windows. Remedy provides Clark's algorithm (cf. rfc813). In a nutshell you set the advertised window to zero when the actual window is smaller than a MSS or the remaining free space is in the rx buffer is less than half of its max size. 

This feature is missing in ns-3. Thus you can run in deadlocks where a very small window is advertised, but the sender refuses to send more because of the SWS avoidance. You can produce this situation with the litte simulation script in the attachment. 

Actually, I think the bug-fix is quite easy. My suggestion is to edit TcpSocketBase::AdvertisedWindowSize as follows: 

uint16_t
TcpSocketBase::AdvertisedWindowSize ()
{
  uint16_t w = std::min (m_rxBuffer.MaxBufferSize () - m_rxBuffer.Size (), (uint32_t)m_maxWinSize);
  return (w < m_segmentSize && w < m_rxBuffer.MaxBufferSize ()/2 ) ? 0 : w;
}



Feedback is highly appreciated.
Comment 1 Florian Tschorsch 2013-01-10 16:40:38 EST
Probably, the implementation of SWS avoidance on the sending side TcpSocketBase::SendPendingData is redundant since Nagle's algorithm should already cover it.
Comment 2 Florian Tschorsch 2013-01-11 07:19:34 EST
Created attachment 1495 [details]
SWS patch

This patch implements Clark's algorithm and straightens Nagle's algorithm/ sending side's SWS avoidance.
Comment 3 Tom Henderson 2013-01-18 17:04:10 EST
> 
> uint16_t
> TcpSocketBase::AdvertisedWindowSize ()
> {
>   uint16_t w = std::min (m_rxBuffer.MaxBufferSize () - m_rxBuffer.Size (),
> (uint32_t)m_maxWinSize);
>   return (w < m_segmentSize && w < m_rxBuffer.MaxBufferSize ()/2 ) ? 0 : w;
> }
> 
> 
> 
> Feedback is highly appreciated.

I agree with this improvement, but deadlocks might still occur if the MSS are unequal between sender and receiver because there are no MSS announcements in ns-3 TCP.  So, I would suggest perhaps a note here that we need to revisit this when the MSS option support is eventually added, such as:

  // m_segmentSize should be replaced by m_sendMssSize when sender's MSS
  // is eventually learned by this implementation

Adrian previously started support for TCP options here:

https://codereview.appspot.com/5452045/

it would be nice to push this along if someone has cycles to do this.  The above code review just adds support for parsing the options but the logic to use the options is still needed.
Comment 4 Tom Henderson 2013-01-18 17:06:53 EST
(In reply to comment #2)
> Created attachment 1495 [details]
> SWS patch
> 
> This patch implements Clark's algorithm and straightens Nagle's algorithm/
> sending side's SWS avoidance.

Looks good to me; I suggest these steps:

1) make the patch conform to ns-3 coding style use of braces, and add my suggested comment about future MSS option support
2) make the sws.cc into a test case that fails without the patch and passes with it.  This will require some testing of e.g. making reasonable progress on the bulk transfer.
3) merge
Comment 5 Florian Tschorsch 2013-01-21 06:40:57 EST
The roadmap sounds great to me. Thanks. 

In addition, I added a proposal for an enhancement to TCPs zero-window behaviour in Bug 1751. This is connected to the topic here.
Comment 6 natale.patriciello 2015-10-27 05:56:39 EDT
ns-3 does not shrink anymore the advertised window, so the bug isn't valid anymore. Please reopen (or better, create a new bug) if you think it's still present.