next up previous contents
Next: Reassembly Up: More Example Protocols Previous: More Example Protocols

Fragmentation

BLAST is an x-kernel protocol that fragments large messages into MTU-sized packets at the sender, and reassembles the fragments back into the complete message at the receiver. The following shows the implementation of blastPush, which contains the for loop that generates and transmits all the fragments in a message. Notice that it is not necessary to calculate how long the last fragment is because the msgBreak operation automatically makes each fragment the minimum of the specified size ( FRAGMENT_SIZE) and how ever many bytes are left in the message.

static XkReturn
blastPush(Sessn s, Msg *msg)
{
    BlastState *state = s->state;
    BlastHdr   *hdr;
    int        num_frags, i;
    Msg        *fragment;
    char       *buf;

    /* get header template and set MID, incrementing last value used */
    hdr = state->hdr_template;
    if (state->mid == MAX_SEQ_NUM)
        state->mid = 0;
    hdr->MID = ++state->mid;

    /* determine number of fragments */
    if (msgLength(msg) <= FRAGMENT_SIZE)
        num_frags = 1;
    else
        num_frags = (msgLength(msg) + FRAGMENT_SIZE - 1)/FRAGMENT_SIZE;
    hdr->NumFrags = num_frags;

    /* create and transmit individual fragments */
    for (i = 1; i <= num_frags; i++) {
        /* carve a fragment off of original msg */
        msgConstructEmpty(fragment);
        msgBreak(msg, fragment, FRAGMENT_SIZE);

        /* fill in dynamic parts of header */
        hdr->len = msgLength(fragment);
        set_fragment_mask(hdr->mask, i);

        /* add header and send fragment */
        buf = msgPush(fragment, HDR_LEN);
        blast_hdr_store(hdr, buf, HDR_LEN, fragment);
        xPush(xGetDown(s, 0), fragment);

        /* save copy of fragment for future retransmit */
        save_for_retransmit(state->frag_list, fragment, i);
    }
    /* schedule DONE timer */
    state->event = evSchedule(giveup, 0, DONE);
}

This routine also uses the event library to schedule a timeout. We show a more complete example of how timeouts are implemented in a later example.



Larry Peterson
Wed Feb 21 13:58:06 MST 1996