空 UDP 和 TCP 数据包的大小?
空 UDP 数据报的大小是多少?那么空 TCP 数据包呢?
我只能找到有关 MTU 的信息,但我想知道这些信息的“基本”大小是多少,以便估计其上的协议的带宽消耗。
What is the size of an empty UDP datagram? And that of an empty TCP packet?
I can only find info about the MTU, but I want to know what is the "base" size of these, in order to estimate bandwidth consumption for protocols on top of them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
希曼舒斯的回答是完全正确的。
在查看以太网帧的结构时,可能会产生误导[请参阅进一步阅读],如果没有有效负载,以太网帧的最小大小将为 18 字节:Dst Mac(6) + Src Mac(6) + Length (2 ) + Fcs(4),加上 IPv4 (20) 和 TCP (20) 的最小大小,总共为 58 个字节。
还没有提到的是,以太网帧的最小有效负载是 46 字节,因此 IPv4 和 TCP 的 20+20 字节是不够的有效负载!这意味着必须填充 6 个字节,这就是总共 64 个字节的来源。
18(最小以太网“标头”字段)+ 6(填充)+ 20(IPv4)+ 20(TCP)= 64 字节
希望这能让事情变得更清楚。
进一步阅读:
Himanshus answer is perfectly correct.
What might be misleading when looking at the structure of an Ethernet frame [see further reading], is that without payload the minimum size of an Ethernet frame would be 18 bytes: Dst Mac(6) + Src Mac(6) + Length (2) + Fcs(4), adding minimum size of IPv4 (20) and TCP (20) gives us a total of 58 bytes.
What has not been mentioned yet is that the minimum payload of an ethernet frame is 46 byte, so the 20+20 byte from the IPv4 an TCP are not enough payload! This means that 6 bytes have to be padded, thats where the total of 64 bytes is coming from.
18(min. Ethernet "header" fields) + 6(padding) + 20(IPv4) + 20(TCP) = 64 bytes
Hope this clears things up a little.
Further Reading:
请参阅用户数据报协议。 UDP 标头的长度为 8 字节(64 位)。
裸 TCP 标头的最小大小为 5 个字(32 位字),而 TCP 标头的最大大小为 15 个字。
最好的祝愿,
法比安
See User Datagram Protocol. The UDP Header is 8 Bytes (64 bits) long.
The mimimum size of the bare TCP header is 5 words (32bit word), while the maximum size of a TCP header is 15 words.
Best wishes,
Fabian
如果您打算计算带宽消耗并将其与网络的最大速率(如 1Gb/s 或 10Gb/s)相关联,则有必要添加 第 1 层以太网成帧开销为 Felix 等人计算出的数字,即
,即每个数据包总共消耗 20 个字节。
If you intend to calculate the bandwidth consumption and relate them to the maximum rate of your network (like 1Gb/s or 10Gb/s), it is necessary, as pointed out by Useless, to add the Ethernet framing overhead at layer 1 to the numbers calculated by Felix and others, namely
i.e. a total of 20 more bytes consumed per packet.
如果您正在寻找软件的视角(毕竟,Stack Overflow 是针对软件问题的),那么该帧不包括 FCS、填充和帧符号开销,答案是 54:
这发生在 TCP ack 数据包的情况下,因为 ack 数据包没有 L4 选项。
至于FCS、填充、成帧符号、隧道等,硬件和中间路由器通常对主机软件隐藏......软件实际上只关心额外的开销,因为它们对吞吐量的影响。正如其他答案所指出的,FCS 在帧中添加了 4 个字节,使其成为 58 个字节的帧。因此,需要 6 字节的填充才能达到 64 字节的最小帧大小。以太网控制器添加了额外的 20 字节帧符号,这意味着数据包在线路上至少占用 84 字节时间(或 672 比特时间)。例如,1Gbps 链路可以每 672ns 发送一个数据包,相当于大约 1.5MHz 的最大数据包速率。此外,中间路由器可以添加各种标签和隧道标头,进一步增加网络内部各点(尤其是公共网络骨干网)的最小 TCP 数据包大小。
然而,考虑到软件可能与其他软件共享带宽,可以合理地假设这个问题不是询问总线路带宽,而是询问主机软件需要生成多少字节。主机依赖于以太网控制器(例如这个 10Mbps 或此 100Gbps一个)添加FCS、填充和成帧符号,并依赖路由器添加标签和隧道(虚拟化卸载控制器,例如第二个链路中的控制器,具有集成的隧道引擎。较旧的控制器依赖于单独的路由器盒)。因此,主机软件生成的最小 TCP 数据包为 54 字节。
If you're looking for a software perspective (after all, Stack Overflow is for software questions) then the frame does not include the FCS, padding, and framing symbol overhead, and the answer is 54:
This occurs in the case of a TCP ack packet, as ack packets have no L4 options.
As for FCS, padding, framing symbol, tunneling, etc. that hardware and intermediate routers generally hide from host software... Software really only cares about the additional overheads because of their effect on throughput. As the other answers note, FCS adds 4 bytes to the frame, making it frame 58 bytes. Therefore 6 bytes of padding are required to reach the minimum frame size of 64 bytes. The Ethernet controller adds an additional 20 bytes of framing symbols, meaning that a packet takes a minimum of 84 byte times (or 672 bit times) on the wire. So, for example, a 1Gbps link can send one packet every 672ns, corresponding to a max packet rate of roughly 1.5MHz. Also, intermediate routers can add various tags and tunnel headers that further increase the minimum TCP packet size at points inside the network (especially in public network backbones).
However, given that software is probably sharing bandwidth with other software, it is reasonable to assume that this question is not asking about total wire bandwidth, but rather how many bytes does the host software need to generate. The host relies on the Ethernet controller (for example this 10Mbps one or this 100Gbps one) to add FCS, padding, and framing symbols, and relies on routers to add tags and tunnels (A virtualization-offload controller, such as in the second link, has an integrated tunnel engine. Older controllers rely on a separate router box). Therefore the minimum TCP packet generated by the host software is 54 bytes.
TCP:
以太网帧的大小 - 24 字节
IPv4 标头的大小(无任何选项)- 20 字节
TCP 标头的大小(无任何选项) - 20 字节
携带带有空 TCP 段的 IP 数据包的以太网帧的总大小 - 24 + 20 + 20 = 64 字节
UDP:
以太网帧的大小 - 24字节
IPv4 标头的大小(无任何选项)- 20 字节
UDP 标头的大小 - 8 字节
携带带有空 UDP 数据报的 IP 数据包的以太网帧的总大小 - 24 + 20 + 8 = 52 字节
编辑:上面错误地将以太网帧字节指定为 24B。相反,它是 18(或 VLAN 标记以太网为 22)。 8B 前导码不是最小 64B 帧的一部分。所以最小的IPv4+TCP数据包是18+20+20=58字节,最小的IPv4+UDP数据包是18+20+8=46字节。在这些情况下,需要以太网填充来填充高达 64B 的帧(TCP 示例为 6B 填充,UDP 示例为 18B)
https://superuser.com/a/394413 同意此编辑
TCP:
Size of Ethernet frame - 24 Bytes
Size of IPv4 Header (without any options) - 20 bytes
Size of TCP Header (without any options) - 20 Bytes
Total size of an Ethernet Frame carrying an IP Packet with an empty TCP Segment - 24 + 20 + 20 = 64 bytes
UDP:
Size of Ethernet frame - 24 Bytes
Size of IPv4 Header (without any options) - 20 bytes
Size of UDP header - 8 bytes
Total size of an Ethernet Frame carrying an IP Packet with an empty UDP Datagram - 24 + 20 + 8 = 52 bytes
EDIT: the above incorrectly states the ethernet frame bytes as 24B. It's instead 18 (or 22 for VLAN-tagged ethernet). The 8B preamble is not part of the minimal-64B frame. So the minimum IPv4+TCP packet is 18+20+20=58 bytes, and minimal IPv4+UDP is 18+20+8=46 bytes. In those cases, there would need to be ethernet padding to fill the frame up to 64B (6B padding for the TCP example, 18B for the UDP example)
https://superuser.com/a/394413 agrees with this edit