Data Link Layer-Unit II
Data Link Layer-Unit II
Introduction
The data link layer specifies the algorithms for achieving reliable,
efficient communication between two adjacent machines at the
data link layer.
By adjacent, we mean the two machines are physically connected
by a communication channel that acts conceptually like a wire
(e.g., A coaxial cable or a phone line).
Data link layer design issues
Router
2 3 2 2 3 2
Data link
Frames Frames
Packets protocol Packets
here here here here
Character count
5123456789801234567789123
Framing
A character stream. (a) Without errors. (b)With one error.
Framing
The trouble with this algorithm is that the count can be altered by
a transmission error. For example if the character count of 7 in
the last frame is changed to 5, the destination will make error in
finding the data from the frame.
Sending a frame back to the source asking for a retransmission
does not help either, since the destination does not know how
many characters to skip over to get to the start of the
retransmission . for this reason the character count method is
rarely used anymore.
Framing
Method 2: Starting and ending flags with byte/character stuffing
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.
Framing
Method 4: physical layer coding violations.
e.g., The IEEE 802 standard LAN uses the following (Manchester)
encoding scheme: a 1 bit is encoded as HL, and a 0 bit as LH.
Character count can be combined with others for extra safety.
Physical Layer Coding Violation.
0 1 0 1 1 0
Menchester Encoding
Error control
The goal (of a reliable connection-oriented service)is to ensure
each frame is ultimately passed to the network layer at the
destination exactly once, no more and no less and in the proper
order.To ensure this following mechanisms can be used.
Error-correcting codes.
Basic idea: including redundant information along with
each block of data sent to enable the receiver to deduce what
the transmitted character must have been.
An n bit unit containing m bits of data and r bits of
redundancy, or check bits, is referred to as an n( =m+r) bits
codeword.
Hamming Code
0 0
Two-dimension Parity Check
• Two- Dimension Parity Checking increases the likelihood of
detecting burst errors. a 2-D Parity check of n bits can detect a
burst error of n bits.
10011011 11110000
+11001010 - 10100110
01010001 01010110
The basic idea of the CRC method:
The sender and receiver must agree upon a
generator polynomial, G(x) in advance. Both high
and low order bits of the generator must be 1.
Error-detecting Codes
In a cyclic code,
If s(x) ≠ 0, one or more bits is corrupted.
If s(x) = 0, either
a. No bit is corrupted. or
b. Some bits are corrupted, but the
decoder failed to detect them.
Standard polynomials
Calculation of the polynomial code checksum.
CHECKSUM
Sender site:
1. The message is divided into 16-bit words.
2. The value of the checksum word is set to 0.
3. All words including the checksum are
added using one’s complement addition.
4. The sum is complemented and becomes the
checksum.
5. The checksum is sent with the data.
Note
Receiver site:
1. The message (including checksum) is
divided into 16-bit words.
2. All words are added using one’s
complement addition.
3. The sum is complemented and becomes the
new checksum.
4. If the value of checksum is 0, the message
is accepted; otherwise, it is rejected.
Examples ̶
Suppose a block of 16 bits need to be sent: 10101001
00111001
10101001
00111001
—————-
Sum 11100010
Checksum 00011101
Sent pattern: 10101001 00111001 00011101
Example(showing no error in bit pattern)
Segment110101001
Segment2 00111001
Checksum 00011101
Sum 11111111
Complement 00000000
Means that the transmission is OK
Flow Control
Flow control is a technique for assuring that a transmitting
entity does not overwhelm a receiving entity with data. The
receiving entity typically allocates a data buffer of some
maximum length for a transfer.When data are received , the
receiver must do a certain amount of processing before passing
the data to the higher level software. In the absence of flow
control , the receiver’s buffer may fill up and overflow while it is
processing old data.
Following protocols are used for flow control….
Flow Control
Stop- and –wait flow control: in this method of flow
control the sender waits for the acknowledgement from
the receiver for sending the next frame after sending a
frame. It means the sender will not send any frame further,
if it does not receive the acknowledgement.
Stop and Wait
Flow Control
Thus the receiver can stop the transmission simply by
withholding the acknowledgement. A source often breaks
up a large block of data into smaller blocks and transmits
the data in many frames
Flow Control
Sliding –window flow control:
In stop and wait flow control only one frame can be transmitted
at any one time and this leads to inefficiency.
In the sliding window method of flow control, the sender can
transmit several frames before it needs an acknowledgement.
The link can be used to carry several frames at once and it’s
capacity can be used efficiently.
Flow Control
The receiver acknowledges only some of the frames , using a
single ACK to confirm the receipt of multiple data frames.
The sliding window refers to imaginary boxes at both the sender
and the receiver. This window can hold frames at either end and
provides upper limit of the no of frames that can be transmitted
before requiring an acknowledgement.
Flow Control
Frames may be acknowledged at any point without waiting for the
window to fill up and may be transmitted as long as the
window is not yet full.
The frames are numbered from 0 to n-1. For example if n=8, the
frames are numbered
0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,0,1……… the size of the
window is n-1.
Flow Control
When the receiver sends an ACK, it includes the number of next
frame it expects to receive. In other words, to acknowledge the
receipt of string of frames ending in frame 4, the receiver sends
an ACK, containing the number 5, it knows that all frames up
through no. 4 have been received.
The window can hold n-1 frames at either end ; therefore, a
maximum of n-1 frames may be sent before an
acknowledgement is required
Sliding Window
Flow Control
Sender window: at the beginning of a transmission, the
sender’s window contains n-1 frames. As frames are sent
out , the left boundary of the window moves inward,
shrinking the size of the window. Given a window of size
w , if three frames have been transmitted since the last
acknowledgement, then the no. Of frames left in the
window is w-3.
Flow Control
Once an ACK arrives , the window expands to allow in a
number of new frames equal to the number of frames
acknowledged by the ACK.
Flow Control
Conceptually the sliding window of the sender shrinks from
the left when frames of data are sent. The sliding window
of the sender expands to the right when
acknowledgements are received.
Sender Sliding Window
Flow Control
Receiver window: at the beginning of transmission, the
receiver window contains no frame but space for n-1
frames. As new frames come in, the size of the receiver
window shrinks. Thus the receiver window represents the
no. Of frames that may still be received before an ACK
must be sent.
Flow Control
As each ACK is sent out , the receiving window expands to
include as many new placeholders as newly acknowledged
frames. The window expands to include a number of new
frame spaces equal to the number of the most recently
acknowledged frame minus the number of the previously
acknowledged frame.
Flow Control
In a 7 frame window , if the prior ACK was for frame 2 and the
current ACK is for frame 5, the window expands by 5-2=3. If
the prior ACK was for frame 3 and current ACK is for frame 1 ,
the window expands by 6(1+8-3).
Conceptually, the sliding window of the receiver shrinks from the
left when frames of data are received. The sliding window of the
receiver expands to the right when acknowledgments are sent.
Receiver Sliding Window
Sliding Window Example
Sender
Receiver
Error Control
Error control refers to mechanism to detect and correct errors
that occur in the transmission of frames. Two types of errors
are possible…..
Lost frames: A frame fails to arrive at the other side. For
example a noise burst may damage a frame to the extent that
the receiver is not aware that a frame has been transmitted.
Error Control
Damaged frame: A recognizable frame does arrive , but
some of the bits are in error(have been altered during
transmission).
Error Control
Collectively, following mechanisms are all referred to as
automatic repeat request(ARQ).
Error detection.
Positive acknowledgement.
Retransmission after timeout.
Negative acknowledgement and retransmission.
The effect of ARQ is to turn an unreliable data link into a reliable
one.
Error Control
Three versions of ARQ are standardized …
Stop – and- wait ARQ.
Go-back-n ARQ.
Selective –reject ARQ.
Error Control
1. Stop-and-wait ARQ: this is a form of stop-and-wait flow
control, extended for retransmission of damaged or lost
frames.
Following features are added to the basic flow- control
mechanism…
Error Control
The sending device keeps a copy of the last frame transmitted
until it receives an acknowledgement for that frame.
For identification purpose , both data frames and ACK frames
are numbered alternately 0 and 1. A data 0 frame is
acknowledged by an ACK 1 frame, indicating that the receiver
has gotten data 0 and expecting data 1.
Sender device is equipped with a timer.
Error Control:Stop and Wait ARQ
source transmits single frame
wait for ACK
if received frame damaged, discard it
transmitter has timeout
if no ACK within timeout, retransmit
if ACK damaged,transmitter will not recognize it
transmitter will retransmit
receiver gets two copies of frame
use alternate numbering and ACK0 / ACK1
Error Control:Stop and Wait ARQ
pros and cons
simple
inefficient
Error Control
2. Sliding window ARQ: to extend sliding window to cover
retransmission of lost or damaged frames, three features
are added to the basic flow control mechanism…
1. The sending device keeps copies of all
transmitted frames, until they have been
acknowledged.
Error Control
0 1
7th bit?
Unstuff
0 1
zero 8th bit?
Continue counting
It is a flag Ones until the next zero
It is a part of
the data <15 Total >=15
Ones?
It is an abort It means an
ideal channel
Stop
e.g. The bit sequence 01111111110 will be sent as
011111011110.
A total of 7 to 14 consecutive 1s indicate an abort and a total of
15 or more 1s indicate an ideal channel.
The address field.
The address field(a) identifies the primary or secondary stations
involved in the frame transmission or reception. An address field
can be one byte or several bytes long , depending on the needs of
the network. One byte can identify up to 128 stations.
If the address field is only one byte , the last bit is always 1 and if it
is more than one byte , all bytes but the last one will end with
zero, only the last will end with 1.Ending each intermediate byte
with zero indicates to the receiver that there are more address
bytes to come.
HDLC Address Field
The control field.
HDLC uses the control field(c) to determine how to control the
communications process. This field contains the commands,
responses and sequence numbers used to maintain the data flow
accountability of the link, defines the functions of the frame and
initiates the logic to control the movement of traffic between
sending and receiving stations. Control fields differ depending on
frame type.
If the first bit of the control field is 0,the frame is an I frame.
If the first bit is a 1 and second bit is a 0 , it is an S- frame
and if both the first and second bits are ones it is a U- frame.
P/f
0
I-frame
N(S) N(R )
P/f
1 0
S- frame code N(R )
U-frame 1 1 P/f
code code
An I-frame contains two 3 bit error and flow control sequences ,
called N(S) and N(R ). N(S) specifies the number of the frame
being sent and N(R ) specifies the number of the frame expected
in return in a two way exchange ; thus N(R ) is the
acknowledgement field. If the last frame received was error free
then , the N( R) number will be that of the next frame in the
sequence. If the last frame was the damaged frame, then N( R) will
be the number of the damaged frame, indicating the need of it’s
retransmission.
S-frames contain no N( S )field, but N(R ) field to indicate the
receiver that no data is available to send. S-frames do not carry
user data.
The poll/final bit(p/f)
The 5th bit position in the control field is called the poll/final bit,
or p/f bit. It can only be recognized when it is set to 1. If it is set
to 0, it is ignored. The poll/final bit is used to provide dialogue
between the primary station and secondary station. The primary
station uses P=1 to acquire a status response from the secondary
station. The P bit signifies a poll. The secondary station responds to
the P bit by transmitting a data or status frame to the primary
station with the P/F bit set to F=1. The F bit can also be used to
signal the end of a transmission from the secondary station under
normal response mode.
.
U- frames contain, no N( S) or N(R ) field and are not
designed for user data exchange or acknowledgement..
Instead u-frames have two code fields, one two bit and one
three bit. These codes are used to identify the type of u-frame
and it’s functions.
Poll/Final
The information field.
This field is not always in a HDLC frame. It is only present when
the frame is I frame or U-frame. The information field contains the
actually data the sender is transmitting to the receiver in case of I-
frame and network management information in a U-
frame.Combining data to be sent with control information is
called piggybacking which is used in I frames.
The frame check sequence field.
This field contains a 16 bit, or 32 bit cyclic redundancy check. It is
used for error detection.
.
HDLC Information Field
HDLC FCS Field
HDLC commands and responses: I frame is the most
straight forward. These are designed for user information
transport and piggybacked acknowledgements and nothing
else.
But S-frames and U-frames can be divided among different
types on the basis of the code bits.
Type 0(Receive Ready) - is an acknowledgement frame used to
indicate the next frame expected. This frame is used when there is
no reverse traffic to use for piggybacking.
1. 1- persistent CSMA
2. non persistent CSMA
3. p-persistent CSMA
1-persistent CSMA
To send data, a station first listens to the channel to see if anyone
else is transmitting.
If so, the station waits (keeps sensing it) until the channel
becomes idle. Otherwise, it transmits a frame.
If a collision occurs , the station waits a random amount of time
and starts all over again.
It is called 1-persistent because the station transmits with a
probability of 1 whenever it starts sensing the channel and finds
the channel idle
1-persistent CSMA
How could collisions happen in CSMA ?
The propagation delay has an important effect on the performance
of the protocol. There is a small chance that just after a station
begins sending , another station will become ready to send and
sense the channel . If the first station’s signal has not yet reached
the second one , the later will sense an idle channel and will also
begin sending, resulting in a collision. The longer the propagation
delay, the more important this effect becomes , and the worse the
performance of the protocol.
1-persistent CSMA
Even if the propagation delay is zero, there will still be
collisions. If two stations become ready in the middle of the
third station’s transmission, both will wait politely until the
transmission ends and then both will begin transmitting
exactly simultaneously, resulting in a collision.
Nonpersistent CSMA:
In this protocol a conscious attempt is made to be less greedy
than in the previous one.
To send data, a station first listens to the channel to see if
anyone else is transmitting.
If so, the station waits a random period of time (instead of
keeping sensing until the end of the transmission) and repeats
the algorithm. Otherwise, it transmits a frame.
Nonpersistent CSMA
random delays reduces probability of collision.
If a collision occurs, the station waits a random amount of time
and starts all over again.
This protocol has better channel utilization
capacity is wasted because medium will remain idle following end
of transmission.
P-persistent CSMA
a compromise to reduce collisions and idle time
p-persistent CSMA rules:
1. if medium idle, transmit with probability p, and delay one time unit with
probability (1–p)
2. if medium busy, listen until idle and repeat step 1
3. if transmission is delayed one time unit, repeat step 1
issue of choosing effective value of p to avoid instability under
heavy load
CSMA with collision Detection:
1 1 1 1 3 7 1 1 1 5 1 2
Multiple Access Protocols:
Protocols like this in which the desire to transmit is
broadcasted before the actual transmission are called
reservation protocols.
Binary countdown:
Example:
Bit time
0123
0010 0___
0100 0___
1001 100_
1010 10 1 0
Result 10 1 0