You are on page 1of 14

KCS603: Computer Networks

Unit-02
Link Layer
Instructor: Md. Shahid
Syllabus: Framing, Error Detection and correction, Flow
control ( Elementary Data Link protocols, sliding windows
protocols). Medium access control and LAN: Channel
allocation, Multiple access protocols, LAN standards, Link
layer switches and bridges (learning bridge and spanning
tree algorithms).

Data link layer (Layer-2)

The data link layer is responsible for moving “frames” from one node (hop) to
the next.

“Once the data link layer (L2 layer) has constructed the frames, it passes them
down to the physical layer (L1 layer) for transmission. The physical layer then takes
the frames and converts them into a stream of bits that can be transmitted over
the physical network medium ( i.e. ethernet cables ).”

Note— The data link layer plays an important role in ensuring that data is
transmitted efficiently and reliably across a network, providing necessary services
to the network layer.
The data link layer is also concerned with the following:

1. Framing
2. Error control
3. Flow control
4. Access control
5. Physical addressing

Two Sub Layers of DLL

1) The logical link control (LLC) sublayer


2) The medium access control (MAC) sublayer

Functions of LLC Sublayer:


1. Error control
2. Flow control

Functions of MAC Layer


3. Access control
4. Error control
5. Framing
6. Physical addressing
Framing [ Layer-2 function]
Taking the packets from the L3 Layer and putting them into frames before
sending them is called framing, which is the primary function of DLL.

“The data link layer (DLL) takes packets from the network layer (layer 3) and
encapsulates them into frames, which are then transmitted over the physical
medium using the physical layer. The framing process involves adding a
header and trailer to the packet, which includes control information and
error detection/correction codes, respectively. This allows the data link layer
to control the flow of data between the devices and detect errors that may
occur during transmission. Framing is a fundamental function of the data link
layer and is essential for providing reliable communication over a physical
link.”

While framing is an essential function of the data link layer, there are
several problems that can arise if framing is not done correctly:

Frame synchronization: One of the main problems with framing at the data
link layer is frame synchronization. The receiver must be able to identify the
start and end of each frame, but this can be difficult if there is noise or
interference on the transmission line. If the receiver is unable to synchronize
with the frame boundaries, it may misinterpret the data, resulting in errors or
loss of data.

Overhead: Framing requires the addition of header and trailer information


to each frame, which increases the overall size of the transmitted data. This
overhead can be a significant problem in low-bandwidth networks where
every bit counts.

Fragmentation and reassembly: When data is transmitted over the


network, it may need to be broken into smaller frames to fit within the
maximum frame size allowed by the network. This fragmentation and
reassembly process can add complexity to the data link layer and may lead
to additional overhead and processing time.

Security: Frames can be vulnerable to attacks such as eavesdropping,


tampering, and replay attacks. If framing is not done securely, these attacks
can compromise the integrity and confidentiality of the transmitted data.

Fixed-size: The first type of frames is of fixed size. There is no requirement to give boundaries
to any frame because frame length behaves as a delimiter itself.

Variable Size : Variable size frames can have different sizes.


A. Length field: In a frame, we can define the length field to show the length
of a frame. It is applied in the Ethernet LAN (802.3). The issue with it is that
the length field may get corrupted sometimes.
B. ED (End Delimiter): In a frame, we can add an end delimiter to show the
completion of a frame. It is applied in the Token Ring LAN (802.5). The
issue with it is that the end delimiter can appear in the data.
I. Bit Stuffing: An arrangement of bits of random length can be
stuffed in a message for differentiating through the delimiter. Also, it
is known as bit-oriented framing.
II. Byte Stuffing: The bytes are stuffed in a message for differentiating
through the delimiter. Also, it is known as character-oriented
framing.

Note— In the upcoming lectures, you will have the opportunity to understand all the
fields of frame formats used in Ethernet LAN and Token Ring LAN.

Physical Addressing [ Layer-2 function ]


The concept of a physical address is that it should be unique within a network. This
means that two different networks can have the same physical address without any
issue. In a TCP/IP network, the MAC address is used as the physical address.

A Media Access Control (MAC) address is a unique identifier assigned to the


network interface controller (NIC) of a device, such as a computer, router, or
network switch (L3 switch).

Every network interface card has a unique MAC address assigned by the
manufacturer, and this address is used to identify the device on the network. MAC
addresses are typically 48 bits long and are expressed as a sequence of six pairs
of hexadecimal digits, such as "0b:1a:32b:3c:4d:5e".
Note— AppleTalk network does not use MAC addresses as physical addresses.
Instead, AppleTalk uses a unique network address called a "node ID" to identify
devices on the network. The AppleTalk protocol suite was widely used in the 1980s
and 1990s, but has since been largely replaced by TCP/IP on most networks.

Types of MAC
1. Unicast MAC address [ LSB of the first byte is “0” ]
2. Multicast MAC address [ LSB of the first byte is “1” ]
3. Broadcast MAC address [ All 1s ]
Example of unicast MAC address: 1A: 2B: 4C: AA: 3D: 2F [ six pairs of
hexadecimal digits]
binary equivalent

0001 101 0

LSB is “0”
Example of multicast MAC address: 13: 2B: 4C: AA: 3D: 2F [ six pairs of
hexadecimal digits]
binary equivalent

0001 001 1

LSB is “1”
Example of broadcast MAC address: FF: FF: FF: FF: FF: FF [ six pairs of hexadecimal
digits]
binary equivalent

11111111: 11111111:11111111:11111111:11111111:11111111:11111111:11111111

All 1s
Error handling
1. Error at the level of packet(s)
2. Error at the level of bit(s)

Error at the level of packet(s) -


We have different methods to handle the packet lost ( for example,
acknowledgment).

Error at the level of bit(s) -


An error is a situation when the message received at the receiver end is not
identical to the message transmitted.
Having received a packet, we can either have a single bit error or multiple bits
(burst) error.

Single-Bit Error:
The only one bit of a given data unit is changed from 1 to 0 or from 0 to 1.

In the above figure, the message which is sent is corrupted as single-bit, i.e., 0 bit is
changed to 1.

45.6M
913

Single-Bit Error mainly occurs in Parallel Data Transmission. For example, if eight wires are
used to send the eight bits of a byte, if one of the wires is noisy, then single-bit is
corrupted per byte.
Burst Error:
The two or more bits are changed from 0 to 1 or from 1 to 0 is known as Burst Error.

The Burst Error is determined from the first corrupted bit to the last corrupted bit.

The duration of noise (undesirable bits) in Burst Error is more than the duration of noise
in Single-Bit.

Burst Errors are most likely to occur in Serial Data Transmission.

The number of affected bits depends on the duration of the noise and data rate.

We have two types of bit(s) error handling techniques:


1. Error detection (Retransmission is required)
2. Error correction ( Retransmission is not required)

Error Detecting Techniques


The most popular error detecting techniques are:

1. Parity check
2. Checksums
3. Cyclic redundancy checks (CRCs)
1. Parity check – A simple parity-check code can detect an odd number of
errors.

Dataword = 0111 [ actual data ]

Codeword = Dataword + even/odd parity bit [ For even, no. of 1s is even.]

Codeword = 01111 [ “1” is appended to make no. of 1s even in the codeword.]

Now, sender sends the codeword which may be corrupted during transmission. The
receiver receives a 5-bit word. The checker at the receiver does the same thing as the
generator in the sender with one exception. The operation is done over all 5 bits. The
result, which is called syndrome, is just 1 bit. The syndrome is 0 when the number of 1s in
the received codeword is even; otherwise, it is 1.

2. Checksums —
Given
Dataword = 0001001100101- and 4-bit checksum generator. Calculate codeword.

Solution— 0001 1001 1100 1011 <= Make dataword into groups having 4 bits each.

Sum all 4 groups ( 1+ 9+12+ 11 = 33 ) and send it ( after making it negative) with
dataword to the sender.

Codeword = 33 + (-33)

At the receiver site, the checker just sums them to get 0 if no error.

Note— A 16-bit checksum is used in IP, TCP and UDP headers.


Cyclic Redundancy Check (CRC) Error Detection Scheme

Note— CRC is used in Ethernet and Token ring frames. Ethernet and Token ring
are two different LAN technologies.

Question. Given the dataword 1010011010 and the divisor 10111.


a. Show the generation of the codeword at the sender site.
b. Show the checking of the codeword at the receiver site (assume no error).

Algorithm
1. If the length of divisor is k bits, append k-1 0s to the dataword.
2. Divide dataword till you get a CRC remainder containing a smaller number of
valid bits than divisor. Use XOR addition.
3. Send Codeword (dataword + CRC remainder) to the receiver
4. Receiver also performs division using the same devisor; if remainder is 0, no
error.
Error correction ( Retransmission is not required)
[ Error is detected and then corrected]
(Hamming code algorithm)

Note –1 To detect or correct errors, we need to send extra (redundant) bits with data.
Note --2 Hamming code is not used in computer networks owing to huge redundant bits
(almost 50% of the dataword).
Note –3 Hamming codes are widely used in various applications where reliable
and accurate data transmission is essential.

Algorithm of Hamming code:


o An information of 'd' bits is added to the redundant bits 'r' to form d + r.
o The location of each of the (d + r) digits is assigned a decimal value.
o The 'r' bits are placed in the positions 20, 21 ,. . . , 2k-1.
o At the receiving end, the parity bits are recalculated. The decimal value of the parity bits
determines the position of an error.

Redundant bit “r” is calculated by using the formula:


2r >= d+r+1
Where, r= number of redundant bits
d= data bits

Parity bits: The bit which is added to the original data of binary bits so that the total
number of 1s is even or odd.

Example 01: Discuss error detection and correction using an


example.
3. Let dataword be 1101 (d=4)
4. 2r >= d+r+1 ( i.e., r =3)
5. We have 7 bits hamming code (4+3).
6. Calculate parity bits (r1, r2, r4).

The 'r' bits are placed in the positions 20, 21 ,. . . , 2k-1 .

Identify parity bits from the message bits

7 6 5 4 3 2 1
D7(1) D6(1) D5(0) R4 D3(1) R2 R1

Note -- Considering even parity ( number of 1 is made even )

R1= (R1 D3 D5 D7) [Check one bit and skip one bit]
We already know the values of D3, D5 and D7; therefore, now
calculate the value of R1 .
0 101 ( R1 = 0 as number of 1 is already even-2)

R2= ( R2 D3 D6 D7) [check the next two bits and skip the next two bits.]
1 111 (Make R2 = 1 as number of 1 is odd-3)

R4= ( R4 D5 D6 D7) [Check the next 4 bits and skip the next 4 bits ]
0 011 ( R4 = 0 as the number of 1 is already even.)
Sender will send (D+R) 1100110

But suppose noise is added and one bit is changed ( D6 becomes 0)


At receiver end: It will receive 1000110

It will calculate parity bits for even parity in the same way.

D7(1) D6(0) D5(0) R4(0) D3(1) R2(1) R1(0)

R1 = R1 D3 D5 D7 = 0101 [ R1=0]
R2 = R2 D3 D6 D7 = 1101 [R2= 1]
R4 = R4 D5 D6 D7= 0001 [ R4=1]

R4 R2 R1 = 110= (6)10
Therefore, 6th bit should be reversed to correct the error.

Note—This PDF just contains a few topics from the second unit that were covered
in the classroom.

You might also like