Download as pdf or txt
Download as pdf or txt
You are on page 1of 55

MODULE 2

DATA LINK LAYER


Syllabus
• Data link layer - Data link layer design issues, Error detection and
correction, Sliding window protocols, High-Level Data Link
Control(HDLC)protocol. Medium Access Control (MAC) sublayer –
Channel allocation problem, Multiple access protocols, Ethernet,
Wireless LANs - 802.11, Bridges & switches - Bridges from 802.x to
802.y, Repeaters, Hubs, Bridges, Switches, Routers and Gateways.
DATA LINK LAYER FUNCTIONS
• The data link layer or layer 2 is the second layer of ISO/OSI model.
• The data link layer divides the stream of bits received from the
network layer into manageable units called Frames
• Adds header to the frame to define the address of the sender and
receiver.
• Responsible for node to node delivery of data
• Adds reliability to the physical layer by adding mechanisms to detect
and retransmit damaged, duplicate or lost frames
◻ Has a number of functions
1. Providing a well-defined service interface to the network layer.
2. Dealing with transmission errors.
3. Regulating the flow of data so that slow receivers are not swamped by fast
senders.

◻ To accomplish these goals, the data link layer takes the packets it gets from the
network layer and encapsulates them into frames for transmission.
◻ Each frame contains a frame header, a payload field for holding the packet, and a
frame trailer
• A Frame consists of following parts
Flag- It points to the starting and completion of the frame
Trailer- It includes the error correction and error detection bits
Payload field- It includes the message to be rendered
Frame header- It includes the origin and target addresses of the frame
Design Issues
1. Services Provided to the Network Layer
2. Framing
3. Error Control
4. Flow Control

1. Services Provided to the Network Layer


◻ The function of the data link layer is to provide services to the network layer. The
principal service is transferring data from the network layer on the source machine
to the network layer on the destination machine.
◻ On the source machine is an entity, call it a process, in the network layer that hands
some bits to the data link layer for transmission to the destination.
◻ The job of the data link layer is to transmit the bits to the destination machine so
they can be handed over to the network layer there, as shown in Fig. 3-2(a). The
actual transmission follows the path of Fig. 3-2(b), but it is easier to think in terms
of two data link layer processes communicating using a data link protocol.
Data link layer provides a variety of services
1. Unacknowledged connectionless service.

2. Acknowledged connectionless service.

3. Acknowledged connection-oriented service.


Unacknowledged connectionless service
o Source Machine send independent frames to the destination machine without
having destination machine acknowledge them
o No logical connection is established
o If a frame is lost due to noise on the line, no attempt is made to recover the loss or
detect it
o Appropriate when error rate is very low or for real time traffic such as audio

Acknowledged connectionless service.


◻ No connection □ But Acknowledgement
◻ Each frame sent is individually acknowledged. In this way, the sender knows
whether a frame has arrived correctly. If it has not arrived within a specified time
interval, it can be sent again. This service is useful over unreliable channels, such
as wireless systems.
Acknowledged connection-oriented service.
◻ With this service, the source and destination machines establish a
connection before any data are transferred.
◻ Each frame sent over the connection is numbered, and the data
link layer guarantees that each frame sent is indeed received.
◻ Furthermore, it guarantees that each frame is received exactly
once and that all frames are received in the right order.
◻ With connectionless service, in contrast, it is conceivable that a
lost acknowledgement causes a packet to be sent several times
and thus received several times.
◻ Connection-oriented service, in contrast, provides the network
layer processes with the equivalent of a reliable bit stream
2. Framing
◻ Breaking bit streams in to frames & compute checksum for each frame
◻ When frame reach destination □ Recompute checksum
o If newly computed checksum is different from the one in the frame the
data link layer knows that error has occurred and discard the bad
frame

Methods in Framing (To identify the starting and ending of the frame)

1. Character Count
2. Flag bytes with byte stuffing
3. Flag bits with bit stuffing
4. Physical layer coding violations.
a. Character Count
◻ Used a field in the header to specify no of characters
◻ When the data link layer at the destination sees the character count, it
knows how many characters follow and where the end of the frame is
◻ Can be garbled by transmission errors.
• Ex: if the character count of destination becomes 7, the destination
will go out of synchronization and will be unable to locate the start of
next frame.
b. Flag Bytes with Byte Stuffing
oEach frame start and end with special bytes called flag. If the receiver
ever loses its synchronization, it just search for flag byte to the find
the end of the current frame.
• A serious problem with this is that sometimes the flag bytes’s bit
pattern occurs in the data. To solve this problem, the sender’s data
link layer insert a special escape byte(ESC) just before each flag byte.
• The data link layer on the receiving end removes the escape byte
before the data are given to network layer. This technique is called
byte stuffing or character stuffing.
c. Bit Stuffing
• Each frame begins and ends with a special bit pattern 01111110 (in
fact a flag byte)
oWhenever the sender’s data link layer encounters five consecutive
1 s in the data, it automatically stuffs a 0 bit in the outgoing bit stream
oWhen the receiver sees five consecutive incoming 1 bits followed by a
0 bit, it automatically deletes the 0 bit. If the user data contains the
flag pattern 01111110 this flag is transmitted as 011111010 but
stored in the receiver’s memory as 01111110.
o In the figure a) Original data b)The data as they appear on the line c)
The data stored in receiver’s memory after destuffing
d. Physical layer Coding Violations
• Some reserved signals are used to indicate the start and end of the
frames
• As they are reserved signals, it is easy to find the start and end of the
frame.
3. Error Control
◻ Deliver frames with out error, in proper order
◻ Mechanisms include,
ACK/NAK :
◻ Feedback
◻ The usual way to ensure reliable delivery is to provide the sender with some
feedback about what is happening at the other end of the line.
◻ Typically, the protocol calls for the receiver to send back special control frames
bearing positive or negative acknowledgements about the incoming frames.
◻ If the sender receives a positive acknowledgement about a frame, it knows the
frame has arrived safely.
◻ On the other hand, a negative acknowledgement means that something has gone
wrong, and the frame must be transmitted again.
Time Out:
◻ Fixed time

◻ This possibility is dealt with by introducing timers into


the data link layer.
◻ When the sender transmits a frame, it generally also
starts a timer. The timer is set to expire after an
interval long enough for the frame to reach the
destination, be processed there, and have the
acknowledgement propagate back to the sender.
◻ Normally, the frame will be correctly received and the
acknowledgement will get back before the timer runs
out, in which case the timer will be canceled
Sequence number:
◻ Distinguish retransmission from originals
◻ However, when frames may be transmitted multiple times there is a danger
that the receiver will accept the same frame two or more times and pass it
to the network layer more than once.
◻ To prevent this from happening, it is generally necessary to assign
sequence numbers to outgoing frames, so that the receiver can
distinguish retransmissions from originals.
◻ The sequence numbering helps distinguishing between various
sequences. For example, if two received frames have the same
sequence number, it means that the same frame was retransmitted. If
the first frame was detected successfully, the second frame (with the
same sequence number) can be ignored.
4. FLOW CONTROL
• Feedback – based Flow Control : In this control technique, sender simply
transmits data or information or frame to receiver, then receiver transmits
data back to sender and also allows sender to transmit more amount of
data or tell sender about how receiver is processing or doing. This simply
means that sender transmits data or frames after it has received
acknowledgements from user.
• Rate – based Flow Control : In this control technique, usually when sender
sends or transfer data at faster speed to receiver and receiver is not being
able to receive data at the speed, then mechanism known as built-in
mechanism in protocol will just limit or restricts overall rate at which data
or information is being transferred or transmitted by sender without any
feedback or acknowledgement from receiver.
Error detection and correction
◻ Data-link layer uses error control techniques to ensure that
frames, i.e. bit streams of data, are transmitted from the
source to the destination with a certain extent of accuracy.
◻ Errors
◻ When bits are transmitted over the computer network, they
are subject to get corrupted due to interference and network
problems. The corrupted bits leads to spurious data being
received by the destination and are called errors.
◻ Types of Errors
◻ Errors can be of three types, namely single bit errors,
multiple bit errors, and burst errors.
◻ Single bit error − In the received frame, only one bit has been corrupted, i.e. either
changed from 0 to 1 or from 1 to 0.

◻ Multiple bits error − In the received frame, more than one bits are corrupted.
◻ Burst error − In the received frame, more than one consecutive bits are
corrupted.

◻ Error Control
◻ Error control can be done in two ways
◻ Error detection − Error detection involves checking whether any error
has occurred or not. The number of error bits and the type of error does
not matter.
◻ Error correction − Error correction involves ascertaining the exact
number of bits that has been corrupted and the location of the corrupted
bits.
Error Detection Techniques

◻ There are three main techniques for detecting errors in frames: Parity Check,
Checksum and Cyclic Redundancy Check (CRC).
◻ Parity Check
◻ The parity check is done by adding an extra bit, called parity bit to the data to
make a number of 1s either even in case of even parity or odd in case of odd
parity.
◻ While creating a frame, the sender counts the number of 1s in it and adds the parity
bit in the following way
◻ In case of even parity: If a number of 1s is even then parity bit value is 0. If the
number of 1s is odd then parity bit value is 1.
◻ In case of odd parity: If a number of 1s is odd then parity bit value is 0. If a
number of 1s is even then parity bit value is 1.
◻ On receiving a frame, the receiver counts the number of 1s in it. In case of even
parity check, if the count of 1s is even, the frame is accepted, otherwise, it is
rejected. A similar rule is adopted for odd parity check.
◻ The parity check is suitable for single bit error detection only.
2. Two-dimensional Parity check
Parity check bits are calculated for each row, which is equivalent to a
simple parity check bit. Parity check bits are also calculated for all
columns, then both are sent along with the data. At the receiving end
these are compared with the parity bits calculated on the received
data.
Two Dimensional Parity Check
3. Cyclic Redundancy Check (CRC)
◻ Cyclic Redundancy Check (CRC) involves binary division
of the data bits being sent by a predetermined divisor agreed
upon by the communicating system. The divisor is generated
using polynomials.
◻ Here, the sender performs binary division of the data
segment by the divisor. It then appends the remainder called
CRC bits to the end of the data segment. This makes the
resulting data unit exactly divisible by the divisor.
◻ The receiver divides the incoming data unit by the divisor. If
there is no remainder, the data unit is assumed to be correct
and is accepted. Otherwise, it is understood that the data is
corrupted and is therefore rejected.
Cyclic Redundancy Check
(CRC)
Cyclic Redundancy Check
The various steps followed in the CRC method are

1. A string of n 0s is appended to the data unit if the length of predetermined divisor


is n+ 1.
2. The newly formed data unit i.e. original data + string of n as are divided by the
divisor using binary division and remainder is obtained. This remainder is called
CRC.
3. Now, string of n 0s appended to data unit is replaced by the CRC remainder
(which is also of n bit).
4. The data unit + CRC is then transmitted to receiver.
5. The receiver on receiving it divides data unit + CRC by the same divisor & checks
the remainder .
6. If the remainder of division is zero, receiver assumes that there is no error in data
and it accepts it.
7. If remainder is non-zero then there is an error in data and receiver rejects it.
Polynomial and Divisor
CRC EXAMPLE
• Suppose the data is 11100 and generator polynomial be x^3+1.
• The steps used in CRC for error detection are
• 1. Convert the generator polynomial to binary data.
Here x^3+1=1x^3+0x^2+0x^1+1x^0. Taking the coefficients we can
generate binary data as 1001(4 bits) and this will be our divisor
2. Here the data is 11100. Our divisor is 4 bits. So we should add 3 0 s
to the end of data(if the length of divisor is n+1, then add n 0 s). So our
new data will be 11100000 which will be our dividend.
3. Perform binary division using dividend and divisor. Perform XOR
during division process
Sender Side

XOR TRUTH TABLE


• The remainder is called CRC and it will be n bits. Here remainder is
111(n=3 bits).
• Append CRC to the data and send to the receiver
• Data is 11100 and CRC is 111. So the total data sent to the receiver
will be 11100111. At the receiver side divide data with the
divisor(1001). If the remainder is zero, data is accepted (no error)
otherwise rejected(error is there)
Receiver Side
Checksum

• A Checksum is an error detection technique based on


the concept of redundancy.
• Checksum generator subdivides the data into equal
segments of n bits each, and all these segments are
added together by using one's complement arithmetic.
The sum is complemented and appended to the
original data, known as checksum field. The extended
data is transmitted across the network.
The Sender follows the given steps:
• The block unit is divided into k sections, and
each of n bits.
• All the k sections are added together by using
one's complement to get the sum.
• The sum is complemented and it becomes
the checksum field.
• The original data and checksum field are sent
across the network.
The Receiver follows the given steps:
• Checksum is verified at the receiver side.
• The block unit is divided into k sections and each of n bits.
• All the k sections along with checksum are added together by
using one's complement algorithm to get the sum.
• The sum is complemented.
• If the result of the sum is zero, then the data is accepted,
otherwise the data is discarded.
Binary addition
0+0=0 0+1=1 10+1 or 1+1+1=11(1 is carry)
1+0=1 1 + 1 = 10(1 is carry)
Error correcting codes
◻ Error Correction Techniques
◻ Error correction techniques find out the exact number of bits that have been
corrupted and as well as their locations. There are two principle ways
◻ Backward Error Correction (Retransmission) − If the receiver detects an error
in the incoming frame, it requests the sender to retransmit the frame. It is a
relatively simple technique. But it can be efficiently used only where
retransmitting is not expensive as in fiber optics and the time for retransmission is
low relative to the requirements of the application.
◻ Forward Error Correction − If the receiver detects some error in the incoming
frame, it executes error-correcting code that generates the actual frame. This saves
bandwidth required for retransmission. It is inevitable in real-time systems.
However, if there are too many errors, the frames need to be retransmitted
➢To understand how errors can be handled, it is
necessary to look closely at what an error really is
➢Normally, 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 codewords one transmitted and next
received,
➢say, 10001001 and 10110001,

44
➢it is possible to determine how many corresponding bits
differ.
➢In this case, 3 bits differ.
➢To determine how many bits differ, just exclusive OR the
two codewords and count the number of 1 bits in the
result.

➢The number of bit positions in which two codewords


differ is called the Hamming distance.
➢Error-detecting and error-correcting properties of a code
depend on its Hamming distance
45
Hamming Code for Single Error Correction

• The procedure for single error correction by Hamming Code


includes two parts, encoding at the sender’s end and decoding
at receiver’s end.
• Encoding a message by Hamming Code
• The procedure used by the sender to encode the message
encompasses the following steps −
• Step 1 − Calculation of the number of redundant bits.
• Step 2 − Positioning the redundant bits.
• Step 3 − Calculating the values of each redundant bit.
2r=d+r+1

Calculation of the number of redundant bits.


• An information of 'd' bits are added to the redundant bits 'r' to form d+r.
Suppose r is the number of redundant bits and d is the total number of the
data bits. The number of redundant bits r can be calculated by using the
formula:
2r>=d+r+1
Suppose the original data is 1010 which is to be sent.
Then total number of data bits 'd' = 4 Number of redundant bits
r : 2r >= d+r+1 2r>= 4+r+1 . Therefore, the value of r is 3 that satisfies the
above relation. Total number of bits = d+r = 4+3 = 7.
Positioning the redundant bits
The r redundant bits placed at bit positions of powers of 2, i.e. 1, 2, 4,
8, 16 etc.
1.The position of r1 = 1
2.The position of r2 = 2
3.The position of r4 = 4
Representation of Data on the addition of parity bits:

Calculating the values of each redundant bit.

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.
We observe from the above figure that the bit positions that includes 1 in the first position
are 1, 3, 5, 7. Now, we perform the even-parity check at these bit positions. The total
number of 1 at these bit positions corresponding to r1 is even, therefore, the value of the
r1 bit is 0 (Refer even parity discussed in Parity check-error detection).

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.
We observe from the above figure that the bit positions that includes 1 in
the second position are 2, 3, 6, 7. Now, we perform the even-parity check
at these bit positions. 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.
We observe from the above figure that the bit positions that includes 1 in the
third position are 4, 5, 6, 7. Now, we perform the even-parity check at these bit
positions. 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

We observe from the above figure that 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.
We observe from the above figure that 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.
• We observe from the above figure that 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.
• Suppose the binary representation is 000 then it means no error.
Practise Question(Important)
• An 8-bit byte with binary value 10101111 is to be encoded
using an even-parity Hamming code. What is the binary
value after encoding?

You might also like