链路层

5.1、链路层的功能(把报文从一个 node到另一个 node),它能提供的各种 services,比如Framing. 并大致描述了一下 链路层在host 和 router 都实现在哪?

5.2 Error-Detection and -Correction 的3个方法:Parity Checks Checksumming Methods,和Cyclic Redundancy Check

5.3 解决 multiple access problem 的3个技术(虽然有很多实现,但分成下面3类):Nevertheless, we can classify just about any multiple access protocol as belonging to one of three categories: channel partitioning protocols, random access protocols, and taking-turns protocols.

channel partitioning protocols:TDM,FDM,CDMA

random access protocols:ALOHA protocols, carrier sense multiple access(CSMA) protocol(Ethernet 部署的是这个)

taking-turns protocols: polling protocol, token-passing protocol

5.4 Switched Local Area Networks 总结

MAC Addresses

Hosts and routers 不仅有 IP地址,而且还有 link-layer addresses,即MAC!实际上,并不是 host 或 router有地址,而它们的 adapters (that is, network interfaces) 有地址,如果一个 host 有多个 adapters ,那么它就会有多个MAC和IP。世界上的所有 adapters 不会有相同的地址,这是因为 IEEE manages the MAC address space!IP 地址类似于一个人的邮寄地址,当你的笔记本电脑在不同的网络中时,地址会发生变化; 而MAC地址相当于一个人的身份信息,它不会因为你的移动而发生变化!

当一个 adapter 想要发送 frame 到另一个 adapter 时,它会把 destination adapter’s MAC address 封装到 frame 中,然后发到LAN中去!一个 switch 有时会把 broadcasts an incoming frame onto all of its interfaces!那么所有接收到这个 frame 的 adapter 会把自己的MAC与destination MAC比较,如果不一致,它会丢弃掉frame!而有些时候,一个 adapter 确实想要LAN内所有的 adapter 处理它发的 frame,这个时候应该把目标MAC地址写成:FF-FF-FF-FF-FF-FF

Address Resolution Protocol (ARP)

ARP 的作用:translate IP addresses to link-layer addresses!

每个 host and router 在它的内存中都有 ARP table,它包含了 mappings of IP
addresses to MAC addresses,如下图例子所示:

链路层

An ARP module in the sending host takes any IP address on the same LAN as input, and returns the corresponding MAC address!它与DNS有些类似,但它们不同的是:DNS resolves host names for hosts anywhere in the Internet, whereas ARP resolves IP addresses only for hosts and router interfaces on the same subnet

发送 frame 到同一个子网的 adapter

链路层

如上图所示,当一个子网中的 adapter 想要发送一个 frame 到子网中的另一个 adapter,它只需要拿目标 IP地址去查询它的 ARP table,然后取得目标主机的 MAC 地址,封装到 frame 中就ok了!

但是,如果它的ARP table 中没有相应的记录应该怎么办呢?其实也很简单,它可以用 ARP protocol 去发送 ARP query packet,这个 query packet 的MAC地址写成 FF-FF-FF-FF-FF-FF,即广播给子网中所有的 host,然后匹配到的主机把自己的MAC发回到查询的主机,从而使其更新 ARP table!知道了对方的 MAC 就可以把 IP datagram 发给对方了!

总结一下:

ARP 的转换IP与MAC 的过程:

1、查询 ARP table,如果有记录,则返回结果
2、如果没有记录,向子网中所有的 host 发送 ARP packet
3、匹配的 host 会看自己的 IP 地址是否与 ARP packet 中要找的 IP 匹配
4、匹配的 host 会返回匹配结果到 querying host
5、因此 querying host 得到了目标IP地址的 MAC 地址
6、更新它的 ARP table

发送 frame 到不同子网的 adapter

链路层

Each router interface there is also an ARP module (in the router) and an adapter!上图的例子中的 router 就有2个interface,因此它有 two IP addresses, two ARP modules, two MAC, and two adapters.

假设 111.111.111.111 的主机想要发送 frame 到另一个子网的 222.222.222.222 的主机。首先通过 ARP 它可以获取到与它在同一个子网中的 router 的 adapter 的 MAC 地址,即 E6-E9-00-17-BB-4B,一旦有了MAC,然后 it creates a frame (containing the datagram addressed to 222.222.222.222) and sends the frame. 到达了 router 以后,router 通过转发表查询这个 datagram 应该被转发到哪个 router 的 adapter,在这个例子中显然是 222.222.222.220 的 adapter,根据222.222.222.222这个 IP,查询这个 adapter 的 ARP table,就可以得到目标主机的 MAC了,router 用这个 MAC 创建一个新的 frame ,然后发给目标主机!

Ethernet Frame Structure

链路层

  • Data field:携带 IP datagram. 大小范围为 46-1500个字节。如果一个 datagram 不足46字节,则填充,然后网络层用 length field 丢弃填充的内容!如果超过1500字节,则 fragment the datagram.
  • Destination address:MAC address of the destination adapter
  • Source address:MAC address of the adapter that transmits the frame onto the LAN
  • Cyclic redundancy check (CRC):CRC field is to allow the receiving adapter, to detect bit errors in the frame
  • 关于其它 field 含义,参考472页

All of the Ethernet technologies provide connectionless service to the network layer.

Ethernet technologies provide an unreliable service to the network layer. 虽然 Ethernet frame 结构有 CRC field,但是无论这个 frame 是否通过 CRC 检查,接收方都不会发送 ACK 去通知发送方! When a frame fails the CRC check, adapter simply discards the frame!

A hub is a physical-layer device that acts on individual bits rather than frames.

When a bit, representing a zero or a one, arrives from one interface, the hub simply re-creates the bit, boosts its energy strength, and transmits the bit onto all the other interfaces. Thus, Ethernet with a hub-based star topology is also a broadcast LAN—whenever a hub receives a bit from one of its interfaces, it sends a copy out on all of its other interfaces.

In the early 2000s Ethernet experienced yet another major evolutionary change. Ethernet installations continued to use a star topology, but the hub at the center was replaced with a switch.

链路层 Switch 的 Filtering 和 Forwarding 功能

The role of the switch is to receive incoming link-layer frames and forward them onto outgoing links. 一个 switch 主要有2个功能:Filtering 和 Forwarding.

Filtering is the switch function that determines whether a frame should be forwarded to some interface or should just be dropped.

Forwarding is the switch function that determines the interfaces to which a frame should be directed, and then moves the frame to those interfaces.

要想实现这2个功能,需要一个 switch table,结构如下图所示:

链路层

为了理解这2个功能,来个例子!假设一个 frame with destination address DD-DD-DD-DD-DD-DD 到达了一个 switch 的接口 x,那么会发生以下3种情况:

  1. There is no entry in the table for DD-DD-DD-DD-DD-DD. Switch 会把这个 frame 转发到所有除了 x 的接口,即 broadcasts 这个 frame.
  2. There is an entry in the table, associating DD-DD-DD-DD-DD-DD with interface x. Switch 执行 Filtering 功能,丢弃这个 frame.
  3. There is an entry in the table, associating DD-DD-DD-DD-DD-DD with interface y != x. Switch 执行 Forwarding 功能,把这个 frame 转发到接口 y.

Switch 是如何配置自己的 switch table 的呢?答案是用 self-learning 自动配置的,它的过程如下:

  1. switch table 初始是空的。
  2. 当某个接口 x 进来一个 frame(假设它的源 MAC 地址为 DD-DD-DD-DD-DD-DD) 时:Switch 会用 DD-DD-DD-DD-DD-DD,x,和当前时间填充 switch table 的3个 field
  3. 如果 switch 在一段时间后,没有收到以某个 MAC 地址作为源地址的 frame,它会自动从 switch table 中删掉这个记录

ARP table VS Switch table

ARP table 是放在 host 或 router 的 adapter 中的,而 Switch table 是放在 Switch 中的。你可以参考文章上面「发送 frame 到不同子网的 adapter」这一小节的开头的图片!

Switches VS Routers

5.4.2 Ethernet 技术(Bus topologies,hub-based star topology,switch)

P28. Consider the single switch VLAN in Figure 5.25, and assume an external
router is connected to switch port 1. Assign IP addresses to the EE and CS
hosts and router interface. Trace the steps taken at both the network layer and
the link layer to transfer an IP datagram from an EE host to a CS host (Hint:
reread the discussion of Figure 5.19 in the text).

MPLS 简短地介绍了一下,我没看,王道需要的时候,在仔细看细节。