免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5546 | 回复: 6
打印 上一主题 下一主题

一个TCP的window scale option选项问题 [复制链接]

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-11-17 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-15 20:19 |只看该作者 |倒序浏览
大家好,我在内核栏目发了此贴,结果没有达人能给我帮助,在此我将那个帖子修改了下,发表在这里,希望能有人帮助我,谢谢!

我在继续研读Stevens的“TCPIP协议详解卷1”中,又遇到了关于window scale option的一个问题,望大家不吝赐教,下面是问题描述。


在24.4 Window Scale Option中有如下文字:
We saw an example of this option in Figure 18.20. The 1-byte shift count is between 0 (no scaling performed) and 14. This maximum value of 14 is a window of 1,073,725,440 bytes (65535 × 2^14).

这里我没有懂的是为啥scale的最大范围是左移14位,即2^14次幂,这个14是如何得到的?

我查阅了下rfc1323,其中有针对这个14的计算来由,但是不幸的是,该rfc中和14有关的地方我仍然没有明白,所以非常郁闷,请大家帮帮我,下面是rfc1323中有关的内容:

2.3  Using the Window Scale Option
        ...
      TCP determines if a data segment is "old" or "new" by testing
      whether its sequence number is within 2**31 bytes of the left edge
      of the window, and if it is not, discarding the data as "old".  To
      insure that new data is never mistakenly considered old and vice-
      versa, the left edge of the sender's window has to be at most
      2**31 away from the right edge of the receiver's window.

这里rfc1323在推导14这个数时,有上面一段话,其中说明了一个数据分段的序号如果距滑动窗口左边沿2**31次幂之内,则都不是old数据,这里我不明白这个31是如何得到的

此外,我把rfc1323中如何计算出14为最大伸缩因子的文字列出,请大家帮忙看看
--------------------------------------------------------------------------------------

      TCP determines if a data segment is "old" or "new" by testing
      whether its sequence number is within 2**31 bytes of the left edge
      of the window, and if it is not, discarding the data as "old".  To
      insure that new data is never mistakenly considered old and vice-
      versa, the left edge of the sender's window has to be at most
      2**31 away from the right edge of the receiver's window.
      Similarly with the sender's right edge and receiver's left edge.
      Since the right and left edges of either the sender's or
      receiver's window differ by the window size, and since the sender
      and receiver windows can be out of phase by at most the window
      size, the above constraints imply that 2 * the max window size
      must be less than 2**31, or

           max window < 2**30

      Since the max window is 2**S (where S is the scaling shift count)
      times at most 2**16 - 1 (the maximum unscaled window), the maximum
      window is guaranteed to be < 2**30 if S <= 14.  Thus, the shift
      count must be limited to 14 (which allows windows of 2**30 = 1
      Gbyte).  If a Window Scale option is received with a shift.cnt
      value exceeding 14, the TCP should log the error but use 14
      instead of the specified value.

可以看出2**31次幂的结果是最关键的地方,这个明白了,后面的好像就说得通了,我就是看不懂这个地方,我的疑问是既然tcp的序号空间范围是32bit,超过后会回绕序号,那么2**31次幂的意思就是将该范围划分为相等的2部分,即2**32/2=2**31,为啥是这样呢?

再有,另外一篇和此问题相关的文字也列出,请大家帮忙看看
--------------------------------------------------------------------------------------

      Even though a 32-bit space is now allowed for the actual window size, the maximum data size is not 4 GB (2**32 ), but rather 1 GB (2**30 ). This is done so that a TCP receiver can uniquely identify an incoming data segment as a new segment. There is no possibility of old and new segments with the same sequence number arriving out of turn and confusing the receiver, as sequence numbers themselves are in the 32-bit space.

为啥这样只利用原来的4G范围的四分之一,即1G,就能保证接收方不会混淆老数据和新数据? 难道1/2或3/4就不行吗?

论坛徽章:
0
2 [报告]
发表于 2010-01-16 15:09 |只看该作者
我也很多地方不明白,在rfc1323里有这样说
More specifically, if the maximum effective bandwidth at which TCP is able to transmit over a particular path is B bytes per second, then the following constraint must be satisfied for error-free operation:
    2**31 / B  > MSL (secs)

序号是32比特的,回绕的话应该发送了2**32比特的数据,不知道为什么这里是2**31

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-11-17 06:20:00
3 [报告]
发表于 2010-01-16 21:00 |只看该作者

回复 #2 snipex 的帖子

阿弥陀佛,总算也有人和我一样有相同的困惑了,呵呵,简单探讨下

To insure that new data is never mistakenly considered old and vice-versa, the left edge of the sender's window has to be at most 2**31 away from the right edge of the receiver's window. Similarly with the sender's right edge and receiver's left edge.

这里left edge of the sender's window,即snd.una,而right edge of the receiver's window,即rcv.wup + rcv_wnd,于是rfc1323中给出的结论为只要我们有下式成立:

|snd.una - (rcv.wup+rcv.wnd)|< 2**31(即32bit序号空间的一半)

则接收方就不会混淆序号回绕后的新分段和老的相同序号的分段,但是如果这样就能解决问题,那么后面的PAWS算法还有什么意义呢?显然这里的现象和PAWS谈到的现象应该有不同之处,难道必须满足这里的2**31次幂的条件后,PAWS算法才能起作用?

帮助下我吧!!!

[ 本帖最后由 jiufei19 于 2010-1-16 21:14 编辑 ]

论坛徽章:
0
4 [报告]
发表于 2010-01-17 16:11 |只看该作者
我觉得不管窗口大小多大PAWS都可以解决回绕问题,即使窗口大到2**32也可以。
可能我有些地方还没明白,资料太少了,只能找到几个RFC但都没具体讲清

论坛徽章:
0
5 [报告]
发表于 2010-01-18 00:55 |只看该作者
路过 支持下楼主

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-11-17 06:20:00
6 [报告]
发表于 2010-01-18 10:35 |只看该作者

回复 #4 snipex 的帖子

那几个rfc似乎给出了如下示意图,我对此只是模模糊糊理解,但是详细分析,又觉得不胜了了

snd.una     
snd.nxt     snd.una + snd.wnd
  +----------+
  |  Sender    |
  +----------+         2**31                  2**32
  +---------------------+-----------------------+
                +-----------+
                | Receiver    |
                +-----------+
           rcv.wup      rcv.wup+rcv.wnd
           rcv.nxt

[ 本帖最后由 jiufei19 于 2010-1-18 10:37 编辑 ]

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-11-17 06:20:00
7 [报告]
发表于 2010-01-18 13:53 |只看该作者

回复 #6 jiufei19 的帖子

我自己尝试下先解决2**31次幂的那个问题

1、序号空间大小是2**32,而所有和窗口大小有关的值都应满足2的整数次幂,所以窗口大小只能是2**32,2**31,2**30,...,所以现在我们要分析的就是2**32不能被用来表示最大可以使用的窗口值

2、在建立连接的TCP收发双方初始时刻,这个时刻是snd.una和rcv.wup + rcv.wnd之间相差最大的时候,于是我们有如下关系:
snd.una           
snd.nxt               snd.una + snd.wnd
  +---------------------+
  |     Sender                |
  +---------------------+
     
  +---------------------+----------------------+
  0                            2**31-1                  2**32-1
   
  +---------------------+
  |    Receiver               |
  +---------------------+
rcv.wup      rcv.wup+rcv.wnd
rcv.nxt

根据TCP滑动窗口的概念,其表示发送方在未收到接收方的确认前,所能发送的最大数据,那么根据上图我们可以看出如果这个最大数据为2**32的话,即表示一个窗口就可以填满整个序号空间的值,那么此时当发送方收到确认后,序号回绕就立刻发生了,因此就会造成之前窗口中部分被延迟分段的序号和新窗口中的序号发生重叠,显然,由于此时TCP还没有引入timestamps的选项,所以这种情况导致接收方产生混乱。

因此,2**32不能作为最大的窗口值,并且由于窗口大小必须是2的整数次幂,于是我们就知道了上图中|snd.una - (rcv.wup + rcv.wnd)| <= 2**31,即这个差的绝对值最大只能是32bit序号空间的一半,此时,发方最多发送2**31字节数据,若还没有收到收发的ACK,则发方必须等待,显然这个初始状态的差值是最大的,以后发送窗口和接收窗口都会随着时间平移,但保持这个差值不大于2**31是恒定的

[ 本帖最后由 jiufei19 于 2010-1-18 13:56 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP