1 / 33

TCP Overview

TCP Overview. 主讲:孟宁 电话:0512-68839302 E-mail:mengning@ustc.edu.cn 主页:http://staff.ustc.edu.cn/~mengning 地址:苏州工业园区独墅湖高等教育区仁爱路166号明德楼A302室. 2010年12月. TCP Overview. TCP in TCP/IP suite TCP Services TCP Segment Format TCP数据传输过程简述 TCP连接的建立与终止 超时与半关闭 TCP的状态变迁.

ricky
Télécharger la présentation

TCP Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TCP Overview 主讲:孟宁 电话:0512-68839302 E-mail:mengning@ustc.edu.cn 主页:http://staff.ustc.edu.cn/~mengning 地址:苏州工业园区独墅湖高等教育区仁爱路166号明德楼A302室 2010年12月

  2. TCP Overview • TCP in TCP/IP suite • TCP Services • TCP Segment Format • TCP数据传输过程简述 • TCP连接的建立与终止 • 超时与半关闭 • TCP的状态变迁

  3. Position of TCP in TCP/IP suite

  4. Overview of TCP/IP protocols BPF:BSD packet filter. This interface provides access to the datalink layerIt is normally found on Berkeley-derived kernels. DLPI: Datalink provider interface. This interface also provides access to the datalink layer. It is normally provided with SVR4

  5. TCP versus IP

  6. TCP Services • 提供一种面向连接的、可靠的字节流服务。 • TCP不在记录(一次发送)之间插入标识 • TCP数据分割(UDP保持数据长度不变) • 等待确认,超时重发 • 数据接收方发送确认 • 对TCP段进行排序,以保证正确的顺序 • IP包的到达可能会失序 • UDP不分割大数据,使用IP的分片服务 • 流量控制,有一个固定大小的缓冲区

  7. TCP Segment Format

  8. TCP Segment • 源端口和目的端口用来标识本地和对方的应用进程。 • sequence number指示TCP段中第一个字节的序号。建立一个新的TCP连接时(SYN标志为1),该域是主机为该连接选择的初始序号,连接建立后发送的第一个字节将具有的序号为sequence number+1(SYN和FIN都占用一个序号)。由于全双工,每个连接的端点都必须单独维持一个序号。 • acknowledgement number表示发送该TCP段的主机准备从对方接收的下一个字节序号(SN+数据长度),即该序号之前的字节已全部正确收到。 • TCP可以表述为没有选择确认或否认的滑动窗口协议。

  9. header length指示TCP头的长度(以4字节为单位),最大值为15(60字节)。 • URG标志指示urgent pointer域是否有效,urgent pointer用来指示紧急数据距当前字节序号的偏移字节数。当接收方收到一个URG为1的段后,立即中断当前正在执行的程序,根据urgent pointer找到段中的紧急数据,优先进行处理。

  10. TCP首部中有6个标志比特 • U R G 紧急指针( urgent pointer)有效。 • A C K 确认序号有效。 • P S H 接收方应该尽快将这个报文段交给应用层。 • R S T 重建连接。 • S Y N 同步序号用来发起一个连接。 • F I N 发端完成发送任务。

  11. Description of flags in the control field

  12. windows size表示发送方可以发送的字节数,为0时表示接收缓冲区满。用于TCP的流量控制。 • checksum对TCP头、TCP数据域及TCP伪头(pseudoheader,12字节长,其中的内容来自于IP分组的头)进行校验。和UDP类似。 • 选项用于提供一种增加额外设置的方法,在常规的TCP头中并不包括。重要的选择有: MSS选项(设定能接受的最大TCP载荷能力;窗口比例选项(可扩大窗口尺寸);选择重发选项等。

  13. TCP数据传输过程简述 • TCP将用户数据打包(分割)成报文段;发送后启动一个定时器;另一端对收到的数据进行确认,对失序的重新排序,丢弃重复数据;TCP提供端到端的流量控制,并计算和验证一个强制性的端到端检验和。

  14. TCP Connection Establishment • The server must be prepared to accept an incoming connection. • by calling socket, bind, and listen. • The client issues an active open by calling connect. • This causes the client TCP to send a "synchronize" (SYN) segment, which tells the server the client's initial sequence number for the data that the client will send on the connection. Normally, there is no data sent with the SYN; it just contains an IP header, a TCP header, and possible TCP options. • The server must acknowledge (ACK) the client's SYN and send its own SYN • The server sends its SYN and the ACK of the client's SYN in a single segment. • The client must acknowledge the server's SYN.

  15. TCP three-way handshake

  16. TCP three-way handshake

  17. 超时 • BSD版TCP采用500ms的定时器 • 第一次SYN之后6秒超时 • 第二次SYN之后24秒超时 • 第三次SYN之后48秒超时 • 建立一个新连接的最长时限为75秒(BSD)

  18. Data transfer 找错误?

  19. TCP Connection Termination • One application calls close first,and we say that this end performs the active close. • The other end that receives the FIN performs the passive close.The received FIN is acknowledged by TCP. • Sometime later, the application that received the end-of-file will close its socket. This causes its TCP to send a FIN. • The TCP on the system that receives this final FIN (the end that did the active close) acknowledges the FIN.

  20. a TCP connection is closed 服务端也可以主动关闭 可在最后一个数据分片中携带FIN 可合并ACK和FIN在一个分片中

  21. Connection termination using three-way handshaking

  22. TIME_WAIT(2MSL) • MSL-Maximum Segment Lifetime • RFC793,MSL=2分钟,实际实现30s,1min或2min。 • 2MSL是让TCP再次发送最后的ACK以防ACK丢失(另一端超时并重发最后的FIN)

  23. 半关闭 • TCP提供了连接的一端在结束它的发送后还能接收来自另一端数据的能力。

  24. shutdown()函数参数说明 • s标识一个套接口的描述字 • how是一个标志,用于描述禁止哪些操作,取值如下表:

  25. FIN_WAIT_2 • 主动关闭之后(发送FIN收到ACK),等待另一端的FIN • 按照规范FIN_WAIT_2可能永远保持这个状态,另一端也处于CLOSE_WAIT状态 • 实际BSD版上,如果连接空闲10分75秒,即进入CLOSED状态。

  26. 虚线:服务器端 实线:客户机端 红线:非正常情况 MSL:30s~120s

  27. Client states 客户机状态

  28. Server states 服务器状态

  29. 谢谢大家! • 使用tcpdump来抓包 • $sudo tcpdump -i lo -S

More Related