Fragmentation layer. Fragments messages larger than frag_size into smaller packets.
Reassembles fragmented packets into bigger ones. The fragmentation number is prepended
to the messages as a header (and removed at the receiving side).
Each fragment is identified by (a) the sender (part of the message to which the header is appended),
(b) the fragmentation ID (which is unique per FRAG2 layer (monotonically increasing) and (c) the
fragement ID which ranges from 0 to number_of_fragments-1.
Requirement: lossless delivery (e.g. NAK, ACK). No requirement on ordering. Works for both unicast and
multicast messages.
Compared to FRAG, this protocol does not need to serialize the message in order to break it into
smaller fragments: it looks only at the message's buffer, which is a byte[] array anyway. We assume that the
size addition for headers and src and dest address is minimal when the transport finally has to serialize the
message, so we add a constant (200 bytes).
author: Bela Ban version: $Id: FRAG2.java,v 1.25.2.1 2007/04/27 08:03:51 belaban Exp $
Number of bytes that we think the headers plus src and dest will take up when
message is serialized by transport. This will be subtracted from frag_size
Send all fragments as separate messages (with same ID !).
Example:
Given the generated ID is 2344, number of fragments=3, message {dst,src,buf}
would be fragmented into:
[2344,3,0]{dst,src,buf1},
[2344,3,1]{dst,src,buf2} and
[2344,3,2]{dst,src,buf3}
1. Get all the fragment buffers
2. When all are received -> Assemble them into one big buffer
3. Read headers and byte buffer from big buffer
4. Set headers and buffer in msg
5. Pass msg up the stack