Let’s Talk Tech: How the Internet Works Part 2: Fragmentation
Welcome to the second episode of our new Let’s Talk Tech series: How the Internet Works! Today, Boss Man John Brewer (AKA Doctor Deep Core) shows us how data gets around the globe thanks to the wonders of Fragmentation.
Full transcript is below the video. Enjoy!
Introduction to Fragmentation
Hello, and welcome to Let’s Talk Tech with Deep Core Data. I’m John Brewer, the owner and Founder here at Deep Core, where we’re using education to help businesses make the best tech choices. In this series we’ll be discussing, at a technical level, how the Internet works.
Today we’re going to talk about IPv4 Packet Fragmentation, or “how do we move large data packets around the internet?”. The answer? Clever packaging!
In our video on the IPv4 packet, we pointed out that 3 of the 13 fields in every IP packet header are about fragmentation. So what is fragmentation?
Imagine you work for “Bulldozers R Us” and you have a large bulldozer that needs to be shipped overseas. Obviously, it’s too large to fit in a single container, but fortunately, it can be dismantled. The shipping service tells you that the individual pieces need to fit into standard crates, so each crate must contain certain instructions on how to reassemble the bulldozer, in the correct order, upon reaching its destination.
An IP packet can be as large as sixty-five thousand, five hundred and thirty five (65,535) bytes, or 64 kilobytes, and that is a huge packet. Not every router ever built will be able to handle a packet that large. In fact, in order to meet the IPv4 specification, a router only needs to be able to handle packets up to 576 bytes.
So how does a huge IP packet get through a network that only wants to handle smaller packets? Just like the bulldozer, it gets broken into smaller pieces, packed with reassembly instructions, and sent forth.
Let’s say I’m sending out an IP packet that’s 2,000-bytes long (20 bytes of header plus 1,980 bytes of data), but my router can only handle 1,000-byte long packets. When I try to send the packet, my router drops it and sends me an ICMP message telling me that the packet was too big.
As an aside, the Internet Control Message Protocol (ICMP) is used by network devices, like routers, to send errors and operational information indicating, for example, that the requested service is not available, or that a hoster router could not be reached.
So back to our large packet; the ICMP messages helpfully includes the maximum size packet that the router can handle. This size is called the Maximum Transmission Unit, or MTU. In our analogy, this would be the box size.
My computer says, OK, I can deal with this, and breaks my 2,000-byte packet down into 3 smaller packets. The first packet is 20 bytes of header and 980 bytes of data. The second is also 20 bytes of header and 980 bytes of data. The third packet is 20 bytes of header and the last 20 bytes of data.
Each packet get the same number in its identification field; or tracking number, in our shipping example. It doesn’t matter what the specific number is, as long as it is the same on each of the three packets.
The first and second packets have their “More Fragments” flag set. This tells the destination computer that there are more fragments coming. Because it is the last fragment, the third packet’s “More Fragments” flag isn’t set, letting the destination computer know all the fragments have been received.
Finally, my computer puts in the offsets for the packets. The first packet contains the first 980 bytes of data, so its offset is zero. The second packet contains the second 980 bytes, so its offset is 980. In our example, offsets are essentially reassembly instructions. The third packet contains the last twenty bytes, so it has an offset of 1,960.
My router, with an MTU of 1,000 bytes, happily accepts all three packets and routes them on to their destination.
So what happens at the destination?
Well, the first packet arrives, and the destination computer immediately realizes this is a fragmented packet because the More Fragments flag is set. Rather than immediately send it to the web browser or email client or whatever application wants it, it stores it until the rest of the fragments come in.
The second packet shows up. The destination computer sees that it has 980 bytes of data, and is supposed to be at offset 980, so it adds the data from the second packet to the first packet.
The third packet shows up. The destination computer sees it has the same ID number as the first two packets. It doesn’t have it’s More Fragments flag set, so the destination computer knows this is the last fragment. It sees the offset is 1,960, so it adds the 20 bytes of data in the third packet to the data from the first two. It now sees that it has the last fragment of the packet, that there are no holes in data from packets that might be lagging or coming in out of order, and so it assembles the 1,980 bytes of data into a complete, original IP packet, and hands it on for processing.
So our bulldozer has arrived at the dock. Our buyer takes the delivery and proceeds to make sure all of the crates have arrived. Then each box is individually opened up, and the reassembly instructions are followed. Hopefully, the instructions match the items in the box, and nothing is missing.
It is worth noting that in this scenario, we had the source computer doing the fragmentation. In IPv4, fragmentation can be done by any router along the way as long as the Don’t Fragment flag isn’t set on the IP packet. In IPv6, however, source host has to do the fragmentation; it’s not allowed to let the routers do it on the way.
In networking, MTU, or Maximum Transmission Unit, is a key metric for a number of reasons. In our example, fragmentation tripled the number of packets sent through the network, and increased the total amount of data sent by 40 bytes. Especially in IPv4 networks, where routers are responsible for fragmenting and reconstituting packets, you can see significant performance impact if applications and computers try to send packets that are larger than the network wants to allow.
Fragmentation is a powerful tool for helping the varied devices of the Internet work together, but it is important to understand how it works and what the implications are.
I hope you enjoyed this episode of How The Internet Works. We’ll be talking a lot more about IPv4 in our next episode. If you enjoyed what you saw, please hit subscribe! And if you have questions or ideas for future episodes, please leave them in a comment below.
I’m John Brewer for Deep Core Data. Thanks for watching.