ch11: User Datagram Protocol

UDP

MindMap

Introduction

UDP面向数据报的运输层协议:进程的每个输出操作都正好产生一个UDP数据报。

格式:

UDP Header

格式如下:

其中长度包含UDP header和UDP数据。

UDP Checksum

header里有一个16位的checksum,和IP的checksum只包含IP Header不同,UDP的checksum包含了UDP Header和UDP data。

这个checksum的计算逻辑和TCP是一样的。

需要注意的有:

  • UDP数据报的长度可以是奇数字节,但是校验和会在最后添加0来补充长度;

  • UDP datagram和TCP segment都有一个伪首部,加上了源IP、目的IP,等信息。

IP Fragmentation

把一份IP数据报分片以后,只有到达目的地才进行重新组装。

在分片时,除最后一片外,其他每一片中的数据部分(除IP首部外的其余部分)必须是8字节的整数倍。

需要注意的术语:

  • IP datagram:is the unit of end-to-end transmission at the IP layer (before fragmentation and after reassembly).

  • Packet: is the unit of data passed between the IP layer and the link layer. A packet can be a complete IP datagram or a fragment of an IP datagram.

一个分片的例子:

ICMP Unreachable Error (Fragmentation Required)

如果需要分片但是IP Header中设置了DF(don't fragment),就会产生这个错误。

格式:

Determining the Path MTU Using Traceroute

我们可以通过Traceroute程序来获得一条链路上的MTU。

思路是这样的:

  • 发送的分组设置不分片标志(DF);

  • 第一个分片的长度和出口MTU相等;

  • 每次收到ICMP Fragmentation Required错误时,就减小分组的长度;

  • 如果路由器返回的ICMP错误含有MTU值,就使用这个值作为下一个分组的长度;

  • 否则就自己确定一个长度;

  • 最后我们可以通过尝试有限次就能得到Path MTU了。

Interaction Between UDP and ARP

  • Most implementations keep only the last packet sent to a given destination while waiting for an ARP reply.

  • The IP layer must start a timer when the first fragment of a datagram appears.

  • Most Berkeley-derived implementations never generate the ICMP message here.

  • The first fragment, the one with an offset of 0 containing the UDP layer, was never received.

  • An implementation is not required to generated the ICMP error unless this first fragment has been received.

ICMP Source Quench Error

当一个系统接收数据报的速度比处理速度快时,就可能产生这个错误。

格式如下:

虽然会产生这个错误,但是接收者一般是忽略这个错误的。

Last updated