概览
我们将网络架构自顶向下地分成 5
层。每一层只需要做好自己的工作就可以了。
由于历史原因,最顶层被叫做 "Layer 7"
Layers of the Internet
Physical Layer
In the Internet, we’re looking for a way to signal bits (1s and 0s)
across space.
The technology could be voltages on an electrical wire, wireless
radio waves, light pulses along optical fiber cables, among others.
Physical Layer 数据的基本单位是bit。
Link Layer
Link Layer cares about how to send the data using Physical Layer.
Link Layer
只负责相邻节点之间的通信,其单位是frame/帧。
Internet Layer
Internet Layer 是路由器工作的最高层,负责决定 next
hop,即把数据转发给谁。其基本单位是packet/包。
IP 协议就是在这一层工作的。
Transport Layer
Transport Layer 负责决定数据传输的可靠性,也就是 TCP/UDP
协议,以及“端到端通信”。
也就是说,他通过端口区分应用的数据的来/去。
其基本单位是段/segment。
Application Layer
只负责考虑如何使用网络。它的基本数据单位被称作
message。
每一层都会把从更低层拿来的数据加上对应的 Header。
Header 是只给这一层看的信息(同时,每一层也只能看自己层级的
header),它指明了信息传输的各种附加信息(采取的协议、收件人/发件人等等)。
在传输过程中,Header 不断被 peel off,然后又被加上新的。
由于 Header 的存在,每一层相当于仅仅和自己同层的 peer
进行通信,因此也要求相同层级采用的协议必须相同。
Resource Sharing
网络的总容量是有限度的,因此如何分配资源是一个重要的问题。
我们先考虑两个问题:
要保证网络正常工作,我们至少要多大的容量?
我们如何分配我们的容量?
第一个问题的解决方案被称作 statistical
multiplexing,其原理非常直观:
第二个问题有两种解决办法,一种被称作 best
effort,通俗而言就是所有人都只管发送信息,并且 "hope for the
best",其对应的策略被称作 packet switching
另一种被称作
reservation,也就是在通信前会先在网络中预留出容量,其对应的策略被称作
Circuit Switching
Properties of Links
The bandwidth of a link tells us how many bits we
can send on the link per unit time. Intuitively, this is the speed of
the link. If you think of a link as a pipe carrying water, the bandwidth
is the width of the pipe. A wider pipe lets us feed more water into the
pipe per second. We usually measure bandwidth in bits per second (e.g. 5
Gbps = 5 billion bits per second).
The propagation delay of a link tells us how long it
takes for a bit to travel along the link. In the pipe analogy, this is
the length of the link. A shorter pipe means that water spends less time
in the pipe before arriving at the other end. Propagation delay is
measured in time (e.g. nanoseconds, milliseconds).
If we multiply the bandwidth and the propagation delay, we get the
bandwidth-delay product (BDP). Intuitively, this is the
capacity of the link, or the number of bits that exist
on the link at any given instant. In the pipe analogy, if we fill up the
pipe and freeze time, the capacity of the pipe is how much water is in
the pipe in that instant.
注意,bandwidth/带宽是指“一秒内发射的 bit 数量”,而 bit
必须是一个一个发射出去的。所以一个 bit 的发射用时是 \(\frac{1}{\text{bandwidth}}\)。
注意区分 delay(或者用全称,propagation delay) 和这个发射用时
(也就是上文的 transmission delay) 的区别。前者是 bit
在物理链路里面传播(propagation)的时间,后者是终端发送一个 packet 所有
bit 的时间。这从我们下文的例子就可以看出来。
Timing Diagram
Suppose we have a link with bandwidth 1 Mbps = 1 million bits per
second, and propagation delay of 1 ms = 0.001 seconds.
We want to send a 100 byte = 800 bit packet along this link. How long
does it take to send this packet, from the time the first bit is sent,
to the time the last bit is received?
To answer this question, we can draw a timing diagram. The left bar
is the sender, and the right bar is the recipient. Time starts at 0 and
increases as we move down the diagram.
Let’s focus on the first bit. We can put 1,000,000 bits on the link
per second (bandwidth), so it takes 1/1,000,000 = 0.000001 seconds to
put a single bit on the link. At time 0.000001 seconds, the link has a
single bit on it, at the sender end.
It then takes 0.001 seconds for this bit to travel across the link
(propagation delay), so at time 0.000001 + 0.001 seconds, the very first
bit arrives at the recipient.
Now let’s think about the last bit. From before, it takes 0.000001 to
put a bit on the link. We have 800 bits to send, so the last bit is
placed on the link at time \(800*0.000001=0.0008\) seconds.
It then takes 0.001 seconds for the last bit to travel across the
link, so at time 0.0008 + 0.001 seconds, the very last bit arrives at
the recipient. This is the time when we can say the packet has arrived
at the recipient.
Packet Delay
从上文例子可以看出,一个完整的 packet 发送的延迟就是 \(\text{transmission delay + propagation
delay}\)
Pipe Diagram
To draw the link, we can imagine the link is a pipe (similar to the
water analogy) and draw the pipe as a rectangle, where the width is the
propagation delay, and the height is the bandwidth. The area of the pipe
is the capacity of the link.
Pipe diagrams can be useful for comparing different links. Let’s look
at the exact same packets traveling through three different links.
Overloaded Links
In the long term, we have enough capacity to send all the outgoing
packets, but at this very instant in time, we have two packets arriving
simultaneously, and we can only send out one. This is called transient
overload, and it’s extremely common at switches in the Internet.
To cope with transient overload, the switch maintains a queue of
packets. If two packets arrive simultaneously, the switch queues one of
them and sends out the other one.
At any given time, the switch could choose to send a packet from one
of the incoming links, or send a packet from the queue. This choice is
determined by a packet scheduling algorithm, and there are lots of
different designs that we’ll look at.
Now that we have a notion of queuing, we need to go back and update
our packet delay formula. Now, packet delay is the sum of
transmission delay, propagation delay, and queuing delay.