0% found this document useful (0 votes)
2 views107 pages

CN-m3c

The document discusses the Data Link Layer's responsibilities, including packetizing, flow control, error control, and access control. It elaborates on error detection and correction methods, such as parity checks, cyclic redundancy checks, and checksums, as well as the Hamming code for single-bit error correction. Additionally, it covers framing techniques for efficient data transmission between nodes.

Uploaded by

rudragodhani246
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views107 pages

CN-m3c

The document discusses the Data Link Layer's responsibilities, including packetizing, flow control, error control, and access control. It elaborates on error detection and correction methods, such as parity checks, cyclic redundancy checks, and checksums, as well as the Hamming code for single-bit error correction. Additionally, it covers framing techniques for efficient data transmission between nodes.

Uploaded by

rudragodhani246
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 107

Module 3:

Data Link Layer


Position of the data-link layer
Hop to Hop Delivery
Data link layer duties
Packetizing(Framing)
• The data-link layer at each node needs to
encapsulate the datagram (packet received
from the network layer) in a frame before
sending it to the next node.
• The node also needs to decapsulate the
datagram from the frame received on the
logical channel
Flow Control
• If the producer produces items that cannot be
consumed, accumulation of items occurs.
• Require buffer at the receiving side to store
receiving frame.
• If the producing rate is more than consuming
rate than buffer will be full.
• Require mechanism to inform the sender to
slow down the sending rate.
Error Control
• Since electromagnetic signals are susceptible
to error, a frame is susceptible to error.
• The error needs first to be detected. After
detection, it needs to be either corrected at
the receiver node or discarded and
retransmitted by the sending node.
Access Control
• When the link is shared by multiple
users(broadcast link),many users can send a
frame at same time which will create a
collision in the network.
• Requires mechanism to manage the access of
multiple users at same time.
• Module 4 for Media Access Control.
Error Detection and Correction
 Networks must be able to transfer data from
one device to another with complete accuracy.
 Data can be corrupted during transmission.
 For reliable communication, errors must be
detected and corrected.
 Error detection and correction are
implemented either at the data link layer or the
transport layer of the OSI model.
Types of Errors
Single-Bit Error
Single bit errors are the least likely type of
errors in serial data transmission because
the noise must have a very short duration
which is very rare. However this kind of
errors can happen in parallel transmission.
Example:
 If data is sent at 1Mbps then each bit lasts
only 1/1,000,000 sec. or 1 μs.
 For a single-bit error to occur, the noise
must have a duration of only 1 μs, which is
very rare.
Burst Error
The term burst error means that two or
more bits in the data unit have changed
from 1 to 0 or from 0 to 1.

Burst errors does not necessarily mean that


the errors occur in consecutive bits, the
length of the burst is measured from the
first corrupted bit to the last corrupted bit.
Some bits in between may not have been
corrupted.
Burst error is most likely to happen in serial
transmission since the duration of noise is normally
longer than the duration of a bit.
The number of bits affected depends on the data
rate and duration of noise.
Example:
🢂 I f data is sent at rate = 1Kbps then a noise of 1/100
sec can affect 10 bits.(1/100*1000)

🢂 I f same data is sent at rate = 1Mbps then a noise of


1/100 sec can affect 10,000 bits.(1/100*106)
Error detection

Error detection means to decide whether the


received data is correct or not without having a
copy of the original message.

Error detection uses the concept of redundancy,


which means adding extra bits for detecting
errors at the destination.
Redundancy
Detection methods
Parity Check
A parity bit is added to every data unit so that the total
number of 1s(including the parity bit) becomes even for
even-parity check or odd for odd-parity check
Detection -examples

Example 1

Suppose the sender wants to send the word world. In


ASCII the five characters are coded as
1110111 1101111 1110010 1101100 1100100
The following shows the actual bits sent
11101110 11011110 11100100 11011000 11001001
Example 2

Now suppose the word world in Example 1 is received


by the receiver without being corrupted in
transmission.
11101110 11011110 11100100 11011000
11001001
The receiver counts the 1s in each character and comes
up with even numbers (6, 6, 4, 4, 4). The data is
accepted.
Example 3

Now suppose the word world in Example 1 is


corrupted during transmission.
11111110 11011110 11101100 11011000
11001001
The receiver counts the 1s in each character and
comes up with even and odd numbers (7, 6, 5, 4, 4).
The receiver knows that the data are corrupted,
discards them, and asks for retransmission.
Exercise
• Write the ASCII code of word “HOLE” using
even parity.
Four types of redundancy checks are used
in data communications
Vertical Redundancy Check
VRC
Performance

🢂 I t can detect single bit error


🢂 I t can detect burst errors only if the total
number of errors is odd.
Longitudinal Redundancy Check
LRC
Longitudinal Redundancy Check
LRC
Performance

🢂 L C R increases the likelihood of


detecting burst errors.
🢂 I f two bits in one data units are
damaged and two bits in exactly the same
positions in another data unit are also
damaged, the LRC checker will not detect
an error.
VRC and LRC
Exercise
• The following bit stream is encoded using VRC,LRC and even
parity. Locate and correct the error if it is present.
1 1 0 0 0 0 1 1, 1 1 1 1 0 0 1 1, 1 0 1 1 0 0 1 0, 0 0 0 0 1 0 1 0,
0 0 1 0 1 0 1 0, 0 0 1 0 1 0 1 1, 1 0 1 0 0 0 1 1, 0 1 0 0 1 0 1 1,
11100001
Cyclic Redundancy Check
CRC
Cyclic Redundancy Check
• Given a k-bit frame or message, the
transmitter generates an n-bit sequence,
known as a frame check sequence (FCS),
so that the resulting frame, consisting of
(k+n) bits, is exactly divisible by some
predetermined number.
• The receiver then divides the incoming
frame by the same number and, if there is
no remainder, assumes that there was no
error.
Binary Division
Polynomial
Polynomial and Divisor
Standard Polynomials
Exercise
1. Generate the CRC code for the data word of
1 1 0 0 1 0 1 0 1.The divisor is 1 0 1 0 1.
2. The codeword is received as 1100 1001
01011.Check whether there are errors in the
received codeword, if the divisor is 10101.
3. If the frame is 1101011011 and generator is
x4 + x +1. What would be the transmitted
frame.
Checksum
Checksum
▪ Data is divided into k segments each of m bits.
▪ Sender Side: Segments are added using 1’s complement arithmetic
to get the sum.
▪ Sum is complemented to get the checksum.
▪ Checksum segment is sent along with the data segments.
▪ Receiver Side: All received segments are added using 1’s
complement arithmetic to get complemented sum.
▪ If the result is zero, the received data is accepted; otherwise
discarded.

41
Checksum - Example
▪ Add two 16-bit integers word

Sender Receiver
1 1110011001100110 1 1110011001100110
1 1101010101010101 1 1101010101010101
wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1011101110111011
+ +
sum 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 1011101110111100
sum
checksum 0100010001000011 1 0100010001000011
1111111111111111
If one of the bits is a 0, then we can
say that error introduced into packet

Note: when adding numbers, a carryout from the most significant


bit needs to be added to the result

42
Internet Checksum
Performance
• It is not as strong as the CRC in error-checking
capability.
• For example, if the value of one word is
incremented and the value of another word is
decremented by the same amount, the two
errors cannot be detected because the sum and
checksum remain the same.
Error Correction
• Error Correction codes are used to detect and
correct the errors when data is transmitted
from the sender to the receiver.
• Error Correction can be handled in two ways:
• Backward error correction: Once the error is
discovered, the receiver requests the sender to
retransmit the entire data unit.
• Forward error correction: In this case, the
receiver uses the error-correcting code which
automatically corrects the errors.
Single-bit error correction
To correct an error, the receiver reverses the value of the
altered bit. To do so, it must know which bit is in error.
Number of redundancy bits needed
• Let data bits = m Redundancy bits = r
Total message sent = m+r
The value of r must satisfy the following relation:
2r ≥ m+r+1
Suppose the number of data bits is 7, then the number of
redundant bits can be calculated using:
= 24 ≥ 7 + 4 + 1
Thus, the number of redundant bits= 4
Hamming Code
• Parity bits: The bit which is appended to the original
data of binary bits so that the total number of 1s is
even or odd.
• Even parity: To check for even parity, if the total
number of 1s is even, then the value of the parity bit
is 0. If the total number of 1s occurrences is odd, then
the value of the parity bit is 1.
• Odd Parity: To check for odd parity, if the total
number of 1s is even, then the value of parity bit is 1.
If the total number of 1s is odd, then the value of
parity bit is 0.
Algorithm of Hamming code:
o An information of 'd' bits are added to the
redundant bits 'r' to form d+r.
o The location of each of the (d+r) digits is
assigned a decimal value.
o The 'r' bits are placed in the positions
1,2,.....2k-1.
o At the receiving end, the parity bits are
recalculated. The decimal value of the parity
bits determines the position of an error.
Error Correction
Relationship b/w Error position &
binary number.
Example
• Let's understand the concept of Hamming code
through an example:
• Suppose the original data is 1010 which is to
be sent.
Determining the position of
the redundant bits
• The number of redundant bits is 3. The three
bits are represented by r1, r2, r4. The position
of the redundant bits is calculated with
corresponds to the raised power of 2.
Therefore, their corresponding positions are 1,
21, 22.
• Representation of Data on the addition of
parity bits:
Determining the Parity Bits
Determining the r1 bit
• The r1 bit is calculated by performing a parity check on the
bit positions whose binary representation includes 1 in the
first position.

The total number of 1 at these bit positions corresponding to


r1 is even, therefore, the vaBl.Tueceh-Seom5f the r1 bit is 0.
Determining r2 bit
• The r2 bit is calculated by performing a parity
check on the bit positions whose binary
representation includes 1 in the second position.

The total number of 1 at these bit positions corresponding


to r2 is odd, therefore, the value of the r2 bit is 1.
Determining r4 bit
• The r4 bit is calculated by performing a parity check
on the bit positions whose binary representation
includes 1 in the third position.

The total number of 1 at these bit positions


corresponding to r4 is even, therefore, the value of
the r4 bit is 0.
• Data transferred is given below:

Suppose the 4th bit is changed from 0 to 1 at


the receiving end, then parity bits are
recalculated
R1 bit
• The bit positions of the r1 bit are 1,3,5,7.
• The binary representation of r1 is 1100.
• Now, we perform the even-parity check, the total
number of 1s appearing in the r1 bit is an even
number. Therefore, the value of r1 is 0.
R2 bit
• The bit positions of r2 bit are 2,3,6,7.
• The binary representation of r2 is 1001.
• Now, we perform the even-parity check, the
total number of 1s appearing in the r2 bit is an
even number. Therefore, the value of r2 is 0.
R4 bit
• The bit positions of r4 bit are 4,5,6,7.
• The binary representation of r4 is 1011.
• Now, we perform the even-parity check, the
total number of 1s appearing in the r4 bit is an
odd number. Therefore, the value of r4 is 1.
• The binary representation of redundant bits,
i.e., r4r2r1 is 100, and its corresponding
decimal value is 4.
• Therefore, the error occurs in a 4th bit position.
The bit value must be changed from 1 to 0 to
correct the error.
Exercise

• Calculate the value of R1,R2,R4 and R8.


• How the receiver will detect and correct if 6th
bit is changed from 0 to 1?
Framing
Data Link Control (DLC) Services

• The data link control (DLC) deals with


procedures for communication between two
adjacent nodes—node-to-node
communication—no matter whether the link is
dedicated or broadcast.
• Data link control functions include framing and
flow and error control
Framing
• The data link layer needs to pack bits into frames, so
that each frame is distinguishable from another.
• Our postal system practices a type of framing. The
simple act of inserting a letter into an envelope
separates one piece of information from another; the
envelope serves as the delimiter.
• Framing in the data-link layer separates a message
from one source to a destination by adding a sender
address and a destination address.
• The destination address defines where the packet is
to go; the sender address helps the recipient
acknowledge the receipt.
• Although the whole message could be packed
in one frame, that is not normally done.
• One reason is that a frame can be very large,
making flow and error control very inefficient.
• When a message is carried in one very large
frame, even a single-bit error would require
the retransmission of the whole frame.
• When a message is divided into smaller
frames, a single-bit error affects only that
small frame.
Frame Size
• Frames can be of fixed or variable size.
• In fixed-size framing, there is no need for
defining the boundaries of the frames; the size
itself can be used as a delimiter.
• In variable-size framing, we need a way to
define the end of one frame and the beginning
of the next.
• Historically, two approaches were used for this
purpose: a character-oriented approach and a
bit-oriented approach.
A frame in a character-oriented
protocol
character-oriented protocol
• Data to be carried are 8-bit characters from a
coding system such as ASCII.
• The header, which normally carries the source
and destination addresses and other control
information, and the trailer, which carries error
detection redundant bits, are also multiples of
8 bits.
• To separate one frame from the next, an 8-bit
(1-byte) flag is added at the beginning and the
end of a frame.
Byte Stuffing
• we send other types of information such as
graphs, audio and video; any character used
for the flag could also be part of the
information.
• If this happens, the receiver, when it
encounters this pattern in the middle of the
data, thinks it has reached the end of the
frame.
• To fix this problem, a byte-stuffing strategy
was added to character-oriented framing.
Byte Stuffing
• In byte stuffing (or character stuffing), a special
byte is added to the data section of the frame
when there is a character with the same
pattern as the flag. The data section is stuffed
with an extra byte.
• This byte is usually called the escape character
(ESC) and has a predefined bit pattern.
• Whenever the receiver encounters the ESC
character, it removes it from the data section
and treats the next character as data, not as a
delimiting flag.
Byte Stuffing and unstuffing
Note

Byte stuffing is the process of adding 1 extra


byte whenever there is a flag or escape
character in the text.
• Character-oriented protocols present another
problem in data communications.
• The universal coding systems in use today, such
as Unicode, have 16-bit and 32-bit characters
that conflict with 8-bit characters.
• We can say that, in general, the tendency is
moving toward the bit-oriented protocols that
we discuss next.
Bit-Oriented Framing
• In bit-oriented framing, the data section of a
frame is a sequence of bits to be interpreted by
the upper layer as text, graphic, audio, video,
and so on.
• However, in addition to headers (and possible
trailers), we still need a delimiter to separate
one frame from the other.
• Most protocols use a special 8-bit pattern flag,
01111110, as the delimiter to define the
beginning and the end of the frame
A frame in a bit-oriented protocol
Bit Stuffing
• Same problem as character-oriented protocols.
• If the flag pattern appears in the data, we need
to somehow inform the receiver that this is not
the end of the frame. We do this by stuffing 1
single bit(instead of 1 byte) to prevent the
pattern from looking like a flag. The strategy is
called bit stuffing.
• In bit stuffing, if a 0 and five consecutive 1 bits
are encountered, an extra 0 is added.
Bit Stuffing
Bit stuffing and unstuffing
Exercise 1
Exercise 2
Flow Control
• Whenever an entity produces items and another
entity consumes them, there should be a balance
between production and consumption rates.
• If the items are produced faster than they can be
consumed, the consumer can be overwhelmed and
may need to discard some items.
• If the items are produced more slowly than they can
be consumed, the consumer must wait, and the
system becomes less efficient. Flow control is related
to the first issue.
• We need to prevent losing the data items at the
consumer site.
Flow control at Data Link Layer
Buffers
• Although flow control can be implemented in several
ways, one of the solutions is normally to use two
buffers; one at the sending data-link layer and the
other at the receiving data-link layer.
• A buffer is a set of memory locations that can hold
packets at the sender and receiver.
• The flow control communication can occur by sending
signals from the consumer to the producer.
• When the buffer of the receiving data-link layer is full,
it informs the sending data-link layer to stop pushing
frames.
Combination of Flow and Error Control

• Flow and error control can be combined.


• In a simple situation, the acknowledgment that is
sent for flow control can also be used for error
control to tell the sender the packet has arrived
uncorrupted.
• The lack of acknowledgment means that there is a
problem in the sent frame.
• A frame that carries an acknowledgment is
normally called an ACK to distinguish it from the
data frame
Note

Flow control refers to a set of procedures used


to restrict the amount of data
that the sender can send before
waiting for acknowledgment.
Note

Error control in the data link layer is based


on automatic repeat request, which is the
retransmission of data.
DATA-LINK LAYER PROTOCOLS
• Traditionally four protocols have been defined
for the data-link layer to deal with flow and
error control:
– Simple (For Noiseless channel)
– Stop-and-Wait ARQ ( For Noisy Channel)
– Go-Back-N and ARQ ( For Noisy Channel)
– Selective-Repeat ARQ ( For Noisy Channel)
ARQ – Automatic Repeat Request.
If the acknowledgement doesn’t come within time
period, sender will retransmit the frame.
Simple Protocol
• Our first protocol is a simple protocol with
neither flow nor error control. We assume that
the receiver can immediately handle any frame
it receives.
• In other words, the receiver can never be
overwhelmed with incoming frames.
• No Frame is lost during transmission.
The design of the simplest protocol
with no flow or error control
Flow diagram for Example 1

Figure shows an example of communication using Simplex protocol.


It is very simple. The sender sends frames one after another without
even thinking about the receiver
Stop and Wait Protocol
• Stop-and-Wait protocol, which uses both flow and error
control.
• In this protocol, the sender sends one frame at a time
and waits for an acknowledgment before sending the
next one.
• To detect corrupted frames, we need to add a CRC to
each data frame. When a frame arrives at the receiver
site, it is checked.
• If its CRC is incorrect, the frame is corrupted and silently
discarded. The silence of the receiver is a signal for the
sender that a frame was either corrupted or lost.
Stop and Wait Protocol
• Every time the sender sends a frame, it starts a
timer. If an acknowledgment arrives before the
timer expires, the timer is stopped and the
sender sends the next frame.
• If the timer expires, the sender resends the
previous frame, assuming that the frame was
either lost or corrupted.
• This means that the sender needs to keep a
copy of the frame until its acknowledgment
arrives.
Stop and Wait Protocol
Example
Example Explained
• The first frame is sent and acknowledged.
• The second frame is sent, but lost. After time-out,
it is resent.
• The third frame is sent and acknowledged, but the
acknowledgment is lost. The frame is resent.
• However, there is a problem with this scheme.
The network layer at the receiver site receives
two copies of the third packet, which is not right.
• we can correct this problem using sequence
numbers and acknowledgment numbers.
Sequence and Acknowledgment
Numbers
• Duplicate packets, as much as corrupted packets, need
to be avoided.
• To correct the problem in previous Example, we need to
add sequence numbers to the data frames and
acknowledgment numbers to the ACK frames.
• However, numbering in this case is very simple.
• Sequence numbers are 0, 1, 0, 1, 0, 1, . . . ; the
acknowledgment numbers can also be 1, 0, 1, 0, 1, 0, …
• In other words, the sequence numbers start with 0, the
acknowledgment numbers start with 1.
• An acknowledgment number always defines the
sequence number of the next frame to receive.
Exercise 1
• Redraw Stop and Wait Flow chart(without
using sequence and acknowledgement
numbers) for the following scenario:
a. The first frame is sent and acknowledged.
b. The second frame is sent and acknowledged,
but the acknowledgment is lost.
c. The second frame is resent, but it is timed-out.
d. The second frame is resent and acknowledged.
Exercise 2
• Redraw Stop and Wait Flow chart(using
sequence and acknowledgement numbers) for
the following scenario:
a. Frame 0 is sent, but lost.
b. Frame 0 is resent and acknowledged.
c. Frame 1 is sent and acknowledged, but the
acknowledgment is lost.
d. Frame 1 is resent and acknowledged.
Note

In Stop-and-Wait ARQ, we use sequence numbers


to number the frames.
The sequence numbers are based on modulo-2
arithmetic.
Note

In Stop-and-Wait ARQ, the acknowledgment


number always announces in modulo-2 arithmetic
the sequence number of the next frame expected.
Piggybacking
• The two protocols we discussed in this section are
designed for unidirectional communication, in which
data is flowing only in one direction although the
acknowledgment may travel in the other direction.
• Protocols have been designed in the past to allow data
to flow in both directions.
• However, to make the communication more efficient,
the data in one direction is piggybacked with the
acknowledgment in the other direction.
• In other words, when node A is sending data to node B,
Node A also acknowledges the data received from node
B.
Sliding Window Example
❑Suppose two stations A and B are connected vi a full duplex link.
❑Station B allocates buffer space for F frames. Thus Station B can
accepts F frames, and Station A is allowed to send F frames without
waiting for acknowledgement.
❑To keep track each frame, it is label using sequence number.
❑Suppose B could receive frames 2,3,4 but withhold
acknowledgement until frame 4 has arrived; by then, returning an
acknowledgement with sequence number 5.
❑Station A maintain a list of sequence numbers that is allowed to
send.
❑Station B maintains a list of sequence numbers that it is prepared to
receive.
Sliding Window

❑In Sliding window multiple frame can be in


transit at a time. Efficiency of flow can be
improved by allowing multiple frames.
❑We can send up to W frames before worrying
about ACKs.
❑We keep a copy of these frames until the
ACKs arrive.
❑This procedure requires additional features to
be added to Stop-and-Wait.
Thank You…

You might also like