Eec 2502 Lec 4
Eec 2502 Lec 4
Data Link Layer is second layer of OSI Layered Model. This layer is one of the most
complicated layers and has complex functionalities and liabilities. Data link layer hides the
details of underlying hardware and represents itself to upper layer as the medium to
communicate.
Data link layer works between two hosts which are directly connected in some sense. This direct
connection could be point to point or broadcast. Systems on broadcast network are said to be on
same link. The work of data link layer tends to get more complex when it is dealing with
multiple hosts on single collision domain.
Data link layer is responsible for converting data stream to signals bit by bit and to send that over
the underlying hardware. At the receiving end, Data link layer picks up data from hardware
which are in the form of electrical signals, assembles them in a recognizable frame format, and
hands over to upper layer.
Data link layer has two sub-layers:
Logical Link Control: It deals with protocols, flow-control, and error control
Media Access Control: It deals with actual control of media
Functionality of Data-link Layer
Data link layer does many tasks on behalf of upper layer. These are:
Framing
Data-link layer takes packets from Network Layer and encapsulates them into Frames. Then, it
sends each frame bit-by-bit on the hardware. At receiver’ end, data link layer picks up signals
from hardware and assembles them into frames.
Flow Control
Stations on same link may have different speed or capacity. Data-link layer ensures flow control
that enables both machine to exchange data on same speed.
Error Control
Sometimes signals may have encountered problem in transition and the bits are flipped.These
errors are detected and attempted to recover actual data bits. It also provides error reporting
mechanism to the sender.
Addressing
Data-link layer provides layer-2 hardware addressing mechanism. Hardware address is assumed
to be unique on the link. It is encoded into hardware at the time of manufacturing.
Media access control
When host on the shared link tries to transfer the data, it has a high probability of collision. Data-
link layer provides mechanism such as CSMA/CD to equip capability of accessing a shared
media among multiple Systems.
Synchronization
When data frames are sent on the link, both machines must be synchronized in order for transfer
to take place.
1. FRAMING
• To provide service to the network layer, the data link layer must use the service provided to it
by the physical layer
• I t breaks up physical layer data stream into small blocks, a process called segmentation and
adds header and frame flag to each block to form a frame, a process called encapsulation
• The usual approach is for the data link layer to break up the bit stream into discrete frames
called framing. Four methods of framing are:
i. Byte count.
ii. Flag bytes with byte stuffing.
iii. Flag bits with bit stuffing.
iv. Physical layer coding violations.
a. FLOW CONTROL
•Flow Control is a technique for speed matching of transmitter and receiver
•Flow control ensures that a transmitting station does not overflow a receiving station with data
•We will discuss two protocols for flow control
1. Stop and Wait
2. Sliding Window
For the time being, we assume that we have a perfect channel no errors)
1. Stop and wait Flow Control
•Simplest form of flow control
•In Stop and Wait flow control, the receiver indicates its readiness to receive data for each frame
•Operations
i. Sender Transmit a single frame
ii. Receiver Transmit acknowledgment
iii. Go to 1
The sender must wait until it receives the ACK frame before sending the next data frame
•Major drawback of Stop and Wait Flow Control is that only one frame can be in transmission at
a time
2. Sliding Window Flow Control
Major drawback of stop-and-wait flow control is only one frame can be transmitted at a time;
this leads to inefficiency if propagation delay is much longer than transmission delay. Sliding
window flow control allows the transmission of multiple frame. It assigns each frame a k-bit
sequence number and the range of sequence no. is [0..2k -1 ].
Let us examine how this might work for two stations, A and B, connected via a full-duplex link.
Station B allocates buffer space for n frames. Thus, B can accept n frames, and A is allowed to
send n frames without waiting for any acknowledgments. To keep track of which frames have
been acknowledged, each is labeled with a sequence number. B acknowledges a frame by
sending an acknowledgment that includes the sequence number of the next frame expected. This
acknowledgment also implicitly announces that B is prepared to receive the next n frames,
beginning with the number specified. This scheme can also be used to acknowledge multiple
frames.
How Flow control is achieved?
• Receiver can control the size of the sending window.
• By limiting the size of the sending window data flow from sender to receiver can be
limited .
The example assumes a 3-bit sequence number field and a maximum window size of seven
frames. Initially, A and B have windows indicating that A may transmit seven frames, beginning
with frame 0 (F0). After transmitting three frames (F0, F1, F2) without acknowledgment, A has
shrunk its window to four frames. The window indicates that A may transmit four frames,
beginning with frame number 3. B then transmits an RR (receive-ready) 3, which means: "I have
received all frames up through frame number 2 and am ready to receive frame number 3; in fact,
I am prepared to receive seven frames, beginning with frame number 3." With this
acknowledgment, A is back up to permission to transmit seven frames, still beginning with frame
3. A proceeds to transmit frames 3, 4, 5 , and 6. B returns an RR 4, which allows A to send up to
and including frame F2.
Fig. Example of Sliding window Protocol
b. ERROR CONTROL
There are many reasons such as noise, cross-talk, distortion, attenuation etc., which may make
data to get corrupted during transmission. If errors do occur, then some of the bits will either
change from 0 to 1 or from 1 to 0. The upper layers work on some generalized view of network
architecture and are not aware of actual hardware data processing. Hence, the upper layers expect
error-free transmission between the systems. Most of the applications would not function
expectedly if they receive erroneous data. Applications such as voice and video may not be that
affected and with some errors they may still function well.
Data-link layer uses some error control mechanism to ensure that frames (data bit streams) are
transmitted with certain level of accuracy. But to understand how errors is controlled, it is
essential to know what types of errors may occur.
Types of Errors
There may be three types of errors:
Single bit error
In a frame, there is only one bit, anywhere though, which is corrupt.
1. Error Detection
Errors in the received frames are detected by means of Parity Check and Cyclic Redundancy
Check (CRC). In both cases, few extra bits are sent along with actual data to confirm that bits
received at other end are same as they were sent. If the counter-check at receiver’ end fails, the
bits are considered corrupted.
i. Parity Check
One Dimensional Parity Check
One extra bit is sent along with the original bits to make number of 1s either even in case of even
parity, or odd in case of odd parity.
The sender while creating a frame counts the number of 1s in it. For example, if even parity is
used and number of 1s is even then one bit with value 0 is added. This way number of 1s remains
even. If the number of 1s is odd, to make it even a bit with value 1 is added.
The receiver simply counts the number of 1s in a frame. If the count of 1s is even and even parity
is used, the frame is considered to be not-corrupted and is accepted. If the count of 1s is odd and
odd parity is used, the frame is still not corrupted.
If a single bit flips in transit, the receiver can detect it by counting the number of 1s. But when
more than one bits are erroneous, then it is very hard for the receiver to detect the error.
Two-Dimensional Parity Check
A better approach is the two dimensional parity checks. In this method, a block of bits is
organized in a table (rows and columns). First we calculate the parity bit for each data unit. Then
we organize them into a table. We then calculate the parity bit for each column and create a new
row of 8 bits. Consider the following example; we have four data units to send. They are
organized in the tabular form as shown below.
We then calculate the parity bit for each column and create a new row of 8 bits; they are the
parity bits for the whole block. Note that the first parity bit in the fifth row is calculated based on
all first bits: the second parity bit is calculated based on all second bits: and so on. We then
attach the 8 parity bits to the original data and send them to the receiver. Two-dimensional parity
check increases the likelihood of detecting burst errors. A burst error of more than ‘n‘ bits is also
detected by this method with a very high probability.
ii. Repetition Code
The repetition code makes use of repetitive transmission of each data bit in the bit stream. In the
case of threefold repetition, ‘1’ and ‘0’ would be transmitted as ‘111’ and ‘000’ respectively. If,
in the received data bit stream, bits are examined in groups of three bits, the occurrence of an
error can be detected. In the case of single-bit errors, ‘1’ would be received as 011 or 101 or 110
instead of 111, and a ‘0’ would be received as 100 or 010 or 001 instead of 000. In both cases,
the code becomes self-correcting if the bit in the majority is taken as the correct bit. There are
various forms in which the data are sent using the repetition code. Usually, the data bit stream is
broken into blocks of bits, and then each block of data is sent some predetermined number of
times. For example, if we want to send eight-bit data given by 11011001, it may be broken into
two blocks of four bits each. In the case of threefold repetition, the transmitted data bit stream
would be 110111011101100110011001.
However, such a repetition code where the bit or block of bits is repeated 3 times is not capable
of correcting two-bit errors, although it can detect the occurrence of error. For this, we have to
increase the number of times each bit in the bit stream needs to be repeated. For example, by
repeating each data bit 5 times, we can detect and correct all two-bit errors. The repetition code
is highly inefficient and the information throughput drops rapidly as we increase the number of
times each data bit needs to be repeated to build error detection and correction capability.
The most commonly used Hamming code is the one that has a code word length of seven bits
with four message bits and three parity bits. It is also referred to as the Hamming (7, 4) code. The
code word sequence for this code is written as P1P2D1P3D2D3D4, with P1, P2 and P3 being the
parity bits and D1,
D2, D3 and D4 being the data bits. We will illustrate step by step the process of writing the
Hamming code for a certain group of message bits and then the process of detection and
identification of error bits with the help of an example. We will write the Hamming code for the
four-bit message 0110 representing numeral ‘6’. The process of writing the code is illustrated in
Table 2.9, with even parity. Thus, the Hamming code for 0110 is 1100110. Let us assume that
the data bit D1 gets corrupted in the transmission channel. The received code in that case is
1110110. In order to detect the error, the parity is checked for the three parity relations
mentioned above. During the parity check operation at the receiving end, three additional bits X,
Y and Z are generated by checking the parity status of P1D1D2D4, P2D1D3D4 and P3D2D3D4
respectively. These bits are a ‘0’ if the parity status is okay, and a ‘1’ if it is disturbed. In that
case, ZYX gives the position of the bit that needs correction. The process can be best explained
with the help of an example.
Examination of the first parity relation gives X =1 as the even parity is disturbed. The second
parity relation yields Y = 1 as the even parity is disturbed here too. Examination of the third
relation gives Z = 0 as the even parity is maintained. Thus, the bit that is in error is positioned at
011 which is the binary equivalent of ‘3’. This implies that the third bit from the MSB needs to
be corrected. After correcting the third bit, the received message becomes 1100110 which is the
correct code.
Example 2.6
By writing the parity code (even) and threefold repetition code for all possible four-bit straight
binary
numbers, prove that the Hamming distance in the two cases is at least 2 in the case of the parity
code
and 3 in the case of the repetition code.
Solution
The generation of codes is shown in Table 2.10. An examination of the parity code numbers
reveals that the number of bit disagreements between any pair of code words is not less than 2. It
is either 2 or 4. It is 4, for example, between 00000 and 10111, 00000 and 11011, 00000 and
11101, 00000 and 11110 and 00000 and 01111. In the case of the threefold repetition code, it is
either 3, 6, 9 or 12 and therefore not less than 3 under any circumstances.
Example 2.7
It is required to transmit letter ‘A’ expressed in the seven-bit ASCII code with the help of the
Hamming
(11, 7) code. Given that the seven-bit ASCII notation for ‘A’ is 1000001 and that the data word
gets corrupted to 1010001 in the transmission channel, show how the Hamming code can be
used to identify
the error. Use even parity.
Solution
• The generalized form of the Hamming code in this case is P1P2D1P3D2D3D4P4D5D6D7
= P1P21P3000P4001.
• The four groups of bits using different parity bits are P1D1D2D4D5D7, P2D1D3D4D6D7,
P3D2D3D4
and P4D5D6D7.
• This gives P1 =0, P2 =0, P3 =0 and P4=1.
• Therefore, the transmitted Hamming code for ‘A’ is 00100001001.
• The received Hamming code is 00100101001.
• Checking the parity for the P1 group gives ‘0’ as it passes the test.
• Checking the parity for the P2 group gives ‘1’ as it fails the test.
• Checking the parity for the P3 group gives ‘1’ as it fails the test.
• Checking the parity for the P4 group gives ‘0’ as it passes the test.
• The bits resulting from the parity check, written in reverse order, constitute 0110, which is the
binary equivalent of ‘6’. This shows that the bit in error is the sixth from the MSB.
• Therefore, the corrected Hamming code is 00100001001, which is the same as the transmitted
code.
• The received data word is 1000001.
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
4. ADDRESSING
Computer network entities need some way to distinguish devices on the network. This is done
through addressing. The Data Link Layer is only concerned with physical devices addresses.
Physical device addressee are, unique hardware addresses typically assigned by hardware
venders. The hardware vendors use addresses that are allocated to them by a standards
organization, the format of the
address depends upon the media access method being used. With Ethernet and Token Ring, the
addresses are very similar. Each uses Media Access Control (MAC) addresses.