Unit 2
Unit 2
Unit-III
Data Link Layer:
Data link layer transforms the physical layer, a raw transmission facility to a link responsible for
node-to-node (hop-to-hop) communication. The data link layer is located between the physical and
network layers. The data link layer provides services to the network layer, it receives services from
the physical layer. When a packet is travelling in the Internet the data link layer of a node is
responsible for delivering a datagram to the next node in the path.
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. That is the data link layer of the sending node needs to encapsulate the datagram
received from the network in a frame and the data link layer of the receiving node needs to
decapsulate the datagram from the frame.
Physical layer provides the DLL with a “virtual bit pipe,” which allows DLL peers to exchange a
continuous stream of bits. The goal of the data link layer is to convert this bit pipe into "virtual
packet pipe" that will allow peers at the network layer to exchange packets (strings of bits). There
are two main issues we will consider here: (1) Framing and (2) Error control.
Data link layer is responsible for transmitting data from source network layer to destination
network layer. Source network layer passes a number of bits to data link layer, who then
packs them into frames and relies on physical layer to do actual communication receiving
data link layer unpacks frame sand passes bits to its network layer.
The data link layer uses the services of the physical layer to send and receive bits over
communication channels. It has a number of functions including:
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.
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 object, call it a process, the network layer adds
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.
Logical Link Control: It deals with protocols, flow-control, and error control DLL protocols can
be implemented either in hardware or software. They can be implemented in special purpose
hardware, known as a network adapter or Network Interface Card (NIC). A common example of
the latter case is an Ethernet NIC. Media Access Control: It deals with actual control of media.
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’s end, data link
layer picks up signals from hardware and assembles them into frames. Framing refers to the
problem of deciding which bits belong to which packets of data at the receiving DLL peer.
Error control arises because the bit pipe provided by the physical layer may introduce errors
in the packets, it may also add additional bits or remove some bits in some cases. Character
count, Character Stuffing, Bit Stuffing and Physical layer coding violations are the methods
used for framing.
Addressing: The 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. Some link layer protocols define three types of addresses unicast
address, multicast address and broadcast address.
Synchronization: When data frames are sent on the link, both machines must be
synchronized in order to transfer to take place.
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.
Flow Control: Stations on same link may have different speed or capacity. Data-link
layer ensures flow control that enables both machines to exchange data on same speed.
Multi-Access/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.
Framing is a function of the data link layer. It provides a way for a sender to transmit a set of bits
that are meaningful to the receiver. Ethernet, token ring, frame relay, and other data link layer
technologies have their own frame structures. Frames have headers that contain information such
as error-checking codes.
1. Fixed size – The frame is of fixed size and there is no need to provide boundaries to the frame,
length of the frame itself acts as delimiter.
Drawback: It suffers from internal fragmentation if data size is less than frame size
Solution: Padding
2. Variable size – In this there is need to define end of frame as well as beginning of next frame
to distinguish. This can be done in two ways:
1. Length field – We can introduce a length field in the frame to indicate the length of the
frame. Used in Ethernet(802.3). The problem with this is that sometimes the length field
might get corrupted.
2. End Delimeter (ED) – We can introduce an ED(pattern) to indicate the end of the frame.
Used in Token Ring. The problem with this is that ED can occur in the data.
Character Count: This method uses a field in the header to specify the number of characters in
the frame. When the data link layer at the destination sees the character count, it knows how many
characters follow, and hence where the end of the frame is. The disadvantage is that if the count is
garbled by a transmission error, the destination will lose synchronization and will be unable to
locate the start of the next frame. So, this method is rarely used.
Bit-oriented framing: This type of framing allows the sender to transmit a long string of bits at
one time. IBM's SDLC (Synchronous Data Link Control) and HDLC (High-level Data Link
Control) are examples of bit-oriented protocols. Most LANs use bit-oriented framing. There is
usually a maximum frame size. For example, Ethernet has a maximum frame size of 1,526 bytes.
The beginning and end of a frame is signaled with a special bit sequence (01111110 for HDLC).
If no data is being transmitted, this same sequence is continuously transmitted so the end systems
remain synchronized.
The advantage of using frames is that data is broken up into recoverable chunks that can easily be
checked for corruption. A glitch in the line during the transmission will corrupt some frames. Only
the lost frames and not the entire set of data needs to be retransmitted.
The final framing method is physical layer coding violations and is applicable to networks in which
the encoding on the physical medium contains some redundancy. In such cases normally, a 1 bit
is a high-low pair and a 0 bit is a low-high pair. The combinations of low-low and high-high which
are not used for data may be used for marking frame boundaries.
Data transmission from one device to another device with acceptable accuracy. For most
applications a system must guarantee that the data received are identical to the data transmitted.
There are many reasons such as noise, cross-talk, electromagnetic interference can alter the given
data unit, which may help data to get corrupted during transmission. It can alter one or more bits of
message. Some applications can tolerate a small level of error for eg: random errors in audio or
video transmissions may be tolerable, but when we transfer text we expect a very high level of
accuracy. Error is reduced using the digital transmission system but complete control of error is not
possible. Error bit rate for copper wire is 10-6, modern optical fiber cable have the error bit rate
10-9 much less than copper wire.
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.
Applications require a mechanism for detecting and correcting errors. 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
Single bit error: In a frame, there is only one bit, anywhere though, which is corrupt.
Multiple bits error: Frame is received with more than one bits in corrupted state.
Single bit errors can happen if we are sending data using parallel transmission whereas burst
error is most likely to happen in serial communication. The number of bits affected depends on
the data rate and duration of noise.
• Error detection
• Error correction
Error Detection: Error detection uses the concept of redundancy, which means adding extra bits
for detecting errors at the destination. 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.
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. Another simple
approach to error detection is to arrange a string of data bits in a two dimensional array with one
parity check for each row and one for each column. This is also called horizontal and vertical parity
check. In two-dimensional parity check, a block of bits is divided into rows and a redundant row
of bits is added to the whole block.
Cyclic Redundancy Check (CRC) : CRC is a different approach to detect if the received frame
contains valid data. This technique involves binary division of the data bits being sent. The divisor
is generated using polynomials. The sender performs a division operation on the bits being sent and
calculates the remainder. Before sending the actual bits, the sender adds the remainder at the end of
the actual bits. Actual data bits plus the remainder is called a code word. The sender transmits data
bits as code words.
At the other end, the receiver performs division operation on code words using the same CRC
divisor. If the remainder contains all zero’s the data bits are accepted, otherwise it is considered as
there some data corruption occurred in transit.
ERROR CORRECTION
Backward Error Correction When the receiver detects an error in the data received, it
requests back the sender to retransmit the data unit.
Forward Error Correction When the receiver detects some error in the data received, it
executes error-correcting code, which helps it to auto-recover and to correct some kinds of
errors.
The first one, Backward Error Correction, is simple and can only be efficiently used where
retransmitting is not expensive. For example, fiber optics. But in case of wireless transmission
retransmitting may cost too much. In the latter case, Forward Error Correction is used. The coding
scheme is divided into two categories block coding and convolution coding. Block code consist of
(n-k) number of check bits being added to k number of information bits to form ‘n’ bit code word.
These (n-k) number of check bits are derived from k information bits. At the receiver the checks
bits are used to detect and correct errors which may occur in the entire ‘n’ bit code words. In
convolution codes the check bits are continuously interleaved with information bits. These check
bits will help to correct errors not only in that particular block but also in other blocks as well.
To correct the error in data frame, the receiver must know exactly which bit in the frame is
corrupted. To locate the bit in error, redundant bits are used as parity bits for error detection. For
example, we take ASCII words (7 bits data), then there could be 8 kind of information we need:
first seven bits to tell us which bit is error and one more bit to tell that there is no error.
Data-link layer is responsible for implementation of point-to-point flow and error control
mechanism.
Flow Control: When a data frame Layer-2 data is sent from one host to another over a single
medium, it is required that the sender and receiver should work at the same speed. That is, sender
sends at a speed on which the receiver can process and accept the data. What if the speed hardware
or software of the sender or receiver differs? If sender is sending too fast the receiver may be
overloaded, and data may be lost.
Stop and Wait: This flow control mechanism forces the sender after transmitting a data frame to
stop and wait until the acknowledgement of the data-frame sent is received.
Sliding Window: In this flow control mechanism, both sender and receiver agree on the number of
data-frames after which the acknowledgement should be sent. As we learnt, stop and wait flow
control mechanism wastes resources, this protocol tries to make use of underlying resources as
much as possible.
Error Control: When data-frame is transmitted, there is a probability that data-frame may be lost
in the transit or it is received corrupted. In both cases, the receiver does not receive the correct data-
frame and sender does not know anything about any loss. In such case, both sender and receiver are
equipped with some protocols which helps them to detect transit errors such as loss of data-frame.
Hence, either the sender retransmits the data-frame or the receiver may request to resend the
previous data-frame.
Error detection - The sender and receiver, either both or any, must ascertain that there is
some error in the transit.
Positive ACK - When the receiver receives a correct frame, it should acknowledge
it.
Negative ACK - When the receiver receives a damaged frame or a duplicate frame, it sends
a NACK back to the sender and the sender must retransmit the correct frame.
Retransmission: The sender maintains a clock and sets a timeout period. If an
acknowledgement of a data-frame previously transmitted does not arrive before the timeout
the sender retransmits the frame, thinking that the frame or its acknowledgement is lost in
transit.
There are three types of techniques available which Data-link layer may deploy to control the
errors by Automatic Repeat Requests (ARQ):
Stop-and-wait ARQ:
Go-Back-N ARQ: Stop and wait ARQ mechanism does not utilize the resources at their best. When
the acknowledgement is received, the sender sits idle and does nothing. In Go-Back-N ARQ
method, both sender and receiver maintain a window. The sending-window size enables the sender
to send multiple frames without receiving the acknowledgement of the previous ones. The
receiving-window enables the receiver to receive multiple frames and acknowledge them. The
receiver keeps track of incoming frame’s sequence number. When the sender sends all the frames
in window, it checks up to what sequence number it has received positive acknowledgement. If all
frames are positively acknowledged, the sender sends next set of frames. If sender finds that it has
received NACK or has not receive any ACK for a particular frame, it retransmits all the frames
after which it does not receive any positive ACK. In Go-Back-N ARQ, the size of the sender
window must be less than 2m; the size of the receiver window is always 1.
Selective Repeat ARQ: In Go-back-N ARQ, it is assumed that the receiver does not have any
buffer space for its window size and has to process each frame as it comes. This enforces the
sender to retransmit all the frames which are not acknowledged.
In Selective-Repeat ARQ, the receiver while keeping track of sequence numbers, buffers the frames
in memory and sends NACK for only frame which is missing or damaged.The sender in this case,
sends only packet for which NACK is received.Layer-3 in the OSI model is called Network layer.
Network layer manages options pertaining to host and network addressing, managing sub-networks,
and internetworking. In Selective Repeat ARQ, the size of the sender and receiver window must be
at most one-half of 2m.
A technique called piggybacking is used to improve the efficiency of the bidirectional protocols.
When a frame is carrying data from A to B, it can also carry control information about frames from
B, when a frame is carrying data from B to A, it can also carry control information about frames
from A.
Network layer takes the responsibility for routing packets from source to destination within or
outside a subnet. Two different subnets may have different addressing schemes or non- compatible
addressing types. Same with protocols, two different subnets may be operating on different
protocols which are not compatible with each other. Network layer has the responsibility to route
the packets from source to destination, mapping different addressing schemes and protocols.
Error correction is usually done at the physical layer; while at the DLL and higher layers, the
common approach is detection and retransmission. One reason for this is that the performance of
error correcting codes is highly dependent on characteristics of the physical channel and thus better
suited for the physical layer.
Another reason is that at the DLL, errors are often rare and occur in bursts. It requires less overhead
to detect a long burst than too correct one. However when an error is detected, then the frame must
be retransmitted, which is also an overhead, but this only occurs when errors are detected instead
of in every packet.
The choice between error detection and correction will depend on the setting. For example if there
is no reverse communication channel available then retransmissions is not an option. Also for links
with long delays, the delay required for retransmission may not be acceptable. These two
approaches are not mutually exclusive; and in many cases both are performed. For example, in a
network it is common for both error correction to be done at the physical layer and error
detection/retransmission to be implemented at the DLL.
HDLC is a bit oriented protocol that supports both half-duplex and full-duplex communication
over point to point & multipoint link.
For any HDLC communications session, one station is designated primary and the other
secondary. A session can use one of the following connection modes, which determine how the
primary and secondary stations interact.
• Normal unbalanced: The secondary station responds only to the primary station.
• Asynchronous: The secondary station can initiate a message.
• Asynchronous balanced: Both stations send and receive over its part of a duplex line.
1. Information frames
• I-frames carry user's data and control information about user's data.
• I-frame carries user data in the information field.
• The I-frame format is shown.
The first bit of control field is always zero, i.e. the presence of zero at this place indicates that it is
I-frame.
• Field N(S) specifies the sequence number of the frame. Thus it specifies the number of the frame
that is currently being sent. Since it is a 3.bit field, only eight sequence numbers are possible 0,
1,2,3,4,5,6, 7 (000 to 111).
The control field is P/F i.e. Poll/Final and is used for these two purposes. It has, meaning only
when it is set i.e. when P/F=1. It can represent the following two cases.
(i) It means poll when frame is sent by a primary station to secondary (when address field contains
the address of receiver).
(ii) It means final when frame is sent by secondary to a primary (when the address field contains
the address of the sender).
• Control field Bit number 6, 7, and 8 specifies N(R) i.e. the sequence number of the frame expected
in return in two-way communication.
If last frame received was error-free then N(R) number will be that of the next frame is sequence.
If the last frame was not received correctly, the N(R) number will be the number of the damaged
frame, asking for its retransmission.
2. Supervisory frame
• S-frame carries control information, primarily data link layer flow and error controls.
• It does not contain information field.
• The format of S-frame is shown in diagram.
The first two bits in the control field of S-frame are always 10.
• Then there is a bit code field that specifies four types of S-frame with combination 00,01, 10, 11
as shown in table :-
1. RR, Receive Ready-used to acknowledge frames when no I-frames are availab1e to piggyback
the acknowledgement.
2. REJ Reject-used by the receiver to send a NAK when error has occurred.
U-frame contains two code fields, one two hit and other three bit.
• These five bits can create upto 32 different U-frames.
• .P/F bit in control field has same purpose in U-frame.
Extended address - HDLC provides another type of extension to the basic format. The address
field may be extended to more than one byte by agreement between the involved parties.
Control field - Serves to identify the type of the frame. In addition, it includes sequence numbers,
control features and error tracking according to the frame type.
FCS - The Frame Check Sequence (FCS) enables a high level of physical error control by allowing
the integrity of the transmitted frame data to be checked.
CONCLUSION
Data link layer is a second layered model. It works between two hosts which are directly connected.
The task of the data link layer is to convert the raw bit stream offered by the physical layer into a
stream of frames for use by the network layer. We have mainly studied data link layer design issues,
functionality of the data link layer which are framing, addressing synchronization, flow control,
error control, Multi-access. We studied types of error, error detection and correction & also we have
compared error detection and correction.