type
status
slug
date
summary
tags
category
password
icon
第二章:应用层HTTPHTTP2Cookiesweb缓存(代理服务器)FTP电子邮件( Simple Mail Transfer Protocol SMTP)DNS第三章 传输层多路复用与多路分解UDPTCPrdt2.0rdt2.1rdt2.2无NAK协议rdt3.0GBNSRTCP结构序号确认号首部长度窗口检验和杂项TCP序号、ACKs思考TCP往返时延(RTT)和超时指数加权移动平均 EWMATCP可靠数据传输机制TCP重传TCP快速重传TCP重传必考题流量控制三次握手四次挥手拥塞控制TCP拥塞控制第四章 网络层网络层的关键功能:网络层:数据平面、控制平面控制平面的两种实现方法网络层的服务模型虚电路和数据报网络数据报网络路由器的工作原理转发表最长前缀匹配交换结构经内存的交换结构经总线的交换结构经交换矩阵的交换结构输入端口排队IPv4为什么TCP/IP在运输层/网络层都执行差错检测?IP分片IP地址1、分类IP地址2、子网的划分3、无分类编址CIDR子网划分以及CIDR练习(重要)动态主机配置协议DHCP组织机构如何获取IP地址NAT:网络地址转换ICMP因特网控制报文协议Internet Control Message ProtocolIPv6通用转发与SDN路由选路算法网络的抽象图模型全局路由算法:链路状态选路算法分布式路由算法—距离向量路由选择算法DV毒性逆转LS算法与DV算法比较例题练习:4.6层次选路域(自治系统)内路由选择RIPOSPF(重要,需要掌握好)Internet 域间选路SDN第五章:链路层链路层概述链路层基础差错检测和纠错发送节点接收节点三种主要差错检测技术奇偶校验Internet校验和方法多路访问链路和协议信道划分协议TDMA时分FDMA频分CDMA码分随机访问协议ALOHACSMACSMA/CD:以太网的多路访问协议轮流协议交换局域网ARP交换机VLANs
很重要的概念积累第二章:应用层
HTTP




HTTP2





Cookies



web缓存(代理服务器)






FTP




电子邮件( Simple Mail Transfer Protocol SMTP)





取邮件是一个拉操作,SMTP是一个推协议
记住三种取邮件协议:
POP、IMAP( Internet Message/Mail Access Protocol)、HTTP(web方式,最流行)



DNS














第三章 传输层
多路复用与多路分解






将运输层报文段中的数据交付到正确的套接字的工作称为多路分解
在源主机从不同套接字中收集数据块,并为每个数据块封装上首部信息(这将在以后用于分解)从而生成报文段,然后将报文段传递到网络层,所有这些工作称为多路复用
注意:UDP套接字使用二元组来标识,并不是说客户端不需要传送自己的IP地址和端口给对方。在创建UDP套接字后,UDP报文段中同样有源端口号,到了网络层,IP数据报中也有源IP,源IP和源端口号同样需要发送给服务器,否则服务器无法回应请求。
使用UDP进行传输,在服务器上对应的进程,不用考虑分组是从哪个客户端来的,所有来自客户的请求都在同一个套接字处理,处理完了再根据源端口号和源 IP 地址,把应答信息发送给客户端。
UDP套接字使用二元组来标识,是因为UDP是无连接的,源端和目的端无需建立关联并对应起来,接收方无需区分/考虑发送方;而TCP是面向连接的,需要和发送方建立对应关系(注意不一定是一一对应,服务器可以并行处理)。
对于UDP,可以认为每个端口都是一个可供协议软件放置收到的数据报的队列。TCP的端口,并不对应于一个简单的目标。TCP是建立在所谓的连接抽象(connection abstraction)之上的,它所对应的对象不是单独的端口而是一个虚电路连接。
由于TCP使用两个端点 (host, port)(四元组)来识别连接,一个机器上的某个TCP端口号可以被多个连接所共享。
UDP


重要:UDP只在网络层之上加了差错检测和多路分解/复用 (端口)的功能





注意这里的长度是指首部和数据的总长度,所以至少都要比8大或者等于(没有数据)





1、1011 1001→ 0010 1110 → 1101 0001
2、为了检测错误,接收方可以直接累加四个字节(三个原始字节和校验和),简单方便高效。
3、如果累加总和包含0,则接收方认为有错误。所有的1位错误都将被检测到,但是2位错误可能不被检测到(例如,如果第一个字节的最后一位变成了0,而第二个字节的最后一位变成1)。

该UDP报文的首部为:
源端口号(0632) 目的端口号(0045)
UDP报文段长度(001C) 校验和(E217)
数据
源端口是0x0632 = 1586
目的端口是0x0045 = 69
UDP 用户数据报总长度是0x001C = 28
数据部分长度是28-8 = 20。
因为目的端口号69 < 1023,是熟知端口,所以此UDP用户数据报是从客户发给服务器。服务器程序实际就是TFTP。

TCP
rdt2.0

rdt2.1
因为发送方可能收到corrupt所以需要重传,这就造成接收方的冗余(如果它发送的是ACK的话),因此需要加入序号,停等协议只需要2个序号即可。
发送方


rdt2.2无NAK协议


rdt3.0



这里d里面rcv ack1的ignore就是状态机里面展示wait for ack1后到wait for call 0 from above这个状态下,会对于之前的ack进行ignore操作,而rdt2.2以及之前的操作不会出现这种多发一个ack在等待上层调用状态下的情况。



这里ppt有问题,分母也应该变成RTT+3 L/R
GBN






SR





TCP结构




序号


注意编号是对于数据部分,也就是应用层数据
还有名词MSS:Maximum Segment Size
指的是报文段里应用层数据的最大长度
确认号

注意和之前的rdt协议里面的ack号不一样(指的是收到的序号),而这里改为是主机期望从对方主机收到的下一字节的序号
首部长度

窗口

说明接收方的缓冲区不超过64KB
检验和


这里对比UDP的伪首部,除了表明协议字段不一样,其它的内容都是一样的:

杂项














TCP序号、ACKs


思考

1、TCP首部除固定长度部分外,还有选项,因此TCP首部长度是可变的。UDP首部长度是固定的。
2、因为TCP报文段的数据部分加上TCP首部的20字节,再加上IP首部的20字节,正好是IP数据报的最大长度65535。所以TCP报文段的数据部分最多有65535-40=65495个字节。
3、可以使用TCP协议来传送,因为序号字段编号到最大值,又重新开始从0开始编号。
TCP往返时延(RTT)和超时

指数加权移动平均 EWMA



TCP可靠数据传输机制



注意timeout这里:retransmit not-yet-acked segment with smallest seq.
还有ack的值是期望收到的下一个字节的序号,所以直接用它更新sendBase作为最早未被确认的字节

TCP重传


TCP快速重传

注意冗余ACK指的是:在收到第一个确认后又收到3个ACK


TCP重传必考题

流量控制

流量控制:接收方控制发送方,因此发送方不会由于发送太多、发送得太快而使得接收方的缓冲区溢出。

目的就是保证缓冲区绝不会溢出!
三次握手
两次握手的问题




四次挥手


拥塞控制






TCP拥塞控制
AIMD










拥塞窗口大小分别为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1,2,4,8,9,10,11,12,1,2,4,6,7,8,9。

第四章 网络层
网络层的关键功能:

网络层:数据平面、控制平面


控制平面的两种实现方法


网络层的服务模型



虚电路和数据报网络

数据报网络


路由器的工作原理



转发表


最长前缀匹配

第一个选择0
第二个选择1



m0
R2
R4
R3
R4
(1)分组的目的站IP地址是:128.96.39.10。
先与子网掩码255.255.255.128相与,得128.96.39.0,可见该分组经接口0转发。
(2)分组的目的IP地址为:128.96.40.12。
与子网掩码255.255.255.128相与得128.96.40.0,经查路由表可知,该项分组经R2转发。
(3)分组的目的IP地址为:128.96.40.151,与子网掩码255.255.255.128相与后得128.96.40.128,与子网掩码255.255.255.192相与后得128.96.40.128,经查路由表知,该分组转发选择默认路由,经R4转发。
(4)分组的目的IP地址为:192.4.153.17。与子网掩码255.255.255.128相与后得192.4.153.0。与子网掩码255.255.255.192相与后得192.4.153.0,经查路由表知,该分组经R3转发。
(5)分组的目的IP地址为:192.4.153.90,与子网掩码255.255.255.128相与后得192.4.153.0。与子网掩码255.255.255.192相与后得192.4.153.64,经查路由表知,该分组经R4转发。

交换结构

经内存的交换结构


经总线的交换结构

经交换矩阵的交换结构

从A到E端口转发分组,从B到D端口转发分组可以同时进行,因此速率高于经总线的交换结构

输入端口排队
线头阻塞:Head-of-the-Line(HOL)blocking


- 当数据报从交换结构到达的速度比链路传输速率快时,就需要缓冲。
- 丢弃策略:如果没有可用缓冲区,应该丢弃哪些数据报(datagram)
- 调度准则:在排队的数据报中选择以进行传输





IPv4


高层指的是上层协议:指出此数据报携带的数据使用何种协议,以便目的主机的IP层将数据部分上交给哪个处理过程

为什么TCP/IP在运输层/网络层都执行差错检测?
- 两者校验和计算的内容不同。IP层只对IP首部计算了校验和,而TCP/UDP对整个TCP/UDP报文段进行了校验和计算。
- TCP/UDP和IP不一定属于同一个协议栈。TCP能够运行在其他的协议上(比如ATM,IPX, Apple Talk DDP等),IP携带的数据也不一定必须要传递给TCP/UDP(传输层还有SCTP等协议)。

注意IP的校验和是针对数据报(datagram)首部

IP分片




注意这里特别强调,TCP报文段不会产生IP分片:因为一旦TCP数据过大,比如超过了MSS,传输层会对TCP报文段进行分段。
IP地址



1、分类IP地址









2、子网的划分










3、无分类编址CIDR









子网划分以及CIDR练习(重要)

(1)以最多台数的部门(60台)为准,需要的最接近数为2^6=64,故要从最后个字节借8-6=2位,
子网分别为 202.1.1.0, 202.1.1.64, 202.1.1.128, 202.1.1.192,在这4个其中任选3个即可。掩码均为255.255.255.192。
注意:由于这里总共有4个子网,包含第一个全0子网和最后一个全1子网,如果不采用CIDR方法,实际本题无解:按照RFC 950,第一个全0子网的网络地址和最后一个全1子网的广播地址分别与没有划分子网前的网络地址和广播地址相冲突,不能使用,实际可以分配的子网只有 2 个;如果再借一位主机位,子网划分为 8 个,每个子网主机数又都只有30台,也不满足题中要求。
(2)若以最多台数的部门(120台)为准,仅能分两个子网,无法满足。故应采用CIDR法:
首先以最小需求台数部门为准(60台),此时主机号位数需要6位(因为60=<2^6),则子网号位数为8-6=2位,然后将子网划分出来。此时和(1)一样;
接下来,部门2、3可以直接在4个子网中任选两个,部门1选剩下2个以满足120台的要求(但这两个子网要连续,以便用CIDR法合并之,做超网)。比如:
部门1用:202.1.1.0、202.1.1.64 -> 需要进行路由聚合(构成超网)
部门2:202.1.1.128
部门3:202.1.1.192
最后将各部门IP段用CIDR超网形式描述,以便对外发布:
部门1:202.1.1.0/25; (注意含义:表示前25位是网络号,且最后一个字节最高位为0,后面7位是主机号)
部门2:202.1.1.128/26; (最后一个字节最高两位为10,后面6位是主机号)
部门3:202.1.1.192/26; (最后一个字节最高两位为11,后面6位是主机号)
说明:将202.1.1.128、202.1.1.192给部门1,202.1.1.0、202.1.1.64分别给部门2、3亦可。此时答案为:
部门2:202.1.1.0/26;
部门3:202.1.1.64/26;
部门1:202.1.1.128/25
动态主机配置协议DHCP
plug-and-play(即插即用)

注意第7步:DHCP若不同意,也就是这里第7步,发回否认报文DHCPNACK。这时DHCP客户必须立即停止使用原来的IP地址,而必须重新申请IP地址(回到步骤2)


依次的操作是:
DHCP Discover: Is there a DHCP server out there?
DHCP Offer: I’m a DHCP server! Here’s an IP address you can use
DHCP request: OK. I would like to use this IP address!
DHCP ACK: OK. You’ve got that IP address!
注意上面所有的通讯的dest地址,全是255.255.255.255说明了这个交流过程全是广播的。


以太网解析出IP地址,UDP解析出DHCP

组织机构如何获取IP地址



NAT:网络地址转换



10.x.x.x、172.16.x.x-172.31.x.x和192.168.x.x等



ICMP因特网控制报文协议Internet Control Message Protocol




IPv6




对比IPv4









通用转发与SDN











路由选路算法

网络的抽象图模型



全局路由算法:链路状态选路算法









分布式路由算法—距离向量路由选择算法DV















毒性逆转




LS算法与DV算法比较


例题练习:

这里它用了毒性逆转:

4.6层次选路


这里很重要一点:不同自治系统内的路由器可以运行不同的区域内路由协议
域(自治系统)内路由选择

RIP



OSPF(重要,需要掌握好)



Internet 域间选路













SDN










第五章:链路层
链路层概述



链路层基础




差错检测和纠错

发送节点

接收节点

说明:
- 差错检测和纠正技术不能保证接收方检测到所有的比特差错,即可能出现未检测到的比特差错,而接收方并未发现。
- 选择一个合适的差错检测方案使未检测到的情况发生的概率很小即可。
- 差错检测和纠错技术越好,越复杂,开销越大。
三种主要差错检测技术
- 奇偶校验:最基本的方法。
- Internet校验和:常用于运输层。
- 循环冗余检测:常用于链路层。
奇偶校验



特点(注意是同时):
- 可以检测并纠正单个比特差错(数据或校验位中)。
- 能够检测(但不能纠正)分组中任意两个比特的差错


Internet校验和方法




多路访问链路和协议

信道划分协议
TDMA时分


FDMA频分

CDMA码分

随机访问协议

ALOHA




CSMA



CSMA/CD:以太网的多路访问协议



对于1km电缆,单程传播时间为1/200000 = 5 μs,往返传播时间为 10 μs ,为了能够按照CSMA/CD工作,最小帧的发射时间不能小于 10 μs 。
以Gb/s速率工作,10μs 可以发送的比特数等于10*10-6/10-9 = 10000,因此,最短帧是10000 bit 或1250 字节长。
由于CSMA/CD算法的限制,以太网帧必须不能小于某个最小长度。以太网中,最小帧长为64字节,这是由最大传输距离和冲突检测机制共同决定的。
规定最小帧长是为了避免这种情况发生:A站点已经将一个数据包的最后一个Bit发送完毕,但这个报文的第一个Bit还没有传送到距离很远的B站点。B站点认为线路空闲继续发送数据,导致冲突。



C
K与冲突次数 n 有关, n < 10时,K∈{ 0, 1, 2, 3, 4, …, 2n-1}之间的一个随机整数;n ≥ 10, K∈{ 0, 1, 2, 3, 4, …, 210-1} 。
n = 5,K∈{ 0, 1, 2, 3, 4, 5, …, 31},从中选择 4 的概率为 1/32,即从32个数中选择数字 4 的概率。

A
轮流协议


交换局域网




ARP

交换机









VLANs

- 作者:liamY
- 链接:https://liamy.clovy.top/article/school/network/exam
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。