IP Datagram Fragmentation total length and payload calculations

5,755

You're expected to assume that all fragments but the last will be as large as the network allows.

You can get the maximum fragment payload size by taking the MTU, subtracting 20, dividing by 8, discarding the fraction, and then multiplying by 8. This works because each packet needs a 20 byte header and each packet but the last must contain a payload length that is a multiple of 8.

128 - 20 = 108
108 / 8 = 13.5
13 * 8 = 104

So for an MTU of 128, the maximum payload size is 104. Let's see how many packets we need to send 302 bytes of payload:

302 / 104 = 2.903

So we'll need two maximum-sized packets and one leftover. How much leftover will we have?

302 - (2 * 104) = 94

So 94 bytes of data in the last packet.

You can get the total length from the payload sizes by adding 20.

Share:
5,755

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    I do not understand how to fragment a IP datagram.

    Let's say the original datagram has a total size of 302 (20bytes header and 282 bytes payload). My datagram needs to be fragmented since it goes through a network of 128MTU. I have to fragment it and add 20 header for each new fragments.

    This is an exercice and the answer is

    • Fragment 1 124 total length (104 bytes payload)

    • Fragment 2 124 total length (104 bytes payload)

    • Fragment 3 94 total length (74 bytes payload)

    If I addition that it gives me indeed the original payload. I do not understand how to find those numbers...

    Why couldn't it be

    • Fragment 1 114 total length (94 bytes payload)
    • Fragment 2 114 total length (94 bytes payload)
    • Fragment 3 114 total length (94 bytes payload)

    (282/3) > 2 so I need 3 fragments. 3Fragments = 60 bytes header added 60 +282 = 342 342/3 = 114 total lenght for each fragments.

    My question is...

    How and why should I get 124 124 and 94?

  • wmz
    wmz over 8 years
    heh you're quicker! So just as and addendum, the division algorithm is govern by RFC 791, page 8: "datagram is divided into two portions on a 8 octet (64 bit) boundary (the second portion might not be an integral multiple of 8 octets, but the first must be)" -and this explains why: "The fragment offset is measured in units of 8 octets (64 bits)"