Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3-2 TCP.

Similar presentations


Presentation on theme: "Chapter 3-2 TCP."— Presentation transcript:

1 Chapter 3-2 TCP

2 Chapter 3 outline 3.5 Connection-oriented transport: TCP
segment structure reliable data transfer flow control connection management 3.6 Principles of congestion control 3.7 TCP congestion control 3.1 Transport-layer services 3.2 Multiplexing and demultiplexing 3.3 Connectionless transport: UDP 3.4 Principles of reliable data transfer Chapter 3-2 TCP 3-2 2

3 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 point-to-point:
one sender, one receiver reliable, in-order byte steam: no “message boundaries” pipelined: TCP congestion and flow control set window size send & receive buffers full duplex data: bi-directional data flow in same connection MSS: maximum segment size connection-oriented: handshaking (exchange of control msgs) init’s sender, receiver state before data exchange flow controlled: sender will not overwhelm receiver Chapter 3-2 TCP

4 TCP segment structure source port # dest port # application data
32 bits application data (variable length) sequence number acknowledgement number Receive window Urg data pnter checksum F S R P A U head len not used Options (variable length) URG: urgent data (generally not used) counting by bytes of data (not segments!) ACK: ACK # valid PSH: push data now (generally not used) # bytes rcvr willing to accept RST, SYN, FIN: connection estab (setup, teardown commands) Internet checksum (as in UDP) Chapter 3-2 TCP 3-4 4

5 simple telnet scenario
TCP seq. #’s and ACKs Seq. #’s: byte stream “number” of first byte in segment’s data ACKs: seq # of next byte expected from other side cumulative ACK Q: how receiver handles out-of-order segments A: TCP spec doesn’t say, - up to implementor Host A Host B User types ‘C’ Seq=42, ACK=79, data = ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ Seq=79, ACK=43, data = ‘C’ host ACKs receipt of echoed ‘C’ Seq=43, ACK=80 time simple telnet scenario Chapter 3-2 TCP

6 TCP Round Trip Time and Timeout
Q: how to set TCP timeout value? longer than RTT but RTT varies too short: premature timeout unnecessary retransmissions too long: slow reaction to segment loss Q: how to estimate RTT? SampleRTT: measured time from segment transmission until ACK receipt ignore retransmissions SampleRTT will vary, want estimated RTT “smoother” average several recent measurements, not just current SampleRTT Chapter 3-2 TCP 3-6 6

7 TCP Round Trip Time and Timeout
EstimatedRTT = (1- )*EstimatedRTT + *SampleRTT Exponential weighted moving average influence of past sample decreases exponentially fast typical value:  = 0.125 Chapter 3-2 TCP 3-7 7

8 Example RTT estimation:
Chapter 3-2 TCP 3-8 8

9 TCP Round Trip Time and Timeout
Setting the timeout EstimtedRTT plus “safety margin” large variation in EstimatedRTT -> larger safety margin first estimate of how much SampleRTT deviates from EstimatedRTT: DevRTT = (1-)*DevRTT + *|SampleRTT-EstimatedRTT| (typically,  = 0.25) Then set timeout interval: TimeoutInterval = EstimatedRTT + 4*DevRTT Chapter 3-2 TCP 3-9 9

10 Chapter 3 outline 3.1 Transport-layer services
3.2 Multiplexing and demultiplexing 3.3 Connectionless transport: UDP 3.4 Principles of reliable data transfer 3.5 Connection-oriented transport: TCP segment structure reliable data transfer flow control connection management 3.6 Principles of congestion control 3.7 TCP congestion control Chapter 3-2 TCP 3-10 10

11 TCP reliable data transfer
TCP creates rdt service on top of IP’s unreliable service Pipelined segments Cumulative acks TCP uses single retransmission timer Retransmissions are triggered by: timeout events duplicate acks Initially consider simplified TCP sender: ignore duplicate acks ignore flow control, congestion control Chapter 3-2 TCP 3-11 11

12 TCP sender events: data rcvd from app: Create segment with seq #
seq # is byte-stream number of first data byte in segment start timer if not already running (think of timer as for oldest unacked segment) expiration interval: TimeOutInterval timeout: retransmit segment that caused timeout restart timer Ack rcvd: If acknowledges previously unacked segments update what is known to be acked start timer if there are outstanding segments Chapter 3-2 TCP

13 TCP sender (simplified)
NextSeqNum = InitialSeqNum SendBase = InitialSeqNum loop (forever) { switch(event) event: data received from application above create TCP segment with sequence number NextSeqNum if (timer currently not running) start timer pass segment to IP NextSeqNum = NextSeqNum + length(data) event: timer timeout retransmit not-yet-acknowledged segment with smallest sequence number event: ACK received, with ACK field value of y if (y > SendBase) { SendBase = y if (there are currently not-yet-acknowledged segments) } } /* end of loop forever */ TCP sender (simplified) Comment: SendBase-1: last cumulatively ack’ed byte Example: SendBase-1 = 71; y= 73, so the rcvr wants 73+ ; y > SendBase, so that new data is acked Chapter 3-2 TCP 3-13 13

14 TCP: retransmission scenarios
Host A Seq=92, 8 bytes data ACK=100 loss timeout lost ACK scenario Host B X time Host A Host B Seq=92 timeout Seq=92, 8 bytes data Seq=100, 20 bytes data ACK=100 ACK=120 Sendbase = 100 Seq=92, 8 bytes data SendBase = 120 Seq=92 timeout ACK=120 SendBase = 100 SendBase = 120 premature timeout time Chapter 3-2 TCP 3-14 14

15 TCP retransmission scenarios (more)
Host A Seq=92, 8 bytes data ACK=100 loss timeout Cumulative ACK scenario Host B X Seq=100, 20 bytes data ACK=120 time SendBase = 120 Chapter 3-2 TCP 3-15 15

16 TCP ACK generation [RFC 1122, RFC 2581]
Event at Receiver Arrival of in-order segment with expected seq #. All data up to expected seq # already ACKed expected seq #. One other segment has ACK pending Arrival of out-of-order segment higher-than-expect seq. # . Gap detected Arrival of segment that partially or completely fills gap TCP Receiver action Delayed ACK. Wait up to 500ms for next segment. If no next segment, send ACK Immediately send single cumulative ACK, ACKing both in-order segments Immediately send duplicate ACK, indicating seq. # of next expected byte Immediate send ACK, provided that segment starts at lower end of gap Chapter 3-2 TCP 3-16 16

17 Fast Retransmit Time-out period often relatively long: long delay before resending lost packet Detect lost segments via duplicate ACKs. Sender often sends many segments back-to-back If segment is lost, there will likely be many duplicate ACKs. If sender receives 3 ACKs for the same data, it supposes that segment after ACKed data was lost: fast retransmit: resend segment before timer expires Chapter 3-2 TCP 3-17 17

18 X time Figure 3.37 Resending a segment after triple duplicate ACK
Host A timeout Host B time X resend 2nd segment Figure 3.37 Resending a segment after triple duplicate ACK Chapter 3-2 TCP 3-18 18

19 Fast retransmit algorithm:
event: ACK received, with ACK field value of y if (y > SendBase) { SendBase = y if (there are currently not-yet-acknowledged segments) start timer } else { increment count of dup ACKs received for y if (count of dup ACKs received for y = 3) { resend segment with sequence number y a duplicate ACK for already ACKed segment fast retransmit Chapter 3-2 TCP Transport Layer 3-19 19

20 Chapter 3 outline 3.5 Connection-oriented transport: TCP
segment structure reliable data transfer flow control connection management 3.6 Principles of congestion control 3.7 TCP congestion control 3.1 Transport-layer services 3.2 Multiplexing and demultiplexing 3.3 Connectionless transport: UDP 3.4 Principles of reliable data transfer Chapter 3-2 TCP Transport Layer 3-20 20

21 TCP Flow Control receive side of TCP connection has a receive buffer:
sender won’t overflow receiver’s buffer by transmitting too much, too fast flow control receive side of TCP connection has a receive buffer: speed-matching service: matching the send rate to the receiving app’s drain rate app process may be slow at reading from buffer Chapter 3-2 TCP Transport Layer 3-21 21

22 TCP Flow control: how it works
Rcvr advertises spare room by including value of RcvWindow in segments Sender limits unACKed data to RcvWindow guarantees receive buffer doesn’t overflow (Suppose TCP receiver discards out-of-order segments) spare room in buffer = RcvWindow = RcvBuffer-[LastByteRcvd - LastByteRead] Chapter 3-2 TCP Transport Layer 3-22 22

23 Chapter 3 outline 3.1 Transport-layer services
3.2 Multiplexing and demultiplexing 3.3 Connectionless transport: UDP 3.4 Principles of reliable data transfer 3.5 Connection-oriented transport: TCP segment structure reliable data transfer flow control connection management 3.6 Principles of congestion control 3.7 TCP congestion control Chapter 3-2 TCP Transport Layer 3-23 23

24 Connection establishment and release
Chapter 3-2 TCP

25 Connection Establishment
Basic idea: To establish a connection, you send off a connection request to the other end. The other end then accepts the connection, and returns an acknowledgment. Big problem: Suppose you don’t get an answer, so you do another request. Your first request didn’t make it: no harm done. The ack didn’t make it back: you’re establishing a second connection, but this can probably be detected. Your first request didn’t make it yet: now you’re really making a second connection and no one knows you didn’t do this on purpose. Chapter 3-2 TCP

26 Connection Establishment Problem
Main cause: The network has storage capabilities, and unpredictable delays. This means that things can pop up out of the blue. Attacking Duplicates Solution: Restrict the lifetime of TPDUs – if the maximum lifetime is known in advance, we can be sure that a previous packet is discarded and that it won’t interfere with successive ones. Basic idea: Assign sequence numbers to TPDUs, and let the sequence number space be so large that no two outstanding TPDUs can have the same number. Chapter 3-2 TCP

27 Connection Establishment Problem
Problem: When a host crashes, it has to start numbering TPDUs again. So, where does it start? You can’t just wait the maximum packet lifetime T and start counting from the start again: in wide area systems, T may be too large to do that. The point is that you must avoid that an initial sequence number corresponds to a TPDU still floating around. So, just find the right initial number. Solution: Assign sequence numbers in accordance to clock ticks, and assume that the clock continues ticking during a crash. This leads to a forbidden region: Chapter 3-2 TCP

28 Linear relation between time and initial sequence numbers
(a) TPDUs may not enter forbidden reg. (b) resynchronization problem Every time you want to assign a next sequence number, check whether that number is in the forbidden region. Watch it: when sequence numbers are assigned at a lower pace than the clock ticks, we may enter the region “from the top.” Likewise, assigning them too fast makes you enter the region “from the bottom.” Chapter 3-2 TCP

29 Error-Free Connection Establishment
Problem: Great, we have a way of avoiding duplicates, but how do we get a connection in the first place? Note: One way or the other we have to get the sender and receiver to agree on initial sequence numbers. We need to avoid that an old (unnumbered) connection request pops up. Solution: Three-way handshake. Chapter 3-2 TCP

30 TCP Connection Management
Three way handshake: Step 1: client host sends TCP SYN segment to server specifies initial seq # no data Step 2: server host receives SYN, replies with SYNACK segment server allocates buffers specifies server initial seq. # Step 3: client receives SYNACK, replies with ACK segment, which may contain data Recall: TCP sender, receiver establish “connection” before exchanging data segments initialize TCP variables: seq. #s buffers, flow control info (e.g. RcvWindow) client: connection initiator Socket clientSocket = new Socket("hostname","port number"); server: contacted by client Socket connectionSocket = welcomeSocket.accept(); Chapter 3-2 TCP Transport Layer 3-30 30

31 TCP connection acknowledgment host A host B client server SYN, SEQ = x
request SYN, ACK, SEQ = y, ACK= x  1 acknowledgment ACK, SEQ = x + 1, ACK = y  1 acknowledgment Chapter 3-2 TCP

32 Three-way Handshake Chapter 3-2 TCP

33 Connection Release Asymmetric release: one party just closes down the connection. May result in loss of data: Chapter 3-2 TCP

34 Symmetric Connection Release
Practical solution: Use timeout mechanisms. This will catch most cases, but it is never a fool-proof solution: the initial DR and all retransmissions may still be lost, resulting in a half-open connection. The two-army problem. Chapter 3-2 TCP

35 Chapter 3-2 TCP

36 TCP Connection Management (cont.)
Closing a connection: client closes socket: clientSocket.close(); Step 1: client end system sends TCP FIN control segment to server Step 2: server receives FIN, replies with ACK. Closes connection, sends FIN. client FIN server ACK close closed timed wait Chapter 3-2 TCP

37 TCP Connection Management (cont.)
Step 3: client receives FIN, replies with ACK. Enters “timed wait” - will respond with ACK to received FINs Step 4: server, receives ACK. Connection closed. Note: with small modification, can handle simultaneous FINs. client server closing FIN ACK closing FIN ACK timed wait closed closed Chapter 3-2 TCP Transport Layer 3-37 37

38 TCP Connection Management (cont)
TCP server lifecycle TCP client lifecycle Chapter 3-2 TCP Transport Layer 3-38 38

39 TCP transition process
SYN, SEQ = x Client process Server process LISTEN(open) (open) SYN_SENT SYN_RCVD ESTABLISHED CLOSE_WAIT FIN_WAIT_2 LAST_ACK TIME_WAIT CLOSED (duplex data transition) SYN, ACK, SEQ = y, ACK = x + 1 ACK, SEQ = x + 1, ACK = y + 1 FIN, SEQ = u ACK, SEQ = v, ACK = u + 1 FIN, ACK, SEQ = v, ACK = u + 1 ACK, SEQ = u + 1, ACK = v + 1 Chapter 3-2 TCP

40 Next Appendix 3.6 Principles of congestion control
3.7 TCP congestion control Chapter 3-2 TCP

41 两次握手 B给A发送一个连接请求分组,A收到了这个分组,并发送了确认应答分组。按照两次握手的协定,A认为连接已经成功地建立了,可以开始发送数据分组。 B在A的应答分组在传输中被丢失的情况下,将不知道A是否已准备好,不知道A建议什么样的序列号,B甚至怀疑A是否收到自己的连接请求分组。 在这种情况下,B认为连接还未建立成功,将忽略A发来的任何数据分组,只等待连接确认应答分组。而A在发出的分组超时后,重复发送同样的分组。这样就形成了死锁。 Chapter 3-2 TCP

42 建立 TCP 连接 A 的 TCP 向 B 发出连接请求报文段,其首部中的同步比特 SYN 应置为 1,并选择序号 x,表明传送数据时的第一个数据字节的序号是 x。 B 的 TCP 收到连接请求报文段后,如同意,则发回确认。 B 在确认报文段中应将 SYN 置为 1,其确认号应为 x  1,同时也为自己选择序号 y。 A 收到此报文段后,向 B 给出确认,其确认号应为 y  1。 A 的 TCP 通知上层应用进程,连接已经建立。 当运行服务器进程的主机 B 的 TCP 收到主机 A 的确认后,也通知其上层应用进程,连接已经建立。 Chapter 3-2 TCP

43 TCP 的数据编号与确认 TCP 协议是面向字节的。TCP 将所要传送的报文看成是字节组成的数据流,并使每一个字节对应于一个序号。
Chapter 3-2 TCP

44 TCP seq. #’s 和 ACKs Seq. #’s: 该数据段第一个字节在(整个报文)字节流中 “编号” ACKs:
A: TCP 没有定义, - 由程序设计者决定 Host A Host B User types ‘C’ Seq=42, ACK=79, data = ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ Seq=79, ACK=43, data = ‘C’ host ACKs receipt of echoed ‘C’ Seq=43, ACK=80 time 简单的 telnet 场景 Chapter 3-2 TCP

45 32 bit TCP 报文段 发送在前 IP 首部 IP 数据部分 比特 0 8 16 24 31 源 端 口 目 的 端 口 序 号
比特 源 端 口 目 的 端 口 序 号 20 字节的 固定首部 TCP 首部 确 认 号 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 TCP 报文段 TCP 首部 TCP 数据部分 发送在前 IP 首部 IP 数据部分 Chapter 3-2 TCP

46 源端口和目的端口字段——各占 2 字节。端口是传输层与应用层的服务接口。传输层的复用和分用功能都要通过端口才能实现。
比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 源端口和目的端口字段——各占 2 字节。端口是传输层与应用层的服务接口。传输层的复用和分用功能都要通过端口才能实现。 Chapter 3-2 TCP

47 比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 序号字段——占 4 字节。TCP 连接中传送的数据流中的每一个字节都编上一个序号。序号字段的值则指的是本报文段所发送的数据的第一个字节的序号。 Chapter 3-2 TCP

48 确认号字段——占 4 字节,是期望收到对方的下一个报文段的数据的第一个字节的序号。
比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 确认号字段——占 4 字节,是期望收到对方的下一个报文段的数据的第一个字节的序号。 Chapter 3-2 TCP

49 数据偏移(首部长度)——占 4 bit,它指出 TCP 报文段的数据起始处距离 TCP 报文段的起始处有多远。“数据偏移”的单位是4 字节。
比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 数据偏移(首部长度)——占 4 bit,它指出 TCP 报文段的数据起始处距离 TCP 报文段的起始处有多远。“数据偏移”的单位是4 字节。 Chapter 3-2 TCP

50 保留字段——占 6 bit,保留为今后使用,但目前应置为 0。
比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 保留字段——占 6 bit,保留为今后使用,但目前应置为 0。 Chapter 3-2 TCP

51 紧急比特 URG —— 当 URG  1 时,表明紧急指针字段有效。它告诉系统此报文段中有紧急数据,应尽快传送(相当于高优先级的数据)。
比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 紧急比特 URG —— 当 URG  1 时,表明紧急指针字段有效。它告诉系统此报文段中有紧急数据,应尽快传送(相当于高优先级的数据)。 Chapter 3-2 TCP

52 确认比特 ACK —— 只有当 ACK  1 时确认号字段才有效。当 ACK  0 时,确认号无效。
比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 确认比特 ACK —— 只有当 ACK  1 时确认号字段才有效。当 ACK  0 时,确认号无效。 Chapter 3-2 TCP

53 比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 推送比特 PSH (PuSH) —— 接收 TCP 收到推送比特置 1 的报文段,就尽快地交付给接收应用进程,而不再等到整个缓存都填满了后再向上交付。 Chapter 3-2 TCP

54 比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 复位比特 RST (ReSeT) —— 当 RST  1 时,表明 TCP 连接中出现严重差错(如由于主机崩溃或其他原因),必须释放连接,然后再重新建立传输连接。 Chapter 3-2 TCP

55 同步比特 SYN —— 同步比特 SYN 置为 1,就表示这是一个连接请求或连接接受报文。
比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 同步比特 SYN —— 同步比特 SYN 置为 1,就表示这是一个连接请求或连接接受报文。 Chapter 3-2 TCP

56 终止比特 FIN (FINal) —— 用来释放一个连接。当FIN  1 时,表明此报文段的发送端的数据已发送完毕,并要求释放传输连接。
比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 终止比特 FIN (FINal) —— 用来释放一个连接。当FIN  1 时,表明此报文段的发送端的数据已发送完毕,并要求释放传输连接。 Chapter 3-2 TCP

57 比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 窗口字段 —— 占 2 字节。窗口字段用来控制对方发送的数据量,单位为字节。TCP 连接的一端根据设置的缓存空间大小确定自己的接收窗口大小,然后通知对方以确定对方的发送窗口的上限。 Chapter 3-2 TCP

58 检验和 —— 占 2 字节。检验和字段检验的范围包括首部和数据这两部分。在计算检验和时,要在 TCP 报文段的前面加上 12 字节的伪首部。
比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 检验和 —— 占 2 字节。检验和字段检验的范围包括首部和数据这两部分。在计算检验和时,要在 TCP 报文段的前面加上 12 字节的伪首部。 Chapter 3-2 TCP

59 紧急指针字段 —— 占 16 bit。紧急指针指出在本报文段中的紧急数据的最后一个字节的序号。
比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 紧急指针字段 —— 占 16 bit。紧急指针指出在本报文段中的紧急数据的最后一个字节的序号。 Chapter 3-2 TCP

60 MSS 是 TCP 报文段中的数据字段的最大长度。
比特 源 端 口 目 的 端 口 MSS 是 TCP 报文段中的数据字段的最大长度。 数据字段加上 TCP 首部 才等于整个的 TCP 报文段。 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 选项字段 —— 长度可变。TCP 只规定了一种选项,即最大报文段长度 MSS (Maximum Segment Size)。MSS 告诉对方 TCP:“我的缓存所能接收的报文段的数据字段的最大长度是 MSS 个字节。” Chapter 3-2 TCP

61 填充字段 —— 这是为了使整个首部长度是 4 字节的整数倍。
比特 源 端 口 目 的 端 口 序 号 20 字节 固定 首部 确 认 号 TCP 首部 数据 偏移 U R G A C K P S H R S T S Y N F I N 保 留 窗 口 检 验 和 紧 急 指 针 选 项 (长 度 可 变) 填 充 填充字段 —— 这是为了使整个首部长度是 4 字节的整数倍。 Chapter 3-2 TCP

62 从 A 到 B 的连接就释放了,连接处于半关闭状态。
至此,整个连接已经全部释放。 TCP 连接释放的过程 主机 A 主机 B 应用进程 释放连接 B 不再发送报文 通知主机 应用进程 应用进程 释放连接 A 不再发送报文 FIN, SEQ = x ACK, SEQ = y, ACK= x  1 确认 从 A 到 B 的连接就释放了,连接处于半关闭状态。 相当于 A 向 B 说: “我已经没有数据要发送了。 但你如果还发送数据,我仍接收。” FIN, ACK, SEQ = y, ACK = x + 1 ACK, SEQ = x + 1, ACK = y  1 确认 Chapter 3-2 TCP

63 TCP 的有限状态机 为了管理因特网,在网络管理中心设有管理 信息库 MIB (Management Information Base)。
TCP 连接表对每个连接都登记了其连接信息。除本地和远地的 IP 地址和端口号外,还要记录每一个连接所处的状态。 连接状态 本地 IP 地址 本地端口 远地 IP 地址 远地端口 连接 1 连接 2 连接 n Chapter 3-2 TCP

64 TCP 的 有 限 状 态 机 起点 CLOSED 被动打开 主动打开 发送 SYN 关闭 收到 SYN 发送 SYN, ACK
LISTEN TCP 的 有 限 状 态 机 被动打开 收到 RST 发送 SYN 关闭 或超时 收到 SYN,发送 SYN, ACK SYN_RCVD SYN_SENT 同时打开 主动打开 收到 ACK 收到 SYN, ACK 发送 ACK 数据传送 阶段 收到 FIN 发送 ACK 被动关闭 关闭 发送 FIN ESTABLISHED CLOSE_WAIT 关闭 发送 FIN 主动关闭 关闭 发送 FIN 收到 FIN 发送 ACK 同时关闭 FIN_WAIT_1 CLOSING 收到 ACK 收到 FIN, ACK 发送 ACK LAST_ACK 收到 ACK 收到 ACK 收到 FIN 发送 ACK Chapter 3-2 TCP FIN_WAIT_2 TIME_WAIT 定时经过两倍报文段寿命后


Download ppt "Chapter 3-2 TCP."

Similar presentations


Ads by Google