Lecture 4 - Datalink Layer
Lecture 4 - Datalink Layer
Datalink layer
Functionalities:
Encapsulation, addressing
Error detection and correction
Flow control
Media access control
1
Overview of Data link layer
2
Link layer: introduction
terminology: mobile network
hosts and routers: nodes national or global ISP
Network LLC
(Logical Link Control)
Data-link
MAC
Physical (Media Access Control) Media dependent
sub-layer
802.2 LLC
Datalink layer
5
Link layer: context
datagram transferred by transportation analogy:
different link protocols over trip from Princeton to Lausanne
different links: • limo: Princeton to JFK
• e.g., WiFi on first link, Ethernet • plane: JFK to Geneva
on next link • train: Geneva to Lausanne
combination of hardware,
software, firmware
network interface
12
Error control
Error detection
Error correction
13
Principle of error detection
17
checksum: receiving
Receiving bit: 0011 0110 1000 1101
Checking:
0011
0110
+ 1000
1101
Overflow
11110
bit 1
1111 🡪 No errors
18
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)
r CRC bits
d data bits
D R bit pattern
<D,R> = D*2r XOR R formula for bit pattern
goal: choose 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)
1011 > x3 +x +1
Example of some CRC using in the pratice:
CRC-8 = x8 + x2 + x + 1
CRC-12 = x12+x11+x3+x2+x
CRC-16-CCITT = x16 + x12 + x5 + 1
CRC-32 = x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5
+ x4 + x2 + x + 1
The longer G is, the more possible that CRC detects
errors.
CRC is widely used in the practice
Wi-fi, ATM, Ethernet…
Operation XOR is implemented in hardware
Capable to detect less than r+1 bits errors
22
CRC – Example
Frame : 1101011011
Generator : G(x) = x4 + x + 1 P = 10011
Dividend : Fk = 11010110110000
R = Fk mod P = 1110
Send : 11010110111110
23
CRC – Example
11010110110000 10011
10011
010011
10011
0000010110
10011
0010100
10011
001110 🡪 Remainder:CRC
24
CRC – Check 11010110111110
11010110111110 10011
10011
010011
10011
0000010111
10011
0010011
10011
000000 🡪 No errors
25
CRC – Check 11010010111110
11010010111110 10011
10011
010010
10011
000011011
10011
010001
10011
00010110
10011
00101 🡪 not 0 🡪 errors
26
Reaction when errors detected
Objective: assure that data Popular techniques:
are transmitted correctly Error detection (as we seen)
even though the chanel is Acknowledgement/confirmation
Retransmis after timeout
not realiable.
Retransmis after a clear
Condition confirmation that frame is not
arrived
Data fram must be
transmitted correctly ARQ technique: (automatic
repeat request). There are 3
Negligible transmission versions:
delay. Stop and Wait ARQ
Possible errors Go Back N ARQ
Selective Reject ARQ
Whole frame loss
Similar to techniques used in
Error frame flow control.
Loss of error warning
message
27
Stop-and-wait ARQ
Normal
Sender Receiver
send pkt0
pkt0 is
OK
rcv ACK
send pkt1
pkt1 is
corrupted
rcv NAK
resend pkt1
Time
28
Stop-and-wait ARQ
ACK/NAK errors
Sender Receiver
pkt1 is
OK
29
Stop-and-wait ARQ
Sender Receiver
Not using NAK
send pkt0
pkt0 is
OK
rcv ACK0
send pkt1
pkt1 is
OK
rcv ACK1
send pkt2
pkt2 is corrupted
rcv ACK1
resend pkt2
Time
30
Stop-and-wait ARQ: Lost ACK?
Data and ACK can be lost
Can’t receive ACK?
How to resend data?
Mechanism
Packets will be numbered and sender automatically resends
packets until receiving ACK of packets
Resending after time-out
How long of timeout?
At least 1 RTT (Round Trip Time)
Each sent packets should have 1 timer
Received packets but lost ACK?
Duplicate packets
Receiver will remove duplicate ones
31
ARQ illustration
32
ARQ illustration (cont.)
33
Flow control
34
What is flow control
Goal: Make sure that the sender does not overload the receiver
Why overloading?
The receiver stores data frame in buffer.
Receiver performs some processing before deliver data to the upper level.
Buffer could be full, leaving no space for receiving more frame some data
fram must be dropped.
Problem of errors in transmission is excluded
All frames are transmitted to correct receiver without error
Propagation time is small and could be ignored
Solution
Stop-and-wait mechanism
Sliding window mechanism
35
Stop-and-wait
Principles
Transmitter sends a single frame
36
Stop-and-wait
transmitter
Emetteur receiver
Récepteur
Packet
Paquets Paquets
Packet
frame
Trâme
Ack
Trâme
frame
frame
Trâme
Trâme
37
38
Stop-and-wait
Advantage
Simple, suitable for transmission of big size
frames
Weakness
When frames are small, the transmission chanel
are not used efficiently.
Cannot use often for big size frame due to
Limitation in buffer size
Big size frame prones to bigger error probability
In shared medium, it is not convenient to leave one
station using medium for long time
39
Sliding window: principle
Transmitter sends more than one frame without waiting
in order to reduce waiting time
Transmitted frame without ACK will still be stored in
buffer.
Number of frame to be transmitted without ACK depends
on the size of buffer at transmitter
When transmitter receives ACK, it realises the
succesfully transmitted frame from buffers
Transmitter continues sending a number of frame
equivalent to the number of succesfully trasmitted
frames.
40
Sliding window: principle
Assume that A and B are two stations connected by a full
duplex media
B has a buffer size of n frame.
B can receives n frame without sending ACK
Acknowledgement
In order to keep track of ACKed frames. It is neccessary to
number frames.
B acknowledge a frame by telling A which fram B is waiting for
(by number of frame), implicitely saying that B receives well all
other frame before that.
One ACK frame serves for acknowledes several frames.
41
Sliding windows: principle
42
Window list the frames to transmit Window list the frames in waiting to receive
Sliding windows
43
Sliding windows
Frame are numbered. The maximum number must
not be smaller than the size of the window.
Frame are ACKed by another message with number
Accumulated ACK: If frame 1,2,3,4 are well
receive, just send ACK 4
ACK with number k means all frame k-1, k-2
…already well received.
44
Sliding windows
Transmitter needs to manage some information:
List of frames transmitted sucessfully
List of frames transmitted without ACK
List of frames to be sent immediatly
List of frames NOT to be sent immediately
Receiver keep tracks of
List of frames well received
List of frames expected to receive
45
Piggy backing
A and B transmitte data in both sides
When B needs to send an ACK while still needs to
send data, B attaches the ACK in the Data frame:
Piggybacking
Otherwise, B can send an ACK frame separatly
After ACK, if B sends some other data, it still put the
ACK information in data frame.
Sliding window is much more efficient than Stop-
and-Wait
More complicated in management.
46
Exercices
Given a link with rate R=100Mbps
We need to send a file over data link layer with file size L=100KB
Assume that the size of a frame is: 1KB, header size is ignored
Round trip time (RTT) between 2 ends of the link is 3ms
An ACK message is sent back from receiver whenever a frame is
arrived. Size of ACK message is negligible
What is the transmission time required if using Stop-and-wait
mechanism?
Transmission time with sliding window if the window size is =7?
Which size of window allow to obtain the fastest transmission?
47
Transmission time with Stop-
and-wait
transmitter
Emetteur receiver
Récepteur
Packet
Paquets Packet
Paquets
T transmit
frame
Trâme
RTT Ack
frame
Trâme
Trâme
frame
Trâme
48
Transmission time with Stop-
and-wait
T total= Nb.frame * (T_transmit + RTT)
T_transmit (F) = L(Frame)/ R
Nb. frame = L/L(frame)
50
Trasmission time with window
size 7
T fastest= (T transmit 7 frames+ wait) * Nb.
Waiting time.
1 waiting= (T transmit 1 frame+ RTT) – T
transmit 7 frames
Nb. Waiting time= Nb frame /7
51
Fastest transmission time with
sliding window
Fastest transmission time
obtained if transmitter
receives ACK of the first
W gói
ACK frame when it finishes
transmitting the last frame
of the sliding window.
Window size:W
T transmit(W fram) >= T
transmit first frame + RTT
52
Fastest transmission time with
sliding window
T transmit (W frame) = W * 1KB/R
=> (W-1)*1KB/R >= RTT
=> W >= RTT*R/1KB +1
W>= 3ms * 100 Mbps/ 1KB + 1
W>=38.5
Smallest value of W = 39
Time to transmit all data L = L/R + RTT =8
ms +3ms =11 ms
53
Media access control
54
Connection types
Point-to-point
ADSL
Telephone modem
Leased Line….
Broadcast
LAN using bus topology
Wireless LAN
HFC:
…
Broadcast networks need media access control
protocol in order to avoid collision when nodes try to
send data.
55
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-fashioned Ethernet
• upstream HFC in cable-based access network
• 802.11 wireless LAN, 4G/4G. satellite
60
ex
TDMA và FDMA 4 stations
FDMA
frequency
time
TDMA:
frequency
time 61
CDMA
Several senders can share the same frequency on a
single physical channel.
Signals come from different senders are encoded by a
different random code
Encrypted signals are mixed and then transmit on a
common frequency.
The signals are recovered at the receiver by using the
same codes as at sender side.
CDMA use the spread spectrum theory, CDMA shows
a lot of advantages that other technology cannot
achieve.
http://en.wikipedia.org/wiki/Spread_spectrum
62
DS-CDMA System Overview
(Forward link)
CDMA is a multiple spread spectrum.
BPF BPF
Data B Despreade Data B
r
Code B
Code B MS-B
•••
BS
•••
66
CSMA
67
Collision in CSMA
Assume that there are 4
nodes in the channel
The propagation of the
signal from one node to
the other requires a
certain delay.
Ex:
Transmissions from B and D
cause collision
68
CSMA/CA
CSMA/CA is used WIFI standard IEEE 802.11
If two stations discover that the channel is busy,
and both wait then it is possible that they will try to
resend data in the same time.
collision
Solution CSMA/CA.
Each station wait for a random period reduce the
collision possibility
69
CSMA/CD
Used in Ethernet
CSMA with Collision Detection:
“Listen while talk”.
A sender listen to the channel,
If the channel is free then transmit data
While a station transmit data, it listens to the channel. If it detects a
collision then transmits a short signal warning the collision then stop
Do not continue the transmission even in collision as CSMA
If the channel is busy, wait then transmit with
probability p
Retransmit after a random waiting time.
70
Comparison between channel
division and random access
Channel division
Efficient, treat stations equally.
Waste of resources if one station has much smaller data to
send than the others
Random access
When total load is small: Efficient since each station can
use the whole chanel
When total load is large: Collision possibility increases.
Token control: compromise between the two above
methods.
71
Token Ring
A “tocken” is passed
T
from one node to the
other in a ring topo
Only the token holder
can transmit data (nothing
After finishing sending to send)
data, the token need to T
be passed to next
nodes.
Some problem
Time consuming in
passing token
Loss of token due to data
72
some reasons
Summary on Media access control
mechanisms
Channel division
Random access
Token
What do you thinks about their advantages
and weaknesses
73