A bit of background.
I'm writing an application that uses UDP. The application will run on a LAN (not internet). I've been assuming that开发者_如何学编程 if my MTU is 1500 then thats how big a UDP payload can be, but I'm not sure if the UDP header is meant to fit within that too.
I'm suspecting that if I send a UDP packet with a 1500 byte payload and the machine MTU is 1500 bytes will it end up sending two packets?
Searching the internet for a clear answer here seems harder than it should be, I've seen conflicting information.
------------------------------------------------------------------------------
|Ethernet | IPv4 |UDP | Data |Ethernet checksum|
------------------------------------------------------------------------------
14 bytes 20 bytes 8 bytes x bytes 4 bytes
\ (w/o options) /
\___________________________________________/
|
MTU
If your MTU is 1500, you have 1500-20-8 = 1472 bytes for your data.
- If you exceed that, the packets will be fragmented ,i.e. split into more packets.
- There might be more layers involved, e.g. 4 byte a vlan header if you're on top of a vlan ethernet.
- Some routers inbetween you and the destination might add more layers.
Yes your example would not fit in one frame.
The ethernet data payload is 1500 bytes. IPv4 requires a minimum of 20 bytes for its header. Alternatively IPv6 requires a minimum of 40 bytes. UDP requires 8 bytes for its header. That leaves 1472 bytes (ipv4) or 1452 (ipv6) for your data.
More information:
- http://en.wikipedia.org/wiki/Ethernet_II_framing
- http://en.wikipedia.org/wiki/IPv4#Header
- http://en.wikipedia.org/wiki/IPv6_packet#Fixed_header
- http://en.wikipedia.org/wiki/User_Datagram_Protocol
So, here is how it works. Ethernet restricts your data flow to 1500 bytes per frame even though you have a 100 meg fat pipe. To really use the line rate, through your UDP application, you will need to use/move to ethernet jumbo frames which may support upto 9000 bytes per frame. Also, if you look at netflix/youtube and other streaming protocols, they test your link before they start streaming. What essentially they do is, they send some data to you and calculate/average the link speed before they dump the stream. They essentially use UDP as well but with a very big packet size. I guess bigger than 1500 bytes for sure.
精彩评论