CITS3002 Computer Networks  
prev
next CITS3002 help3002 CITS3002 schedule  

Transmitting across the Physical Layer

Our transmit_frame() function performs the final actions before something is transmitted across the Physical Layer.

Parameters provide the message to be transmitted, an indication as to whether it is data or an acknowledgment, its length, and its sequence number as part of the stopandwait protocol.

void transmit_frame(MSG *msg, FRAMEKIND kind, size_t msglen, int seqno)
{
    FRAME       f;

    f.kind      = kind;
    f.seq       = seqno;
    f.checksum  = 0;
    f.len       = msglen;

    switch(kind) {
      case DL_ACK :
        printf("ACK transmitted, seq=%d\n",seqno);
        break;

      case DL_DATA : {
        CnetTime   timeout;

        memcpy(&f.msg, msg, msglen);
        printf(" DL_DATA transmitted, seq=%d\n",seqno);

	timeout   = (FRAME_SIZE(f)*8000000 / OS->links[1].bandwidth) + OS->links[1].propagationdelay;
        lasttimer = CNET_start_timer(EV_TIMER1, timeout, 0);
        break;
      }
    }
    msglen      = FRAME_SIZE(f);
    f.checksum  = CNET_ccitt((unsigned char *)&f, (int)msglen);

    CHECK(CNET_write_physical(1, &f, &msglen));
}




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