Lecture 4 - Datalink Layer
Lecture 4 - Datalink Layer
Datalink layer
l Functionalities:
l Encapsulation, addressing
l Error detection and correction
l Flow control
l Media access control
1
Overview of Data link layer
2
Network nodes and links
“link”
l Network nodes:
l PCs, Laptop, Routers,
Server…
l Links:
l Communication chanel
between adjacent nodes
l Wired link: Ethernet LAN,
ADSL, fiber optic…
l Wireless link: Wi-fi, FSO,
Satellite,…
l Datalink layer
responsibility:
l Transmit data between
adjacent elements.
3
Datalink layer in Layer
architecture
Application Media independent
sub-layer
Transport
Network LLC
(Logical Link Control)
Data-link
MAC
Physical (Media Access Control) Media dependent
sub-layer
802.2 LLC
Datalink layer
5
Functionalities
l Framing:
l Sender: place the network layer packet into the
frame, add header, tail
l Receiver: Remove the header, tail for extracting
the network packet.
l Addressing:
l Physical address in the header of the frame for
identifying the source and the destination.
6
Framing-Example of HDLC frame
7
Functionalities (2)
l Media access control:
l If the nodes in the network share common media,
a Media access control protocol is required.
l Flow control:
l Control the transmission speed of the sender so
that the receiver does not overloaded.
l Error control:
l Detect and correct errors
l e.g. parity check, checksum, CRC check
8
Error control
Error detection
Error correction
9
Principle of error correction
EDC= Error Detection Code (redundancy)
EDC is added to data before sending to the destination.
Data Data
Y
All bit in Error
Data’
OK? N
10
Parity code
A check bit is added to the original data to ensure that the
total number of bit 1 is even (even parity code) or odd (odd
parity code)
l Single code
l Able to detect single bit
error
101011 101011
l Two dimension code 111100 101100
l Detect and correct single bit 011101 011101
error
001010 001010
D R D’ R’
12
Link with bit errors
CRC: How to find R
l 1011 ß> x3 +x +1
l Example of some CRC using in the pratice:
l CRC-8 = x8 + x2 + x + 1
l CRC-12 = x12+x11+x3+x2+x
l CRC-16-CCITT = x16 + x12 + x5 + 1
l CRC-32 = x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5
+ x4 + x2 + x + 1
l The longer G is, the more possible that CRC detects
errors.
l CRC is widely used in the practice
l Wi-fi, ATM, Ethernet…
l Operation XOR is implemented in hardware
l Capable to detect less than r+1 bits errors
14
Reaction when errors detected
l Objective: assure that data l Popular techniques:
are transmitted correctly l Error detection (as we seen)
even though the chanel is l Acknowledgement/
confirmation
not realiable. l Retransmis after timeout
l Condition l Retransmis after a clear
confirmation that frame is not
l Data fram must be arrived
transmitted correctly l ARQ technique: automatic
l Negligible transmission repeat request). There are 3
delay. versions:
Stop and Wait ARQ
l Possible errors l
l Go Back N ARQ
l Whole frame loss l Selective Reject ARQ
l Error frame l Similar to techniques used in
l Loss of error warning flow control.
message
15
Media access control
16
Connection types
l Point-to-point
l ADSL
l Telephone modem
l Leased Line….
l Broadcast
l LAN using bus topology
l Wireless LAN
l HFC:
l …
l Broadcast networks need media access control
protocol in order to avoid collision when nodes try to
send data.
17
Classification of MAC protocol
l Chanel division:
l Resources of the media is divided into small parts (time -
TDMA, frequency- FDMA, Code- CDMA)
l Distribute a part to each nodes
l Random access:
l Chanel is not divided, all nodes are allowed to access
simultaneously with collision possibility
l Need a mechanism to avoid collision
l e.g. Pure Aloha, Slotted Aloha, CSMA/CD, CSMA/CA…
l Sequent access:
l Nodes can send data one after the other.
l Token Ring, Token Bus….
18
Channel division
l FDMA: frequency division multiple access
l TDMA: time division multiple access
19
ex
TDMA và FDMA 4 stations
FDMA
frequency
time
TDMA:
frequency
time 20
CDMA
l Several senders can share the same frequency on a
single physical channel.
l Signals come from different senders are encoded by a
different random code
l Encrypted signals are mixed and then transmit on a
common frequency.
l The signals are recovered at the receiver by using the
same codes as at sender side.
l CDMA use the spread spectrum theory, CDMA shows
a lot of advantages that other technology cannot
achieve.
http://en.wikipedia.org/wiki/Spread_spectrum
21
DS-CDMA System Overview
(Forward link)
CDMA is a multiple spread spectrum.
Freq. Freq.
Freq. Freq.
BPF BPF
Data B Despreade Data B
r
Code B
Code B MS-B
•••
BS
•••
25
CSMA
26
Collision in CSMA
l Assume that there are 4
nodes in the channel
l The propagation of the
signal from one node to
the other requires a
certain delay.
l Ex:
l Transmissions from B and D
cause collision
27
CSMA/CA
l CSMA/CA is used WIFI standard IEEE 802.11
l 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.
l à collision
l Solution CSMA/CA.
l Each station wait for a random period à reduce the
collision possibility
28
CSMA/CD
l Used in Ethernet
l CSMA with Collision Detection:
l “Listen while talk”.
l A sender listen to the channel,
l If the channel is free then transmit data
l 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
l Do not continue the transmission even in collision as CSMA
l If the channel is busy, wait then transmit with
probability p
l Retransmit after a random waiting time.
29
Comparison between channel
division and random access
l Channel division
l Efficient, treat stations equally.
l Waste of resources if one station has much smaller data to
send than the others
l Random access
l When total load is small: Efficient since each station can
use the whole chanel
l When total load is large: Collision possibility increases.
l Token control: compromise between the two above
methods.
30
Token Ring
l A “tocken” is passed
from one node to the T
l Token
32
Flow control
33
What is flow control
l Goal: Make sure that the sender does not overload the receiver
l Why overloading?
l The receiver stores data frame in buffer.
l Receiver performs some processing before deliver data to the upper level.
l Buffer could be full, leaving no space for receiving more frame à some data
fram must be dropped.
l Problem of errors in transmission is excluded
l All frames are transmitted to correct receiver without error
l Propagation time is small and could be ignored
l Solution
l Stop-and-wait mechanism
l Sliding window mechanism
34
Stop-and-wait
l Principles
l Transmitter sends a single frame
35
ole 2
Stop-and-wait
transmitter
Emetteur receiver
Récepteur
répéter
eReseau.donnerPaquet() Packet
Paquets Paquets
Packet
uireTrame(p)
sique.prendreTrame(t)
sique.attendreAquittement() frame
Trâme
Ack
répéter
ePhysique.donnerTrame()
ePaquet(t) Trâme
frame
eau.prendrePaquet(p)
sique.envoyerAcquittement()
frame
Trâme
Trâme
36
40
Sliding windows: principle
41
Window list the frames to transmit Window list the frames in waiting to receive
Sliding windows
42
Sliding windows
l Frame are numbered. The maximum number must
not be smaller than the size of the window.
l Frame are ACKed by another message with number
l Accumulated ACK: If frame 1,2,3,4 are well
receive, just send ACK 4
l ACK with number k means all frame k-1, k-2 …
already well received.
43
Sliding windows
l Transmitter needs to manage some information:
l List of frames transmitted sucessfully
l List of frames transmitted without ACK
l List of frames to be sent immediatly
l List of frames NOT to be sent immediately
l Receiver keep tracks of
l List of frames well received
l List of frames expected to receive
44
Piggy backing
l A and B transmitte data in both sides
l When B needs to send an ACK while still needs to
send data, B attaches the ACK in the Data frame:
Piggybacking
l Otherwise, B can send an ACK frame separatly
l After ACK, if B sends some other data, it still put the
ACK information in data frame.
l Sliding window is much more efficient than Stop-
and-Wait
l More complicated in management.
45
Exercices
l Given a link with rate R=100Mbps
l We need to send a file over data link layer with file size L=100KB
l Assume that the size of a frame is: 1KB, header size is ignored
l Round trip time (RTT) between 2 ends of the link is 3ms
l An ACK message is sent back from receiver whenever a frame is
arrived. Size of ACK message is negligible
l What is the transmission time required if using Stop-and-wait
mechanism?
l Transmission time with sliding window if the window size is =7?
l Which size of window allow to obtain the fastest transmission?
46
e2 Transmission time with Stop-
and-wait
transmitter
Emetteur receiver
Récepteur
éter
eseau.donnerPaquet() Packet
Paquets Packet
Paquets
Trame(p)
ue.prendreTrame(t) T transmit
ue.attendreAquittement() frame
Trâme
RTT Ack
éter
ysique.donnerTrame()
aquet(t) frame
Trâme
u.prendrePaquet(p)
ue.envoyerAcquittement()
frame
Trâme
Trâme
47
49
Trasmission time with window
size 7
l T fastest= (T transmit 7 frames+ wait) * Nb.
Waiting time.
l 1 waiting= (T transmit 1 frame+ RTT) – T
transmit 7 frames
l Nb. Waiting time= Nb frame /7
50
Fastest transmission time with
sliding window
l 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.
l Window size:W
l T transmit(W fram) >= T
transmit first frame + RTT
51
Fastest transmission time with
sliding window
l T transmit (W frame) = W * 1KB/R
l => (W-1)*1KB/R >= RTT