selective repeat source code in c
#3

(04-12-2012, 05:52 PM)Guest Wrote: Below is the code for Go Back N ARQ. I need to implement the same code using selective repeat with different timer(real time) for each frame and a case where negative acknowledgement is sent by reciever.Please go through the code and post appropriate addition for Selective repeat ARQ
Code:
#include<iostream.h>

#include<conio.h>

#include<math.h>

class sender

{
      public :
int size,sf,sn,t,a[500],q[500],w,ff,sent  ;
sender(){}//default constructor
sender(int x,int aa)//parameterised constructor
{
ff=aa;//ff and aa = total no of frames
size=pow(2,x)-1;//size of sliding window
sn=0;//next frame to sent
sf=0;//first outstanding frame
w=0;//count of frames
if(aa<=5)
t=2;//timer (decremented by 1 after a frame is sent)
else
t=5;//timer (decremented by 1 after a frame is sent)
sent=0;
for(int i=0;i<aa;i=i+size+1)//to assign sequence no to frames
{
for(int j=0;j<=size;j++)
{
if(i+j < aa)
a[i+j]=j;
}
}
}
void reqstsend()//to send frames
{
if(w<ff)//check whether the no. of frame sent is less than total no of frames
{
if(t<=0 )//check for time out
{
cout<<endl<<"Caution : Timer out"<<endl;
timeout();
}
else if((sn-sf)>=size || sf==sn+1 )
{
cout<<endl<<"Caution : Window is full"<<endl;
t--;

}
  
/*else if(sn == size)//special case when sn==size sn should be =0
{
cout<<endl<<"frame F"<<sn<<" sent..."<<endl;
sn=0;
t--;
w++;
sent++;
show();
cout<<endl<<"frames sent :- ";
for(int i=0;i<w;i++)
{
        cout<<" "<<a[i]<<" ";
}
}*/
else//normal sending
{
cout<<endl<<"Frame F"<<sn<<" sent..."<<endl;
sn++;
t--;
w++;
sent++;
show();
cout<<endl<<"Frames sent :- ";
for(int i=0;i<w;i++)
{      
cout<<" "<<a[i]<<" ";
}
}
}
else
cout<<endl<<" ***All Frames Sent***"<<endl;
}
void arivack(int y)//recieving acknowledgement
{
sf=y;
t=sn-sf;
}
void timeout()
{
sn=sf;
if(ff<5)
{
  t=2;
w=w-2;
sent=sent-2;
}
Else
{    
t=5;
w=w-5;
sent=sent-5;
}
}
void sdisplay()//displaying frames initially
{
cout<<endl<<"Frames :- ";
for(int i=0;i<ff;i++)
cout<<" "<<a[i]<<" ";
cout<<endl<<endl<<"sn = "<<sn<<endl<<"sf = "<<sf<<endl;
}
void show()
{
     cout<<endl<<"No of frames sent ="<<sent<<endl;
}
};//class sender ends

class reciever : public sender
{
public :
int rn,b[500],c,reci;
sender *s;//sender class pointer
reciever(sender *y,int q)//contructor to initialise variables and element of array
{
reci =0;
rn=size;//next expected frame
c=0;//counter
for(int i=0;i<q;i++)
b[i]=0;
s=y;
}
void arivnot(int x)
{
if(rn == x)//recieve in order
{
if(rn != s->size)//recieving frames
{
b[c]=rn;
c++;
rn++;
}
else//special case when rn =size, then rn should be =0
{
b[c]=rn;
c++;
rn=0;
}
}
}
void sendack(int z)
{
cout<<endl<<"Acknowledgement A"<<z<<" sent"<<endl;
s->arivack(z);
}

void sendlostack(int z)
{
cout<<endl<<"Acknowledgement A"<<z<<" sent"<<endl;
}

void rdisplay()
{    
cout<<endl<<"No of frames recieved ="<<c<<endl;
cout<<endl<<"Frames recieved :- ";
for(int i=0;i<c;i++)
cout<<" "<<b[i]<<" ";
cout<<endl<<endl<<"rn = "<<rn<<endl<<endl;
}
};//class reciever ends  

int main()
{
int m,x=3,h,y,counter=0;
cout<<endl<<"Enter the value of sequence no. (m no of bits) => ";
cin>>m;
cout<<"Sliding window size ="<<pow(2,m-1)<<endl;
cout<<"Recieving window size ="<<pow(2,m-1)<<endl;
cout<<"Enter the total no of frames you want to send "<<endl;
cin>> h;
sender pqr(m,h),*g=&pqr;
reciever rec(g,h),*r=&rec;
while(1)
{
                 if(counter==0)
{
                      cout<<endl<<"Press 1 for going to sender side"<<endl
                      <<"Press 0 to exit"<<endl <<"enter code => ";
                     cin>>x;
if(x==2)
x=8;
counter++;
if(x!=1)
counter--;
}
else
{
             cout<<endl<<"Press 1 for going to sender side"<<endl <<"Press 2 for going to receiver             side"<<endl <<"Press 0 to exit"<<endl  <<"enter code => ";
cin>>x;
}
switch(x)
{
case 1 : while(y != 3)
{

            pqr.sdisplay();
            cout<<endl<<"Press 1 to send frame"<<endl <<"Press 2 to send frame (lost or incorrect)"<<endl
             <<"Press 3 to go back"<<endl<<" => ";
             cin>>y;
switch(y)

             {

             case 1 :
        
                  pqr.reqstsend();

                  if(pqr.sn == 0)

                  r->arivnot(pqr.size);

                  else

                  r->arivnot(pqr.sn-1);
    
                  break;

             case 2 : pqr.reqstsend();

                  break;

             case 3 :
                  
                   break;

             default :
                    
                   cout<<endl<<"Caution !!! error in code !!!  please enter right choice "<<endl;

                   break;

             }

             }

             y=0;

             break;

case 2 : while(y != 3)

             {

             r->rdisplay();

             cout<<endl<<"Press 1 to send Acknowledgement"<<endl

                        <<"Press 2 to send ack (lost)"<<endl
                        
                         <<"Press 3 to go back"<<endl

                         <<" => ";

             cin>>y;

             switch(y)

             {

             case 1 :
                  
                         r->sendack(rec.rn);  // cout<<endl<<"no of frames sent ="<<pqr.sent<<endl;

                         break;
              
             case 2:
                  
                         r->sendlostack(rec.rn);
                  
                   break;

             case 3:
                  
                   break;

             default :
                     cout<<endl<<"Caution !!! error in code !!!"<<endl;

                         break;

             }

             };

             y=0;

             break;

case 0 :
    
     exit(0);
    
      break;

default :
        
        cout<<endl<<"Caution !!! error in code !!!"<<endl;

                break;

}

}

getch();

return 0;

}

Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Tagged Pages: selective repeat protocol in c, selective repeat arq implementation in c, selective protocol c program, selective repeat program in java, selective repeat arq c code, programs of selective repeat protocol, selective repeat protocal in c,
Popular Searches: mousetrap pow, selective repeat c, selective repeat in python, vcu repeat course, selective repeat arq opengl source code description, selective image source code in java, selective repeat algorithm implementation in c,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Messages In This Thread
selective repeat source code in c - by Guest - 04-12-2012, 05:52 PM
RE: selective repeat source code in c - by Guest - 15-10-2014, 05:33 PM
RE: selective repeat source code in c - by Guest - 11-05-2015, 01:26 PM
RE: selective repeat source code in c - by Guest - 21-10-2016, 06:51 PM
RE: selective repeat source code in c - by ijasti - 22-10-2016, 09:10 AM

Possibly Related Threads...
Thread Author Replies Views Last Post
  free download source code of online college magazine 5 18,607 29-06-2018, 10:09 AM
Last Post: Guest
  opengl source code for butterfly 3 3,328 14-05-2018, 08:57 AM
Last Post: Akshatha k
  ice cream parlour management system in vb source code 4 5,352 04-04-2018, 11:58 PM
Last Post: vprk77
  source code in php for online training and placement cell management 1 6,733 23-03-2018, 09:06 AM
Last Post: ritzi
  free download college website project in html with source code 2 4,695 24-02-2018, 10:46 AM
Last Post: Guest
  source code for hospital management system in jsp 4 1,986 13-01-2018, 10:51 AM
Last Post: dhanabhagya
  source code in c for dna cryptography in computer sc ppt 1 1,568 09-01-2018, 09:59 PM
Last Post: harshavarshinib
  java programmings for bus ticket reservation source code 1 6,255 09-11-2017, 11:28 PM
Last Post: Ayushi Nagar
  location alarm android tutorial and source code 1 1,499 14-10-2017, 02:53 PM
Last Post: shakil19944
  source code in matlab for fuzzy based traffic light controll system 2 1,465 08-10-2017, 02:12 PM
Last Post: nomanamjad143

Forum Jump: