\documentclass[全部作业]{subfiles} \input{mysubpreamble} % \definecolor{shadecolor}{RGB}{255,255,255} \setcounter{chapter}{4} \setlist[1]{label=\arabic{enumi},listparindent=\parindent} \begin{document} \chapter{数据链路层} \begin{enumerate} \Rquestionandanswer[1]{What are some of the possible services that a link-layer protocol can offer to the network layer? Which of these link-layer services have corresponding services in IP? In TCP?}{ 数据链路层可以提供流量控制,差错检测和纠正,共享广播信道-多路访问,链路层编址。其中流量控制、差错检测在IP和TCP中都有相应的服务,链路层编址在IP有类似的IP地址。 } \Rquestionandanswer[2]{If all the links in the Internet were to provide reliable delivery service, would the TCP reliable delivery service be redundant? Why or why not?}{ 如果在因特网中的所有链路都能提供可靠收发服务,TCP的可靠收发服务也不是多余的。这样虽然能保证到达的包没有差错,但是IP层可能把数据包转发到错误的地方导致丢包,或者各个数据包通过不同的链路到达目的,导致数据包乱序,TCP的可靠收发服务需要解决丢包和乱序的问题。 } \Rquestionandanswer[9]{Why is an ARP query sent within a broadcast frame? Why is an ARP response sent within a frame with a specific destination MAC address?}{ ARP查询使用广播帧是因为发送端此时还不知道接收端的MAC地址,无法单播,所以只能使用广播帧;而ARP响应帧理论上使用广播MAC地址也行,只要查询方能收到就行,但其他没有发送ARP查询帧的主机收到ARP响应帧也会丢弃,因此还不如不使用广播帧,其他主机收到目的MAC不是自己的帧就提早丢弃了。 } \Rquestionandanswer[10]{Suppose nodes A, B, and C each attach to the same broadcast LAN (through their adapters). If A sends thousands of IP datagrams to B with each encapsulating frame addressed to the MAC address of B, will C's adapter process these frames? If so, will C's adapter pass the IP datagrams in these frames to the network layer C? How would your answers change if A sends frames with the MAC broadcast address?}{ C的适配器会将这些帧首部的目的MAC地址和C的MAC地址比较,发现不相同,就把这些帧丢弃了,所以C的适配器会处理这些帧,但是将这些帧丢弃了,所以不会将IP数据传递给C的网络层。但是如果A发送的帧使用了MAC广播地址,那么C的适配器会处理这些帧,并且将帧里的IP数据包传递给C的网络层(网络层还是有可能丢弃报文的)。 } \Rquestionandanswer[11]{In CSMA/CD, after the fifth collision, what is the probability that a node chooses K = 4? The result K = 4 corresponds to a delay of how many seconds on a 10 Mbps Ethernet?}{ 第五次冲突后,$K$的取值范围为$[0,2^{5}-1]$,即$K$等可能地从$[0,31]$中选取一个整数,因此$P(K=4)=\dfrac{1}{32}$。 而$K=4$就意味着延迟$4\times 512 \operatorname{bit}$的传输时间,因此在 10 Mbps 的以太网中,延时为 $$ \text{Delay}=\frac{4\times 512 \text{bit}}{10 \text{Mbps}}=\frac{2048 \text{bit}}{10 \times 10^{6} \text{bit/s}}= 0.0002048\ \text{秒} $$ } \Rquestionandanswer[13]{Suppose a 10 Mbps adapter sends into a channel an infinite stream of 1s using Manchester encoding. The signal emerging from the adapter has how many transitions per second?}{ 曼彻斯特编码在每位信号的中间都有一个跳变,由于数据全1,所以在每位信号的开始处还需要归零,因此一位信号有2个跳变。而在10 Mbps 的适配器上每秒能传输$10\times 10^{6}$位信号,所以每秒的跳变数为$20 \times 10^{6}$。 } \Pquestionandanswer[1]{Suppose the information content of a packet is the bit pattern 1010 1010 1010 1011 and an even parity scheme is being used. What would the value of the field containing the parity bits be for the case of a two-dimensional parity scheme? Your answer should be such that a minimum-length checksum field is used.}{ 由于需要二维奇偶校验和长度最小,并且此数据包的长度为16个字节,$\sqrt{16}=4$,所以应当一行4个字节,共4行。校验过程可以画出二维表格如下: \begin{center} \begin{tabular}{ccccl} $1$ & $0$ & $1$ & $0$ \vline & $0$ \\ $1$ & $0$ & $1$ & $0$ \vline & $0$ \\ $1$ & $0$ & $1$ & $0$ \vline & $0$ \\ $1$ & $0$ & $1$ & $1$ \vline & $1$ \\ \hline $0$ & $0$ & $0$ & $1$ \vline & $1$ \\ \end{tabular} \end{center} 于是带校验的数据为 10100 10100 10100 10111 00011。 } \Pquestionandanswer[15]{Suppose nodes A and B are on the same 10 Mbps Ethernet bus, and the propagation delay between the two nodes is 225 bit times. Suppose node A begins transmitting a frame and, before it finishes, node B begins transmitting a frame. Can A finish transmitting before it detects that B has transmitted? Why or why not? If the answer is yes, then A incorrectly believes that its frame was successfully transmitted without a collision. \textit{Hint:} Suppose at time t = 0 bit times, A begins transmitting a frame. In the worst case, A transmits a minimum-sized frame of 512 + 64 bit times. So A would finish transmitting the frame at t = 512 + 64 bit times. Thus, the answer is no, if B's signal reaches A before bit time t = 512 + 64 bits. In the worst case, when does B's signal reach A?}{ 题目中已经给出了提示,在最差的情况下,A传输的帧为8个字节的前同步码加上64个字节的有效帧的部分(数据字段长度最小为46字节),也就是$64+512=576$位。A的信号到达B需要225个比特时间,在最差的情况下,在A发出的帧到达B的一瞬间,B发出了自己的帧,此时B的信号再到达A又需要225个比特时间,因此在第$2\times 225=450$个比特时间,B的信号到达A,$450<576$,因此A不会在检测到B传输之前结束传输。 } \Pquestionandanswer[16]{Suppose two nodes, A and B, are attached to opposite ends of an 900 m cable, and that they each have one frame of 1,000 bits (including all headers and preambles) to send to each other. Both nodes attempt to transmit at time $t$ = 0. Suppose there are four repeaters between A and B, each inserting a 20-bit delay. Assume the transmission rate is 10 Mbps, and CSMA/CD with backoff intervals of multiples of 512 bits is used. After the first collision, A draws $K$ = 0 and B draws $K$ = 1 in the exponential backoff protocol. Ignore the jam signal and the 96-bit time delay.}{} \begin{enumerate} \Pquestionandanswer[-]{\item What is the one-way propagation delay (including repeater delays) between A and B in seconds? Assume that the signal propagation speed is $2\times 10^{8}$ m/sec.}{ 这里说的包括中继器的延时是要把每个中继器20比特时间的延时也算进去?但这不是传输延时的范畴了?不过既然说了那就这样算吧。 信号传播速度是$2\times 18^{8}$ m/sec,AB之间使用900 m的电缆连接。因此在不考虑中继器的情况下传播延时为 $$ \frac{900 \text{m}}{2\times 10^{8} \text{m/sec}}=4.5 \times 10^{-6}\ \text{秒} $$ 每个中继器有20比特时间的延时,传输率为10 Mbps,因此每个中继器的延时为 $$ \frac{20 \text{bit}}{10 \text{Mbps}}=\frac{20 \text{bit}}{10\times 10^{6} \text{bit/s}}=2\times 10^{-6}\ \text{秒} $$ 所以在考虑中继器的情况下总的传播延时为 $$ 4.5\times 10^{-6}+ 4\times 2\times 10^{-6}=12.5\times 10^{-6}\ \text{秒} $$ } \Pquestionandanswer[-]{\item At what time (in seconds) is A's packet completely delivered at B?}{ 这里为什么用的是“packet”?“packet”不应该是指网络层的协议数据单元吗?这题不是关注数据链路层吗?而且题目中也说了传输了一帧(frame)。 首先将上一小题计算的传播延时转化为比特时间,数据传输率为10 Mbps,所以 $$ 10 \text{Mbps} \times (12.5\times 10^{-6}) \text{sec}=(10\times 10^{6}) \text{bit/s} \times (12.5\times 10^{-6}) \text{sec}=125 \text{bit(比特时间)} $$ A和B都在$t=0$时刻发出帧,在$t=125$时刻,A和B都检测到了冲突,忽略48比特的拥塞信号,直接停止发送。A在指数退避中选择了$K=0$,因此会立刻重新准备发送,此时信道忙,A继续侦听。B在指数退避中选择了$K=1$,因此会在512比特时间后重新发送帧。 在$t=125+125=250$时刻,B发送的帧已经全部到达了A,此时信道空闲,忽略96比特的侦听时间,A立刻重新发送帧。 在$t=250+125=375$时刻,B开始接受帧。 在$t=125+512+737$时刻,B准备重发帧,但信道忙(B正在接收帧),因此不会发送。 在$t=375+1000=1375$时刻,B完整接收了帧。 再将比特时间转化为秒 $$ \frac{1375 \text{bit}}{10\times 10^{6} \text{bit/s}}=137.5\times 10^{-6}\ \text{秒} $$ 所以在$137.5\times 10^{-6}$秒,A的帧完全到达B。 % 上一小题已经算出了传播延时,这里只需要计算传输延时。传输率为10 Mbps ,一帧为1000 bits,所以传输延时为: % $$ % t_{\text{transmission}}=\frac{1000 \text{bit}}{10 \text{Mbps}}=\frac{1000 \text{bit}}{10\times 10^{6} \text{bit/s}}=10\times 10^{-6}\ \text{秒} % $$ % 因此总延时(不考虑排队延时和处理延时)为 % $$ % t_{\text{all}}=t_{\text{propagation}}+t_{\text{transmission}}=12.5\times 10^{-6}+1\times 100^{-6}=112.5 \times 10^{-6}\ \text{秒} % $$ % 由于A在$t=0$时刻发出帧,所以在$t=112.5\times 10^{-6}$(秒)时刻A的帧完全到达B。 } \Pquestionandanswer[-]{\item Now suppose that only A has a packet to send and that the repeaters are replaced with switches. Suppose that each switch has a 20-bit processing delay in addition to a store-and-forward delay. At what time, in seconds, is A's packet delivered at B?}{ 只有A发送包,因此不考虑冲突以及排队延时。这时就不便于使用比特时间来计算了,因此还是使用秒为单位来计算。 传播延时只需要整体考虑A到B之间的线缆即可 $$ t_{\text{propagation}} = \frac{900 \text{m}}{2\times 10^{8} \text{m/sec}}=4.5 \times 10^{-6}\ \text{秒} $$ 4个交换机,每个交换机的处理延时为20个比特时间,应该是处理的这段时间里能传输20比特的数据的意思吧,那么根据数据传输率为10 Mbps,可以计算出处理延时 $$ t_{\text{processing}}=4\times \frac{20 \text{bit}}{10\times 10^{6} \text{bit/s}}=8\times 10^{-6}\ \text{秒} $$ 由于每个交换机都采用存储转发方式,所以传输延时为(4个交换机把链路分成了5段) $$ t_{\text{transmission}}=5\times \frac{1000 \text{bit}}{10\times 10^{6}\text{bit/s}}=500\times 10^{-6}\ \text{秒} $$ 所以总延时为 $$ \begin{aligned} t_{\text{all}} & = t_{\text{propagation}}+t_{\text{processing}}+t_{\text{transmission}} \\ & = 4.5\times 10^{-6}+8\times 10^{-6}+500\times 10^{-6} \\ & = 512.5\times 10^{-6}\ \text{秒} \\ \end{aligned} $$ 所以在$512.5\times 10^{-6}$秒,A的帧完全到达B。 } \end{enumerate} \Pquestionandanswer[17]{Suppose nodes A and B are on the same 10 Mbps Ethernet bus, and the propagation delay between the two nodes is 225 bit times. Suppose A and B send frames at the same time, the frames collide, and then A and B choose different values of K in the CSMA/CD algorithm. Assuming no other nodes are active, can the retransmissions from A and B collide? For our purposes, it suffices to work out the following example. Suppose A and B begin transmission at $t$ = 0 bit times. They both detect collisions at $t$ = 225 bit times. They finish transmitting a jam signal at $t$ = 225 + 48 = 273 bit times. Suppose $K_A$ = 0 and $K_B$ = 1. At what time does B schedule its retransmission? At what time does A begin transmission? (\textit{Note:} The nodes must wait for an idle channel after returning to Step 2—see protocol.) At what time does A's signal reach B? Does B refrain from transmitting at its scheduled time?}{ 上一题不考虑48 bit的拥塞信号时间和96 bit的侦听时间,这一题就要考虑了。 根据题意,A和B都在$t=225$时刻检测到了冲突,在$t=225+48=273$时刻结束发送拥塞信号。之后在指数退避过程中A选择了$K=0$,因此立刻进入侦听状态。由于B之前发送的帧还没有完全到达A,因此这时A侦听到信道忙。 B的信号在225个比特时间后完全到达A,因此在$t=273+225=498$时刻,A侦听到信道开始空闲,于是在96个比特时间后,也就是$t=498+96=594$时刻,A开始重新发送帧。 在225个比特时间后,也就是$t=594+225 = 819$时刻,A重新发送的帧开始到达B。 由于在指数退避过程中B选择了$K=1$,因此在512个比特时间后,也就是$t=273+512=785$时刻,B进入侦听状态,此时信道空闲,但是在$t=819=785+34$时刻,B开始接收A发送的帧,此时信道开始忙,$34<96$,也就是在96个比特时间内信道开始忙了,所以此时B不会发送帧。 因此,A和B的重发帧不会冲突。 } \Pquestionandanswer[19]{Consider three LANs interconnected by two routers, as shown in the figure below. \begin{center} \includegraphics[width=0.5\linewidth]{imgs/2023-12-31-09-55-13.png} \end{center} }{} \begin{enumerate} \Pquestionandanswer[-]{ \item Redraw the diagram to include adapters. \item Assign IP addresses to all of the interfaces. For Subnet 1 use addresses of the form 111.111.111.xxx; for Subnet 2 uses addresses of the form 122.122.122.xxx; and for Subnet 3 use addresses of the form 133.133.133.xxx. \item Assign MAC addresses to all of the adapters. }{ % \includesvgpdf{5.19.1.drawio} \noindent\includexopp{5.19.1} } \Pquestionandanswer[-]{ \item Consider sending an IP datagram from Host A to Host F. Suppose all of the ARP tables are up to date. Enumerate all the steps, as done for the single-router example in Section 5.4.2. }{ 第一跳,主机A已知主机F的IP地址(133.133.133.2),于是封装了一个源IP为111.111.111.1,目的IP为133.133.133.2的IP包,之后A发现目的IP和本机IP不在一个子网,于是A从自己的ARP表中查找网关(路由器)的IP(111.111.111.11)对应的MAC(01:23:45:67:89:11),将目的MAC为01:23:45:67:89:11,源MAC为01:23:45:67:89:01放到数据链路层首部,形成帧并发送出去。 第二跳,路由器1的接口1收到该帧,比较该帧首部的MAC和自己的MAC,确认是发送给自己的后,查看该帧内的IP层内容,发现目的IP(133.133.133.2)和接口1、接口2都不在一个子网,于是查看自己的路由表,发现该子网的数据包应该发送给路由器2的接口1的IP(122.122.122.21),并且应该从接口2发出,之后查看自己的ARP表,找到此IP对应的MAC(01:23:45:67:89:21),将目的MAC为01:23:45:67:89:21,源MAC为01:23:45:67:89:12(接口2)放到数据链路层首部,形成帧从接口2发出。 第三跳,路由器2的接口1收到帧,比较该帧首部的MAC和自己的MAC,确认是发送给自己的后,查看该帧内的IP层内容,发现目的IP(133.133.133.2)和接口2在同一个子网,于是查看自己的ARP表,找到此IP对应的MAC(01:23:45:67:89:06),将目的MAC为01:23:45:67:89:06,源MAC为01:23:45:67:89:22(接口2)放到数据链路层首部,形成帧从接口2发出。 最后,主机F收到帧,比较该帧首部的MAC和自己的MAC,确认是发送给自己的后,查看该帧内的IP层内容,比较目的IP和自己的IP,确认是发送给自己的后,将IP层的数据解包后交给上层处理。 } \Pquestionandanswer[-]{ \item Repeat (d), now assuming that the ARP table in the sending host is empty (and the other tables are up to date). }{ 首先,仍然是主机A已知主机F的IP地址(133.133.133.2),于是封装了一个源IP为111.111.111.1,目的IP为133.133.133.2的IP包,之后A发现目的IP和本机IP不在一个子网,于是查找网关(路由器的IP)(已经配置为111.111.111.11)对应的MAC,但ARP表为空,无法找到此IP对应的MAC。于是A发送ARP查询广播,将目的MAC设为广播地址(全1),源MAC为A的MAC(01:23:45:67:89:01),源IP为A的IP(111.111.111.1),目的IP设为111.111.111.11。路由器1的接口1收到该帧,该帧为广播帧,因此不需要和自己的MAC比较,直接查看该帧封装的数据部分,发现是ARP查询报文,并且目的IP和自己的IP相同,于是准备发送ARP响应报文。路由器1在自己的ARP表中查询该报文中的源(111.111.111.1)IP对应的MAC,查找到为01:23:45:67:89:01,于是将目的MAC设为01:23:45:67:89:01,源MAC为路由器1接口1的MAC(01:23:45:67:89:11),源IP为路由器1接口1的IP(111.111.111.11),目的IP为111.111.111.1,将该帧从接口1发送出去。 A收到该帧,比较该帧首部的MAC和自己的MAC,确认是发送给自己的后,查看该帧内的IP层内容,比较目的IP和自己的IP,确认是发送给自己的后,发现IP层内的数据为ARP响应报文,并且此响应报文中的源IP(111.111.111.11)正好是自己刚才查询的IP,于是将此帧的源IP和源MAC放入自己的ARP表中,于是A就知道网关(路由器的IP)对应的MAC为01:23:45:67:89:11了,之后的步骤就和上一小题相同了。 } \end{enumerate} \end{enumerate} \end{document}