You are on page 1of 48

Unit-II Chapter-I

Data Link Layer and Medium Access


Sub Layer

1
Unit – 2 - SYLLABUS
• Data Link Layer and Medium Access Control Sub Layer:
• Error Detection and Error Correction :
• Fundamentals, Block coding,
• Hamming Distance, CRC

• Flow Control and Error Control Protocols:


• Stop and Wait,
• Stop and Wait ARQ
• Go Back-N ARQ,
• Selective Repeat ARQ,
• Sliding Window,
• Piggybacking
• Multiple Access Protocols:
• Pure ALOHA, Slotted ALOHA
• CSMA/CD, CSMA/CA 2
Data Link Layer

●Error Detection and Correction

3
Data Link Layer
● Functions: The Data Link layer is concerned with the
following:
● Framing: Breaking input data into frames (typically a few
hundred bytes) and caring about the frame boundaries and the
size of each frame.
● Physical addressing, each node has its unique address.
● Flow Control: Necessary for a fast transmitter to keep pace with
a slow receiver.
● Error control, normally achieved through a trailer to the end of
the frame.
● Access Control: Determine which device has right to send data
in an multipoint connection.

4
Error: Introduction
● Networks must be able to transfer data from one device to another with
acceptable accuracy.
● For most applications, a system must guarantee that the data received are
identical to the data transmitted.
● Any time data are transmitted from one node to the next, they can become
corrupted in passage. Many factors can alter one or more bits of a message.
● Some applications require a mechanism for detecting and correcting errors.
● Errors in the data are basically caused due to the various impairments that occur
during the process of transmission.
● When there is an imperfect medium or environment in the transmission, then it
is prone to errors in the original data.
● Errors can be classified as follows:
● Attenuation ( w.r.t. Distance)
● Noise (Electro magnetic signal)
● Distortion (Interference)

5
Types of Errors
● An error occurs when a bit is altered between transmission and reception i.e 0 to
1 or 1 to 0
● If the signal comprises of binary data there can be two types of errors which are
possible during the transmission:
● 1. Single bit errors
● 2. Burst Errors
● Single bit errors: The term single-bit error means that 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.

● Burst Errors: The term burst error means that 2 or more bits in the data unit
have changed from 1 to 0 or from 0 to 1.

6
Redundancy
●To detect or correct errors, we need to send extra
(redundant) bits with 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.

7
Detection Vs Correction
● The correction of errors is more difficult than the detection.
● In error detection, we are looking only to see if any error has
occurred.
● Not interested in the number of errors. A single-bit error is the
same for us as a burst error.
● In error correction, we need to know the exact number of bits
that are corrupted and more importantly, their location in the
message.
● The number of the errors and the size of the message are
important factors.

8
Block Coding
● In block coding, we divide our message into blocks, each of k bits,
called datawords. We add r redundant bits to each block to make the
length n = k + r. The resulting n-bit blocks are called codewords.
● With k bits, we can create a combination of 2k datawords; with n bits, we can
create a combination of 2n codewords.
● Since n > k, the number of possible codewords is larger than the number of
possible datawords.
● The block coding process is one-to-one; the same dataword 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.

9
Error Detection
• Error detection is performed by calculating an error-detecting
code(redundant code) that is a function of the bits being
transmitted.
• The code is appended to the transmitted bits
• The receiver calculates the error-detecting code based on the
incoming bits and compares it to the incoming (received) error-
detecting code to check for errors.
• A detected error occurs if and only if there is a mismatch between
the received and calculated error-detecting code.
• But still there is a chance of undetected error i.e. residual error rate
● There are different techniques used for error detection.
● 1) Parity Check
● 2) Cyclic Redundancy check
● 3) Checksum 10
Error Detection-Parity Check
Parity Check:
● Perhaps the most familiar error-detecting code is the simple parity-check code.
● In this code, a k-bit dataword is changed to an n-bit codeword where n = k + 1.
The extra bit, called the parity bit, is selected to make the total number of 1’s in
the codeword even (or Odd in some cases).
● It is a single-bit error-detecting code. It cannot correct any error.
● Simple parity check can detect all single-bit errors. It can also detect burst errors
as long as the total number of bits changed is odd. This method cannot detect
errors where the total number of bits changed is even.

11
Error Detection-Parity Check(Example)
● Ex: Let us assume that k = 2 and n = 3. Assume the
sender encodes the dataword 01 as 011 and sends it to the
receiver. Consider the following cases:
● 1. The receiver receives 011. It 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.
12
Error

Detection-Parity Check(Process)
The encoder uses a generator that takes a
copy of a 4-bit dataword (a0, a1, a2 and a3)
and generates a parity bit r0.
●The dataword bits and the parity bit create
the 5-bit codeword.
●The parity bit that is added makes the
number of 1’s in the codeword even.
●This is normally done by adding the 4 bits
of the dataword (modulo-2); the result is the
parity bit. In other words, r0= a3 + a2 + a1 +
a0) (modulo-2)
●If the number of 1’s is even, the result is 0;
if the number of 1’s is odd, the result is 1.
●In both cases, the total number of 1’s in the
codeword is even.
●The sender sends the codeword which may
be corrupted during transmission.

13
Error

Detection-Parity Check(Process)
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 addition is done over
all 5 bits. The result, which is called the
syndrome, is just 1 bit. The syndrome is 0
when the number of 1’s in the received
codeword is even; otherwise, it is 1.
●s0=b3+b2+b1+b0+r0 (modulo-2)
● The syndrome is passed to the decision
logic analyzer. If the syndrome is 0, there
is
●no error in the received codeword; the
data portion of the received codeword is
accepted as the dataword;
●if the syndrome is 1, the data portion of
the received codeword is discarded. The
dataword is not created.
14
Error Detection-Parity Check(Example)
● Assume the sender sends the dataword 1011.
● The codeword created from this dataword is 10111, which is sent to the
receiver. We examine five cases:
● 1.No error occurs; the received codeword is 10111. The syndrome is 0. The
dataword 1011 is created.
● 2.One single-bit error changes a1. The received codeword is 10011. The
syndrome is 1. No dataword is created.
● 3. One single-bit error changes r0 . The received codeword is 10110. The
syndrome is 1. No dataword is created.
● 4. An error changes r0 and a second error changes a3 .The received codeword
is 00110. The syndrome is 0.The dataword 0011 is created at the receiver.
Note that here the dataword is wrongly created due to the syndrome value.
● 5. Three bits—a3, a2, and a1—are changed by errors. The received codeword
is 01011. The syndrome is 1. The dataword is not created. This shows that
the simple parity check, guaranteed to detect one single error, can also find
any odd number of errors.
15
Error Detection-Parity Check(Example)
● A better approach is the two-dimensional parity check.
● In this method, the dataword is organized in a table (rows and columns). The data
to be sent, five 7-bit bytes, are put in separate rows. For each row and each
column, 1 parity-check bit is calculated.
● The whole table is then sent to the receiver, which finds the syndrome for each
row and each column. The two-dimensional parity check can detect up to three
errors that occur anywhere in the table (arrows point to the locations of the
created nonzero syndromes). However, errors affecting 4 bits may not be detected.

16
Error Detection-Parity Check(Exercise)
●Ex: Assuming even parity, find the parity bit for each of
the following data units.
●a. 1001011
●b. 0001100
●c. 1000000
●d. 1110111

17
Error Detection (Cyclic Redundancy check)
● Cyclic Redundancy check(CRC):
● It is the most powerful of the redundancy
checking techniques.
● This method is based on the binary division.
● The desired sequence of redundant bits are
generated and is appended to the end of
data unit(dataword). It is also called as CRC
remainder. So that the resulting data
unit(codeword) becomes exactly divisible
by a predetermined binary number.
• Receiver divides the received data unit
(codeword) by the same binary number
• if no remainder, assume no error
• Else error
● To be valid, a CRC must have few qualities: It must
have exactly one less bit than the divisor, and
appending it to the end of the data string must make
the resulting bit sequence exactly divisible by the
divisor. 18
Error Detection (CRC Process)
● CRC Encoder and Decoder example:
● In the encoder, the dataword has k bits (consider 4 here); the codeword has n bits (consider
7 here).
● The size of the dataword is augmented by adding n - k (3 here) 0s to the right-hand side of
the word. The n-bit result is fed into the generator. The generator uses a divisor of size n -
k + 1 (4 here), predefined and agreed upon. (The algebraic polynomial chosen as a CRC
generator should have at least the following properties)
● It should not be divisible by x.(This condition guarantees that all the burst errors of length equal to
the length of polynomial are detected.)
● It should be divisible by x+1.(This condition guarantees that all the burst errors affecting an odd
number of bits are detected.)
● The generator divides the augmented dataword by the divisor (modulo-2 division). The
quotient of the division is discarded; the remainder (r2r1 r0) is appended to the dataword to
create the codeword.
● The decoder receives the possibly corrupted codeword. A copy of all n bits is fed to the
checker which is a replica of the generator. The remainder produced by the checker is a
syndrome of n - k (3 here) bits, which is fed to the decision logic analyzer. The analyzer
has a simple function.
● If the syndrome bits are all 0s, the 4 leftmost bits of the codeword are accepted as the
19
dataword (interpreted as no error); otherwise, the 4 bits are discarded (error) .
Error Detection (CRC Process)

20
Error Detection: CRC( Sender Side Encoding)
• CRC generator does the binary division process.
• Given k bits(4 here) data, n-k+1 bits (4 here)
divisor(which is based on the generator
polynomial).
• n-k (3 here) bits whose value is all 0’s are appended
to the right of the data to form n bits(7 here).
• This sequence of bits is divided using Modulo2 by
the divisor.
• During division if leftmost bit of the remainder
becomes zero, then n-k+1 zero bits are used instead
of the original divisor as shown.
• On completion of the division process, we get
remainder. This is appended to the right of the
original k data bits.
• Then the k data + n-k CRC bits are sent to the
receiver.
• On receiving n bits the receiver divides it using the
same n-k+1 bit divisor (using Modulo2 arithmetic).
• If the final remainder comes Zero, data is accepted
as with no error, else rejected as error is detected. 21
Error Detection: CRC( Receiver Side Decoding)
● The decoder does the same
division process as the
encoder.
● The remainder of the division
is the syndrome.
● On receiving n bits the
receiver divides it using the
same n-k+1 bit divisor (using
Modulo2 arithmetic).
● If the syndrome is all Zeros,
dataword is separated from
the received codeword and
accepted as with no error,
else rejected as error is
detected. 22
Error Detection: CRC( Standard Polynomials)
● It is most often represented
not as a string of 1s and 0s,
but as an algebraic
polynomial.

23
Error Detection: CRC( Example)
● Ex: Compute 8-bit CRC for an 8-bit message: ‘W’.
● Sol: ASCII for ‘W’: 8710 = 5716
● Select Generator: CRC-8-ATM
● Polynomial: x8 + x2 + x + 1.
● Corresponds to: 100000111
● Two different orders are possible for the message.
● Msbit-first: 010101112 = x6 + x4 + x2 + x + 1
● Lsbit-first: 111010102 = x7 + x6 + x5 + x3 + x
● We will focus on Msbit-first order.
● Append 8(0s) bits to message: 0101011100000000.
● Perform long-division of message by generator.
● Quotient is not needed.
● Instead of subtraction perform simple XOR.
● CRC code is the remainder. 24
Error Detection: CRC( Example- contd…)
● 100000111) 0101011100000000
100000111
001011011000000
100000111
0011010110000
100000111
01010101100
100000111
0010100010

CRC Code: 10100010


25
Error Detection-CRC (Performance)
●Performance:
●CRC is a very effective error detection method.
●If the divisor is chosen according to the previously
mentioned rules
●CRC can detect all burst errors that affect an odd number
of bits.
●CRC can detect all burst errors of length less than or equal
to the degree of the polynomial
●CRC can detect, with a very high probability, burst errors
of length greater than the degree of the polynomial.

26
Error Detection-CRC (Exercise)
●Ex: Let g(x)=x3+x+1. Consider the information sequence
1001.
●a) Find the codeword corresponding to the preceding
information sequence.
●b) Suppose that the codeword has a transmission error in
the first bit. What does the receiver obtain (syndrome)
when it does its error checking?

27
Error Detection-Checksum
Checksum:
●A checksum is fixed length data that is
the result of performing certain
operations on the data to be sent from
sender to the receiver.
●The sender runs the appropriate
checksum algorithm to compute the
checksum of the data, appends it as a
field in the packet that contains the data
to be sent, as well as various headers.
●When the receiver receives the data, the
receiver runs the same checksum
algorithm to compute a fresh checksum.
The receiver compares this freshly
computed checksum with the
checksum that was computed by the
sender.
●If the two checksum matches, the
receiver of the data is assured that the
28
data has not changed during the transit.
Error Detection-Checksum
Checksum(Basic Idea):
● Suppose our data is a list of five 4-bit numbers that we want to send to a
destination.
● In addition to sending these numbers, we send the sum of the numbers.
● For example, if the set of numbers is (7,11,12,0,6), we send
(7,11,12,0,6,36), where 36 is the sum of the original numbers.
● The receiver adds the five numbers and compares the result with the
sum.
● If the two are the same, the receiver assumes no error, accepts the five
numbers, and discards the sum. Otherwise, there is an error somewhere
and the data are not accepted.
● Another way: We can make the job of the receiver easier if we send the
negative (complement) of the sum, called the checksum. In this case, we
send (7, 11, 12,0,6, -36). The receiver can add all the numbers received
(including the checksum). If the result is 0, it assumes no error;
otherwise, there is an error. 29
Error Detection-Checksum
Checksum(One's Complement):
● The previous example has one major drawback. All of our data can be written as a 4-bit
word (they are less than 15) except for the checksum.
● One solution is to use one's complement arithmetic. In this arithmetic, we can represent
unsigned numbers between 0 and 2n - 1 using only n bits. If the number has more than n
bits, the extra leftmost bits need to be added to the n rightmost bits (wrapping).
● In one's complement arithmetic, a negative number can be represented by inverting all
bits (changing a 0 to a 1 and a 1 to a 0). This is the same as subtracting the number from
2n - 1.
● Ex: How can we represent the number 21 in one's complement arithmetic using only
four bits?
● Sol: The number 21 in binary is 10101 (it needs five bits). We can wrap the leftmost bit
and add it to the four rightmost bits. We have (0101 + 1) = 0110 or 6.
● Ex: How can we represent the number -6 in one's complement arithmetic using only
four bits?
● Sol: In one's complement arithmetic, the negative or complement of a number is found
by inverting all bits. Positive 6 is 0110; negative 6 is 100I. If we consider only unsigned
numbers, this is 9. In other words, the complement of 6 is 9. Another way to find the
complement of a number in one's complement arithmetic is to subtract the number from 30
n
Error Detection-Checksum
● Checksum(One's Complement): Same Ex
●The sender initializes the checksum to 0 and adds
all data items and the checksum (the checksum is
considered as one data item and is shown in
color). The result is 36.
●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). The sender now
sends six data items to the receiver including the
checksum 9.
● The receiver follows the same procedure as the
sender. It adds all data items (including the
checksum); the result is 45. The sum is wrapped
and becomes 15.
●The wrapped sum is complemented and becomes
0.
●Since the value of the checksum is 0, this means
that the data is not corrupted. The receiver drops
the checksum and keeps the other data items. If the 31
Error Detection-Checksum
Internet Checksum
● Traditionally, the Internet has been using a
16-bit checksum.
● Sender site:
1. The message is divided into 16-bit words.
2. The value of the checksum word is set to 0.
3. All words including the checksum are added
using one's complement addition.
4. The sum is complemented and becomes the
checksum.
5. The checksum is sent with the data.
● Receiver site:
1. The message (including checksum) is
divided into 16-bit words.
2. All words are added using one's complement
addition.
3. The sum is complemented and becomes the
new checksum.
4. If the value of checksum is 0, the message is 32
Error Detection-Checksum- Example
● Ex: Sender wants to
send 4 frames each of
8 bits, where the
frames are 11001100,
10101010, 11110000
and 11000011.
● The bits are added
using 1s complement
arithmetic. While
adding two numbers
using 1’s complement
arithmetic, if there is a
carry over, it is added
to the sum.

33
Error Detection-Checksum- Another Example
● Ex: Calculate the checksum for a text of 8 characters (“Forouzan”).
● Sol: The text needs to be divided into 2-byte (16-bit) words. Use ASCII
to change each byte to a 2-digit hexadecimal number.
● For example, F is represented as 0x46 and o is represented as 0x6F. In
part a of the figure, the value of partial sum for the first column is 0x36.
We keep the rightmost digit (6) and insert the leftmost digit (3) as the
carry in the second column. The process is repeated for each column.
● Note that if there is any corruption, the checksum recalculated by the
receiver is not all 0s..

34
35
Error Detection-Checksum- Performance
● The traditional checksum uses a small number of bits (16) to detect
errors in a message of any size (sometimes thousands of bits).
● However, it is not as strong as the CRC in error-checking capability.
● The checksum detects all errors involving an odd number of bits.
● It detects most errors involving an even number of bits.
● If one or more bits of a segment are damaged and the corresponding
bit or bits of opposite value in a second segment are also damaged,
the sums of those columns will not change and the receiver will not
detect a problem.
● For example, if the value of one word is incremented and the value
of another word is decremented by the same amount, the two errors
cannot be detected because the sum and checksum remain the same.

36
Error Detection-Checksum- Exercise
Ex: A sender needs to send the four data items 0x3456,
0xABCC, 0x02BC, and 0xEEEE. Answer the following:
●a. Find the checksum at the sender site.
●b. Find the checksum at the receiver site if there is no error.
●c. Find the checksum at the receiver site if the second data
item is changed to 0xABCE.
●d. Find the checksum at the receiver site if the second data
item is changed to 0xABCE and the third data item is
changed to 0x02BA.

37
Error Detection-Checksum- Exercise

38
Error Detection-Checksum- Exercise
Ex: A sender needs to send the two data items
1001001110010011 and 1001100001001101. Find the
checksum value.

39
Error Correction
● Error correction is much more difficult than error detection.
● In error detection, the receiver needs to know only that the received
codeword is invalid; in error correction the receiver needs to find (or
guess) the original codeword sent.
● We need more redundant bits for error correction than for error
detection.
● The idea is the same as error detection but the checker functions are
much more complex.

40
Error Correction- Example
● Ex: Let us assume that k = 2 and n = 3. Table shows
the list of datawords and codewords.
● Let us add more redundant bits to see if the receiver
can correct an error without knowing what was
actually sent.
● We add 3 redundant bits to the 2-bit dataword to
make 5-bit codewords. Table2 shows the datawords
and codewords.
● 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 41
Error Correction-Example contd…
●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.
●2. By the same reasoning, the original codeword
cannot be the third or fourth one in the table.
●3. 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. The
receiver replaces 01001 with 01011 and consults
the table to find the dataword 01.

42
Hamming distance
●The Hamming distance between two words is the number
of differences between corresponding bits.
● Hamming Distance is the number of bit flips needed to change D1 to
D2
● Hamming distance between two words x and y is shown as d(x, y).
● The Hamming distance can easily be found if we apply the XOR
operation on the two words and count the number of 1’s in the result.
● Ex: The Hamming distance d(000, 011) is 2 because

● Ex2: The Hamming distance d (10101, 11110) is ____?

43
Minimum Hamming Distance
● The minimum Hamming distance is the smallest Hamming distance
between all possible pairs in a set of words.
● dmin is used to define the minimum Hamming distance in a coding
scheme.
● Ex: Find the minimum Hamming distance of the coding scheme
given in Table.
● Sol: First find all the Hamming distances

● The dmin in this case is 3.

44
Hamming Distance and Error
● When a codeword is corrupted during transmission, the Hamming
distance between the sent and received codewords is the number of
bits affected by the error.
● In other words, the Hamming distance between the received
codeword and the sent codeword is the number of bits that are
corrupted during transmission.
● 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

45
Minimum Distance for Error Detection
●To guarantee the detection of up to s errors in all cases,
the minimum Hamming distance in a block code must be
dmin = s + 1. In other words, For a code of distance s+1,
up to s errors will always be detected
●The minimum Hamming distance for our first code
scheme 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.
●Our second block code scheme has d min=3. This code can
detect up to two errors. Again, we see that 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 46
Minimum Distance for Error Correction
●To guarantee correction of up to t errors in all cases, the
minimum Hamming distance in a block code must be
● dmin= 2t + 1.
●In other words, for a code of distance 2t+1, up to t errors can
always be corrected by mapping to the closest codeword.
●Ex: A code scheme has a Hamming distance dmin= 4. What is
the error detection and correction capability of this scheme?
●Sol: This code guarantees the detection of up to three errors
(s = 3), but it can correct up to one error.
●In other words, if this code is used for error correction, part
of its capability is wasted. Error correction codes need to
have an odd minimum distance (3, 5, 7, . . . ).
47
Hamming Distance- Exercise
●Ex: What is the Hamming distance for each of the
following codewords:
●a. d (10000, 01000)
●b. d (10101, 10010)
●c. d (1111,1111)
●d. d (0000, 0000)
●Ex2: Find the minimum Hamming distance for the
following cases:
●a. Detection of two errors
●b. Correction of two errors.
●c. Detection of 3 errors or Correction of two errors.
●d. Detection of 6 errors or Correction of two errors. 48

You might also like