Flow Control and Error
Control
            Divya Rani R,
            Lecturer,
            Dept. of MCA & CS
            Kuvempu University
              Data Link Layer
➢ Data link layer packs bits into frames
➢ Main functions:
  ➢ Data link control – deals with the design &
  procedures for communication b/w two adjacent
  nodes (flow control and error control)
  ➢ Media access control – how to share a link
          FLOW CONTROL AND ERROR CONTROL
➢ Flow control – Coordinates the amount of data that can
be sent before receiving an acknowledgement
➢ Error control – Allows the receiver to inform the sender
if any frames lost or damaged in transmission &
coordinates the retransmission of those frames by the
sender
➢ Protocols are used
Figure : Taxonomy of protocols
                  FLOW CONTROL
➢ Coordinates the amount of data that can be sent before
receiving acknowledgement
➢ It is a set of procedures that tells the sender how much
data it can transmit before it must wait for an
acknowledgement from the receiver
➢ Receiver has a limited speed at which it can process
incoming data and a limited amount of memory in which
to store incoming data
                   FLOW CONTROL
➢ Receiver must inform the sender before the limits are
reached and request that the transmitter to send fewer
frames or stop temporarily
➢ Since the rate of processing is often slower than the
rate of transmission, receiver has a block of memory
(buffer) for storing incoming data until they are processed
                   ERROR CONTROL
➢ Includes both error detection and error correction
➢ It allows the receiver to inform the sender if a frame is lost
or damaged during transmission and coordinates the
retransmission of those frames by the sender
➢ Error control refers to methods of error detection &
retransmission
➢ Error control in the data link layer is based on automatic
repeat request (ARQ)
➢ Whenever an error is detected, specified frames are
retransmitted
      Flow and Error Control Mechanisms
➢ Stop-and-Wait ARQ
➢ Go-Back-N ARQ
➢ Selective-Repeat ARQ
                 STOP-AND-WAIT ARQ
➢ The protocol is called Stop-and-Wait protocol because the
sender sends one frame, stops until it receives confirmation
from the receiver and then sends the next frame
➢Sender keeps a copy of the last frame transmitted until it
receives an acknowledgement for that frame
➢ For identification purpose, both data frames and
acknowledgements (ACK) frames are numbered alternatively
0&1
➢ Sender has a control variable (S) that holds the number of
the recently sent frame (0 or 1)
➢ Receiver has a control variable (R) that holds the number
of the next frame expected (0 or 1)
             STOP-AND-WAIT ARQ (cont..)
➢ Sender starts a timer when it sends a frame. If an ACK
is not received within a allocated time period, the sender
assumes that the frame was lost or damaged and resends it
➢ The receiver sends only positive ACK for frames
received safe and keeps silence about damaged or lost
frames
➢ ACK number always defines the number of the next
expected frame
             STOP-AND-WAIT ARQ Cases
➢While transmitting a frame, possible situations are:
   ➢Normal operation
   ➢The frame is lost
   ➢The acknowledgment is lost
   ➢The acknowledgment is delayed
STOP-AND-WAIT ARQ (Normal Operation)
STOP-AND-WAIT ARQ (Lost or Damaged Frame)
STOP-AND-WAIT ARQ (Lost Acknowledgement)
STOP-AND-WAIT ARQ (Delayed Acknowledgement)
                    Piggybacking
➢ A method to combine
a data frame with ACK
➢ Station A and B both
have data to send
➢ Instead of sending
separately, station A
sends a data frame that
includes an ACK
➢ Station B does the
same thing
➢ Piggybacking   saves
bandwidth
               DISADVANTAGES
➢ Any point in time, there is only one frame is sent and
waiting to be acknowledged
➢ This is not a good use of transmission medium
➢ To improve efficiency, multiple frames should be in
transition while waiting for ACK
➢ Two protocol use the above concept
   ➢ Go-Back-N ARQ
   ➢ Selective Repeat ARQ
                GO-BACK-N ARQ
➢ Based on sliding window protocol
➢ Possible to send ‘n’ frames before worrying about ACKs
➢ Copy of these frames are kept until the ACKs arrive
➢ Sender sets a time for each frame sent, receiver has no
timers
              SEQUENCE NUMBERS
➢ Frames from a sender are numbered sequentially
➢ Need to use limited sequence numbers bcz these numbers
are included in each frame in the header
➢ If the header of the frame allows ‘m’ bits for sequence
number, the sequence numbers range from 0 to 2m – 1
➢ For ex: m = 3, sequence numbers are: 0, 1, 2, 3, 4, 5, 6, 7
➢ Sequence numbers can be repeated
      0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, …
              Sender Sliding Window
➢ At the sending site, to hold the outstanding frames until
they are acknowledged, we use the concept of a window
➢ All frames are stored in a buffer
➢ Outstanding frames are enclosed in a window
➢ The size of the window is at most 2m -1 where m is the
number of bits for the sequence number
➢ Size of the window can be variable, ex: TCP
➢ The window slides to include new unsent frames when
the correct ACKs are received – Sliding Window
         Sender Sliding Window (cont..)
The window slides two frames over because an ACK is
received for frames 0 and 1
Figure : Send window for Go-Back-N ARQ
              Receiver Sliding Window
➢ Size of the window at the receiving site is always 1 in this
protocol
➢ Receiver is always looking for a specific frame to arrive
in a specific order
➢ Any frame arriving out of order is discarded and needs to
be resent
➢ Receiver window slides one frame after receiving the
expected frame, and it is waiting for next frame
       Receiver Sliding Window (cont..)
Received frame 0, now expecting frame 1
Figure : Receive window for Go-Back-N ARQ
                 Control Variables
➢ Sender has 3 variables: S, SF , and SL
➢ ‘S’ holds the sequence number of recently sent frame
➢ ‘SF’ holds the sequence number of the first frame
➢ ‘SL’ holds the sequence number of the last frame
➢ Size of the window, W = SL – SF + 1
➢ Receiver only has only one variable R
➢ ‘R’ holds the sequence number of the frame it expects to
receive
➢ If the sequence number is same as the value of R, the
frame is accepted, otherwise rejected
Control Variables (cont..)
                Acknowledgement
➢ Receiver sends positive ACK if a frame arrived safe
and in order
➢ If the frames are damaged/out of order, receiver is
silent and discard all subsequent frames until it receives
the one it is expecting
➢ The silence of the receiver causes the timer of the
unacknowledged frame to expire
➢ Then the sender resends all frames, beginning with the
one with the expired timer
      GO-BACK-N ARQ (Normal Operation)
➢ Sender keeps track of the outstanding frames and
updates the variables and windows as the ACKs arrive
GO-BACK-N ARQ (Damaged or Lost Frame)
                 GO-BACK-N ARQ
     (Damaged or Lost or Delayed Acknowledgement)
➢ If an ACK is damaged/lost, we can have two situations:
   ➢ If the next ACK arrives before the expiration of any
   timer, there is no need for retransmission of frames
   because ACKs are cumulative in this protocol
   ➢ If ACK1, ACK2, and ACK3 are lost, ACK4 covers
   them if it arrives before the timer expires
➢ If ACK4 arrives after time-out, the last frame and all the
frames after that are resent
➢ Receiver never resends an ACK
➢ A delayed ACK also triggers the resending of frames
         GO-BACK-N ARQ (Sender Window Size)
➢ Size of the sender window must be less than 2m. Size of the
receiver is always 1. If m = 2, window size = 2m – 1 = 3.
      Bidirectional Transmission & Piggybacking
➢ It can also be bidirectional
➢ By piggybacking we can improve the efficiency of the
transmission
➢ Each direction needs both a sender window & a
receiver window
        Advantages & Disadvantages
➢ Go-Back-N ARQ simplifies the process at the receiver site
➢ Receiver only keeps track of only one variable, and there
is no need to buffer out-of-order frames, they are simply
discarded
➢ However, Go-Back-N ARQ protocol is inefficient for
noisy link
➢ Inefficient   bandwidth   usage   &   slows   down    the
transmission
                  Selective Repeat ARQ
➢ In Selective Repeat ARQ, only the damaged frame is resent
➢ Subsequent frames are accepted by the receiver and buffered
➢ Minimizes the amount of retransmissions
➢ More bandwidth efficient but more complex processing at
receiver
➢ Receiver must maintain large enough buffer, and must
contain logic for reinserting the retransmitted frame in the
proper sequence
➢ It defines a negative ACK (NAK) to report the sequence
number of a damaged frame before the timer expires
➢ Size of the sender and receiver windows must be at most
one-half of 2m
Selective Repeat ARQ (cont..)
Figure : Flow diagram
                   HDLC
➢ High-level Data Link Control (HDLC) is a bit-
oriented protocol for communication over point-to-
point and multipoint links
➢ Designed to support both half-duplex & full-duplex
communication
➢ It implements the ARQ mechanisms
➢ HDLC provides two common              modes     of
transmission: NRM and ABM
            HDLC Station Types
➢ Primary station
   ➢ Controls operation of link
   ➢ Issues commands (frames)
   ➢ Maintains separate logical link to each secondary
   station
➢ Secondary station
   ➢ Under control of primary station
   ➢ Issues responses (frames)
➢ Combined station
   ➢ May issue commands and responses
   ➢ Combines the features of primary and secondary
   stations
       HDLC Link Configurations
➢ Unbalanced
  ➢ One primary and one or more secondary stations
  ➢ Supports full duplex and half duplex
➢ Balanced
  ➢ Two combined stations
  ➢ Supports full duplex and half duplex
            Normal Response Mode (NRM)
➢ Station configuration is unbalanced - One primary & multiple
secondary stations
➢ Primary station can send commands, a secondary station can only
respond
➢ Used for both point-to-point and multi point
          Asynchronous Balanced Mode (ABM)
➢ Station configuration is balanced
➢ Link is point-to-point, and each station can function
as a primary & a secondary (combined)
Figure : HDLC Frame Format
              HDLC FRAME FORMAT
➢ Flag field - is an 8-bit sequence with the bit pattern
01111110 that identifies both the beginning & the end of a
frame & serves as a synchronization pattern for the receiver
➢ Address field - contains the address of the secondary
station
   ➢ If a primary station created the frame, it contains a to
   address
   ➢ If a secondary creates the frame, it contains a from
   address
➢ An address field can be 1 byte or several bytes long
➢ One byte can identify up to 128 stations (l bit is used for
another purpose)
               HDLC FRAME FORMAT
➢ Control field - is a 1- or 2-byte segment of the frame used
for flow & error control
➢ Interpretation of bits in this field depends on the frame
type
➢ Information field - contains the user's data from the
network layer or management information. Its length can
vary from one network to another.
➢ FCS (Frame Check Sequence) field - is the HDLC error
detection field. It can contain either a 2- or 4-byte ITU-T
CRC.
                     FRAMES
➢ Three types of frames: Information frames (I-frames),
Supervisory frames (S-frames), & Unnumbered frames
(U-frames)
➢ Each type serves as an envelope for the transmission of a
different type of message
➢ I-frames - used to transport user data and control
information relating to user data (piggybacking)
➢ S-frames - used only to transport control information
➢ U-frames - reserved for system management
Figure : HDLC Frames
                   I - FRAME
➢ Designed to carry user data from the network layer
➢ Include flow & error control information (piggybacking)
               I – FRAME (cont..)
➢ First bit of control field is 0 (indication for I-frame)
➢ Next 3 bits, N(S) – sequence number of the frame in
travel. This value corresponds to the value of S in ARQ
protocols.
➢ P/F (Poll or final)
   ➢ Poll – frame is sent by primary station to secondary
   ➢ Final – frame is sent by a secondary to a primary
➢ Next 3 bits, N(R) – value of the ACK when piggybacking is
used
                  S - FRAMES
➢ Used for flow & error control whenever piggybacking is
either impossible or inappropriate
                 S – FRAMES (cont..)
➢ First 2 bits of control field are 10 (indication for S-frame)
➢ Second 2 bits defines the 4 types of S-frames:
   ➢ Receive Ready (RR) – code has value 00. This frame
   acknowledges a safe & sound frame.
   ➢ Receive not Ready (RNR) – value 10. It acknowledges the
   receipt of a frame & announces that receiver is busy & cannot
   receive more frames (Congestion control).
   ➢ Reject (REJ) – value 01. This is a NAK frame (not like
   Selective Repeat ARQ). Informs the sender before time expires,
   as frame has lost or damaged.
   ➢ Selective reject (SREJ) – value 11. NAK frame used in
   Selective Repeat ARQ.
➢ Fifth bit is P/F (Poll or Final)
➢ Next 3 bits – N(R), corresponds to the ACK or NAK value
                    U - FRAMES
➢ Used to exchange session management & control
information b/w connected devices
➢ Two sections: 2-bit prefix before P/F & 3-bit suffix after P/F
➢ Together 5 bits can be used to create up to 32 different types
of U-frames
Table : U-frame control command and response
Figure : Example of piggybacking without error
Figure : Example of piggybacking with error
                POINT-TO-POINT PROTOCOL
➢Although HDLC is a general protocol that can be used
for both point-to-point and multipoint configurations, one
of the most common protocols for point-to-point access is
the Point-to-Point Protocol (PPP)
➢ PPP is a byte-oriented protocol
                    PPP Frame
1. Flag Filed
2. Address Field
3. Control Field (same as U-frame in HDLC)
4. Protocol Filed
5. Data / Payload Field
6. Frame Check Sequence (FCS) Field
Figure: PPP frame format