zoukankan      html  css  js  c++  java
  • TCP窗口扩大选项Window Scale

    窗口扩大选项使TCP的窗口定义从16bit增加到32bit。这并不是通过修改TCP首部来实现的,TCP首部仍然使用16bit,而是通过定义一个选项实现对16bit的扩大操作来完成的。于是TCP在内部将实际的窗口大小维持为32bit的值;

    窗口扩大选项的取值范围为0<=shif.cnt<=14;最大值为14的原因如下:

    【这段内容为本人理解,非书中原文】TCP需要保留一半的序号用于判断是否是以前的旧数据段,(2^32-1)/2<2^31,也就是现在用于处理新数据段小于2^31个;假如窗口大小为wnd,发送方第一次发送[0,wnd-1]一个窗口的数据,这时接收方收到数据,并统一发送一个ack确认这个窗口的数据,确认完之后,窗口移动准备接收[wnd, 2wnd-1]段的数据;若发送方如果没有收到这个ack,需要重传[0, wnd-1]的数据,若收到了ack,则发送[wnd, 2wnd-1]的数据,这两种情况下,接收方都需要满足序号,也就是序号需要满足2*wnd;前面说了序号的一半用于新数据,也就是2*wnd<2^31,wnd<2^30,即(2^16-1)*2^shif < 2^30,得出shift<=14,即除了TCP首部的16bit,这里最多也就是30-16=14bit;

    【这段是找到的RFC原文】大概意思是发送和接收窗口,一个窗口的左边沿到另外一个窗口的右边沿最大不能超过2^31,如果超过这个值就与保留的旧序号重叠了,也就是2*wnd < 2^31,wnd  < 2^30,得出shift<=14;

          RFC1323
          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.

    这个选项只能出现在SYN报文段中,因此当连接建立起来后,每个方向上的扩大因子是固定的。为了使用窗口扩大,两端必须在他们的SYN报文段中发送该选项。主动建立连接的一方在其SYN中发送这个选项,但是被动建立连接的一方只能够在接收到带这个选项的SYN之后才可以发送这个选项。每个方向上的扩大因此可以不同;

    如果主动连接的一方发送一个非零的扩大因子,但是没有从另一端收到一个扩大选项,它就将发送和接收的移位计数器设置为0。这就允许较新的系统能够与较旧的系统进行互相操作;

    假定我们正在使用窗口扩大选项,发送移位计数为S,而接收到的移位计数为R。于是我们从另一端接收到的16bit的通告窗口将被左移R位以获得实际的通告窗口大小。每次当我们向对方发送一个窗口通告的时候,我们将实际的32bit窗口大小右移S位,然后用它来替换TCP首部中的16bit窗口值;

    TCP根据接收缓存的大小自动选择位移技术。这个大小是由系统设置的,但是通常向应用程序提供了修改途径;

    文章来源: <TCP/IP详解>

  • 相关阅读:
    django 静态文件模版上传下载配置
    drf ModelViewSet之匹配路由参数
    Django drf序列化外键关联表ID以为字段
    Django 自关联递归序列化模块 django-rest-frame-recursive模块
    Python利用Psycopg2模块将Excel表格数据导入Postgressql
    PyTorch中view的用法
    P1113 杂务 【拓扑排序】
    P3916 图的遍历 【反向建图+DFS】
    P2814 家谱【map型的并查集】
    P1102 A-B 数对【map】
  • 原文地址:https://www.cnblogs.com/wanpengcoder/p/11750598.html
Copyright © 2011-2022 走看看