Computer Networks Chapter 2
Computer Networks Chapter 2
UNIT 2
DATA LINK LAYER
SYLLABUS
Introduction to Data-Link Layer, Link-Layer Addressing: Address Resolution Protocol
(ARP), Error Detection and Correction: Introduction, Types of Errors, Redundancy,
Detection versus Correction, Coding, Block coding: Error Detection, Cyclic Code: Cyclic
Redundancy Check, Polynomials, Cyclic Code Analysis and its Advantages, Checksum,
Forward Error Correction: Using Hamming Distance, Using XOR, Chunk Interleaving.
The data-link layer at Alice’s computer communicates with the data-link layer at router R2.
The data-link layer at router R2 communicates with the data-link layer at router R4, and so
on.
Finally, the data-link layer at router R7 communicates with the data-link
layer at Bob’s computer.
1
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
The reason is that Alice’s and Bob’s computers are each connected to a single network, but
each router takes input from one network and sends output to another network.
The first node is the source host; the last node is the destination host.
The other four nodes are four routers.
The first, the third, and the fifth links represent the three LANs, whereas the second and the
fourth links represent the two WANs.
Services:
The duty scope of the data-link layer is node-to-node.
When a packet is travelling in the Internet, the data-link layer of a node (host or router) is
responsible for delivering a datagram to the next node in the path.
The data-link layer of the source host needs only to encapsulate, the data-link layer of the
destination host needs to decapsulate.
But each intermediate node needs to both encapsulate and decapsulate.
We need encapsulation and decapsulation at each intermediate node.
The reason is that each link may be using a different protocol with a different frame format.
Even if one link and the next are using the same protocol, encapsulation and decapsulation
are needed because the link-layer addresses are normally different.
Services of Datalink Layer are
Unacknowledged connectionless service:
This contains separate frames from the source host to the destination host without some
acknowledgment structure. It does not have any link established or launched. It does not
manage with frame recovery due to channel noise.
Acknowledged connectionless service:
The transmission medium is more error-prone. This requires acceptance service for each
frame shared between two hosts to provide that the frame has occurred correctly.
2
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
Error Control:
It includes sequencing frames and sending control frames for acceptance. A noisy channel
can avoid scanning of bits, falling bits from a frame, introducing specific bits in the frame,
frames final sinking, etc.
Flow Control:
There is another fundamental problem in the data link design to regulate the cost of data
communication between two source and destination hosts. If the conflict among the source
and destination hosts data sending and receiving speed, it will create packets to drop at the
receiver end.
Sequence Integrity:
The data link layer supports the data bits sequence and sends them to the physical layer in the
similar sequence as received from the network layer. It supports a reliable share of data link
service data unit (DLSDU) over the data link connections.
Two Sublayers:
To better understand the functionality of and the services provided by the link layer, we can
divide the data-link layer into two sublayers:
1. Data link control (DLC)
The data link control sublayer deals with all issues common to both point-to-point and
broadcast links.
2. Media access control (MAC)
The media access control sublayer deals only with issues specific to broadcast links.
In other words
We separate these two types of links at the data-link layer, as shown in following diagram.
Link-Layer Addressing:
A link-layer address is sometimes called a link address, sometimes a physical address, and
sometimes a MAC address.
Since a link is controlled at the data-link layer, the addresses need to belong to the data-link
layer.
When a datagram passes from the network layer to the data-link layer,
the datagram will be encapsulated in a frame and two data-link addresses are added to the
frame header.
These two addresses are changed every time the frame moves from
one link to another. Following diagram demonstrates the concept in a small internet.
3
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
4
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
If a host or a router needs to find the link-layer address of another host or router in its
network, it sends an ARP request packet.
The packet includes the link-layer and IP addresses of the sender and the IP address of the
receiver.
Because the sender does not know the link-layer address of the receiver, the query is
broadcast over the link using the link-layer broadcast address.
Every host or router on the network receives and processes the ARP request packet, but only
the intended recipient recognizes its IP address and sends back an ARP response packet.
The response packet contains the recipient’s IP and link-layer addresses. The packet is
unicast directly to the node that sent the request packet.
In above diagram, the system on the left (A) has a packet that needs to be delivered to another
system (B) with IP address N2.
5
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
System A needs to pass the packet to its data-link layer for the actual delivery, but it does not
know the physical address of the recipient.
It uses the services of ARP by asking the ARP protocol to send a broadcast ARP request
packet to ask for the physical address of a system with an IP address of N2.
This packet is received by every system on the physical network, but only system B will
answer it, as shown in above diagram(b), System B sends an ARP reply packet that includes
its physical address.
Now system A can send all the packets it has for this destination using the physical address it
received.
Packet Format
Following diagram shows the format of an ARP packet.
The hardware type field defines the type of the link-layer protocol; Ethernet is given the type
1.
The protocol type field defines the network-layer protocol: IPv4 protocol is (0800)16.
The source hardware and source protocol addresses are variable-length fields defining the
link-layer and network-layer addresses of the sender.
The destination hardware address and destination protocol address fields define the receiver
link layer rand network-layer addresses.
An ARP packet is encapsulated directly into a data-link frame.
The frame needs to have a field to show that the payload belongs to the ARP and not to the
network-layer datagram.
Types of Errors:
There are two types of errors:
1. Single Bit Error: It means only 1 bit of a given data unit (such as a byte, character, or
packet) is changed from 1 to 0 or from 0 to 1.
2. Burst Error: It means 2or more bits in the data unit have changed from 1 to 0 or
from 0 to 1.
Following diagram shows the effect of a single-bit and a burst error on a data unit.
6
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
Redundancy:
The central concept in detecting or correcting errors is redundancy.
To be able to detect or correct errors, we need to send some extra bits with our data.
These redundant bits are added by the sender and removed by the receiver. Their presence
allows the receiver to detect or correct corrupted bits.
Coding:
Redundancy is achieved through various coding schemes. The sender adds redundant bits
through a process that creates a relationship between the redundant bits and the actual data
bits.
The receiver checks the relationships between the two sets of bits to
detect errors.
The ratio of redundant bits to data bits and the robustness of the process
are important factors in any coding scheme.
We can divide coding schemes into two broad categories:
1. Block coding
2. Convolution coding
Block Coding:
In block coding, we divide our message into blocks, each of k bits, called data words.
We add r redundant bits to each block to make the length n = k + r.
The resulting n-bit blocks are called codewords.
The block coding process is one-to-one; the same data word
is always encoded as the same codeword.
This means that we have 2n − 2k codewords that are not used.
We call these codewords invalid or illegal.
The trick in error detection is the existence of these invalid codes.
7
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
If the receiver receives an invalid codeword, this indicates that the data was corrupted during
transmission.
Error Detection:
How can errors be detected by using block coding? If the following two conditions are met,
the receiver can detect a change in the original codeword.
1. The receiver has (or can find) a list of valid codewords.
2. The original codeword has changed to an invalid one.
Following diagram shows the role of block coding in error detection.
The sender creates codewords out of data words by using a generator that applies the rules
and procedures of encoding.
Each codeword sent to the receiver may change during transmission.
If the received codeword is the same as one of the valid codewords, the
word is accepted; the corresponding data word is extracted for use.
If the received codeword is not valid, it is discarded.
However, if the codeword is corrupted during transmission but the received word still
matches a valid codeword, the error remains undetected.
Hamming Distance:
One of the central concepts in coding for error control is the idea of the Hamming distance.
The Hamming distance between two words (of the same size) is the number of differences
between the corresponding bits.
We show the Hamming distance between two words x and y as d(x, y).
Hamming distance is important for error detection.
The reason is that the Hamming distance between the received codeword and the sent
codeword is the number of bits that are corrupted during transmission.
For example
If the codeword 00000 is sent and 01101 is received, 3 bits are in error and the Hamming
distance between the two is d(00000, 01101) = 3.
In other words, if the Hamming distance between the sent and the received codeword is not
zero, the codeword has been corrupted during transmission.
The Hamming distance can easily be found if we apply the XOR operation (⊕) on the two
words and count the number of 1s in the result.
Note that the Hamming distance is a value greater than or equal to zero.
8
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
widespread because their structure makes theoretical analysis and implementation difficult.
We therefore concentrate on linear block codes.
The formal definition of linear block codes requires the knowledge of abstract algebra
(particularly Galois fields), which is beyond the scope of this book. We therefore give an
informal definition.
For our purposes, a linear block code is a code in which the exclusive OR (addition modulo-
2) of two valid codewords creates another valid codeword.
Cyclic Code:
Cyclic codes are special linear block codes with one extra property.
In a cyclic code, if a codeword is cyclically shifted (rotated), the result is another codeword.
For example, if 1011000 is a codeword and we cyclically left-shift, then 0110001 is also a
codeword.
In this case, if we call the bits in the first word a0 to a6, and the bits in the second word b0 to
b6, we can shift the bits by using the following:
b1=a0 b2=a1 b3=a2 b4=a3 b5=a4 b6=a5 b0=a6
In the rightmost equation, the last bit of the first word is wrapped around and
becomes the first bit of the second word.
At receiver’s side:
Receives DATA + CRC bits.
Receiver also applying Division operation on the whole data by using CRC generator
then finally will get result.
If the result is Zeros, then receiver will believe that there is no corrupted bit in the
message that’s why receiver will accept the message.
Otherwise, will receiver will reject the message.
Example:
Data is 1010000 and CRC generator is x3+1, check if there is any error in the code word.
Solution:
Here CRC generator= 1(x3) +0(x2) +0(x1) +1(x0) = 1001
Now sender’s side whole data= 10100001001
9
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
Note: During XOR operation the most significant bit (MSB) should always be 1, if 0 is
present in that place erase it.
Polynomials:
A better way to understand cyclic codes and how they can be analysed is to represent them as
polynomials.
A pattern of 0s and 1s can be represented as a polynomial with coefficients of 0 and1.
The power of each term shows the position of the bit; the coefficient shows the value of the
bit.
Following diagram shows a binary pattern and its polynomial representation. In below
diagram(a) we show how to translate a binary pattern into a polynomial;
In below diagram(b) we show how the polynomial can be shortened by removing all terms
with zero coefficients and replacing x1 by x and x0 by 1.
Following diagram shows one immediate benefit; a 7-bit pattern can be replaced by three
terms.
The benefit is even more conspicuous when we have a polynomial such as
1
0
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
Degree of a Polynomial:
The degree of a polynomial is the highest power in the polynomial.
For example
The degree of the polynomial x6 + x + 1 is 6.
Note that the degree of a polynomial is 1 less than the number of bits in the pattern. The bit
pattern in this case has 7 bits.
In our analysis we want to find the criteria that must be imposed on the generator, g(x) to
detect the type of error we especially want to be detected. Let us first find the relationship
among the sent codeword, error, received codeword, and the generator. We can say
Received codeword 5 c(x) 1 e(x)
In other words, the received codeword is the sum of the sent codeword and the error.
The receiver divides the received codeword by g(x) to get the syndrome. We can write this as
Received Codword c (x) e(x )
g (x)
= +
g ( x ) g ( x)
The first term at the right-hand side of the equality has a remainder of zero
(According to the definition of codeword).
So, the syndrome is actually the remainder of the second term on the right-hand side.
If this term does not have a remainder (syndrome = 0), either e(x) is 0 or e(x) is divisible by
g(x).
We do not have to worry about the first case (there is no error); the second case is very
important.
Those errors that are divisible by g(x) are not caught.
Checksum:
1
1
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
Example:
1
2
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
Retransmission of corrupted and lost packets is not useful for real-time multimedia
transmission because it creates an unacceptable delay in reproducing:
we need to wait until the lost or corrupted packet is resent.
We need to correct the error or reproduce the packet immediately.
Several schemes have been designed and used in this case that are
collectively referred to as forward error correction (FEC) techniques.
Parity Bit:
Parity bit is an additional bit added to the data before transmitting the data.
There are two types:
1. Even Parity:
If the data bit has even number of 1’s, the parity bit is 0.
Example: M=1001, The Parity bit is 0.
If the data bit has odd number of 1’s, the parity bit is 1
Example: M=1101, The Parity bit is 1.
2. Odd Parity:
If the data bit has odd number of 1’s, the parity bit is 0.
Example: M=1101, The Parity bit is 0.
If the data bit has even number of 1’s, the parity bit is 1.
Example: M=1001, The Parity bit is 1.
1
3
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
Bit Designation P1 P2 M1 P3 M2 M3 M4
Bit Position 1 2 3 4 5 6 7
Binary Position 001 010 011 100 101 110 111
Message Bits 1 1 0 1
Parity Bits 1 0 0
Let us assume the even parity hamming code from the above example (1010101) is
transmitted and the received code is (1000101). Now from the received code, let us detect
and correct the error.
Bit Position 1 2 3 4 5 6 7
Bit Designation P1 P2 M1 P3 M2 M3 M4
Binary Position 001 010 011 100 101 110 111
Received Code 1 0 0 0 1 0 1
1
4
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
P2 checks 2,3,6,7
0,0,0,1 Here we have odd number of 1’s.
Therefore, it is a Bad Parity 1
P3 checks 4,5,6,7
0,1,0,1 Here we have even number of 1’s.
Therefore, it is a Good Parity 0
When there is error in data, we will get bad parities, otherwise we will not get bad parities.
If there are no bad parities in received data, then the received data is correct.
Using XOR:
Another recommendation is to use the property of the exclusive OR operation as shown
below.
In other words, if we apply the exclusive OR operation on N data items (P1 to PN), we can
recreate any of the data items by exclusive-ORing all of the items, replacing the one to be
created by the result of the previous operation (R).
This means that we can divide a packet into N chunks, create the exclusive OR of all the
chunks and send N + 1 chunks.
If any chunk is lost or corrupted, it can be created at the receiver site.
Now the question is what should the value of N be.
If N = 4, it means that we need to send 25 percent extra data and be able to correct the data if
only one out of four chunks is lost.
Chunk Interleaving:
Another way to achieve Forward Error Correction in multimedia is to allow some small
chunks to be missing at the receiver.
We cannot afford to let all the chunks belonging to the same packet be missing; however, we
can afford to let one chunk be missing in each packet.
Following diagram shows that we can divide each packet into 5 chunks (normally the number
is much larger).
We can then create data chunk by chunk (horizontally), but combine the chunks into packets
vertically.
In this case, each packet sent carries a chunk from several original packets. If the packet is
lost, we miss only one chunk in each packet, which is normally acceptable in multimedia
communication.
1
5
COMPUTER NETWORKS JSS COLLEGE OF ARTS, COMMERCE AND SCIENCE
1
6