中科大,计算机网络课件r12_2
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
TCP是专门设计用于提供可靠的、端到端的字节流通信的协议,它使得 进程与进程之间好像如同由“管道”连接一般。 发送方TCP实体将应用程序的输出流分为不超过64k字节(实际通常 为1500字节)的数据片段(piece),并将每个数据片段封装在一个IP分 组中发送出去。 接收方TCP实体根据字节序号(32位)将接收到的各个数据片段组 装成连续的字节流交给应用程序。
Stream Delivery Service 流交付服务 Full-Duplex Communication 全双工通信服务 Connection-Oriented Service 面向连接服务 Reliable Service 可靠的服务
Chapter12 10
Stream delivery 流交付
Chapter12 15
Example 2
Suppose a TCP connection is transferring a file of 5000 bytes. The first byte is numbered 10001. What are the sequence numbers for each segment if data is sent in five segments, each carrying 1000 bytes? S o l u t i o n The following shows the sequence number for each segment:
Chapter12 20
TCP数据段头的说明-2
• header length指示TCP头的长度(以4字节 为单位),最大值为15(60字节)。 • URG标志指示urgent pointer域是否有效, urgent pointer用来指示紧急数据距当前字 节序号的偏移字节数。当接收方收到一个 URG为1的段后,立即中断当前正在执行的 程序,根据urgent pointer找到段中的紧急 数据,优先进行处理。
Segment 1 ➡ Sequence Number: 10,001 (range: 10,001 to 11,000) Segment 2 ➡ Sequence Number: 11,001 (range: 11,001 to 12,000) Segment 3 ➡ Sequence Number: 12,001 (range: 12,001 to 13,000) Segment 4 ➡ Sequence Number: 13,001 (range: 13,001 to 14,000) Segment 5 ➡ Sequence Number: 14,001 (range: 14,001 to 15,000)
Chapter12 22
TCP数据段头的说明-4
• windows size表示发送方可以发送的字节数, 为0时表示接收缓冲区满。用于TCP的流量控 制。 • checksum对TCP头、TCP数据域及TCP伪头 (pseudoheader,12字节长,其中的内容来 自于IP分组的头)进行校验。 • 选项用于提供一种增加额外设置的方法,在常 规的TCP头中并不包括。重要的选择有: MSS选项(设定能接受的最大TCP载荷能力; 窗口比例选项(可扩大窗口尺寸);选择重发 选项等。
Chapter12
2
Position of TCP in TCP/IP protocol suite
Chapter12
3
传输层的责任:
1. 创建进程到进程的通信 2. 提供传输层控制机制(流量控制、差错控制、分组确 认等) 3. 为进程提供连接机制
TCP
通过使用端口号来完成进程到进程的通信 使用滑动窗口协议完成流量控制 使用确认分组、超时和重传来完成差错控制
Chapter12
5
TCP versus IP
Chapter12
6
Port numbers
Chapter12
7
Table 12.1 Well-known ports used by TCP
Chapter12
8
Example 1
As we said in Chapter 11, in UNIX, the well-known ports are stored in a file called /etc/services. Each line in this file gives the name of the server and the well-known port number. We can use the grep utility to extract the line corresponding to the desired application. The following shows the ports for FTP.文
Chapter12 16
Note: The value in the sequence number field of a segment defines the number of the first data byte contained in that segment.
Chapter12
17
Chapter12
26
12.4 A TCP CONNECTION
TCP is connection-oriented. A connection-oriented transport protocol establishes a virtual path between the source and destination. All of the segments belonging to a message are then sent over this virtual path. A connection-oriented transmission requires three phases: connection establishment, data transfer, and connection termination.
Chapter12 21
TCP数据段头的说明-3
• ACK标志为1时表示acknowledgement number 中是一个有效的应答序号。 • PSH标志为1时表示接收方收到数据后应尽快 交给应用程序,而不是等接收缓冲区满后再递 交。 • RST标志为1时表示复位一个连接。通常在主 机崩溃后复位连接,也可表示拒绝建立一个连 接或拒绝接收一个非法的段。 • SYN标志为1时表示建立一个连接。 • FIN标志为1时表示数据发送结束,但仍可继续 接收另一个方向的数据。
Chapter 12
Transmission Control Protocol
Transmission Control Protocol
PROCESS-TO-PROCESS COMMUNICATION 进程到进程的通信 TCP SERVICES TCP的服务 NUMBERING BYTES 给字节编号//A FLOW CONTROL 流量控制 SILLY WINDOW SYNDROME 糊涂窗口综合症 ERROR CONTROL 差错控制 TCP TIMERS TCP的计时 CONGESTION CONTROL 拥塞控制 SEGMENT 报文段 OPTIONS 选项0-40B(往返时间-时间戳) 比较 IP CHECKSUM 检验和 CONNECTION 连接 建立连接的时候 参数就已经协好了 STATE TRANSITION DIAGRAM 状态转换图 含义 TCP OERATION TCP的操作 TCP PACKAGE TCP软件包
面向连接的协议在源端和目的端之间建立一条虚路径。
The topics discussed in this section include: Connection Establishment Data Transfer Connection Termination Connection Reset
Chapter12
本解析
$ grep ftp /etc/services ftp-data ftp-control 20/tcp 21/tcp
Chapter12
9
12.1.2 TCP SERVICES TCP的服 务
We explain the services offered by TCP to the processes at the application layer. 【我们要解释一下TCP向应用层进程提供的 服务。】
Chapter12 11
Sending and receiving buffers 发送缓存和接收缓存
白色:表示空位置 灰色:已发送但还没确认字节 红色:将要发送的字节
白色:表示空位置 红色:接收到的字节
Chapter12
12
TCP segments TCP 报文段
报文段:若干个字节构成的TCP分组,报文段的长度 不尽相同,大约是几百字节~几千字节。
Chapter12 13
12.1.3全双工通信
全双工通信服务
即数据可以在同一时间双向流动。
面向连接服除连接。
使用确认机制来检查数据是否完整地到达。
可靠的服务
Chapter12
14
12.2 给字节编号
字节号:TCP对所有发送的字节都编了号。 起始字节号:第一个字节的编号,在0~ 232-1之间随机产生的一个数。32b 序号:TCP 给每个报文指派一个序号,该 序号就是该报文段中的第一个字节数据的 字节号。 确认号:TCP通信中的一方期望接收的下 一个字节的编号。(确认号是累计的)
TCP 是面向连接的、可靠的传输协议 TCP是专门设计用于在不可靠的Internet上提供 可靠的、端到端的字节流通信的协议。
Chapter12 4
12.1.1 PROCESS-TO-PROCESS
COMMUNICATION 进程到进程的通信
Port Numbers 端口号 Socket Addresses 套接字地址
chapter12chapter12transmissiontransmissioncontrolprotocolcontrolprotocolchapter12transmissioncontrolprotocoltransmissioncontrolprotocolprocesstoprocesscommunication进程到进程的通信tcpservicestcp的服务numberingbytes给字节编号aflowcontrol流量控制sillywindowsyndrome糊涂窗口综合症errorcontrol差错控制tcptimerstcp的计时congestioncontrol拥塞控制segment报文段options选项040b往返时间时间戳比较ipchecksum检验和connection连接建立连接的时候参数就已经协好了statetransitiondiagram状态转换图含义tcpoerationtcp的操作tcppackagetcp软件包chapter12tcpipprotocolsuitechapter12tcp是面向连接的可靠的传输协议tcp是专门设计用于在不可靠的internet上提供可靠的端到端的字节流通信的协议
Note: The value of the acknowledgment field in a segment defines the number of the next byte a party expects to receive. The acknowledgment number is cumulative.
27
Figure 12.9
Connection establishment using three-way handshaking
Chapter12
28
Note: A SYN segment cannot carry data, but it consumes one sequence number.
Chapter12 18
12.3 SEGMENT 报文段
Chapter12
19
TCP数据段头的说明-1
• 源端口和目的端口用来标识本地和对方的应用 进程(端连接点)。 • sequence number指示TCP段中第一个字节的 序号。建立一个新的TCP连接时(SYN标志为 1),该域是主机为该连接选择的初始序号, 连接建立后发送的第一个字节将具有的序号为 sequence number+1。由于全双工,每个连接 的端点都必须单独维持一个序号。 • acknowledgement number表示发送该TCP段 的主机准备从对方接收的下一个字节序号,即 该序号之前的字节已全部正确收到。
Chapter12 23
Table 12.2 Description of flags in the control field
Chapter12
24
Figure 12.7
Pseudoheader added to the TCP datagram
Chapter12
25
Figure 12.8
Encapsulation and decapsulation