CITS3002 Computer Networks  
prev
next CITS3002 help3002 CITS3002 schedule  

A Sample selective-repeat Protocol

Here we develop a sample selective-repeat protocol for the data link layer.

We'll assume that the size of the sender's and receiver's windows have been defined as integer constants with NRBUFS and MAXSEQ.

We omit the declaration of structures and variables, but note that the sender will need a number of timers (one per outstanding frame), and the receiver needs record which frames have arrived (but not yet to be sent to the layer above).

#include <cnet.h>
#include <stdlib.h>
#include <stdbool.h>

FRAME  *inframe;
FRAME  *outframe;

//  other declarations omitted....

EVENT_HANDLER(reboot_node)
{
    inframe   = calloc(NRBUFS, sizeof(FRAME));
    outframe  = calloc(NRBUFS, sizeof(FRAME));

    timers    = calloc(NRBUFS, sizeof(CnetTimerID));

    arrived   = calloc(NRBUFS, sizeof(bool));

    // we really should check if the allocations were successful!

    for(int b=0 ; b < NRBUFS ; b++) {
	arrived[b]    = false;
	timers[b]     = NULLTIMER;
    }

    CHECK(CNET_set_handler(EV_APPLICATIONREADY, appl_ready, 0));
    CHECK(CNET_set_handler(EV_PHYSICALREADY,    physical_ready, 0));
    CHECK(CNET_set_handler(EV_TIMER1,           DLL_timeouts, 0));

    CNET_enable_application(ALLNODES);
}




CITS3002 Computer Networks, Lecture 3, Data Link Layer protocols, p29, 13th March 2024.