Link Layer Protocols
Link Layer Protocols
Link Layer 3
Link layer: context
▪ datagram transferred by
different link protocols over
different links:
• e.g., WiFi on first link,
Ethernet on next link
▪ each link protocol provides
different services
• e.g., may or may not provide
reliable data transfer over link
Link Layer 4
Link layer: services
▪ framing, link access: …
• encapsulate datagram into frame, adding …
header, trailer Cable access
• channel access if shared medium
• “MAC” addresses in frame headers identify
source, destination (different from IP
address!)
▪ reliable delivery between adjacent nodes
cellular
• we already know how to do this!
• seldom used on low bit-error links Ethernet LANs
• wireless links: high error rates
• Q: why both link-level and end-end
WiFi
reliability?
Link Layer 5
Link layer: services (more)
…
▪ flow control:
• pacing between adjacent sending and …
receiving nodes Cable access
▪ error detection:
• errors caused by signal attenuation, noise.
• receiver detects errors, signals
retransmission, or drops frame
▪ error correction: cellular
• receiver identifies and corrects bit error(s)
without retransmission Ethernet LANs
▪ half-duplex and full-duplex:
• with half duplex, nodes at both ends of link WiFi
can transmit, but not at same time
Link Layer 6
Host link-layer implementation
▪ in each-and-every host
▪ link layer implemented on-chip or
in network interface card (NIC) application
transport
• implements link, physical layer network
link
cpu memory
Link Layer 7
Interfaces communicating
application application
transport transport
cpu memory memory CPU
datagram network network
link link
Link Layer 9
Error detection
EDC: error detection and correction bits (e.g., redundancy)
D: data protected by error checking, may include header fields
Link Layer 10
Parity checking Can detect and correct errors
single bit parity: (without retransmission!)
▪ detect single bit errors ▪ two-dimensional parity: detect
and correct single bit errors
0111000110101011 1 row parity
d data bits d1,1 ... d1,j d1,j+1
d2,1 ... d2,j d2,j+1
parity bit
... ... ... ...
Even/odd parity: set parity bit so di,1 ... di,j di,j+1
there is an even/odd number of 1’s column
parity di+1,1 ... di+1,j di+1,j+1
At receiver:
▪ compute parity of d received detected 10101 1
no errors: 1 0 1 0 1 1
bits 11110 0 and 10110 0 parity
error
▪ compare with received parity bit 01110 1
correctable
single-bit 01110 1
– if different than error detected 10101 0 error: 10101 0
parity
error
* Check out the online interactive exercises for more examples: http://gaia.cs.umass.edu/kurose_ross/interactive/
Cyclic Redundancy Check (CRC)
▪ more powerful error-detection coding
▪ D: data bits (given, think of these as a binary number)
▪ G: bit pattern (generator), of r+1 bits (given, specified in CRC standard)
r CRC bits
d data bits
D R bits to send
<D,R> = D *2r XOR R formula for these bits
sender: compute r CRC bits, R, such that <D,R> exactly divisible by G (mod 2)
• receiver knows G, divides <D,R> by G. If non-zero remainder: error detected!
• can detect all burst errors less than r+1 bits
• widely used in practice (Ethernet, 802.11 WiFi)
Link Layer 12
Cyclic Redundancy Check (CRC): example
Sender wants to compute R G 1 0 1 0 1 1
such that: 1 0 0 1 1 0 1 1 1 0 0 0 0
D . 2r XOR R = nG 1 0 0 1
1 0 1 D* 2r (here, r=3)
0 0 0
... or equivalently (XOR R both sides): 1 0 1 0
D . 2r = nG XOR R 1 0 0 1
1 1 0
... which says: 0 0 0
if we divide D . 2r by G, we 1 1 0 0
1 0 0 1
want remainder R to satisfy: 1 0 1 0
D.2r 1 0 0 1
R = remainder [ ] algorithm for 0 1 1
G computing R
R
* Check out the online interactive exercises for more examples: http://gaia.cs.umass.edu/kurose_ross/interactive/
Link Layer 13
Multiple Access Protocols
Link Layer 14
Multiple access links, protocols
two types of “links”:
▪ point-to-point
• point-to-point link between Ethernet switch, host
• PPP for dial-up access
▪ broadcast (shared wire or medium)
• old-school Ethernet
• upstream HFC in cable-based access network
• 802.11 wireless LAN, 4G/4G. satellite
shared wire (e.g., shared radio: 4G/5G shared radio: WiFi shared radio: satellite humans at a cocktail party
cabled Ethernet) (shared air, acoustical)
Link Layer 15
Multiple access protocols
▪ single shared broadcast channel
▪ two or more simultaneous transmissions by nodes: interference
• collision if node receives two or more signals at the same time
Link Layer 16
An ideal multiple access protocol
given: multiple access channel (MAC) of rate R bps
desiderata:
1. when one node wants to transmit, it can send at rate R.
2. when M nodes want to transmit, each can send at average
rate R/M
3. fully decentralized:
• no special node to coordinate transmissions
• no synchronization of clocks, slots
4. simple
Link Layer 17
MAC protocols: taxonomy
Three broad classes:
▪ channel partitioning
• divide channel into smaller “pieces” (time
slots, frequency, code)
• allocate piece to node for exclusive use
• TDMA, FDMA, CDMA
▪ random access
• channel not divided, allow collisions
• “recover” from collisions or do not let collision
happen
• ALOHA, Slotted ALOHA, CSMA/CD, CSMA/CA
▪ “taking turns”
• nodes take turns, but nodes with more to
send can take longer turns
• Polling, Token passing
Link Layer 18
A.1 Channel partitioning MAC protocols: TDMA
TDMA: time division multiple access
▪ access to channel in “rounds”
▪ each station gets fixed length slot (length = packet transmission
time) in each round
▪ unused slots go idle
▪ example: 6-station LAN, 1,3,4 have packets to send, slots 2,5,6 idle
6-slot 6-slot
frame frame
1 3 4 1 3 4
Link Layer 19
A.2 Channel partitioning MAC protocols: FDMA
FDMA: frequency division multiple access
▪ 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 to send, frequency bands 2,5,6 idle
frequency bands
FDM cable
Link Layer 20
A.3 Code Division Multiple Access (CDMA)
• Code Division Multiple Access system is very different from time and frequency multiplexing. In this
system, a user has access to the whole bandwidth for the entire duration. The basic principle is that different
CDMA codes are used to distinguish among the different users.
• A signal is generated which extends over a wide bandwidth. A code called spreading code is used to perform
this action.
• Using a group of codes, which are orthogonal to each other, it is possible to select a signal with a given code
in the presence of many other signals with different orthogonal codes.
node 2 2 2 2
C: collision
S: success
node 3 3 3 3
E: empty
C E C S E C E S S
Pros: Cons:
▪ single active node can ▪ collisions, wasting slots
continuously transmit at full rate ▪ idle slots
of channel
▪ nodes may be able to detect collision in
▪ highly decentralized: only slots in less than time to transmit packet
nodes need to be in sync
▪ simple ▪ clock synchronization
Link Layer 25
Slotted ALOHA: efficiency
efficiency: long-run fraction of successful slots (many nodes, all with
many frames to send)
▪ suppose: N nodes with many frames to send, each transmits in slot with
probability p
• prob that given node has success in a slot = p(1-p)N-1
• prob that any node has a success = Np(1-p)N-1
• max efficiency: find p* that maximizes Np(1-p)N-1
• for many nodes, take limit of Np*(1-p*)N-1 as N goes to infinity, gives:
max efficiency = 1/e = 0.37
▪ at best: channel used for useful transmissions 37% of time!
Link Layer 26
B.3 CSMA (carrier sense multiple access)
simple CSMA: listen before transmit:
• if channel sensed idle: transmit entire frame
• if channel sensed busy: defer transmission
▪ human analogy: don’t interrupt others!
Link Layer 27
B.3 Concepts of Carrier Sense and Collision Detection
V
Vth2
MAC/
PHY Data Vth1
Time
Collision?
Tx Rx Carrier?
Medium
B.3 CSMA with Collision Detection
A B C D
5-29
B.3 CSMA with Collision Detection
5-30
New frame
Exponential backoff
CSMA/CD Start:
i=0
Sense medium
Wait Bus Y
TB = R*Tp Wait
y
N
Yes
Success
Error
5-31
B.3 CSMA with Collision Detection
32
Computers A, B, and C and one router are connected
to an Ethernet bus 100 metres apart
to make a LAN using the CSMA/CD protocol.
Assume that signal propagates on the Ethernet bus at a
speed of 2 x 108 m/sec, and all nodes can transmit data
at the rate of 100 Mbps .
A B C Router
100 m 100 m 100 m
• After finding the bus to be idle for a little while, A and the router start
transmitting their frames exactly at the same time. How many bits of data can
node A transmit before detecting collision?
• What is the maximum time gap between the start of transmission and detection
of collision by A?
• What is the length of the smallest frame that A can transmit while knowing
whether or not it collided with a transmission from the router?
5-33
CSMA/CA is discussed later on
5-34
C. Taking turns MAC protocols
channel partitioning MAC protocols:
▪ share channel efficiently and fairly at high load
▪ inefficient at low load: delay in channel access, 1/N
bandwidth allocated even if only 1 active node!
random access MAC protocols
▪ efficient at low load: single node can fully utilize channel
▪ high load: collision overhead
“taking turns” protocols
▪ look for best of both worlds!
Link Layer 35
C.1 Taking turns MAC protocols: Polling
Polling:
▪ centralized controller “invites”
other nodes to transmit in turn data
poll
▪ typically used with “dumb”
devices centralized
data controller
▪ concerns:
• polling overhead
• latency
client devices
• single point of failure (master)
• Bluetooth uses polling
Link Layer 36
C.2 Taking turns MAC protocols: Token Passing
T
token passing:
▪ control token message
explicitly passed from one node
(nothing
to next, sequentially to send)
▪ transmit while holding token T
▪ concerns:
• token overhead
• latency
• single point of failure
(token) data
Link Layer 37
Summary of MAC protocols
▪ channel partitioning, by time, frequency or code
• Time Division, Frequency Division
▪ random access (dynamic),
• ALOHA, S-ALOHA, CSMA, CSMA/CD
• carrier sensing: easy in some technologies (wire), hard in others
(wireless)
• CSMA/CD used in Ethernet
• CSMA/CA used in 802.11 (later)
▪ taking turns
• polling from central site, token passing
• Bluetooth, FDDI, token ring
5-39
MAC addresses
▪ 32-bit IP address:
• network-layer address for interface
• used for layer 3 (network layer) forwarding
• e.g.: 128.119.40.136
▪ MAC (or LAN or physical or Ethernet) address:
• function: used “locally” to get frame from one interface to another
physically-connected interface (same subnet, in IP-addressing sense)
• 48-bit MAC address (for most LANs) burned in NIC ROM, also
sometimes software settable
• e.g.: 1A-2F-BB-76-09-AD
hexadecimal (base 16) notation
(each “numeral” represents 4 bits)
Link Layer: 6-40
MAC addresses
each interface on LAN
▪ has unique 48-bit MAC address
▪ has a locally unique 32-bit IP address (as we’ve seen)
137.196.7.78
1A-2F-BB-76-09-AD
LAN
(wired or wireless)
137.196.7/24
71-65-F7-2B-08-53 58-23-D7-FA-20-B0
137.196.7.23 137.196.7.14
0C-C4-11-6F-E3-98
137.196.7.88
D
Link Layer: 6-44
ARP protocol in action
example: A wants to send datagram to B
• B’s MAC address not in A’s ARP table, so A uses ARP to find B’s MAC address
C
ARP table in A
IP addr MAC addr TTL
TTL
137.196. 58-23-D7-FA-20-B0 500
A B
7.14
71-65-F7-2B-08-53 58-23-D7-FA-20-B0
137.196.7.23 137.196.7.14
twisted pair
hub
5-49
Ethernet switch
▪ Switch is a link-layer device: takes an active role
• store, forward Ethernet (or other type of) frames
• examine incoming frame’s MAC address, selectively forward frame
to one-or-more outgoing links when frame is to be forwarded on
segment, uses CSMA/CD to access segment
▪ transparent: hosts unaware of presence of switches
▪ plug-and-play, self-learning
• switches do not need to be configured
B’ C
A’ A A’
S4
S1
S3
A S2
F
D I
B C
G H
E
6-586-58
Link Layer:
Virtual LAN
2 8 10 16
… …
EE (VLAN ports 1-8) CS (VLAN ports 9-15)
2 8 10 16
1 7 9 15 1 3 5 7
2 8 10 16 2 4 6 8
… … …
EE (VLAN ports 1-8) CS (VLAN ports 9-15) Ports 2,3,5 belong to EE VLAN
Ports 4,6,7,8 belong to CS VLAN
5
1 7 9 15 1 3 7
2 8 10 16 IP Ethernet 2 4 6 8
datagram frame
… … …
Sunnyvale Bangalore
data center Ethernet data center
CSMA/CD
IEEE 802.3 Protocol Number LAN
Ethernet
CSMA/CA
IEEE 802.11 CSMA/CD
WiFi
5-65
WLAN: Basic idea
C Access
Point Basic Service Set
(identified by the MAC address of the AP:
C
BSSID)
▪ all use CSMA/CA for multiple access, and have base-station and ad-hoc
network versions
Class 22: 68
Different Modes of Operation of MAC in IEEE 802.11
Modes of IEEE
802.11 MAC
5-69
PCF Mode
The AP
• Operates as the central controller in the BSS.
• Decides who transmits and when.
• There is no contention for medium access
• Can follow a round-robin policy to allocate slots.
This mode
• Leads to waste of bandwidth if a scheduled node has no traffic.
• Is based on the idea of polling 🡸 Recall “taking-turns” MAC
70
DCF Mode
An AP
▪ Need not be used.
• Computers can directly communicate among themselves <= Ad hoc.
▪ Is used to provide connectivity to the Internet.
In DCF
▪ All nodes, including the AP, compete for medium access.
▪ The AP does not operate as a central controller.
71
AP
Handshake
Without
handshake
5-72
Handshake mode
5-73
DCF with handshake
Control Frames:
RTS: Request To Send
CTS: Clear To Send
Repeat this…
74
DCF without handshake
Sender Receiver
Repeat
this…
75
Signal from all nodes
must reach all others
Wired
This diff. leads
to some problems
Signal from some nodes
A B C
may not reach all others
Wireless
D
5-76
As a result, if your frame
encountered collision at the
receiver, you are NOT aware Hidden Terminal Problem
of that. Exposed Terminal Problem
5-77
Hidden Terminal Problem
C is transmitting a frame to B.
A is unaware of C’s Tx.
A B C
5-78
Exposed Terminal Problem
A B C
No solution has
been provided so
D far…..
A is transmitting a frame to D.
B knows that someone is transmitting.
If B transmits a frame to C, it does not collide with A’s at D.
However, B does not transmit because B is unaware of D’s location.
5-79
WLAN MAC: CSMA/CA (basic idea)
Collision is avoided by using two techniques
▪ PHY-level carrier sensing: Done in receiver hardware
Time 80
CSMA/CA: NAV in detail
• Recall the handshake mechanism with RTS and CTS
• A duration field in frame header indicates the length
of time the sender of the frame may use the medium.
• All nodes which receive RTS and CTS (and DATA )
update their NAV as follows
Events that update NAV: Initially NAV = 0
81
RTS and CTS Frames
RTS Frame
Duration RA TA FCS
Control
2 2 6 6 4 bytes
82
DATA Frame
Frame Seq.
Contr Duration A1 A2 A3 contr A4 Frame Body FCS
ol ol
RA TA
TA RA
83
Timing Intervals
The IEEE 802.11 MAC defines 4 timing intervals
• 2 at the PHY level
• SIFS: Short Inter-Frame Space (10 micro-sec) between successive frames (RTS,
CTS, DATA, ACK, …)
• aSlot (20 micro-sec)
Time
84
Timing intervals are used to control priority
SIFS
PIFS
DIFS
5-85
Handshake using RTS/CTS (A wants to send data to B)
(Note: “duration” info in DATA will not be shown.)
A B
Medium is idle
&& NAV == 0 D
C
Value of “duration” in RTS
C
(neighbors of A)
Min value of NAV of D
D
(neighbors of B) Time
5-86
F: a new data frame to be transmitted
DCF with Hand-shake: Tx
i = 0, CW = CWmin
No NAV =0?
End of
Yes backoff
Yes
Send RTS
Start a timer
Timeout
CTS is received
Cancel timer
Send DATA (F)
Start a timer
Timeout
ACK is received
i = i+1
CW = CWmin*2i
( CW saturates at CWmax)
5-87
Backoff Mechanism
Initialize a counter: Backoff Time Counter (BTC)
▪ BTC = Random(0,CW-1) ……time unit of BTC is aSlot
88
Backoff Mechanism
Time
DIFS DIFS
X X X X
B 5 4 3 3 3 2 1 0
BTC = 5
B is executing backoff
X = aSlotTime
5-89
DCF with Handshake: Rx
Receive RTS
Receive DATA frame
No
NAV = 0?
Yes
Yes
5-90
DCF Mode without Handshake
91
Data transmission without handshake
(A wants to send data to B)
A B
Medium is idle D
&& NAV == 0
C
Value of “duration” in
DATA
DIFS DATA
A
SIFS
ACK
B
Value of NAV of C
C
(neighbor of A)
D
(neighbor of B) Time
5-92
PCF Mode: AP becomes the controller: How?
AP alternates between PCF and DCF modes
SIFS
PIFS
DIFS
If AP finds medium to be idle (no carrier && NAV == 0) for PIFS, it transmits a
beacon frame.
Beacon contains a CFPMaxDuration field (CFP: Contention Free Period)
93
Optional
PCF Mode of Operation (Contd.)
• DATA frame
• CF Poll frame (CF: Contention Free)
• DATA+CF Poll frame
• ACK frame
• CF End frame
94
PCF Mode of Operation (Contd.) Optional
SIFS SIFS
DATA DATA
SIFS SIFS
ACK ACK
PIFS PIFS
Time
5-95
PCF Mode of Operation (Contd.) Optional
SIFS
SIFS
ACK
DATA
SIFS
ACK
PIFS
Note 2: If User 1 does not receive ACK, it does not retransmit data.
The polled user receives data from the AP and sends data to
another user.
5-96
Optional
PCF Mode of Operation (Contd.)
DATA from AP (unicast): 1 🡪 1 DATA from AP (broadcast): 1 🡪 all
User 2
AP User 1 User 1 AP
DATA DATA
DATA
PIFS
SIFS
DATA
DATA
ACK PIFS
PIFS
DATA DATA
DATA
(lost)
PIFS
SIFS DATA
DATA
(lost)
ACK
No ACK….
5-97
Optional
PCF Mode of Operation (Contd.)
CF End frame
▪ Identifies the end of CF period
98
Summary: Link Layer Protocols
▪ principles behind data link layer services:
• error detection, correction
• sharing a broadcast channel: multiple access
• link layer addressing
▪ instantiation, implementation of various link layer technologies
• Ethernet
• switched LANS, VLANs
▪ Wireless Networks