## IP DATAGRAM REASSEMBLY ALGORITHMS

```                             David D. Clark
MIT Laboratory for Computer Science
Computer Systems and Communications Group
July, 1982
```
1. Introduction

One of the mechanisms of IP is fragmentation and reassembly. Under

## alternate approach which should prove more suitable in some machines.

```     A  superficial  examination  of  the reassembly process may suggest
```

## algorithm that tests for a number of different options.

```     In  fact,  the  process  of  reassembly  is  extremely simple. This
```

## appropriate for almost any sort of operating system.

```     The reader should consult the IP specification document to be  sure
```

## process.

1. The Algorithm
```     In  order  to  define this reassembly algorithm, it is necessary to
```

## will assume that all of the hole descriptors for a particular datagram

```     The  general  form  of  the  algorithm  is  as follows.  When a new
```

## can be passed to higher protocol levels for further processing.

```     The algorithm will be described in two phases. In the  first  part,
```

## management of the hole descriptor list.

1. Fragment Processing Algorithm

An arriving fragment can fill any of the existing holes in a number

## complicated algorithm. In fact, if properly expressed, the algorithm

```     We  start  the algorithm when the earliest fragment of the datagram
```

## fragment.

```   1. Select the next hole  descriptor  from  the  hole  descriptor
list.  If there are no more entries, go to step eight.
```
1. If fragment.first is greater than hole.last, go to step one.
1. If fragment.last is less than hole.first, go to step one.
```         - (If  either  step  two  or  step three is true, then the
newly arrived fragment does not overlap with the hole in
any way, so we need pay no  further  attention  to  this
we select the next hole for examination.)
```
1. Delete the current entry from the hole descriptor list.
```         - (Since  neither  step  two  nor step three was true, the
newly arrived fragment does interact with this  hole  in
some  way.    Therefore,  the current descriptor will no
longer be valid.  We will destroy it, and  in  the  next
two  steps  we  will  determine  whether  or  not  it is
necessary to create any new hole descriptors.)
```

## create a new descriptor for this smaller hole.)

```   6. If fragment.last is less  than  hole.last  and  fragment.more

fragments   is  true,  then  create  a  new  hole  descriptor
"new_hole", with new_hole.first equal to  fragment.last  plus
one and new_hole.last equal to hole.last.

- (This   test  is  the  mirror  of  step  five  with  one
additional feature.  Initially, we did not know how long
the reassembled datagram  would  be,  and  therefore  we
created   a   hole   reaching  from  zero  to  infinity.
Eventually, we will receive the  last  fragment  of  the
datagram.    At  this  point, that hole descriptor which
reaches from the last octet of the  buffer  to  infinity
can  be discarded.  The fragment which contains the last
fragment indicates this fact by a flag in  the  internet
header called "more fragments".  The test of this bit in
this  statement  prevents  us from creating a descriptor
for the unneeded hole which describes the space from the
end of the datagram to infinity.)
```
1. Go to step one.
1. If the hole descriptor list is now empty, the datagram is now complete. Pass it on to the higher level protocol processor for further handling. Otherwise, return.
```     4.  Part Two:  Managing the Hole Descriptor List

The  main  complexity  in  the  eight  step  algorithm above is not
```

## with implementation idiosyncrasies.

```     There  is  only  one obvious pitfall to this storage strategy.  One
```

## have already been rendered obsolete.

1. Loose Ends
```     Scattering  the  hole  descriptors throughout the reassembly buffer
```

## obvious location is the checksum field.

```     When  the final fragment of the datagram arrives, the packet length
```
1. Options

The preceding description made one unacceptable simplification. It

## fragment" is the fragment containing octet zero of the original

### datagram.)

```     Until  one  knows how big the internet header is, one does not know
```

## descriptors together. It is easy to see how to untrash the pointers.

```     The source and record route options have  the  interesting  feature
```

## the first fragment and ignore the other versions.

1. The Complete Algorithm

In addition to the algorithm described above there are two parts to

## protocol ID, and the identification field.

```     The  final  part  of  the  algorithm  is  some  sort of timer based
```

## mechanism is appropriate, to reap the datagram when its time has come.

```     An implementation of the complete algorithm  comprising  all  these
```

## 400 nova machine instructions. That portion of the algorithm actually

```     The   version  of  the  algorithm  described  here  is  actually  a
```