Lecture Slide Data Link Layer

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 63

Founded 1991 by Md.

Alimullah Miyan 1991-2016

Yearlong Countrywide Silver Jubilee Celebration (2016-2017)

CSC 465
Data Communication and Computer Networks

Abhijit Saha, Ph.D.


Professor
Dept. of Computer Science and Engineering (CSE)
College of Engineering and Technology (CEAT)
IUBAT, Uttara, Dhaka
Email: asaha@iubat.edu
English is the First Language of IUBAT Campus

• This is mandatory for everyone including students in all


interactions and communications as of January 1, 2014.
• If any student face difficulty, s/he is advised to contact
Mr Nazmul Haque Khan (Room No: 224/A, Cell:
01727277166, Email: nazmul@iubat.edu, Ext: 460, )
for arranging special spoken English training.
• Violation of English as the First Language in the
Campus will lead to administrative and disciplinary
action.
• All are urged to help each other to develop the Facility
of Communicating in English as the First Language in
the Campus
Data link layer
• Position and responsibilities of the data link layer

Data Packets from Network Layer

Data Link Layer

CSC 465 3
Data link layer
ADDRESSSING
Logical Addressing : Networking Layer
Physical Addressing: Data Link Layer
Data Packet

PC A PC B
IP1 IP1 IP2 Segment Trailer IP2

MAC1 MAC2 IP1 IP2 Segment Trailer MAC2


MAC1

Frame

65.32.AB.3A.87.C7 95.22.AC.3B.77.A7
Media

CSC 465 4
Two basic functions of data link layer
1. It allows upper layers of OSI model to access media
Use Technique: Framing Search the request and send
laptop iubat.edu

Req “…”
Browser/HTTP Req “ …” Server/HTTP

e2esend(msg “TCP” 216.235.75.143:80) EH ET

e2eH e2eT Segment


E2E TCP TCP
Switch
Netsend(seg Switch
“IP”, ” 216.235.75.143) NETH

Network IP NetH IP Packet IP IP

linksend(pkt “WiFi:1”) EH ET

Link WiFi WiFi ENET ENET ENET ENET

EH ET EH ET
WH WT Frame

CSC 465 5
Framing

The data link layer needs to pack bits into frames, so


that each frame is distinguishable from another. Our
postal system practices a type of framing. The simple
act of inserting a letter into an envelope separates one
piece of information from another; the envelope serves
as the delimiter.
Topics discussed in this section: Fixed-Size Framing
Variable-Size Framing

Figure A frame in a character-oriented protocol


CSC 465 6
Framing (Cont’)
Byte stuffing is the process of adding 1 extra byte whenever
there is a flag or escape character in the text.

Figure Byte stuffing and unstuffing


CSC 465 7
Framing (Cont’)
Bit stuffing is the process of adding one extra 0 whenever five
consecutive 1s follow a 0 in the data, so that the receiver does not
mistake the pattern 0111110 for a flag.

Figure Bit stuffing and unstuffing

CSC 465 8
Flow Control and Error Control
The most important responsibilities of the data link
layer are flow control and error control. Collectively,
these functions are known as data link control.
Topics discussed in this section: Flow Control
Error Control
Flow control refers to a set of procedures used to restrict the
amount of data that the sender can send before waiting for
acknowledgment.
Error control in the data link layer is based on automatic repeat
request, which is the retransmission of data.
Protocols: Now let’s see how the data link layer can combine
Protocols:
framing, flow control, and error control to achieve the delivery of
data from one node to another
another..
CSC 465 9
Flow Control and Error Control (Cont’)

Taxonomy of Protocols

CSC 465 10
Flow Control and Error Control (Cont’)
NOISELESS CHANNELS
In an ideal channel, no frames are lost, duplicated, or corrupted.
Two protocols are discussed here for this type of channel:
Simplest Protocol, and Stop-and-Wait Protocol

Figure The design of the simplest protocol with no flow or error control

CSC 465 11
Flow Control and Error Control (Cont’)
NOISELESS CHANNELS (Cont’)

Figure An example flow diagram for simplest protocol


Above figure shows an example of communication using simplest protocol. It is
very simple. The sender sends a sequence of frames without even thinking about
the receiver. To send three frames, three events occur at the sender site and three
events at the receiver site. Note that the data frames are shown by tilted boxes; the
height of the box defines the transmission time difference between the first bit and
the last bit in the frame.
CSC 465 12
Flow Control and Error Control
NOISELESS CHANNELS (Cont’)

Figure Design of Stop-and-Wait Protocol

Right-side figure shows an example of


communication using Stop-and-Wait protocol.
It is still very simple. The sender sends one
frame and waits for feedback from the receiver.
When the ACK arrives, the sender sends the
next frame. Note that sending two frames in the
protocol involves the sender in four events and
the receiver in two events.

Figure An example flow diagram for


Stop-and-Wait Protocol
CSC 465 13
Flow Control and Error Control (Cont’)
NOISEY CHANNELS
Although the Stop-and-Wait Protocol gives an idea of how to add
flow control to its predecessor, noiseless channels are nonexistent.
Three protocols are discussed here that use error control: Stop-and-
Wait Automatic Repeat Request, Go-Back-N Automatic Repeat
Request, and Selective Repeat Automatic Repeat Request

1. Stop-and-Wait Automatic Repeat Request:


• 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.
• In Stop-and-Wait ARQ, the acknowledgment number always announces in
modulo-2 arithmetic the sequence number of the next frame expected.
CSC 465 14
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

Figure Design of the Stop-and-Wait ARQ Protocol

CSC 465 15
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

Figure An example flow diagram for Stop-and-Wait ARQ


The above figure shows an example of Stop-and-Wait ARQ. Frame 0 is sent and
acknowledged. Frame 1 is lost and resent after the time-out. The resent frame 1 is
acknowledged and the timer stops. Frame 0 is sent and acknowledged, but the
acknowledgment is lost. The sender has no idea if the frame or the acknowledgment is lost,
so after the time-out, it resends frame 0, which is acknowledged.
CSC 465 16
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

2. Go-Back-N Protocol Automatic Repeat Request:


In the Go-Back-N Protocol, the sequence numbers are modulo 2m,
where m is the size of the sequence number field in bits.

Figure Send window for Go-Back-N ARQ


CSC 465 17
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)
Go-Back-N Protocol Automatic Repeat Request (Cont’):
• 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.

Figure Receive window for Go-Back-N ARQ


CSC 465 18
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)
Go-Back-N Protocol Automatic Repeat Request (Cont’):
• 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.

Figure Design of Go-Back-N ARQ

CSC 465 19
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)
Go-Back-N Protocol Automatic Repeat Request (Cont’):
• 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.

Figure Window size for Go-Back-N ARQ 20


CSC 465
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)
Right-side figure shows an
example of Go-Back-N. Here, the
forward channel is reliable, but the
reverse is not. No data frames are
lost, but some ACKs are delayed
and one is lost. Also, how
cumulative acknowledgments can
help if acknowledgments are
delayed or lost has been shown.
After initialization, there are seven
sender events. Request events are
triggered by data from the network
layer; arrival events are triggered
by acknowledgments from the
physical layer. There is no time-out
event here because all outstanding
frames are acknowledged before
the timer expires. Note that
although ACK 2 is lost, ACK 3 Figure An example flow diagram for Go-Back-N ARQ
serves as both ACK 2 and ACK 3.
CSC 465 21
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

Figure An example flow diagram for Go-Back-N ARQ


CSC 465 22
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

The previous slide figure shows what happens when a frame is lost. Frames 0, 1, 2, and 3
are sent. However, frame 1 is lost. The receiver receives frames 2 and 3, but they are
discarded because they are received out of order. The sender receives no acknowledgment
about frames 1, 2, or 3. Its timer finally expires. The sender sends all outstanding frames
(1, 2, and 3) because it does not know what is wrong. Note that the resending of frames 1,
2, and 3 is the response to one single event. When the sender is responding to this event, it
cannot accept the triggering of other events. This means that when ACK 2 arrives, the
sender is still busy with sending frame 3.
The physical layer must wait until this event is completed and the data link layer goes back
to its sleeping state. We have shown a vertical line to indicate the delay. It is the same story
with ACK 3; but when ACK 3 arrives, the sender is busy responding to ACK 2. It happens
again when ACK 4 arrives. Note that before the second timer expires, all outstanding
frames have been sent and the timer is stopped.
CSC 465 23
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

2. Selective Repeat Automatic Repeat Request:


Selective Repeat ARQ is a special case of Go-Back-N ARQ in which the size of
the send window is 1.

Figure Send window for


Selective Repeat ARQ

Figure Receive window for


Selective Repeat ARQ
CSC 465 24
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

Figure Design of Selective Repeat ARQ

CSC 465 25
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

Figure Selective Repeat ARQ, window size


• In Selective Repeat ARQ, the size of the sender and receiver window must be at most
one-half of 2m. 26
CSC 465
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

Figure Delivery of data in Selective Repeat ARQ

CSC 465 27
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

This example is similar to Example 11.3 in which frame 1 is lost. We show how Selective
Repeat behaves in this case. Figure 11.23 shows the situation. One main difference is the
number of timers. Here, each frame sent or resent needs a timer, which means that the timers
need to be numbered (0, 1, 2, and 3). The timer for frame 0 starts at the first request, but stops
when the ACK for this frame arrives. The timer for frame 1 starts at the second request, restarts
when a NAK arrives, and finally stops when the last ACK arrives. The other two timers start
when the corresponding frames are sent and stop at the last arrival event.

At the receiver site we need to distinguish between the acceptance of a frame and its delivery
to the network layer. At the second arrival, frame 2 arrives and is stored and marked, but it
cannot be delivered because frame 1 is missing. At the next arrival, frame 3 arrives and is
marked and stored, but still none of the frames can be delivered. Only at the last arrival, when
finally a copy of frame 1 arrives, can frames 1, 2, and 3 be delivered to the network layer.
There are two conditions for the delivery of frames to the network layer: First, a set of
consecutive frames must have arrived. Second, the set starts from the beginning of the
window.

CSC 465 28
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

Another important point is that a NAK is sent after the second arrival, but not after the
third, although both situations look the same. The reason is that the protocol does not want
to crowd the network with unnecessary NAKs and unnecessary resent frames. The second
NAK would still be NAK1 to inform the sender to resend frame 1 again; this has already
been done. The first NAK sent is remembered (using the nakSent variable) and is not sent
again until the frame slides. A NAK is sent once for each window position and defines the
first slot in the window.

The next point is about the ACKs. Notice that only two ACKs are sent here. The first one
acknowledges only the first frame; the second one acknowledges three frames. In
Selective Repeat, ACKs are sent when data are delivered to the network layer. If the data
belonging to n frames are delivered in one shot, only one ACK is sent for all of them.

CSC 465 29
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)

Figure Flow diagram from last two slides


CSC 465 30
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)
Stop and Wait Go back N Selective Repeat
• Only one frame transmit • Multiple frame transmit • Multiple frame transmit
• Sender window =1 and • Sender window = and • Sender window =
Receiver window=1 Receiver window=1 and Receiver window=
• The minimum sequence • The Minimum Sequence • The Minimum Sequence
number in the Stop and Number in the Go-Back-N Number in the Selective
Wait procedure is 2. protocol is N+1, where N is Repeat protocol is 2N, where
the number of packets sent. N is the number of packets
•Efficiency formula is transmitted.
1/(1+2x) where x is ratio of •Efficiency formula is •Efficiency formula is N/(1+2x)
propagation delay vs. N/(1+2x) where x =Tp/Tt and where x =Tp/Tt and N is
transmission delay (Tp/Tt). N is number of packets sent. number of packets sent.
• Acknowledgement type • Acknowledgement type is • Acknowledgement type is
is individual. cumulative. individual.
• At the receiver end, no • Only in-order delivery is • Out-of-order deliveries can
specific order is required. accepted at the receiver end also be accepted at receiver end.
• In case of packet drop, • Number of retransmission • Number of retransmission is
number of retransmission is N. 1.
is 1.
CSC 465 31
MEDIA ACCESS CONTROL
The technique used to get the frame on and over the media is call media access control (MAC)

• What is medium access?


– Who gets to transmit? How? When?
– Multiplexing: How many stations can share a single link?
• FDMA, TDMA, CDMA in circuit switched voice networks
• CSMA/CD in Ethernet (simplicity)
– Duplexing
• How communication from station A to station B is separated from
the communication from station B to station A
• FDD or TDD
• Impact of architectures
• Infrastructure – Centralized, fixed base station
• Ad Hoc – Distributed, Peer-to-Peer
• Simplicity and overhead

CSC 465 32
MEDIA ACCESS CONTROL (Cont’)
MAC protocol Taxonomy
• Three broad classes:
 Channel Partitioning
– divide channel into smaller
“pieces” (time slots, frequency and
code)
– allocate piece to node for exclusive
use
 Random Access
– channel not divided, allow
collisions.
– “recover” from collisions.
 Controlled-Access Protocols
– nodes take turns, but nodes with
more to send can take longer
turns.
CSC 465 33
MEDIA ACCESS CONTROL (Cont’)
Frequency Division Multiple Access (FDMA)
 Channel spectrum divided into frequency bands.
 Each station assigned fixed frequency band.
 Unused transmission time in frequency bands go idle.
 Example: 6-station LAN, 1,3,4 have packet, frequency bands 2,5,6
idle.
 Used in First Generation Cellular (AMPS - Advanced Mobile
Phone Service) Analog
frequency bands

FDM cable

CSC 465 34
MEDIA ACCESS CONTROL (Cont’)
Time Division Multiple Access (TDMA)

 Access to channel in "rounds“.


 Each station gets fixed length slot (length = packet transmission
time) in each round. (N * T Seconds)
 Unused slots go idle.
 Example: 6-station LAN, 1,3,4 have packet, slots 2,5,6 wasted (idle).
 Used in 2nd generation – GSM (Global System for Mobile
communication), GPRS (General Packet Radio Services ), EDGE
(Enhanced Data Rates for Global Evolution)

6-slot
frame
1 3 4 1 3 4

CSC 465 35
MEDIA ACCESS CONTROL (Cont’)
Code Division Multiple Access (CDMA)
  Assign a user a unique code for transmission between sender and
receiver, users transmit on the same frequency at the same time
 Narrowband message signal is multiplied by very large bandwidth
spreading signal using direct sequence spread spectrum
 All users can use same carrier frequency and may transmit
simultaneously
 Each user has own unique access spreading codeword which is
approximately orthogonal to other users codewords
 Receiver performs time correlation operation to detect only
specific codeword, other users codewords appear as noise due to
decorrelation
 Used in 3rd generation - 3GPP2-CDMA (3rd Generation Partnership
Project 2), CDMA-EVDO
CSC 465 36
MEDIA ACCESS CONTROL (Cont’)
Code Division Multiple Access

• One channel carries all transmissions simultaneously in CDMA

d1 d2
User User
Station1 Station2
d1.c1 d2.c2
d1.c1 + d2.c2 + d3.c3 + d4.c4 Common Channel
DATA
d3.c3 d4.c4
User User
Station3 Station4
d3 d4
A simple idea of communication with code

37
MEDIA ACCESS CONTROL (Cont’)
CDMA Example
Data bit => 0 represent (-1)
=> 1 represent (+1)

Code1 = {1 1 1 1}
User User Code2 = {1 -1 1 -1}
Data1 = -1
Station1 Station2 Data2 = 1
Code1Data1 = {-1 -1 -1 -1}
Code2Data2 = {1 -1 1 -1}
Encoding { 0 -4 0 0}

User Code4 = {1 -1 -1 1}
Code3 = {1 1 -1 -1}
User Data4 = 1
Station4
Station3 Data3 = -1
Code3Data3 = {-1 -1 1 1} Code4Data4 = {1 -1 -1 1}

Decoding
Receiver1 = {1 1 1 1} * (0 -4 0 0} = {0 -4 0 0} = -4/4 = -1
Receiver2 = {1 -1 1 -1} * (0 -4 0 0} = {0 4 0 0} = 4/4 = +1
Receiver3 = {1 1 -1 -1} * (0 -4 0 0} = {0 -4 0 0} = -4/4 = -1
Receiver4 = {1 -1 -1 1} * (0 -4 0 0} = {0 4 0 0} = 4/4 = +1
CSC 465 38
MEDIA ACCESS CONTROL (Cont’)
Carrier Sensing
 Carrier sensing
• It is an improvement of ALOHA (no carrier sensing in
ALOHA)
• Depending on the protocol a variety of CSMA
protocols exist
 Non-persistent
 p-persistent
 Binary exponential back-off
• Collision detection Vs Collision avoidance
 Most random access protocols are based on some form
of carrier sensing
CSC 465 39
MEDIA ACCESS CONTROL (Cont’)
Problems with Carrier Sensing
 The signal strength is a function of distance and
location
 Not all terminals at the same distance from a
transmitter can “hear” the transmitter and
vice versa
 The hidden node problem
 The exposed node problem
 capture

CSC 465 40
MEDIA ACCESS CONTROL (Cont’)
Hidden node/terminal problem
 A MS that is within the
range of the destination but
out of range of a transmitter
 MS A transmits to the AP
 MS B cannot sense the
signal
• MS B may also transmit
resulting in collisions
• MS B is called a “hidden
terminal” with respect to
MS A
CSC 465 41
MEDIA ACCESS CONTROL (Cont’)
Solution to hidden terminal problem
 Busy-tone multiple access (BTMA)
• Out of band signaling scheme
• Any node that hears a transmission
will transmit a busy tone in an out
of band channel
 Control handshaking
• Use a three-way handshake RTS CTS
• Terminal A sends a short request-to-
send (RTS) packet to the AP
• The AP sends a short clear-to-send A AP B
(CTS) packet that is received by
Terminal A AND Terminal B
• Terminal B defers to terminal A
CSC 465 42
MEDIA ACCESS CONTROL (Cont’)
Exposed Terminal Problem

• Hidden terminal is not the only


challenge for a distributed wireless
MAC protocol D A B C
• A blocks B, and C doesn’t know what
is happening (B is exposed)

Solution:
• The exposed terminal problem is solved by the MAC (medium
access control) layer protocol IEEE 802.11 RTS/CTS, with the
condition that the stations are synchronized and frame sizes
and data speed are the same
• Any station hearing the RTS is close to the transmitting station
and remains silent long enough for the CTS
CSC 465 43
MEDIA ACCESS CONTROL (Cont’)
Carrier Sense Multiple Access (CSMA)
Transmission Strategies
non-persistent CSMA 1-persistent CSMA
‘ The less-greedy algorithm’ ‘The greedy algorithm’
1. Sense the channel 1. Sense the channel
2. IF the channel is idle, THEN 2. IF the channel is idle, THEN
transmit transmit
3. IF the channel is busy, THEN wait a 3. IF the channel is busy, THEN
random amount of time and repeat continue to listen until channel is
the algorithm idle and transmit immediately
P-persistent CSMA
‘A slotted approximation’
1. Sense the channel
2. IF the channel is idle, THEN with probability p transmit and with probability
(1-p) delay one time slot and repeat the algorithm
3. IF the channel is busy, THEN delay one time slot and repeat the algorithm
CSC 465 44
MEDIA ACCESS CONTROL (Cont’)
CSMA/CD (Collision Detection)
• Computers send data without interfering data from other
computers
• Especially if the network has a lot of computers that are
sending and receiving the data at the same time
• Collisions happen time to time.
• A technology was developed not only to help avoid collisions but
also to respond correctly if a collision does happen knows as
CSMA/CD
• CSMA/CD used on early Ethernet networks where half duplex
networks utilized earlier versions of twisted pair as well as
coaxial cable

CSC 465 45
MEDIA ACCESS CONTROL (Cont’)
CSMA/CD (Cont’)
• Each computer first senses if the wire is idle
• Computer sends its data if the wire is idle
• But if two computers send data at the same time, a
collision will happen
• Computer that detects collision at first, sends a
jamming signal to notify other computers
• Therefore, computers that were attempting to
transmit waits a random amount of time and
then attempts to retransmits the data
• Not as relevant today

CSC 465 46
MEDIA ACCESS CONTROL (Cont’)
CSMA/CA (Collision Avoidance)
• CSMA/CA used on wireless networks
• When a computer wants to send data on wireless
network, it can’t sense or hear the collisions because
cable is not involved there
• Computer wants to send data, it first sense, any other
transmissions happening there or not
• If it detects the other transmissions, it waits a short
amount of time before checking the channel again
• If channel is free, it waits a short amount time and
send it’s data
• upon receiving the data destination respond with an
acknowledgement
CSC 465 47
MEDIA ACCESS CONTROL (Cont’)
CSMA/CA (cont’)
• CSMA/CA uses optional RTS/CTS protocol to avoid the
collisions
• Computer sends a RTS to WAP
• If AP grants the request, it temporarily stop all other
communication on the network and sends a CTS to the
requested computer
• Then the computer is ready to send the data to WAP
• WAP is the traffic controller on the wireless network

CSC 465 48
Error Detection and Correction

• Basic Concepts
 Networks must be able to transfer data from one device to another
with complete accuracy

 Data can be corrupted during transmission.

 For reliable communication, errors must be detected and corrected

 Error detection and correction are implemented either at the


data link layer or the transport layer of the OSI model

CSC 465 49
Error Detection and Correction (Cont’)
Types of Errors

• Single-Bit Error is when only one bit in the data unit has
changed

CSC 465 50
Error Detection and Correction (Cont’)
Types of Errors (Cont’)
• Multiple-Bit Error is when two or more nonconsecutive bits in
the data unit have changed

• Burst Error means that 2 or more consecutive bits in the data


unit have changed

CSC 465 51
Error Detection and Correction (Cont’)

• Error detection means to decide whether the received data is


correct or not without having a copy of the original message
• Error detection uses the concept of redundancy, which
means adding extra bits for detecting errors at the destination

• Redundancy

• Error Detection Methods

CSC 465 52
Error Detection and Correction (Cont’)
 Parity Check
A parity bit is added to every data unit so that the total
number of 1s(including the parity bit) becomes even for
even-parity check or odd for odd-parity check
• Simple Parity Check

CSC 465 53
Error Detection (Cont’)
 Examples :
• Suppose the sender wants to send the word world. In ASCII
the five characters are coded as
1110111 1101111 1110010 1101100 1100100
The following shows the actual bits sent
11101110 11011110 11100100 11011000 11001001

• Now, suppose the word world is received by the receiver


without being corrupted in transmission.
11101110 11011110 11100100 11011000 11001001
The receiver counts the 1s in each character and comes up with
even numbers (6, 6, 4, 4, 4). The data are accepted.

CSC 465 54
Error Detection (Cont’)
 Examples (Cont’) :
• Now suppose the word world is corrupted during transmission
11111110 11011110 11101100 11011000 11001001
The receiver counts the 1s in each character and comes up with
even and odd numbers (7, 6, 5, 4, 4). The receiver knows that the
data are corrupted, discards them, and asks for retransmission

Two –Dimensional Parity Check

CSC 465 55
Error Detection (Cont’)

 Hamming Code: R. W. Hamming


• It is single error correcting code.
•7-bits hamming code is used commonly
• Number of parity bits can be calculated by
2p p+d+1 {7, 4}
Where d = number of data bits and p= parity bits
d=4 2p p+4+1  2p=3 3+4+1  23 3+4+1  8=8
20 21 22
1 2 3 4 5 6 7
p1 p2 d1 p3 d2 d3 d4

CSC 465 56
Error Detection (Cont’)
 Hamming Code Generation
• Generate (7, 4) hamming code for the data 1110
2p p+d+1
•7–4=3
d=4 2p p+4+1  2p=3 3+4+1  23 3+4+1  8=8
20 21 22 000
1 2 3 4 5 6 7 001
010
P1 P2 d1 P3 d2 d3 d4 011
100
P1 P2 1 P3 1 1 0
101
0 0 1 0 1 1 0 (even parity) 110
1 1 1 1 1 1 0 (odd parity) 111
(for even parity)
(for odd parity)
P1  1 3 5 7  P1 110  0110
P1  1 3 5 7  P1 110  1110
P2  2 3 6 7  P2110  0110
P2 2 3 6 7  P2110  1110
P3  4 5 6 7  P3 110  0110
P3  4 5 6 7  P3 110  1110
CSC 465 57
Error Detection (Cont’)
 Hamming Code Generation

• Construct (7, 4) hamming code for the data (1000) that even
parity exist
• Construct (7, 4) hamming code for the data (1010) such that
odd parity exist

CSC 465 58
Error Detection (Cont’)
 Hamming Code Error correction
• A (7,4) hamming code is received as 1010111. correct the
code when even parity is there
1 2 3 4 5 6 7
1 0 1 0 1 1 1 000
001
E3  4 5 6 7  0111  Even parity  E3 = 1 010
E2  2 3 6 7  0111  Even parity  E2 = 1 011
E1  1 3 5 7  1111  Even parity  E1 = 0 100
101
(if the result is E3E2E1 = 000, then there is no error) 110
E3 E2 E1 = 1 1 0 = 6 represents error 111
1 0 1 0 1 0 1

CSC 465 59
Error Detection (Cont’)
 Cyclic Redundancy Check : It is based on binary division

Data: 100100
CRC Generator: x3 + x2 + 1
= 1101

CRC generator: uses


modular-2 division

Binary Division
Binary Division in a CRC Checker
in a CRC Generator

CSC 465 60
Error Detection (Cont’)
• Checksum

CSC 465 61
Error Detection (Cont’)
• To create the checksum the sender does the following:
– The unit is divided into K sections, each of n bits
– Section 1 and 2 are added together using one’s complement
– Section 3 is added to the result of the previous step
– Section 4 is added to the result of the previous step
– The process repeats until section k is added to the result of the
previous step
– The final result is complemented to make the checksum

• Data unit and Checksum

CSC 465 62
Error Detection (Cont’)
• Checksum Example:
Sender
Original data : 10101001 00111001
10101001
00111001
--------------
11100010 Sum
00011101 Checksum
10101001 00111001 00011101 (Checksum added)

Receiver
Received data : 10101001 00111001 00011101
10101001
00111001
00011101
---------------
11111111  Sum
00000000  Complement

CSC 465 63

You might also like