0% found this document useful (0 votes)
5 views

Program To Implement Sliding Window Protocol

Uploaded by

sneha600ad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Program To Implement Sliding Window Protocol

Uploaded by

sneha600ad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Program To Implement Sliding Window Protocol - Selective Repeat ARQ

Pseudo Code
#include<iostream>

using namespace std;

int main()
{
int w,i,f,frames[50];

cout<<"Enter window size: ";


cin>>w;

cout<<"\nEnter number of frames to transmit: ";


cin>>f;

cout<<"\nEnter "<<f<<" frames: ";

for(i=1;i<=f;i++)
cin>>frames[i];

for(i=1;i<=f;i++)
{
if(i%w==0)
{
cout<<frames[i]<<"\n";
cout<<"Acknowledgement of above frames sent is received by sender\n\n";
}
else
cout<<frames[i]<<" ";
}

if(f%w!=0)
cout<<"\nAcknowledgement of above frames sent is received by sender\n";

return 0;
}
Algorithm - Sender’s side

begin

frame s; //s denotes frame to be sent

frame t; //t is temporary frame

S_window = power(2,m-1); //Assign maximum window size

SeqFirst = 0; // Sequence number of first frame in window

SeqN = 0; // Sequence number of Nth frame window

while (true) //check repeatedly

do

Wait_For_Event(); //wait for availability of packet

if ( Event(Request_For_Transfer)) then

//check if window is full

if (SeqN–SeqFirst >= S_window) then

doNothing();

end if;

Get_Data_From_Network_Layer();

s = Make_Frame();

s.seq = SeqN;

Store_Copy_Frame(s);

Send_Frame(s);

Start_Timer(s);

SeqN = SeqN + 1;

end if;

if ( Event(Frame_Arrival) then
r = Receive_Acknowledgement();

//Resend frame whose sequence number is with ACK

if ( r.type = NAK) then

if ( NAK_No > SeqFirst && NAK_No < SeqN ) then

Retransmit( s.seq(NAK_No));

Start_Timer(s);

end if

//Remove frames from sending window with positive ACK

else if ( r.type = ACK ) then

Remove_Frame(s.seq(SeqFirst));

Stop_Timer(s);

SeqFirst = SeqFirst + 1;

end if

end if

// Resend frame if acknowledgement haven’t been received

if ( Event(Time_Out)) then

Start_Timer(s);

Retransmit_Frame(s);

end if

end
Algorithm – Receiver Side

Begin

frame f;

RSeqNo = 0; // Initialise sequence number of expected frame

NAKsent = false;

ACK = false;

For each slot in receive_window

Mark(slot)=false;

while (true) //check repeatedly

do

Wait_For_Event(); //wait for arrival of frame

if ( Event(Frame_Arrival) then

Receive_Frame_From_Physical_Layer();

if ( Corrupted ( f.SeqNo ) AND NAKsent = false) then

SendNAK(f.SeqNo);

NAKsent = true;

end if

if ( f.SeqNo != RSeqNo AND NAKsent = false ) then

SendNAK(f.SeqNo);

NAKsent = true;

if ( f.SeqNo is in receive_window ) then

if ( Mark(RSeqNo) = false ) then

Store_frame(f.SeqNo);

Mark(RSeqNo) = true;
end if

end if

else

while ( Mark(RSeqNo))

Extract_Data(RSeqNo);

Deliver_Data_To_Network_Layer();

RSeqNo = RSeqNo + 1;

Send_ACK(RSeqNo);

end while

end if

end if

end while

end

You might also like