Presentation is loading. Please wait.

Presentation is loading. Please wait.

主页:http://staff.ustc.edu.cn/~mengning 地址:苏州工业园区独墅湖高等教育区仁爱路166号明德楼A302室

Similar presentations


Presentation on theme: "主页:http://staff.ustc.edu.cn/~mengning 地址:苏州工业园区独墅湖高等教育区仁爱路166号明德楼A302室"— Presentation transcript:

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

2 TCP Overview TCP in TCP/IP suite TCP Services TCP Segment Format
超时与半关闭 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

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

8 TCP Segment Format

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

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

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

12 Description of flags in the control field

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

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

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

16 TCP three-way handshake

17 TCP three-way handshake

18 超时 BSD版TCP采用500ms的定时器 第一次SYN之后6秒超时 第二次SYN之后24秒超时 第三次SYN之后48秒超时

19 Data transfer 找错误?

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

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

22 Connection termination using three-way handshaking

23

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

25

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

27 shutdown()函数参数说明 1 2 s标识一个套接口的描述字 how是一个标志,用于描述禁止哪些操作,取值如下表: 关闭方式 参数值
说  明 SD_RECEIVE 表示不允许再调用接收函数,它关闭读通道。套接口接收缓冲区中的所有数据都被丢弃,并且有新数据到达套接口时,也被TCP协议层丢弃,但它对发送缓冲区没有影响,进程仍然可以在套接口上发送数据 SD_SEND 1 表示不允许再调用发送函数,它关闭写通道。在套接口发送缓冲区中的数据都被发送出去,得到接收端确认之后,就生成一个FIN包关闭连接。但它对接收缓冲区没有影响,进程仍然可以在套接口上接收数据 SD_BOTH 2 关闭读写通道,相当于执行了上面SD_RECEIVE和SD_SEND两个命令

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

29

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

31 Client states 客户机状态

32 Server states 服务器状态

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


Download ppt "主页:http://staff.ustc.edu.cn/~mengning 地址:苏州工业园区独墅湖高等教育区仁爱路166号明德楼A302室"

Similar presentations


Ads by Google