By B.A.Khivsara Asst Prof. Computer Dept SNJB’s KBJ COE,Chandwad Sliding window protocols are used where Reliable In- order delivery of packets is required, & such as in the (OSI model) in the Transmission Control Protocol(TCP).

The sliding window technique places varying limits on the number of data packets that are sent before waiting for an acknowledgment signal back from the receiving computer. The number of data packets is called the window size. protocols are divided into 2 types

noiseless (error-free) channels

noisy (error- creating) channels Figure Taxonomy of protocols

11.4 Let us first assume we have an ideal channel in which no frames are lost, duplicated, or corrupted.

We introduce two protocols for this type of channel. The first is a protocol that does not use ; the second is the one use flow control. If data frames arrive at the receiver site faster than they can be processed, the frames must be stored until their use.

To prevent the receiver from becoming overwhelmed with frames, we need to tell the sender to slow down.

In this protocol the sender sends one frame, stops until it receives confirmation from the receiver and then sends the next frame. Figure Flow diagram for stop and wait Protocol

11.7 NOISY CHANNELS ()

Although the Stop-and-Wait Protocol gives us an idea of how to add flow control to its predecessor, noiseless channels are nonexistent. We discuss three protocols in this section that use error control.

Topics discussed in this section: Stop-and-Wait Go-Back-N Automatic Repeat Request Selective Repeat Automatic Repeat Request

11.8 Note

Error correction in Stop-and-Wait ARQ is done by keeping a copy of the sent frame and retransmitting of the frame when the timer expires.

11.9 Noiseless channels are nonexistent, so we need to add error control to our protocols.

Stop-and-Wait Automatic Repeat Request protocol add a simple error control mechanism to the Stop-and-Wait Protocol.

To detect and correct corrupted frames, we need to add redundancy bits to our data frame.

When the frame arrives at the receiver site, it is checked and if it is corrupted, it is silently discarded. Lost frames are more difficult to handle than corrupted ones.

The received frame could be the correct one, or a duplicate, or a frame out of order.

The solution is to number the frames.

When the receiver receives a data frame that is out of order, this means that frames were either lost or duplicated. The completed and lost frames need to be resent in this protocol.

The sender keeps a copy of the sent frame. At the same time, it starts a timer.

If the timer expires and there is no ACK for the sent frame, the frame is resent, the copy is held, and the timer is restarted. Since an ACK frame can also be corrupted and lost, it too needs redundancy bits and a sequence number.

The ACK frame for this protocol has a sequence number field. Design of the Stop-and-Wait ARQ Protocol

11.14 Figure Flow diagram for Stop and Wait ARQ

11.15 Go-Back-N ARQ is a specific instance of the automatic repeat request (ARQ) protocol, in which the sending process continues to send a number of frames specified by a window size even without receiving an acknowledgement (ACK) packet from the receiver.

The receiver process keeps track of the sequence number of the next frame it expects to receive, and sends that number with every ACK it sends. The receiver will discard any frame that does not have the exact sequence number it expects and will resend an ACK for the last correct in-order frame.

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 the sequence number of the last ACK it received from the receiver process and fill its window starting with that frame and continue the process over again. Figure 11.14 Design of Go-Back-N ARQ Figure 11.16 Flow diagram for Example 11.6 Concept of Selective Repeat

 Selective Repeat is part of the automatic repeat-request (ARQ).

 With selective repeat, the sender sends a number of frames specified by a window size even without the need to wait for individual ACK from the receiver as in go- back-n ARQ.

 The receiver may selectively reject a single frame, which may be retransmitted alone;

 this contrasts with other forms of ARQ, which must send every frame from that point again.

 The receiver accepts out-of-order frames and buffers them.

 The sender individually retransmits frames that have timed out. Comparison of Go-back-n (fig. a) & Selective Repeat (Fig. b)

Data Communication Use GBN or SR?

 If errors low, might use GBN.

 If errors high, might use SR.

 If bandwidth cheap, might use GBN.

 If bandwidth costly, might use SR. Program in Java for Sliding Window Protocol Sender side & Receiver Side Sender side import java.net.*; import java.io.*; import java.rmi.*; public class slidsender { public static void main(String a[])throws Exception { ServerSocket ser=new ServerSocket(10); Socket s=ser.accept(); DataInputStream in=new DataInputStream(System.in); DataInputStream in1=new DataInputStream(s.getInputStream()); String sbuff[]=new String[8]; PrintStream p; int sptr=0,sws=8,nf,ano,i; String ch; Do { p=new PrintStream(s.getOutputStream()); System.out.print("Enter the no. of frames : "); nf=Integer.parseInt(in.readLine()); p.println(nf); if(nf<=sws-1) { System.out.println("Enter "+nf+" Messages to be send\n"); for(i=1;i<=nf;i++) { sbuff[sptr]=in.readLine(); p.println(sbuff[sptr]); sptr=++sptr%8; } sws-=nf; System.out.print("Acknowledgment received"); ano=Integer.parseInt(in1.readLine()); System.out.println(" for "+ano+" frames"); sws+=nf; } Else { System.out.println("The no. of frames exceeds window size"); break; } System.out.print("\nDo you wants to send some more frames : "); ch=in.readLine(); p.println(ch); } while(ch.equals("yes")); s.close(); } } Receiver import java.net.*; import java.io.*; class slidreceiver { public static void main(String a[])throws Exception { Socket s=new Socket(InetAddress.getLocalHost(),10); DataInputStream in=new DataInputStream(s.getInputStream()); PrintStream p=new PrintStream(s.getOutputStream()); int i=0,rptr=-1,nf,rws=8; String rbuf[]=new String[8]; String ch; System.out.println(); do { nf=Integer.parseInt(in.readLine()); if(nf<=rws-1) { for(i=1;i<=nf;i++) { rptr=++rptr%8; rbuf[rptr]=in.readLine(); System.out.println("The received Frame " +rptr+" is : "+rbuf[rptr]); } rws-=nf; System.out.println("\nAcknowledgment sent\n"); p.println(rptr+1); rws+=nf; } else break; ch=in.readLine(); } while(ch.equals("yes")); } } How to Run Program

 Sender on one Machine

 Receiver on another machine

 Run sender first

 Then run receiver OUTPUT: //SENDER OUTPUT Enter the no. of frames : 4 Enter 4 Messages to be send hiii how r u i am fine how is evryone Acknowledgment received for 4 frames Do you wants to send some more frames : no

//RECEIVER OUTPUT The received Frame 0 is : hiii The received Frame 1 is : how r u The received Frame 2 is : i am fine The received Frame 3 is : how is evryone Acknowledgment sent