Go Back N Arq

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 25

GO BACK N ARQ

M S RAMAIAH INSTITUTE OF TECHNOLOGY


AUTONOMOUS INSTITUTE AFFILIATED TO VTU

Information Science and Engineering


Department

Group no: 10
Group name : THE KING MAKERS
Group
members:
Chetan .S
(1ms07is021)
Deepak.P.J
(1ms07is022)
Pavan.R
(1ms07is062)
Phaneesh.L.N ( 1ms07is066)
Introduction:
ARQ is a method of data transmission which uses timeouts and
acknowledgement signals to achieve reliable transmission over
an unreliable service i.e the internet. An acknowledgement is a
message sent by the receiver to the transmitter to indicate that it
has correctly received a data frame or packet. A timeout is a
reasonable point in time after the sender sends the frame/packet;
if the sender does not receive an acknowledgement before the
timeout, it usually re-transmits the frame/packet until it receives
an acknowledgement or exceeds a predefined number of re-
transmissions.
There are mainly 3 types of ARQ
• Stop and wait ARQ
• Go back n ARQ
• Selective repeat ARQ

Here we deal about go back n ARQ

Go back n ARQ is a protocol in which the sender continues


to send a number of frames without receiving the ACK
(acknowledgement) signal from the receiver. The receiver
receives the next frame in accordance with the sequence
number and sends that number with every ACK it sends.
The receiver will not accept the frames that don’t have the
SEQ number it expects.
Once the sender has sent all of the frames in its window, it
will detect that all of the frames since the first
lost frame are outstanding, and will go back to sequence
number of the last ACK it received from the receiver
process after time out it sends the outstanding and the
subsequent frames.

LITERATURE SURVEY
The present invention relates to a data transmission system
using an automatic repeat request (hereinafter is referred to
as abbreviation "ARQ") and more particularly to
a data transmission system for realizing a procedure of
retransmission of error detected frames, which is adapted to
a transmission channel such as radio communication with
relatively high transmission error-rate.

The recovery of transmission error in data transmission has


been conducted by automatic retransmission using ARQ
and/or by error-correction technique using error-correction
code. ARQ is a method of recovering an error in a data
transmission in which any blocks of data found to contain
errors at the receiving terminal are automatically requested
for repeat transmission from the transmitting terminal. In
response to this request, the required blocks are transmitted
again from the transmitting terminal to the receiving
terminal. A Go-back-N ARQ method and a selective repeat
ARQ method are representative.

An example of procedure of the Go-back-N ARQ method


is as follows:
In this method, the transmitting terminal transmits data
with additions of an error detection code and transmission
sequential number, and the receiving terminal performs
error checking on every frame of the received data. When
any frame containing an error is detected, the receiving
terminal informs the transmitting terminal of the sequential
number of the frame concerned and requests repeat
transmission of the data from the transmitting terminal. The
transmitting terminal searches back the sequential number
of the frame and repeats transmission of
the sequence of data starting from the required frame.

The detailed procedure of retransmission of frames by the


Go-back-N ARQ is as follows:

The transmitting terminal transmits data with error


detection codes and transmission sequence numbers N(S).
At the receiving terminal, aframe with transmission
sequence number N(S)=2 is now found to contain an error.
In this case, the receiving terminal transmits a REJ frame
with a numeral 2 previously set in a received sequence
number N(R) for requesting repeat transmission of the
frame having the sequence number 2. Upon receipt of the
REJ frame, the transmitting terminal returns to transmission
number N(S)=2 and repeats transmission of data in the
sequence beginning from the specified sequence number.
However, this method has relatively low efficiency and
reduces a throughput in data transmission since it requires
repeat transmission of the already transmitted correct
frames following the requested frame.
ALGORITHM
SENDER

Sw = 2 ^m -1;
Sf = 0;
Sn = 0;

While ( true)
{
Waitforevent ( );
If (event (requesttosend) )
{
If (Sn-Sf >=Sw)
Sleep ( );
Getdata ( ) ;
Makeframes (Sn);
Storeframes (Sn);
Sendframes (Sn);
Sn =Sn+1;
If ( timer not running)
Starttimer ( );
}

If ( event ( arrivalnotification ) )

{
Receive (ACK);
If ( corrupted (ACK) )
Sleep ( );
If ( ( ackno > Sf ) && ( ackno <= Sn ) ) ;
While ( Sf <= ackno )
{
Purgeframe ( Sf );
Sf = Sf + 1;
}
Stoptimer ( );
}
If ( event ( timeout ) )

{
Starttimer ( ) ;
Temp = Sf ;
While ( temp < Sn );
{
Sendframe ( Sf );
Sf = Sf + 1;
}

}
RECEIVER

Rn = 0;

While ( true )

Waitforevent ( ) ;

If ( event (arrivalnotification ) )

Receive ( frame ) ;

If ( corrupted ( frame ) )

Sleep ( ) ;

If ( seqno == Rn )

Deliverdata ( ) ;

Rn = Rn + 1 ;

sendACK ( Rn ) ;

}
PROGRAM :
#include<iostream>
#include<cstring>
#include<string>
#include<fstream>
using namespace std;
int flag=0;
int flag1=0;
int flag2=0;
int flag4=0;
int flag5=0;
int flag6=0;
int loop2;
char ch1;
char ch2;
int loop;
char sender[50]="How many wants to live after 2012 ?";
char recive[50];
int lensender;
int senderack[50];
int curpos;
int i;
int k;
int trav=0;
int Ws;
int recnext;
int errack[10]={-1};
int errno;
int errpck[10]={-1};
int waste;
char ch='r';
void dispsending();
void send();
void shift();
void dispsimple();
void dispreceiving();
int timer(char str[50],char value[50],int colval) //function takes read, to
be searched string and field, size of str1
{
int k,count=0,i=0,flag=2; //outer loop to travers through ':'
for(k=0;k<40;k++) //timer started to check the sender and receiver
{
if(str[k]==':') //to start search only after required position
got
count++;
else
if(count==colval) //start positon
{
count++; //count incremented so that loop wont search again
while( isdigit(value[i]) ) //loop till the key element
traversed
{
if(!isdigit(str[k+i])) //this returns if
key element is greater size wise
{
flag=1;
return flag+10;
}
if(str[k+i]!=value[i]) //if values are not
matching find if its greater
{
if(flag==2) //this condition makes flag change
only once its lifetime
flag=-1;
if(str[k+i]>value[i])
{
if(flag==-1) //same as above usage
flag=3; //assign if data is
greater
}
else
if(flag==-1)
flag=1;
}
i++; //increment the searching loop for size of key
element
}
if(isdigit(str[k+i])) //if next element after the search
is digit then data is greater
flag=3;
}
}
return flag+10;
}

//start of pgm

int main()
{

curpos=0;
recnext=0;
cout<<"enter the sliding window size\n";
cin>>Ws;
lensender=strlen(sender);
cout<<"how many packets to miss?";
cin>>errno;
for(i=0;i<errno;i++)
{
cin>>errpck[i]; //read the packets to miss
}
cout<<"how many ack's to miss?";
cin>>errno;
for(i=0;i<errno;i++)
{
cin>>errack[i]; //read the acks to miss
}

while(curpos<lensender)
{
cout<<" press Y to miss ack or packet: ";
while(ch=='!')
{
cin>>ch;
}
if(ch=='y')
{ //reads the second time
cout<<"how many packets to miss?";
cin>>errno;
for(i=0;i<errno;i++)
{
cin>>errpck[i]; //read the packets to miss
}
cout<<"how many ack's to miss?";
cin>>errno;
for(i=0;i<errno;i++)
{
cin>>errack[i]; //read the acks to miss
}

}
cout<<"\n\n---------------THE NEW WINDOW POSITION------------\n";
dispsimple();

send();
int use=timer(sender,recive,Ws);
if(use==-1) //if timed out the packets are resent
send();
dispsending();
dispreceiving();
//cout<<"the acknowledge\n\n";
//for(i=0;i<lensender;i++)
//cout<<senderack[i];
//cout<<endl;
loop2=curpos;
for(;senderack[loop2]==1;loop2++) //slide the
window till a acknowledge is recieved properly
{
curpos++;
}

ch='!';
cout<<"\n\n----------------- x ------ x -----------------\n";
}

return 0;
} //end of main

void send()
{

for(loop=0;loop<Ws;loop++) //if packet is missing then entire


ack's from that packet sould n be sent
{

if((curpos+loop)!=errpck[flag4])
{
if(recnext==(curpos+loop))
{ //to find the first
defect packet
recive[recnext]=sender[curpos+loop];
recnext++;
}
}
else
{
break; //flag 5 used to detect if packet failure
is happen
}

}
int temp=loop;

for(loop=0;loop<Ws;loop++) //if packet is missing then entire


ack's from that packet sould n be sent
{

if((curpos+loop)!=errpck[flag4])
{
if(recnext==(curpos+loop))
{
recive[recnext]=sender[curpos+loop];
recnext++;
}
}
else
{
flag4++;
flag5=1; //flag 5 used to detect if packet failure
is happen
}

}
for(loop=0;loop<temp;loop++)
{
if((curpos+loop)==errack[flag2])
{
senderack[curpos+loop]=-1;
flag2++;
flag1=1; //this is set so that we will come to know
if error in ack is occured
}
else
{
senderack[curpos+loop]=1;
}
}
}

/*int flag=0,flag1=0,flag2=0,loop2,loop;
char sender[50]="bhaskar is very good person";
char recive[50];
int lensender,senderack[50],curpos,i,k,Ws,recnext,errack,errpck;*/

void dispsending()
{
int temp;
int q;
q=trav; //used to identify the packet currently in
temp=(Ws/2)+curpos+1;
cout<<" ";
for(k=0;k<temp;k++)
cout<<" "; //print the top part
cout<<"|";
for(;k<(lensender+10+(strlen(recive)/2));k++)
cout<<"`";
cout<<"|";k++;
waste=k;
cout<<endl;

cout<<" ";

for(k=0;k<curpos && k<lensender;k++)


cout<<" ";
cout<<" "; //for packet sending
for(;k<(curpos+Ws) && k<lensender;k++)
{
if(errpck[q]==k)
{
cout<<" ";
q++;
}
else
cout<<"|";
}
cout<<" ";
for(;k<waste-2;k++)
cout<<" ";
cout<<"| (sending...)";
cout<<endl;
q=trav;
cout<<" ";
for(k=0;k<curpos && k<lensender;k++)
cout<<" ";
cout<<" "; //for packet sending line 2
for(;k<(curpos+Ws) && k<lensender;k++)
{
if(errpck[q]==k)
{
cout<<" ";
q++;
}
else
cout<<"|";
}

cout<<" ";
for(;k<waste-2;k++)
cout<<" ";
cout<<"| ";

cout<<endl;

q=trav;
cout<<" ";
for(k=0;k<curpos && k<lensender;k++)
cout<<" ";
cout<<" ";
ch1='&'; //for packet sending line 2
for(;k<(curpos+Ws) && k<lensender;k++)
{
if(errpck[q]==k)
{
cout<<ch1;
ch1++;
q++;
}
else
cout<<"|";
}

cout<<" ";
for(;k<waste-2;k++)
cout<<" ";
cout<<"| ";
for(k=curpos+1;k<(curpos+Ws);k++)
{ for(i=0;i<10;i++)
if(flag5==0)
{
if(errpck[i]==k)
{
cout<<"packet-"<<errpck[i];
flag5=1;
errpck[i]=-1;
}
}
else
if(errpck[i]==k)
{
cout<<","<<errpck[i];
errpck[i]=-1;
}

}
cout<<endl;

trav=q;
cout<<" ";
for(k=0;k<curpos && k<lensender;k++)
cout<<" ";
cout<<",";
for(;k<(curpos+Ws) && k<lensender;k++)
cout<<"|";
cout<<",";
for(;k<waste-2;k++)
cout<<" ";
cout<<"V ";
if(flag6==1)
cout<<" missing :-(";
cout<<endl;

cout<<" ";
for(i=0;i<curpos;i++)
cout<<sender[i];
cout<<"|";
for(;i<(curpos+Ws) && i<lensender;i++)
cout<<sender[i];
cout<<"|";
for(;i<lensender;i++)
cout<<sender[i];
for(;i<waste-2;i++)
cout<<" ";
cout<<"V";
cout<<endl;

cout<<" ";
for(k=0;k<curpos;k++)
cout<<" ";
cout<<"`";
for(;k<(curpos+Ws) && k<lensender;k++)
cout<<"`";
cout<<"`";
for(;k<lensender+10;k++)
cout<<" ";
cout<<recive;
cout<<endl;
cout<<endl<<endl;

void dispsimple()
{

cout<<" ";
for(k=0;k<curpos && k<lensender;k++)
cout<<" ";
cout<<",";
for(;k<(curpos+Ws) && k<lensender;k++)
cout<<",";
cout<<",";
cout<<endl;

cout<<" ";
for(i=0;i<curpos;i++)
cout<<sender[i];
cout<<"|";
for(;i<(curpos+Ws) && i<lensender;i++)
cout<<sender[i];
cout<<"|";
for(;i<lensender;i++)
cout<<sender[i];
for(;i<lensender+3;i++)
cout<<" ";
cout<<"-->";
for(;i<lensender+10;i++)
cout<<" ";
cout<<recive;
cout<<endl;

cout<<" ";
for(k=0;k<curpos;k++)
cout<<" ";
cout<<"`";
for(;k<(curpos+Ws) && k<lensender;k++)
cout<<"`";
cout<<"`";

cout<<endl<<endl;
}

void dispreceiving()
{
int temp;

temp=(Ws/2)+curpos+1;
cout<<" ";
for(k=0;k<temp;k++)
cout<<" "; //print the top part
cout<<"|";
for(;k<(lensender+10+(strlen(recive)/2));k++)
cout<<"`";
cout<<"|";k++;
waste=k;
cout<<endl;

cout<<" ";
for(k=0;k<curpos && k<lensender;k++)
cout<<" ";
cout<<" "; //for packet sending
for(;k<(curpos+Ws) && k<lensender;k++)
{ if(senderack[k]==1)
cout<<"|";
else
if(senderack[k]==0)
cout<<" ";
else
if(senderack[k]==-1)
cout<<"|";
}
cout<<" ";
for(;k<waste-2;k++)
cout<<" ";
cout<<"|";
cout<<endl;
cout<<" ";
for(k=0;k<curpos && k<lensender;k++)
cout<<" ";
cout<<" ";
ch2='@'; //for packet sending line 2
for(;k<(curpos+Ws) && k<lensender;k++)
{ if(senderack[k]==1)
cout<<"|";
else
if(senderack[k]==0)
cout<<" ";
else
if(senderack[k]==-1)
{
cout<<ch2;
ch2--;
}
}
cout<<" ";
for(;k<waste-2;k++)
cout<<" ";
cout<<"| (received)";
cout<<endl;

cout<<" ";
for(k=0;k<curpos && k<lensender;k++)
cout<<" ";
cout<<" "; //for packet sending line 2
for(;k<(curpos+Ws) && k<lensender;k++)
{ if(senderack[k]==1)
cout<<"|";
else
if(senderack[k]==0)
cout<<" ";
else
if(senderack[k]==-1)
cout<<" ";
}
cout<<" ";
for(;k<waste-2;k++)
cout<<" ";
cout<<"| ";
flag6=0;
for(k=curpos;k<(curpos+Ws);k++)
{
if(flag6==0)
{
if(senderack[k]==-1)
{
cout<<"ACK-"<<k;
flag6=1;
}
}
else
if(senderack[k]==-1)
{
cout<<","<<k;
}

}
cout<<endl;

cout<<" ";
for(k=0;k<curpos && k<lensender;k++)
cout<<" ";
cout<<",";
for(;k<(curpos+Ws) && k<lensender;k++)
{ if(senderack[k]==1)
cout<<"|";
else
cout<<",";
}
cout<<",";
for(;k<waste-2;k++)
cout<<" ";
cout<<"| ";
if(flag6==1)
cout<<" missing :-(";

cout<<endl;

cout<<" ";
for(i=0;i<curpos;i++)
cout<<sender[i];
cout<<"|";
for(;i<(curpos+Ws) && i<lensender;i++)
cout<<sender[i];
cout<<"|";
for(;i<lensender;i++)
cout<<sender[i];
for(;i<waste-2;i++)
cout<<" ";
if(flag6==1 || flag5==1)
cout<<"| TIME OUT (resending...)";
else
cout<<"|";
flag6=0,flag5=0;
cout<<endl;

cout<<" ";
for(k=0;k<curpos;k++)
cout<<" ";
cout<<"`";
for(;k<(curpos+Ws) && k<lensender;k++)
cout<<"`";
cout<<"`";
for(;k<lensender+10;k++)
cout<<" ";
cout<<recive;
cout<<endl;
cout<<" ";
for(k=0;k<curpos-1;k++)
cout<<" ";
cout<<curpos<<",0 <-";
for(;k<curpos+Ws-6;k++)
cout<<" ";
cout<<"-> "<<Ws-1;
cout<<endl;
}
RESULTS : ( OUT PUT )
LIMITATIONS
• Even the transmitted frames should be sent again if there is
failure in successful transmission of the previously sent
frames.
• The receiver can’t accept any frames which is out of order.

• The size of the receiver window is 1 so the efficiency is

not that great.

CONCLUSION

We can conclude by saying that GO BACK N ARQ overcomes


the short coming of stop n wait ARQ and also increases the
efficiency of transmission by utilizing the bandwidth to the
maximum possible.
Implementation of go back is comparatively simpler that is it’s
algorithm is easy to understand and efficient.
The only disadvantage being the necessity to send even the
transmitted frame again due to the failure in the successful
transmission of the previously sent frame. This is over come by
a more efficient ARQ (selective repeat ARQ) which is more
complex.

You might also like