CN-Unit - 3 Notes - AR20 - REC
CN-Unit - 3 Notes - AR20 - REC
Unit -III
COURSE OBJECTIVES:
The objectives of studying of Computer Networks-Unit-3 are as follows
1. Understand the functioning of Data link layer in OSI Model.
COURSE OUTCOMES
Upon the completion of the Unit-3 the students will be able to:
1. Analyze protocols implemented in data link layer for error and flow
control
Framing
• Data link layer needs to pack bits into frames, so that each frame is distinguishable
from another
• Separate a message from one source to a destination, or from other messages to other
destinations, by adding a sender address and a destination address
• Variable-size framing
– Need a way to define the end of the frame and the beginning of the next
Character-Oriented Protocols
• Frame structure
1
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
Byte stuffing: process of adding 1 extra byte whenever there is a flag or escape character in
the text
Bit-Oriented Protocols
• Frame structure
Bit stuffing: process of adding one extra 0 whenever five consecutive 1s follow a 0 in the data
• Flow control refers to a set of procedures used to restrict the amount of data that the
sender can send before waiting for acknowledgement
• Error control in the data link layer is based on automatic repeat request (ARQ), which is
the retransmission of data
Type of Errors
• Single-bit error: 0 → 1 or 1 → 0
Single-Bit Error
Burst Error
• Burst error does not necessarily mean that the errors occur in consecutive bits
3
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• Number of bits affected depends on the data rate and duration of noise
Redundancy
• Error detection uses the concept of redundancy, which means adding extra (redundant)
bits for detecting errors at the destination
Error Control
– Correction: Need to know the exact number of bits that are corrupted, and
their location in the message
– Block coding:
– Convolution coding
4
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
Modular Arithmetic
• In modulo-N arithmetic, we use only the integers in the range 0 to N-1, inclusive.
Block Coding
• Add r redundant bits to each block to make the length n = k + r. The resulting n-bit
blocks are called codewords
– k = 4 and n = 5.
5
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• Example:
(Table 10.1)
• Assume the sender encodes the dataword 01 as 011 and sends it to the receiver.
Consider the following cases:
1. The receiver receives 011 which is a valid codeword. The receiver extracts the dataword 01
from it.
2. The codeword is corrupted during transmission, and 111 is received. This is not a valid
codeword and is discarded.
3. The codeword is corrupted during transmission, and 000 is received. This is a valid codeword.
The receiver incorrectly extracts the dataword 00. Two corrupted bits have made the error
undetectable.
→ An error-detecting code can detect only the types of errors for which it is designed;
other types of errors may remain undetected
6
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• Example:
n = 5 (Table 10.2)
• Assume the dataword is 01. The sender creates the codeword 01011. The codeword is
corrupted during transmission, and 01001 is received. First, the receiver finds that the
received codeword is not in the table. This means an error has occurred. The receiver,
assuming that there is only 1 bit corrupted, uses the following strategy to guess the
correct dataword
1. Comparing the received codeword with the first codeword in the table (01001 versus
00000), the receiver decides that the first codeword is not the one that was sent because there
are two different bits. (the same for third or fourth one in the table)
2.. The original codeword must be the second one in the table because this is the only one that
differs from the received codeword by 1 bit.
Hamming Distance
• The Hamming distance between two words is the number of differences between
corresponding bits.
7
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• The minimum Hamming distance is the smallest Hamming distance between all
possible pairs in a set of words
- dmin = 2
– Codeword size n
– Dataword size k
– Hamming distance between the received codeword and the sent codeword is
the number of bits that are corrupted
• The minimum Hamming distance in Table 10.1 is 2. This code guarantees detection of
only a single error.
For example, if the third codeword (101) is sent and one error occurs, the received
codeword does not match any valid codeword. If two errors occur, however, the received
codeword may match a valid codeword and the errors are not detected.
• In Table 10.2, it has dmin = 3. This code can detect up to two errors.
When any of the valid codewords is sent, two errors create a codeword which is not in the
table of valid codewords. The receiver cannot be fooled. However, some combinations of three
errors change a valid codeword to another valid codeword. The receiver accepts the received
codeword and the errors are undetected.
8
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
dmin = s + 1.
• Almost all block codes used today belong to a subset called linear block codes.
• A linear block code is a code in which the exclusive OR (addition modulo-2) of two
valid codewords creates another valid codeword
• The minimum Hamming distance is the number of 1s in the nonzero valid codeword with
the smallest number of 1s
9
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
10
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
11
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
Simplest Protocol
• Sender-site algorithm
• Receiver-site algorithm
12
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
Stop-and-Wait Protocol
• Sender-site algorithm
• Receiver-site algorithm
13
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• Error correction in Stop-and-Wait ARQ is done by keeping a copy of the sent frame
and retransmitting of the frame when the timer expires
• In Stop-and-Wait ARQ, we use sequence numbers to number the frames. The sequence
numbers are based on modulo-2 arithmetic
14
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• Sender-site algorithm
15
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• Receiver-site algorithm
16
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
Go-Back-N ARQ
• In the Go-Back-N Protocol, the sequence numbers are modulo 2m, where m is the size
of the sequence number field in bits
• The send window is an abstract concept defining an imaginary box of size 2m − 1 with
three variables: Sf, Sn, and Ssize
• The send window can slide one or more slots when a valid acknowledgment arrives.
17
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• The receive window is an abstract concept defining an imaginary box of size 1 with
one single variable Rn. The window slides when a correct frame has arrived; sliding
occurs one slot at a time.
18
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• In Go-Back-N ARQ, the size of the send window must be less than 2m; the size of the
receiver window is always 1
• Stop-and-Wait ARQ is a special case of Go-Back-N ARQ in which the size of the send
window is 1
19
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
20
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
21
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
22
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
23
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• The size of the sender and receiver window must be at most one-half of 2m
24
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
25
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
Piggybacking
26
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
Type of Errors
• Single-bit error: 0 → 1 or 1 → 0
Single-Bit Error
27
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
Burst Error
• Burst error does not necessarily mean that the errors occur in consecutive bits
• Number of bits affected depends on the data rate and duration of noise
Redundancy
• Error detection uses the concept of redundancy, which means adding extra (redundant)
bits for detecting errors at the destination
Error Control
28
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
– Correction: Need to know the exact number of bits that are corrupted, and
their location in the message
– Block coding
– Convolution coding
Modular Arithmetic
• In modulo-N arithmetic, we use only the integers in the range 0 to N-1, inclusive.
Block Coding
• Add r redundant bits to each block to make the length n = k + r. The resulting n-bit
blocks are called codewords
– k = 4 and n = 5.
29
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• Example:
(Table 10.1)
• Assume the sender encodes the dataword 01 as 011 and sends it to the receiver.
Consider the following cases:
1. The receiver receives 011 which is a valid codeword. The receiver extracts the dataword 01
from it.
2. The codeword is corrupted during transmission, and 111 is received. This is not a valid
codeword and is discarded.
3. The codeword is corrupted during transmission, and 000 is received. This is a valid codeword.
The receiver incorrectly extracts the dataword 00. Two corrupted bits have made the error
undetectable.
→ An error-detecting code can detect only the types of errors for which it is designed;
other types of errors may remain undetected
30
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• Example:
n = 5 (Table 10.2)
• Assume the dataword is 01. The sender creates the codeword 01011. The codeword is
corrupted during transmission, and 01001 is received. First, the receiver finds that the
received codeword is not in the table. This means an error has occurred. The receiver,
assuming that there is only 1 bit corrupted, uses the following strategy to guess the
correct dataword
1. Comparing the received codeword with the first codeword in the table (01001 versus
00000), the receiver decides that the first codeword is not the one that was sent because there
are two different bits. (the same for third or fourth one in the table)
2.. The original codeword must be the second one in the table because this is the only one that
differs from the received codeword by 1 bit.
Hamming Distance
• The Hamming distance between two words is the number of differences between
corresponding bits.
31
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• The minimum Hamming distance is the smallest Hamming distance between all
possible pairs in a set of words
- dmin = 2
– Codeword size n
– Dataword size k
– Hamming distance between the received codeword and the sent codeword is
the number of bits that are corrupted
• The minimum Hamming distance in Table 10.1 is 2. This code guarantees detection of
only a single error.
For example, if the third codeword (101) is sent and one error occurs, the received
codeword does not match any valid codeword. If two errors occur, however, the received
codeword may match a valid codeword and the errors are not detected.
• In Table 10.2, it has dmin = 3. This code can detect up to two errors.
When any of the valid codewords is sent, two errors create a codeword which is not in the
table of valid codewords. The receiver cannot be fooled. However, some combinations of three
errors change a valid codeword to another valid codeword. The receiver accepts the received
codeword and the errors are undetected.
• Almost all block codes used today belong to a subset called linear block codes.
32
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• A linear block code is a code in which the exclusive OR (addition modulo-2) of two
valid codewords creates another valid codeword
• The minimum Hamming distance is the number of 1s in the nonzero valid codeword with
the smallest number of 1s
33
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
34
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
Hamming Code
• r0 = a2 + a1 + a0 modulo-2
• r1 = a3 + a2 + a1 modulo-2
• r2 = a1 + a0 + a3 modulo-2
• s0 = b2 + b1 + b0 + q0 modulo-2
• s1 = b3 + b2 + b1 + q1 modulo-2
• s2 = b1 + b0 + b3 + q2 modulo-2
35
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• Let us trace the path of three datawords from the sender to the destination:
1 The dataword 0100 becomes the codeword 0100011. The codeword 0100011 is received.
The syndrome is 000, the final dataword is 0100.
2. The dataword 0111 becomes the codeword 0111001. The codeword 0011001 received. The
syndrome is 011. After flipping b2 (changing the 1 to 0), the final dataword is 0111.
3. The dataword 1101 becomes the codeword 1101000. The codeword 0001000 received (two
errors). The syndrome is 101. After flipping b0, we get 0000, the wrong dataword. This shows
that our code cannot correct two errors.
• Cyclic codes are special linear block codes with one extra property.
36
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
37
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
Polynomials
Polynomial Operation
(x5 + x3 + x2 + x) (x2 + x1 + 1)
= x7 + x6 + x5 +x5 + x4 + x3 + x4 + x3 + x2 + x3 + x2 + x
38
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
= x7 + x6 + x3 + x
• Shifting
The divisor in a cyclic code is normally called the generator polynomial or simply the
generator.
In a cyclic code,
2. If s(x) = 0, either
a. No bit is corrupted. Or
b. Some bits are corrupted, but the decoder failed to detect them
39
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
In a cyclic code, those e(x) errors that are divisible by g(x) are not caught
Error Detection
• Single-bit error
If the generator has more than one term and the coefficient of x0 is 1, all single errors
can be caught.
If a generator cannot divide xt + 1 (t between 0 and n – 1), then all isolated double
errors can be detected
Example 1
• Which of the following g(x) values guarantees that a single-bit error is caught? For
each case, what is the error that cannot be caught?
a. x + 1 b. x3 c. 1
Solution
c. All values of i make xi divisible by g(x). No single-bit error can be caught. This g(x) is useless.
Example 2
• Find the status of the following generators related to two isolated, single-bit errors.
a. x + 1 b. x4 + 1 c. x7 + x 6+ 1 d. x15 + x14 + 1
Solution
a. This is a very poor choice for a generator. Any two errors next to each other cannot be
detected.
b. This generator cannot detect two errors that are four positions apart.
40
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
d. This polynomial cannot divide xt + 1 if t is less than 32,768. A codeword with two isolated
errors up to 32,768 bits apart can be detected by this generator..
Error Detection
• Burst errors
1 – (1/2)r–1.
1 – (1/2)r.
Checksum
41
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
– If the number has more than n bits, the extra leftmost bits need to be added to
the n rightmost bits (wrapping)
Checksum: Example
• The sender initializes the checksum to 0 and adds all data items and the checksum.
However, 36 cannot be expressed in 4 bits. The extra two bits are wrapped and
added with the sum to create the wrapped sum value 6. The sum is then
complemented, resulting in the checksum value 9 (15 − 6 = 9).
Internet Checksum
Sender site:
3. All words including the checksum are added using one’s complement
addition.
42
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
Receiver site:
rejected.
HDLC
Two common transfer mode: normal response mode (NRM) and asynchronous balanced mode
(ABM)
43
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
HDLC: Frames
• Control Field: 1- or 2-byte segment of the frame used for flow and error control
• Determine the type of frame and define its functionality
• Control field for I-frame: P/F (poll/final bit for primary/secondary)
44
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
HDLC: Example 1
45
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
46
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• Many Internet users who need to connect their home computer to the server of an
Internet service provider use PPP
• A point-to-point link protocol is required to control and manage the transfer of data
47
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
• PPP defines/provides
– how two devices negotiate the establishment of the link and the exchange of
data
– how network layer data are encapsulated in the data link frame
PPP Frame
Flag: 01111110 the same as HDLC, but it treated as a byte because of PPP is a byte-
oriented protocol
Control: No need because PPP has no flow control and limited error control
PPP is a byte-oriented protocol using byte stuffing with the escape byte 01111101
48
Dr.P.M.Manohar, Dept.of CSE, Raghu Engineering College(A), Visakhapatnam,
Computer Networks – Unit 3 – Data Link Layer
PPP: Multiplexing
• PPP uses another set of other protocols to establish the link, authenticate the parties,
and carry the network layer data
• Three sets of protocols defined for powerful PPP: LCP, two APs, several NCPs
49