Computer Networks UNIT-2 Data Link Layer
Computer Networks UNIT-2 Data Link Layer
Data link layer: Design issues, Framing: fixed size framing, variable size framing, flow control, error
control, error detection and correction codes, CRC, Checksum: idea, one’s complement internet
checksum, services provided to Network Layer
Elementary Data Link Layer protocols: simplex protocol, Simplex stop and wait, Simplex protocol for
Noisy Channel.
Sliding window protocol: One bit, Go back N, Selective repeat-Stop and wait protocol, Data link layer
in HDLC: configuration and transfer modes, frames, control field, point to point protocol (PPP):
framing transition phase, multiplexing, multi link PPP.
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:
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.
The function of the data link layer is to provide service 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.
The network layer 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 on the destination machine.
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
Actual communication
In this communication, no physical medium is present for Data Link Layer to transmit data.
It can be only be visualized and imagined that two Data Link Layers are communicating with
each other with the help of or using data link protocol.
Virtual communication
In this communication, physical medium is present through which Data Link Layer simply
transmits data frames.
The actual path is Network Layer -> Data link layer -> Physical Layer on sending machine,
then to physical media and after that to Physical Layer -> Data link layer -> Network
Layer on receiving machine.
The data link layer can be designed to offer various services. The actual services that are
offered vary from protocol to protocol.
Three reasonable possibilities that we will consider in turn are:
Here, the data link layer of the sending machine sends independent frames to the data link
layer of the receiving machine.
The receiving machine does not acknowledge receiving the frame. No logical connection is
set up between the host machines. Error and data loss is not handled in this service.
This is applicable in Ethernet services and voice communications.
Here, no logical connection is set up between the host machines, but each frame sent by the
source machine is acknowledged by the destination machine on receiving.
If the source does not receive the acknowledgment within a stipulated time, then it resends
the frame.
This is used in Wifi (IEEE 802.11) services.
This is the best service that the data link layer can offer to the network layer.
A logical connection is set up between the two machines and the data is transmitted along
this logical path.
The frames are numbered, that keeps track of loss of frames and also ensures that frames
are received in correct order.
It is appropriate for satellite communications and long-distance telephone circuits.
It is appropriate for satellite communications and long-distance telephone circuits.
The service has three distinct phases –
1. Set up of connection – A logical path is set up between the source and the destination
machines. Buffers and counters are initialised to keep track of frames.
2. Sending frames – The frames are transmitted.
3. Release connection – The connection is released, buffers and other resources are
released.
Framing
The data link layer needs to pack bits into frames, so that each frame is distinguishable from
another.
Frames are generally data unit of data link layer that is transmitted or transferred among
various network points.
It includes complete and full addressing, protocols that are essential, and information under
control.
Physical layers only just accept and transfer stream of bits without any regard to meaning or
structure.
Therefore it is up to data link layer to simply develop and recognize frame boundaries. Data-
link layer takes the packets from the Network Layer and encapsulates them into frames.
If the frame size becomes too large, then the packet may be divided into small sized frames.
Smaller sized frames makes flow control and error control more efficient.
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.
Parts of a Frame
Types of framing
1. Bit-oriented approach
HDLC-Frame format
8 16 16 8
In a data link frame, the delimiting flag sequence generally contains six or more consecutive
1s. In order to differentiate the message from the flag in case of the same sequence, a single
bit is stuffed in the message.
Whenever a 0 bit is followed by five consecutive 1bits in the message, an extra 0 bit is
stuffed at the end of the five 1s.
When the receiver receives the message, it removes the stuffed 0s after each sequence of
five 1s. The un-stuffed message is then sent to the upper layers.
Byte oriented approach
8 8 8 8 8 16
1. SYN Character-It establishes synchronization of the incoming message with the receiver and
precedes all message packets. It can also be inserted into the middle of longer messages to
maintain synchronization
2. SOH–It indicates the Start Of Header
3. STX character –It signals the Start of TeXt
4. ETX character – It signals the End of TeXt
5. Payload-This is the actual message received from the Network layer.
Frame format
8 8 8 16 16
Fields
Flag -1 Byte that marks the beginning and the end of the frame. The bit pattern of the flag is
01111110
Address-1 byte which is set to 11111111 in case of broadcast
Control-1 byte set to a constant value of 11000000
Protocol-1 or 2 bytes that define the type of data contained in the payload field.
Payload –This carries the data from the network layer. The maximum length of the payload
field is 1500 bytes. However this may be negotiated between the endpoint of
communications
The danger is that if transmission error could corrupt the count field then the end of the frame
would not be correctly detected by the receiver.
Character stuffing
Byte stuffing or character stuffing is the process of adding one extra byte whenever there is
a flag sequence appear in the payload
Protocols in the data link layer are designed so that this layer can perform its basic functions:
1. Framing- Framing is the process of dividing bit - streams from physical layer into data
frames whose size ranges from a few hundred to a few thousand bytes
2. Error control- Error control mechanisms deals with transmission errors and
retransmission of corrupted and lost frames
3. Flow control-Flow control regulates speed of delivery and so that a fast sender does not
drown a slow receiver.
Error control
Error control is basically process in data link layer of detecting or identifying and re-
transmitting data frames that might be lost or corrupted during transmission.
In both of these cases, receiver or destination does not receive correct data-frame and
sender or source does not even know anything about any such loss regarding data frames.
Therefore, in such type of cases, both sender and receiver are provided with some essential
protocols that are required to detect or identify such type of errors like loss of data frames.
The Data-link layer follows technique known as re-transmission of frames to detect or
identify transit errors and also to take necessary actions that are required to reduce or
remove such errors. Each and every time an effort is detected during transmission,
particulardata frames retransmitted and this process is known as ARQ (Automatic Repeat
Request).
Error Detection :
Types of errors
1.Bit error
2.Burst error
• Error detection means to decide whether the received data is correct or not without having
a copy of the original message.
• To detect or correct errors, we need to send some extra bits with the data.
2. Checksum
The circuit which adds a parity bit to the data at transmitter is called “Parity generator”. The parity
bits are transmitted and they are checked at the receiver. If the parity bits sent at the transmitter
and the parity bits received at receiver are not equal then an error is detected. The circuit which
checks the parity at receiver is called “Parity checker”.
2.Checksum
Checksums are similar to parity bits except, the number of bits in the sums is larger than
parity and the result is always constrained to be zero. That means if the checksum is zero,
error is detected. A checksum of a message is an arithmetic sum of code words of certain
length. The sum is stated by means of 1’s compliment and stored or transferred as a code
extension of actual code word. At receiver a new checksum is calculated by receiving the bit
sequence from transmitter.
The checksum method includes parity bits, check digits and longitudinal redundancy check
(LRC). For example, if we have to transfer and detect errors for a long data sequence (also
called as Data string) then we divide that into shorter words and we can store the data with
a word of same width. For each another incoming bit we will add them to the already stored
data. At every instance, the newly added word is called “Checksum”.
At receiver side, the received bits checksum is same as that of transmitter’s, there is no error
found.
1.Break the original message into ‘k’ number of blocks with ‘n’ bits in each block.
Example
Solution
Step 1: Break the original message into ‘k’ number of blocks with ‘n’ bits in each block.
At receiver side
In CRC, a sequence of redundant bits, called cyclic redundancy check bits, are appended to
the end of data unit so that the resulting data unit becomes exactly divisible by a second,
predetermined binary number.
At the destination, the incoming data unit is divided by the same number. If at this step
there is no remainder, the data unit is assumed to be correct and is therefore accepted.
A remainder indicates that the data unit has been damaged in transit and therefore must be
rejected.
1. At the receiver side, we divide the received code word with the same divisor to get the
actual code word.
2. For an error free reception of data, the reminder is 0. If the reminder is a non – zero,
that means there is an error in the received code / data sequence.
Example
Find the CRC for the data blocks 100100 with the divisor 1101?
At sender side
At receiver side
Error correction, as name suggests, simply means correction or solving or fixing of errors.
It simply means reconstruction and rehabilitation of original data that is error-free. But error
correction method is very costly and is very hard.
The techniques that we have discussed o far can detect errors, but do not correct them.
Error correction can be handled in 2 ways
1. One I when error is discovered, the receiver can have the sender retransmit the entire
data unit
2. The receiver can use an error correcting code which automatically corrects certain errors.
Hamming Code
This error detecting and correcting code technique is developed by R.W.Hamming . This
code not only identifies the error bit, in the whole data sequence and it also corrects it.
This code uses a number of parity bits located at certain positions in the codeword. The
number of parity bits depends upon the number of information bits.
The hamming code uses the relation between redundancy bits and the data bits and this
code can be applied to any number of data bits.
Redundancy means “The difference between number of bits of the actual data sequence and
the transmitted bits”. These redundancy bits are used in communication system to detect
and correct the errors, if any.
How the Hamming code actually corrects the errors?
In Hamming code, the redundancy bits are placed at certain calculated positions in order to
eliminate errors. The distance between the two redundancy bits is called “Hamming
distance”.
To understand the working and the data error correction and detection mechanism of the
hamming code, let’s see to the following stages.
Parity bits
• A parity bit is a bit appended to a data of binary bits to ensure that the total number of 1’s in
the data is even or odd. Parity bits are used for error detection. There are two types of parity
bits:
• In the case of odd parity, for a given set of bits, the number of 1’s are
counted. If that count is even, the parity bit value is set to 1, making the
total count of occurrences of 1’s an odd number. If the total number of 1’s in
a given set of bits is already odd, the parity bit’s value is 0.
• All bit positions that are power of 2 marked as parity bits(1,2,4,8…) and the remaining bits
are marked as data bits.
D7 D6 D5 P4 D3 P2 P1
D-data bit
P-parity bit
The value of the parity bit determined by the sequence of bit that is alternatively check and
skips.
P1 –check 1 bit,skip 1 bit, check 1 bit,skip 1 bit,
P1=1,3,5,7,9,11………….
P2 –check 2 bits,skip 2 bits, check 2 bits,skip 2 bit,
P2=2,3,6,7,10,11………….
P4 –check 4 bits,skip 4 bits, check 4 bits,skip 4 bits
P4=4,5,6,7,12,13,14,15………….
P1 D3 D5 D7
P1 1 0 1
P1=1
P2 D3 D6 D7
P2 1 1 1
P2=0
P4 D5 D6 D7
P4 0 1 1
P4=1
Detecting errors
Correcting of errors
1 0 1
The decimal value for E=5(101) which shows that 5th bit is in error.
Flow control
Flow control is a technique that allows two stations working at different speeds to
communicate with each other.
It is a set of measures taken to regulate the amount of data that a sender sends so that a
fast sender does not overwhelm a slow receiver.
In data link layer, flow control restricts the number of frames the sender can send before it
waits for an acknowledgment from the receiver.
Simplex protocol
The Simplex protocol is data link layer protocol for transmission of frames over computer
network.
It is hypothetical protocol designed for unidirectional data transmission over an ideal
channel, i.e. a channel through which transmission can never go wrong.
It is assumed that both the sender and the receiver are always ready for data processing and
both of them have infinite buffer.
The sender simply sends all its data available onto the channel as soon as they are available
its buffer.
The receiver is assumed to process all incoming data instantly. It is does not handle flow
control or error control. Since this protocol is totally unrealistic, it is often called Utopian
Simplex protocol.
Design
Sender Site:
1. The data link layer in the sender site waits for the network layer to send a data packet.
2. On receiving the packet, it immediately processes it and sends it to the physical layer for
transmission.
Receiver Site:
1. The data link layer in the receiver site waits for a frame to be available.
2. When it is available, it immediately processes it and sends it to the network layer.
Stop-and-Wait Protocol
It is a data link layer protocol for transmission of frames over noiseless channels.
It provides unidirectional data transmission with flow control facilities but without error
control facilities.
After transmitting one frame ,the sender waits for an acknowledgement before transmitting
the next frame.
Design
Sender side
Rule 2-Send the next packet only after receiving acknowledgement for the previous.
Receiver side
After timeout on sender side, a delayed AK might be wrongly considered as ACK of some
other data packet.
3. Stop-and-Wait ARQ
Drawbacks
1. It sends One frame at a time
2. Poor utilization of bandwidth
3. Poor performance.
Sliding Window
This protocol improves the efficiency of stop and waits protocol by allowing multiple frames
to be transmitted before receiving an acknowledgment.
The working principle of this protocol can be described as follows –
Both the sender and the receiver has finite sized buffers called windows. The sender and the
receiver agrees upon the number of frames to be sent based upon the buffer size.
The sender sends multiple frames in a sequence, without waiting for acknowledgment.
When its sending window is filled, it waits for acknowledgment.
On receiving acknowledgment, it advances the window and transmits the next frames,
according to the number of acknowledgments received.
Go-back-N-ARQ
Go-back-N-ARQ uses the concept of protocol pipelining i.e., the sender can send multiple
frames before receiving the ACK for the first frame.
There are finite number of frame and the frames are numbered in a sequence manner.
The number of frames that can be sent depends on the window size of the sender.
If the ACK of a frame I not received within an agreed upon time period,all frames in the
current window are transmitted.
Working Principle
Go – Back – N ARQ provides for sending multiple frames before receiving the
acknowledgment for the first frame.
The frames are sequentially numbered and a finite number of frames. The maximum
number of frames that can be sent depends upon the size of the sending window.
If the acknowledgment of a frame is not received within an agreed upon time period, all
frames starting from that frame are retransmitted.
The size of the sending window determines the sequence number of the outbound frames. If
the sequence number of the frames is an n-bit field, then the range of sequence numbers
that can be assigned is 0 to 2n−1.
Consequently, the size of the sending window is 2n−1. Thus in order to accommodate a
sending window size of 2n−1, a n-bit sequence number is chosen.
The sequence numbers are numbered as modulo-n. For example, if the sending window size
is 4, then the sequence numbers will be 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, and so on.
The number of bits in the sequence number is 2 to generate the binary sequence 00, 01, 10,
11.
Selective repeat protocol, also called Selective Repeat ARQ (Automatic Repeat reQuest), is a
data link layer protocol that uses sliding window method for reliable delivery of data frames.
Here, only the erroneous or lost frames are retransmitted, while the good frames are
received and buffered.
The receiver while keeping track of sequence numbers ,buffers the frames in memory and
sends NACK(negative acknowledgement) for only frame which is missing or damaged.
The sender will send/retransmit packet for which NACK(negative acknowledgement) is
received
It uses two windows of equal size: a sending window that stores the frames to be sent and a
receiving window that stores the frames receive by the receiver.
The size is half the maximum sequence number of the frame. For example, if the sequence
number is from 0 – 15, the window size will be 8.
Working Principle
Selective Repeat protocol provides for sending multiple frames depending upon the
availability of frames in the sending window, even if it does not receive acknowledgement
for any frame in the interim.
The maximum number of frames that can be sent depends upon the size of the sending
window.
The receiver records the sequence number of the earliest incorrect or un-received frame. It
then fills the receiving window with the subsequent frames that it has received.
It sends the sequence number of the missing frame along with every acknowledgement
frame.
The sender continues to send frames that are in its sending window. Once, it has sent all the
frames in the window, it retransmits the frame whose sequence number is given by the
acknowledgements. It then continues sending the other frames.
High-level Data Link Control (HDLC)
High-level Data Link Control (HDLC) is a group of communication protocols of the data link layer for
transmitting data between network points or nodes. Since it is a data link protocol, data is organized
into frames. A frame is transmitted via the network to the destination that verifies its successful arrival.
It is a bit - oriented protocol that is applicable for both point - to - point and multipoint communications.
Transfer Modes
HDLC supports two types of transfer modes, normal response mode and asynchronous balanced mode.
Normal Response Mode (NRM) − Here, two types of stations are there, a primary station that send
commands and secondary station that can respond to received commands. It is used for both point - to -
point and multipoint communications.
Asynchronous Balanced Mode
In asynchronous balanced mode (ABM), the configuration is balanced. The link is point-to-point, and
each station can function as a primary and a secondary (acting as peers), as shown in below Figure.
This is the common mode today.
HDLC Frame
HDLC is a bit - oriented protocol where each frame contains up to six fields. The structure varies
according to the type of frame. The fields of a HDLC frame are −
Flag − It is an 8-bit sequence that marks the beginning and the end of the frame. The bit pattern of the
flag is 01111110.
Address − It contains the address of the receiver. If the frame is sent by the primary station, it contains
the address(es) of the secondary station(s). If it is sent by the secondary station, it contains the address
of the primary station. The address field may be from 1 byte to several bytes.
Control − It is 1 or 2 bytes containing flow and error control information.
Payload − This carries the data from the network layer. Its length may vary from one network to
another.
FCS − It is a 2 byte or 4 bytes frame check sequence for error detection. The standard code used is CRC
(cyclic redundancy code)
Types of HDLC Frames
There are three types of HDLC frames. The type of frame is determined by the control field of the frame
−
I-frame − I-frames or Information frames carry user data from the network layer. They also include flow
and error control information that is piggybacked on user data. The first bit of control field of I-frame is 0.
S-frame − S-frames or Supervisory frames do not contain information field. They are used for flow and
error control when piggybacking is not required. The first two bits of control field of S-frame is 10.
U-frame − U-frames or Un-numbered frames are used for myriad miscellaneous functions, like link
management. It may contain an information field, if required. The first two bits of control field of U-frame
is 11.
POINT-TO-POINT PROTOCOL:
Although HDLC is a general protocol that can be used for both point-to-point and multipoint
configurations, one of the most common protocols for point-to-point access is the Point-to-Point
Protocol (PPP). Today, millions of Internet users who need to connect their home computers to the
server of an Internet service provider use PPP. The majority of these users have a traditional
modem; they are connected to the Internet through a telephone line, which provides the services of
the physical layer. But to control and manage the transfer of data, there is a need for a point-to-
point protocol at the data link layer. PPP is by far the most common.
2. PPP defines how two devices can negotiate the establishment of the link and the exchange of
data.
3. PPP defines how network layer data are encapsulated in the data link frame.
5. PPP provides multiple network layer services supporting a variety of network layer protocols.
6. PPP provides connections over multiple links.
7. PPP provides network address configuration. This is particularly useful when a home user needs a
temporary network address to connect to the Internet.
On the other hand, to keep PPP simple, several services are missing:
I. PPP does not provide flow control. A sender can send several frames one after another with no
concern about overwhelming the receiver.
2. PPP has a very simple mechanism for error control. A CRC field is used to detect errors. If the
frame is corrupted, it is silently discarded; the upper-layer protocol needs to take care of the
problem. Lack of error control and sequence numbering may cause a packet to be received out of
order.
3. PPP does not provide a sophisticated addressing mechanism to handle frames in a multipoint
configuration.
Framing:
PPP is a byte-oriented protocol. Framing is done according to the discussion of byte oriented
protocols.
Frame Format
Below Figure shows the format of a PPP frame. The description of each field follows:
Flag-A PPP frame starts and ends with a I-byte flag with the bit pattern 01111110. Although this
pattern is the same as that used in HDLC, there is a big difference. PPP is a byte-oriented protocol;
HDLC is a bit-oriented protocol. The flag is treated as a byte, as we will explain later.
Address-The address field in this protocol is a constant value and set to 11111111(broadcast
address). During negotiation (discussed later), the two parties may agree to omit this byte.
Control- This field is set to the constant value 11000000 (imitating unnumbered frames in HDLC). As
we will discuss later, PPP does not provide any flow control. Error control is also limited to error
detection. This means that this field is not needed at all, and again, the two parties can agree, during
negotiation, to omit this byte.
Protocol-The protocol field defines what is being carried in the data field: either user data or other
information. We discuss this field in detail shortly. This field is by default 2 bytes long, but the two
parties can agree to use only 1 byte.
Payload field-This field carries either the user data or other information that we will discuss shortly.
The data field is a sequence of bytes with the default of a maximum of 1500 bytes; but this can be
changed during negotiation. The data field is byte stuffed if the flag byte pattern appears in this field.
Because there is no field defining the size of the data field, padding is needed if the size is less than
the maximum default value or the maximum negotiated value.
FCS-The frame check sequence (FCS) is simply a 2-byte or 4-byte standard CRC.
Transition Phases
A PPP connection goes through phases which can be shown in a transition phase diagram.
Dead-In the dead phase the link is not being used. There is no active carrier (at the physical layer)
and the line is quiet.
Establish- When one of the nodes starts the communication, the connection goes into this phase. In
this phase, options are negotiated between the two parties. If the negotiation is successful, the
system goes to the authentication phase (if authentication is required) or directly to the networking
phase. The link control protocol packets, discussed shortly, are used for this purpose. Several
packets may be exchanged here.
Authenticate-The authentication phase is optional; the two nodes may decide, during the
establishment phase, not to skip this phase. However, if they decide to proceed with authentication,
they send several authentication packets, discussed later. If the result is successful, the connection
goes to the networking phase; otherwise, it goes to the termination phase.
Network- In the network phase, negotiation for the network layer protocols takes place. PPP
specifies that two nodes establish a network layer agreement before data at the network layer can
be exchanged. The reason is that PPP supports multiple protocols at the network layer. If a node is
running multiple protocols simultaneously at the network layer, the receiving node needs to know
which protocol will receive the data.
Open- In the open phase, data transfer takes place. When a connection reaches this phase, the
exchange of data packets can be started. The connection remains in this phase until one of the
endpoints wants to terminate the connection.
Terminate- In the termination phase the connection is terminated. Several packets are exchanged
between the two ends for house cleaning and closing the link.
Multilink PPP
PPP was originally designed for a single-channel point-to-point physical link. The availability of
multiple channels in a single point-to-point link motivated the development of Multilink PPP. In this
case, a logical PPP frame is divided into several actual PPP frames. A segment of the logical frame is
carried in the payload of an actual PPP frame, as shown in below Figure. To show that the actual PPP
frame is carrying a fragment of a logical PPP frame, the protocol field is set to Ox003d. This new
development adds complexity. For example, a sequence number needs to be added to the actual
PPP frame to show a fragment's position in the logical frame.
Example Let us go through the phases followed by a network layer packet as it is transmitted
through a PPP connection. Below Figure shows the steps. For simplicity, we assume unidirectional
movement of data from the user site to the system site (such as sending an e-mail through an ISP).
The first two frames show link establishment. We have chosen two options (not shown in the
figure): using PAP for authentication and suppressing the address control fields. Frames 3 and 4 are
for authentication. Frames 5 and 6 establish the network layer connection using IPCP