Professional Documents
Culture Documents
Lecture Slide Data Link Layer
Lecture Slide Data Link Layer
Lecture Slide Data Link Layer
CSC 465
Data Communication and Computer Networks
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
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
linksend(pkt “WiFi:1”) EH ET
EH ET EH ET
WH WT Frame
CSC 465 5
Framing
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’)
CSC 465 15
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)
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.
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)
CSC 465 25
Flow Control and Error Control (Cont’)
NOISEY CHANNELS (Cont)
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)
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)
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
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
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
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
CSC 465 51
Error Detection and Correction (Cont’)
• Redundancy
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
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
CSC 465 55
Error Detection (Cont’)
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
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
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