🍪
cookielau
  • Introduction
  • Machine Learning
    • Distributed
      • Bookmarks
    • NLP
      • Transformers
    • MLC
      • Tensor Program Abstraction
      • End-to-End Module Execution
  • Framework
    • PyTorch
      • Bookmarks
      • Model
      • Shared
      • Miscellaneous
    • Tensorflow
      • Bookmarks
      • Model
      • Shared
      • Miscellaneous
    • CUDA
      • Bookmarks
    • DeepSpeed
    • Bagua
      • Model
      • Optimizer
    • Others
      • Bookmarks
  • About Me
    • 2022-04-28
  • Random Thoughts
  • Archives
    • CPP
      • Bookmarks
      • Container
      • Algorithm
      • FILE CONTROL
      • Virtual Table
      • Assembly
      • Key Words
      • Problems
      • Others
    • JAVA
      • String Container
      • Maps
    • PYTHON
      • Bookmarks
      • Python Tools
        • Batch Rename
        • Combine Excel
        • Excel Oprations
        • Read Write Excel
        • Rotate PDF
      • Library
        • Pandas Notes
        • Numpy Notes
        • Json Notes
      • Spider
        • Selenium Install
        • Selenium Locating
        • Selenium Errors
        • Selenium Basics
      • Django
        • Start Up
      • Others
    • LINUX
      • Installation
      • Cli Tools
      • WSL
      • Bugs
    • JUNIOR2
      • Economics
        • Chapter 0x01 经济管理概述
        • Chapter 0x02 微观市场机制分析
        • Chapter 0x03 生产决策与市场结构
        • Chapter 0x04 宏观经济市场分析
        • Chapter 0x05 管理的职能
        • Chapter 0x06 生产系统结构与战略
        • Chapter 0x0b 投资项目经济评价
        • Chapter 0x0f 投资项目经济评价
      • Computer Network
        • 概述
        • 分层模型
        • 物理层
        • 数据链路层
        • 网络层
        • 传输层
        • 应用层
        • HTTP(s)实验
        • [Practice]
      • Software Engineering
        • Introduction
        • Demand Analysis
        • Task Estimation
        • Presentation
      • Network Security
        • Chapter 0x01 概述
        • Chapter 0x02 密码学
        • Chapter 0x03 公钥体制
        • Chapter 0x04 消息认证
        • Chapter 0x05 密钥管理
        • Chapter 0x06 访问控制
        • Assignments
      • x86 Programming
        • Basic Knowledge
        • Program Design
        • System Interruption
        • Frequently used functions
    • MD&LaTex
      • Markdown
      • LaTex
    • NPM
      • NPM LINK
    • MyBlogs
      • 2020BUAA软工——“停下来,回头看”
      • 2020BUAA软工——“初窥构建之法”
      • 2020BUAA软工——“上手软件工程,PSP初体验!”
      • 2020BUAA软工——“深度评测官”
      • 2020BUAA软工——“并肩作战,平面交点Pro”
    • SC
      • PAC 2022
        • Lectures
      • OpenMP & MPI
        • MPI Overview
        • Message Passing Programming
        • OpenMP Overview
        • Work Sharing Directives
        • Annual Challenge
        • Future Topics in OpenMP
        • Tasks
        • OpenMP & MPI
    • Hardware
      • Nvidia GPU
        • Frequent Error
        • Memory Classification
        • CUDA_7_Streams_Simplify_Concurrency
        • Optimize_Data_Transfers_in_CUDA
        • Overlap_Data_Transfers_in_CUDA
        • Write_Flexible_Kernels_with_Grid-Stride_Loops
        • How_to_Access_Global_Memory_Efficiently
        • Using_Shared_Memory
      • Intel CPU
        • Construction
        • Optimization
        • Compilation
        • OpenMP
    • English
      • Vocab
      • Composition
    • Interview
      • Computer Network
Powered by GitBook
On this page
  • TCP/IP
  • Reference

Was this helpful?

  1. Archives
  2. Interview

Computer Network

TCP/IP

  1. 为什么 ack=seq+1 而不是 ack=seq? 通过查询资料和所学内容,我们知道: 1. 三次握手的前两次握手,client和server会根据一定的算法(连接四元组和时间戳还有Security Number)生成ISS。 2. 三次握手的后两次握手,client和server分别会对对方发过来的SYN进行应答,在ack序列上等于seq+1。 3. 后面传输数据的时候,sender发送len长度的data,receiver就会将ack(receiver)=seq(sender)+len(sender)。

    所以说,3中接收到多少数据就讲多少数据长度的len加在seq上是一个正常的行为,问题出在2的确认SYN中为什么将ack=seq+1,搜索到结果有如下几个: 1. SYN和FIN也是需要确认的信息,所以需要占据一个seq,表示该信息已经被确认,不需要重传。 2. 如果SYN和FIN不占据一个seq,对于FIN而言,四次挥手的第二三次server的挥手除了FLAG外其他其实是一样的,即一样的ack,可能也有一样的seq(没有数据需要传输的情况下),可能导致client段无法分辨第二次挥手的ACK和第三次挥手的FIN。

    Notice that the acknowledgement number has been increased by 1 although no payload data has yet been sent by the client. This is because the presence of the SYN or FIN flag in a received packet triggers an increase of 1 in the sequence. (This does not interfere with the accounting of payload data, because packets with the SYN or FIN flag set do not carry a payload.)

    注:收到的报文中只有ACK时不需要将seq+1。

  2. TCP传输中ACK的优化 已经知道的有延迟ACK,还有就是ACK和需要传输的数据一起过去,SO上面已经有大佬画了图:

    Before ACK Optimization:   
     +-------------------------------------------------------+
     |     client           network            server        |
     +-----------------+                +--------------------|
     |    (connect)    | ---- SYN ----> |                    |
     |                 | <-- SYN,ACK -- |     (accepted)     |
     |   (connected)   | ---- ACK ----> |                    |
     \_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/
    
     when client sends...
     \_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/
     |                 |                |                    |
     |     (send)      | ---- data ---> |                    |
     |                 | <---- ACK ---- |  (data received)   |
     \_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/
    
     when server sends...
     \_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/
     |                 |                |                    |
     |                 | <--- data ---- |       (send)       |
     | (data received) | ---- ACK ----> |                    |
     \_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/
    
     ...and so on, til the connection is shut down or reset
    
     =========================================================
     =========================================================
     After ACK Optimization:
     \_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/
     |                 |                |                    |
     |                 | <--- data ---- |       (send)       |
     | (data received) |                |                    |
     |     (send)      | -- data,ACK -> |                    |
     |                 |                |  (data received)   |
     |                 | <- data,ACK -- |       (send)       |
     | (data received) |                |                    |
     |  (wait a bit)   | <--- data ---- |       (send)       |
     | (data received) |                |                    |
     |     (send)      | -- data,ACK -> |                    |
     |                 |                |  (data received)   |
     |     (send)      | ---- data ---> |   (wait a bit)     |
     |                 |                |  (data received)   |
     |                 | <- data,ACK -- |       (send)       |
     | (data received) |                |                    |
     |  (wait a bit)   |   (dead air)   |                    |
     |                 | ---- ACK ----> |                    |
     \_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/
  3. TCP Connection State Diagram in rfc793

                               +---------+ ---------\      active OPEN
                               |  CLOSED |            \    -----------
                               +---------+<---------\   \   create TCB
                                 |     ^              \   \  snd SYN
                    passive OPEN |     |   CLOSE        \   \
                    ------------ |     | ----------       \   \
                     create TCB  |     | delete TCB         \   \
                                 V     |                      \   \
                               +---------+            CLOSE    |    \
                               |  LISTEN |          ---------- |     |
                               +---------+          delete TCB |     |
                    rcv SYN      |     |     SEND              |     |
                   -----------   |     |    -------            |     V
    +---------+      snd SYN,ACK  /       \   snd SYN          +---------+
    |         |<-----------------           ------------------>|         |
    |   SYN   |                    rcv SYN                     |   SYN   |
    |   RCVD  |<-----------------------------------------------|   SENT  |
    |         |                    snd ACK                     |         |
    |         |------------------           -------------------|         |
    +---------+   rcv ACK of SYN  \       /  rcv SYN,ACK       +---------+
    |           --------------   |     |   -----------
    |                  x         |     |     snd ACK
    |                            V     V
    |  CLOSE                   +---------+
    | -------                  |  ESTAB  |
    | snd FIN                  +---------+
    |                   CLOSE    |     |    rcv FIN
    V                  -------   |     |    -------
    +---------+          snd FIN  /       \   snd ACK          +---------+
    |  FIN    |<-----------------           ------------------>|  CLOSE  |
    | WAIT-1  |------------------                              |   WAIT  |
    +---------+          rcv FIN  \                            +---------+
    | rcv ACK of FIN   -------   |                            CLOSE  |
    | --------------   snd ACK   |                           ------- |
    V        x                   V                           snd FIN V
    +---------+                  +---------+                   +---------+
    |FINWAIT-2|                  | CLOSING |                   | LAST-ACK|
    +---------+                  +---------+                   +---------+
    |                rcv ACK of FIN |                 rcv ACK of FIN |
    |  rcv FIN       -------------- |    Timeout=2MSL -------------- |
    |  -------              x       V    ------------        x       V
     \ snd ACK                 +---------+delete TCB         +---------+
      ------------------------>|TIME WAIT|------------------>| CLOSED  |
                               +---------+                   +---------+

Reference

  1. StackOverflow | Does TCP send a SYN/ACK on every packet or only on the first connection?

  2. Understanding TCP Sequence and Acknowledgment Numbers

  3. Why does an pure ACK increment the sequence number?

  4. RFC 793

PreviousInterview

Last updated 4 years ago

Was this helpful?