The following is the student section of the code for the transport layer
#include "stdafx.h"
int A_Base = 0;// sender state
int A_nextseqnum =0; // Receiver state
int B_Expectedseqnum;
#define A_N 3 // this is the window size
struct pkt A_sndpkt[1000]; // buffer
struct pkt B_sndpkt; // ack packet
void A_output(struct msg message) // rdt_send(data)
{
if (A_nextseqnum< A_Base+A_N)
{
A_sndpkt[A_nextseqnum].seqnum = A_nextseqnum;
for(int i = 0;i<20;i++) A_sndpkt[A_nextseqnum].payload[i] = message.data[i];
//calculate checksum
tolayer3(A,A_sndpkt[A_nextseqnum]);
if(A_Base == A_nextseqnum)
starttimer(A,10.0);
A_nextseqnum ++;
}
else
{
// do nothing
}
}
void B_output(struct msg message)
{
}
//layer 3 checks for corruption
void A_input(struct pkt packet)
{
int corrupt =0; // if not corrupt
for(int i = 0;i<20;i++) corrupt +=packet.payload[i];
if
(corrupt == packet.checksum)
{
A_Base = packet.acknum;
if (A_Base == A_nextseqnum)
stoptimer(A);
else
starttimer(A,10.0);
}
}
void A_timerinterrupt() //checks for a timeout
{
starttimer(A,10.0);
for(int i= A_Base;i<A_nextseqnum-1;i++)
tolayer3(A,A_sndpkt[i]);
}
void A_init()
{
A_Base = 1;
A_nextseqnum =1;
}
void B_input(struct pkt packet) //check if sequence number is correct and packet is not corrupt
{
int corrupt =0;
for(int i = 0;i<20;i++) corrupt +=packet.payload[i];
if(packet.seqnum == B_Expectedseqnum && corrupt == packet.checksum)
{
//send all information
tolayer5(B,packet.payload);
B_sndpkt.acknum = B_Expectedseqnum;
tolayer3(B,B_sndpkt);
B_Expectedseqnum++;
}
else
{
tolayer3(B,B_sndpkt);
}
}
/* called when B's timer goes off */
void B_timerinterrupt()
{
}
void B_init()
{
B_Expectedseqnum = 1;
B_sndpkt.acknum = 0;
}
#include "stdafx.h"
int A_Base = 0;// sender state
int A_nextseqnum =0; // Receiver state
int B_Expectedseqnum;
#define A_N 3 // this is the window size
struct pkt A_sndpkt[1000]; // buffer
struct pkt B_sndpkt; // ack packet
void A_output(struct msg message) // rdt_send(data)
{
if (A_nextseqnum< A_Base+A_N)
{
A_sndpkt[A_nextseqnum].seqnum = A_nextseqnum;
for(int i = 0;i<20;i++) A_sndpkt[A_nextseqnum].payload[i] = message.data[i];
//calculate checksum
tolayer3(A,A_sndpkt[A_nextseqnum]);
if(A_Base == A_nextseqnum)
starttimer(A,10.0);
A_nextseqnum ++;
}
else
{
// do nothing
}
}
void B_output(struct msg message)
{
}
//layer 3 checks for corruption
void A_input(struct pkt packet)
{
int corrupt =0; // if not corrupt
for(int i = 0;i<20;i++) corrupt +=packet.payload[i];
if
(corrupt == packet.checksum)
{
A_Base = packet.acknum;
if (A_Base == A_nextseqnum)
stoptimer(A);
else
starttimer(A,10.0);
}
}
void A_timerinterrupt() //checks for a timeout
{
starttimer(A,10.0);
for(int i= A_Base;i<A_nextseqnum-1;i++)
tolayer3(A,A_sndpkt[i]);
}
void A_init()
{
A_Base = 1;
A_nextseqnum =1;
}
void B_input(struct pkt packet) //check if sequence number is correct and packet is not corrupt
{
int corrupt =0;
for(int i = 0;i<20;i++) corrupt +=packet.payload[i];
if(packet.seqnum == B_Expectedseqnum && corrupt == packet.checksum)
{
//send all information
tolayer5(B,packet.payload);
B_sndpkt.acknum = B_Expectedseqnum;
tolayer3(B,B_sndpkt);
B_Expectedseqnum++;
}
else
{
tolayer3(B,B_sndpkt);
}
}
/* called when B's timer goes off */
void B_timerinterrupt()
{
}
void B_init()
{
B_Expectedseqnum = 1;
B_sndpkt.acknum = 0;