Unit-2 new
Unit-2 new
UNIT-II
Data link layer:
Data-Link Layer has responsibility of transferring frames
from one node to adjacent node over a link
DATA LINK LAYER DESIGN ISSUES:
Data link layer has a number of specific functions to carry
out. These functions include
Provides a well-defined service interface to the network layer.
Determines how the bits of the physical layer are grouped into
frames (framing).
Deals with transmission errors (CRC and ARQ).
Systems which automatically request the
retransmission of missing packets or packets with
errors are called Automatic Repeat reQuest (ARQ)
Regulates the flow of frames.
Data link layer-Introduction
The data link layer takes the packets it gets from the network layer
and encapsulates them into frames for transmission .
Each frame contains frame header ,a payload field for holding the
packet ,and a frame trailer
1 2 3 4 5
1) character count
Bit stuffing
(a) The original data.
(b) The data as they appear on the line.
(c) The data as they are stored in receiver’s memory
after destuffing.
Error Control:
The protocol calls for the receiver to send back special control
frames bearing positive and negative acknowledgements about
the incoming frames
Error Control:
For e.g.
On a reliable medium : Error Detection is sufficient where
the error rate is low and asking for retransmission after
Error Detection would work efficiently
In contrast, on an unreliable medium : Retransmission after
Error Detection may result in another error and still
another and so on. Hence Error Correction is desirable.
Error correcting codes:
A frame consists of m data (i.e,message ) bits and r
redundant, or check bits.
Let the total length be n (i.e., n=m+r).an n-bit unit containing
data and check bits is often referred to as an n-bit codeword.
Given any two code words ,say,10001001 and 10110001,it is
possible to define how many bits differ .In this case 3 bits
differ. To determine how many bits differ ,just EXCLUSIVE
OR the two code words ,and count the number of 1 bits in the
result. The number of bit positions in which two code words
differ is called the Hamming distance.
Its significance is that if two code words are a hamming
distance d a apart, it will require d single-bit errors to convert
one into another.
Error correcting codes:
Forward Error Correction: FEC is the only error correction
scheme that actually detects and corrects transmission errors
at the receive end with out calling for retransmission.
Ex: Hamming code
No of bits in hamming code is dependent on the no. of bits in
the data character by using the relation.
2n>=m+n+1
Where n=no. of hamming bits
m= no. of bits in the data character
Ex: For a 12-bit data stream of 101100010010,determine
the hamming bits ,assume a single bit in error & prove how
hamming code detects it.
Error correcting codes:
No. of bits in hamming code
2n>=m+n+1
Take n=4
24=16>=12+4+1
16>=17
Take n=5
25=32>=12+5+1=18
32>=18 ---- 5 bits are required for hamming code.
12 bits of data +5 bits of code=17 bits of data stream.
Error correcting codes:
Hamming Code
Hamming Code:
consider the example m= 1101110
2n >=m+n+1
n=4 i.e 24>=7+4+1
16>=12
4 hamming bits needed.
11 10 9 8 7 6 5 4 3 2 1
1 1 0 r 1 1 1 r 0 r r
11 10 9 8 7 6 5 4 3 2 1
1 1 0 r 1 1 1 r 0 r r
Express all bit positions that contains a 1 as four bit number and xor them together.
Bit position binary number
5 0101
6 0110
Xor 0011
7 0111
xor 0100
10 1010
xor 1110
11 1011
0101
Error correcting codes:
11 10 9 8 7 6 5 4 3 2 1
1 1 0 r 1 1 1 r 0 r r
1 1 0 0 1 1 1 1 0 0 1
Error correcting codes:
11 10 9 8 7 6 5 4 3 2 1
1 1 0 0 1 1 1 1 0 0 1
Beginning with the most significant bit in the original message and for
each bit position that follows, look at the c+1 bit remainder:
If the most significant bit of the remainder is a one, the divisor is said to
divide into it. If that happens (just as in any other long division) it is
necessary to indicate a successful division in the appropriate bit position
in the quotient and to compute the new remainder. In the case of
modulo-2 binary division, we simply:
Set the appropriate bit in the quotient to a one, and
XOR the remainder with the divisor and store the result back into
the remainder
Otherwise (if the first bit is not a one):
The final value of the remainder is the CRC of the given message.
What's most important to notice at this point
is that we never use any of the information in
the quotient, either during or after computing
the CRC. So we won't actually need to track
the quotient in our software implementation.
Also note here that the result of each XOR
with the generator polynomial is a remainder
that has zero in its most significant bit. So we
never lose any information when the next
message bit is shifted into the remainder
Frame header of Data link layer
packet
frame
Continued
Some definitions needed in the protocols to follow.
These are located in the file protocol.h.
Protocol
Definitions
(ctd.)
Some definitions
needed in the
protocols to follow.
These are located in
the file protocol.h.
unrestricted simplex protocol
Data are transmitted in one direction only.
Both the transmitting and receiving network layers are always
ready
processing time can be ignored
Infinite buffer space is available
The protocol consists of two distinct procedures, a sender and
a receiver. The sender runs in the data link layer of the source
machine and the receiver runs in the data link layer of the
destination machine.
MAX-SEQ is not used because No sequence numbers and
Acknowledgements are used here.
The only event type possible is frame-arrival (i.e. an arrival of
undamaged frame)
A simplex stop-and-wait protocol:
If data frames arrives at the receiver side faster than
they can be processed, the frames must be stored until
their use
Normally ,the receiver does not have enough storage
space ,especially if it is receiving data from many
sources
This may result in the discarding frames
To prevent this there must be feedback from the
receiver to the sender.
A simplex stop-and-wait protocol:
Def : Protocol in which the sender sends one frame
and then waits for acknowledgement before
proceeding is called stop-and-wait.
Flow Diagram:
A B
Request
Frame
Arrival
Ack
Arrival
Frame
Request Ack
Arrival
A simplex stop-and-wait protocol:
Receiver 2 is that after delivering a packet to the network
layer, receiver 2 sends an acknowledgement frame back to the
sender before entering the wait loop again. because the only
arrival of the frame back at the sender is important. the
receiver need not put any particular information on it.
points:
1) sender start out fetching a packet from the network
layer, using it to construct a frame and sending it on its
way.
2)sender must wait until an acknowledgement frame
arrives before looping back and fetching the next packet
from the network layer
Ambiguities with Stop-and-Wait
[unnumbered frames]
(a) Frame 1 lost Time-out
time
A frame frame frame frame
0 1 1 2
ACK ACK
B
In parts (a) and (b) transmitting station A acts the same way,
but part (b) receiving station B accepts frame 1 twice.
A simplex protocol for a Noisy Channel
The channel is noisy, frames may be damaged or lost
Good scene : data frame reaches intact, ack sent back and
received, next frame sent
Bad scene :
Data frame damaged or lost ..hence no ack – sender times
out and resends .. No problems
Data frame reaches intact but Ack lost .. Times
out ..resends.. Receiver receives duplicate frames. Problem
Solution :Keep a sequence number for each frame to
distinguish between the new frame and a duplicate frame
A simplex protocol for a Noisy Channel
What should be minimum number of bits required for the
sequence number?
The only ambiguity in this protocol is between a frame,m.and
its direct successor,m+1.If a frame m is lost or damaged ,the
receiver will not acknowledge it ,so the sender will keep
trying to send it. Once it has been correctly received ,the
receiver will send an ack back to the sender. Depending upon
whether the acknowledgement frame gets back to the sender
correctly or not ,the sender may try to send m or m+1.the
event triggers the sender to start sending m+2 is the arrival
of an acknowledgement m+1.
Protocols in which the sender waits for a positive
acknowledgement before advancing to the next data item are
often called (PAR-Positive acknowledgement retransmission
or ARQ- Automatic Repeat Request)
A simplex protocol for a Noisy Channel
A positive
acknowledg
ement with
retransmissi
on protocol.
A simplex protocol for a Noisy Channel
source Destination
Ack(frame1)+Frame2
• When a data frame arrives, instead of immediately sending a separate
control frame, the receiver restrains itself and waits until the network
layer passes it the next packet.
• The acknowledgement is attached to the outgoing data frame
• Disadv: This technique is temporarily delaying outgoing
acknowledgements.
• If the datalinklayer waits longer than the senders timeout period, the
frame will be retransmitted.
Sliding window protocols:
Rule: sender waiting a fixed number of milliseconds. If a
new packet arrives quickly the acknowledgement is
piggybacked onto it. other wise if no new packet has arrived
by the end of this time period ,the data link layer just sends a
separate acknowledgement frame.
In sliding window protocol each frame contains a sequence
number ranging from 0 up to some maximum.
The maximum is usually 2n-1 so the sequence number fits
nicely in an n-bit field.
The stop-and-wait sliding window protocol uses n=1
restricting the sequence numbers 0 and 1.
The sender must keep all these frames in its memory for
possible retransmission
Sliding window protocols:
Thus if the maximum window size is n, the sender needs n
buffers to hold the unacknowledged frames
3 bit field -000
001
010..etc
here n=3 i.e. 23-1=7
window size is 0 to 7
Sliding window :: sender has a window of frames and maintains a
list of consecutive sequence numbers for frames that it is
permitted to send without waiting for ACKs.
receiver has a window that is a list of frame sequence numbers it is
permitted to accept.
Note – sending and receiving windows do NOT have to be the same
size.
Sliding window protocols: