Fragmentation and Reassembly
To make IPv4 more tolerant of different networks the concept of fragmentation was added so that, if necessary, a device could break up the data into smaller pieces. This is necessary when the maximum transmission unit (MTU) is smaller than the packet size.For example, the maximum size of an IP packet is 65,535 bytes while the typical MTU for Ethernet is 1,500 bytes. Since the IP header consumes 20 bytes (without options) of the 1,500 bytes, 1,480 bytes are left for IP data per Ethernet frame (this leads to an MTU for IP of 1,480 bytes). Therefore, a 65,535-byte data payload (including 20 bytes of header information) would require 45 packets (65535-20)/1480 = 44.27, rounded up to 45.
Fragmentation
When a device receives an IP packet it examines the destination address and determines the outgoing interface to use. This interface has an associated MTU that dictates the maximum data size for its payload. If the MTU is smaller than the data size then the device must fragment the data.
The device then segments the data into segments where each segment is less-than-or-equal-to the MTU less the IP header size (20 bytes minimum; 60 bytes maximum). Each segment is then put into its own IP packet.
For example, if a 4,500-byte data payload is inserted into an IP packet with no options (thus total length is 4,520 bytes) and is transmitted over a link with an MTU of 1,500 bytes then it will be broken up into three fragments.
Eg. The amount of data has been preserved — 1480 + 1000 + 1480 + 540 = 4500 — and the last fragment offset plus data — 3960 + 540 = 4500 — is also the total length.
Reassembly
When a receiver detects an IP packet where either of the following is true:
"more fragments" flag set
"fragment offset" field is non-zero
then the receiver knows the packet is a fragment. The receiver then stores the data with the identification field, fragment offset, and the more fragments flag. When the receiver receives a fragment with the more fragments flag set to 0 then it knows the length of the original data payload since the fragment offset plus the data length is equivalent to the original data payload size.
The example above, when the receiver receives fragment 4 the fragment offset (495 or 3960 bytes) and the data length (540 bytes) added together yield 4500 — the original data length.
Once it has all the fragments then it can reassemble the data in proper order (by using the fragment offsets) and pass it up the stack for further processing.
Comments