A Sample selective-repeat Protocol, continued
We have most work to perform when a frame arrives at the Physical Layer -
either some DL_DATA or an DL_ACK.
As with earlier protocols,
we must first determine if the frame has been corrupted.
A more complex selective-repeat protocol may incorporate
DL_NACKs.
EVENT_HANDLER(physical_ready)
{
FRAME frame;
int link, checksum;
size_t len;
len = sizeof(FRAME);
CHECK(CNET_read_physical(&link, &frame, &len));
checksum = frame.checksum;
frame.checksum = 0;
if(CNET_ccitt((unsigned char *)&frame, len) != checksum) {
return; // bad checksum, simply ignore frame
}
if(frame.kind == DL_ACK) {
if(between(ackexpected, frame.seqno, nextdatatosend)) {
while(between(ackexpected, frame.seqno, nextdatatosend)) {
--nbuffered; // buffer now available
CNET_stop_timer(timers[ackexpected % NRBUFS]);
timers[ackexpected % NRBUFS] = NULLTIMER;
inc(&ackexpected);
}
CNET_enable_application(ALLNODES);
}
}
|
CITS3002 Computer Networks, Lecture 3, Data Link Layer protocols, p31, 13th March 2024.
|