CITS3002 Computer Networks  
prev
next CITS3002 help3002 CITS3002 schedule  

Detecting Frame Corruption

Next, we'll remove the assumption that the channel is error free; frames (only) may now be corrupted during transmission, introducing the need for checksums. We'll now introduce a FRAMETYPE to distinguish what a frame is being used for.

Known (agreed to) by both the sender and receiver:

typedef enum { DLL_DATA, DLL_ACK, DLL_NACK } FRAMETYPE;

typedef struct {
// firstly, the frame's header
    FRAMETYPE type;
    int       checksum;         // checksum of the whole frame
    int       len;              // length of the payload, only 

// followed by the payload
    char      data[MAX_DATA_SIZE];
} FRAME;

In the sender:

FRAME frame, ackframe;
int   link, len, acklen;

while( true ) {
    READ_NETWORK_LAYER(frame.data, &len);

    frame.type     = DLL_DATA;
    frame.len      = len;
    frame.checksum = 0;
    frame.checksum = checksum_crc16(&frame, FRAME_SIZE(frame));

    while( true ) {
        link = 1;
        WRITE_PHYSICAL_LAYER(link, &frame, FRAME_SIZE(frame));

        READ_PHYSICAL_LAYER(&link, &ackframe, &acklen);
        if(ackframe.type == DLL_ACK)
            break;
    }
}




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