Chapter 3 - Datalink Layer
Chapter 3 - Datalink Layer
Datalink layer
• Functionalities:
• Encapsulation, addressing
• Error detection and correction
• Flow control
• Media access control
1
Overview of Data link layer
2
Network nodes and links
“link”
• Network nodes:
• PCs, Laptop, Routers,
Server…
• Links:
• Communication chanel
between adjacent nodes
• Wired link: Ethernet LAN,
ADSL, fiber optic…
• Wireless link: Wi-fi, FSO,
Satellite,…
• Datalink layer responsibility:
• Transmit data between
adjacent elements.
3
Datalink layer in Layer architecture
Network LLC
(Logical Link Control)
Data-link
MAC
Physical (Media Access Control) Media dependent sub-
layer
802.2 LLC
4
Functionalities
Datalink layer
5
Functionalities
• Framing:
• Sender: place the network layer packet into the
frame, add header, tail
• Receiver: Remove the header, tail for extracting the
network packet.
• Addressing:
• Physical address in the header of the frame for
identifying the source and the destination.
6
Framing-Example of HDLC frame
7
Functionalities (2)
8
Error control
• Error detection
• Error correction
9
Principle of error detection
Data Data
Y
Error
All bit in Dataʼ
OK?
N
10
Principal of error detection
11
Parity code
13
Checksum code
• Sender:
• Divides data into small parts of n bit
• Calculates binary sum of all parts. If there are some overflow bit,
add the overflow bit to the result.
• Alters all bits (two’s complement) to get the checksum
• Sends the checksum with data
• Receiver:
• Extracts data and checksum
• Divides data into block of n bits
• Calculates the sum as in the sender side including with the
checksum received
• If result contains at least one bit 0à error.
14
Checksum: Example
Overflow
10001
bit 1
0010
Alter bit -> checksum code: 1101
Bits to send: 0011 0110 1000 1101
15
Checksum: Processing on receiver
16
CRC: Cyclic Redundancy Check
• Data is considered as a binary string: D
• We wants to generate a error code with length r
• Choose another binary string of (r+1) bit, G (Generator)
• Find a string R with length r bits such that the concatenation of D and
R is a binary number that divides G (modulo 2)
• <D, R> divides G
D D
Y
N
<Dʼ, Rʼ> mod G = 0 ?
<D, R> mod G = 0
D R Dʼ Rʼ
• 1011 ß> x3 +x +1
• Example of some CRC generators 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
19
Reaction when errors detected
20
Stop-and-wait ARQ
Normal case
Sender Receiver
send pkt0 p k t0
pkt0 is
AC K OK
rcv ACK
send pkt1 p k t1
pkt1 is
N AK corrupted
rcv NAK p k t1
resend pkt1
Time
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
21
Stop-and-wait ARQ
Error ACK/NAK
Sender Receiver
• ACK error, resend the
previous packet
• Duplicated packets send pkt0 p k t0
problem.
pkt0 is
• To eliminate repeated AC K OK
packet: Use Seq.# rcv ACK
send pkt1 p k t1
• All packets are assigned
Seq# before sending out. pkt1 is
Repeated packet has AC K OK
identical Seq#
rcv sth corrupted! p k t1
resend pkt1 rcv pkt1
duplicate,
Time discard it
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
22
Stop-and-wait ARQ
not using NAK
Sender Receiver • ACK packet carries
#Seq of the packet to
be acknowledged.
pkt0
send pkt0 This number is called
pkt0 is acknowledgment
ACK0 OK number
rcv ACK0
send pkt1
pkt1 • An ACK with
acknowledgment
ACK1 pkt1 is number n implicitly
OK
rcv ACK1 pkt2 pkt2 is corrupted
confirms that all
send pkt2 packet with #seq
number < =n have
ACK1
been well received
rcv ACK1 pkt2
resend pkt2
Time
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
23
Stop-and-wait ARQ: When ACK is lost
25
ARQ with timeout
26
Media access control
27
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.
28
Classification of MAC protocol
• Chanel division:
• Resources of the media is divided into small parts (time -
TDMA, frequency- FDMA, Code- CDMA)
• Distribute a part to each nodes
• Random access:
• Chanel is not divided; all nodes are allowed to access
simultaneously with collision possibility
• Need a mechanism to avoid collision
• e.g. Pure Aloha, Slotted Aloha, CSMA/CD, CSMA/CA…
• Sequent access/Taking turns:
• Nodes can send data one after the other.
• Token Ring, Token Bus….
29
Channel division
30
TDMA và FDMA
example
4 stations
FDMA
frequency
time
TDMA:
frequency
32
CDMA
33
Random access: Pure Aloha
35
Random access: Slotted Aloha
36
Random access: CSMA
37
CSMA
38
Collision in CSMA
39
CSMA/CA (Collision Avoidance)
40
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.
41
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.
42
Token Ring
a ring topo
l Only the token holder can
transmit data (nothing
l After finishing sending to send)
data, the token need to T
be passed to next nodes.
l Some problem
l Time consuming in passing
token
l Loss of token due to some
reasons data
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
43
Summary on Media access control mechanisms
• Channel division
• Random access
• Token
• What do you thinks about their advantages and
weaknesses ?
44
Point-to-Point forwarding
mechanism
Hub, Switch, Bridge
45
Devices of LAN
46
Hub
47
Devices of LAN (cont.)
lBridge
lMore intelligent than hub
lCan store and forward data (Ethernet frame)
according to MAC address.
lBridge breaks the network into two collision
domains.
lLayer 2 intermediate system
lSwitch
lMore ports than bridge
lCan store and forward data according to
MAC address
l Receive full frame, check error, forward
48
Bridge
Collision domains
bridge
hub hub
49
Switch
50
Switch: Self learning mechanism
Source: A
Dest: A’
A A A’
lSwitch learns the MAC
addresses of all hosts C’ B
connected to the switch
lEach time switch receive a 1 2
frame, it may update the 6 3
source MAC address of the frame 4
and corresponding connected 5
port
• if the address is not in MAC table C
• If the address is in the MAC table,
but the corresponding pỏt is B’
different to that in the table A’
lForwarding table
MAC addr interface TTL
A 1 60
51
Switch: forwarding mechanism
52
Source: A
Dest: A’
Ex: A A A’
C’ B
lOutgoing port 1 2
unknown: Broadcast A6A’ 3
5 4
l Know A:
C
A’ A
Direct transfering
B’ A’
53
Connecting switches in cascade
S4
S1
S3
A S2
F
D I
B C
G H
E
54
A typical LAN
mail server
Connect to
outside
router web server
IP subnet
55
Flow control
56
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
57
Stop-and-wait
• Principles
• Transmitter sends a single frame
• Receiver receives the fram, process and then
informs the transmitter that it is ready to receives
next frames by a clear acknowledgement (ACK).
• Transmitter waits until reception of the ACK before
sending next frames.
58
Stop-and-wait
e2
transmitter
Emetteur receiver
Récepteur
éter
eseau.donnerPaquet() Packet
Paquets Paquets
Packet
Trame(p)
ue.prendreTrame(t)
ue.attendreAquittement() frame
Trâme
Ack
éter
ysique.donnerTrame()
aquet(t) frame
Trâme
u.prendrePaquet(p)
ue.envoyerAcquittement()
frame
Trâme
Trâme
59
Conception et architectures des réseaux
Stop-and-wait
60
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
61
Sliding window: principle
62
Sliding window: principle
63
Sliding windows: principle
65
Sliding windows
66
Sliding windows
67
Piggyback
68
Exercices
69
e2 Transmission time with Stop-and-wait
transmitter
Emetteur receiver
Récepteur
éter
Packet
Paquets Packet
Paquets
eseau.donnerPaquet()
eTrame(p)
que.prendreTrame(t) T transmit
que.attendreAquittement() frame
Trâme
RTT Ack
éter
hysique.donnerTrame()
aquet(t) frame
Trâme
u.prendrePaquet(p)
que.envoyerAcquittement()
Trâme
frame
Trâme
71
Transmission schema with Sliding windows
72
Trasmission time with window size 7
73
Fastest transmission time with sliding window
74
Fastest transmission time with sliding window
75
LAN: Local Area Network
Reading: 4.3 Computer Networks, Tanenbaum
76
LAN topology
WLAN
Traditional bus
topo
hub, switch
Ring
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology Star
77
LAN Standards
78
Ethernet LAN
Metcalfe’s Ethernet
sketch
79
IEEE 802.3 and Ethernet Standards
MAC protocol
application
and frame format
transport
network 100BASE-TX 100BASE-T2 100BASE-FX
link 100BASE-T4 100BASE-SX 100BASE-BX
physical
Transceiver
Interface
cable
Ether
Ref: Computer
Figure 4-13. Network,
Architecture ofTanenbaum
School of Information and Communication Technology
classic Ethernet.
81
Structure of Ethernet frame
82
Switched Ethernet
l Switched Ethernet (popular nowdays):
l Star topology,
l Use a central switch Ethernet
l The switch outputs a frame only to the port linking to the
destination è independent connection for each pair of two nodes
l No collision
l No media access control is needed.
switch
83
Wireless LAN
84
Overview of 802.11 LAN
l802.11b l802.11g
lBand 2.4-5 GHz (unlicensed lBand 2.4-5 GHz
spectrum) lMaximum speed 54
lMaximum speed 11 Mbps Mbps
86
802.11: Chanel and connection
87
802.11: Chanel and connection
88
Scanning mechanism: active/passive
AP 1 AP 2 AP 1 1 AP 2
1 1 2 2
2 3
3 4
H1 H1
89
IEEE 802.11: Multiple access control
• 802.11: CSMA
• 802.11: CA – Collision Avoidance
• It is difficult to implement Collision detection (CD) in
wireless environment.
• In some cases, it is even impossible to detect the collision :
hidden terminal, fading
A B C
C
A’s signal C’s signal
B strength strength
A
90
IEEE 802.11 MAC Protocol: CSMA/CA
Sender
1 If the channel is available during DIFS time then Sender Receiver
Send the entire frame (no CD)
2 if channel is busy then DIFS
Starting random back-off (waiting)
At the end of back-off time, send data
data
If no ACK is received, double the back-off
time and try again.
Receiver SIFS
92
Collision Avoidance using RTS-CTS
A B
AP
RTS(A) RTS(B)
reservation collision
RTS(A)
C T S (A ) C T S (A )
DATA (A)
defer
time
A C K (A ) A C K (A )
93
802.11 frame: Addressing
2 2 6 6 6 2 6 0 - 2312 4
frame address address address seq address
duration payload CRC
control 1 2 3 control 4
Address 4: Using in
adhoc mode
Address 1: address of
the destination Address 3: MAC address of
the router attached to the
AP
Address 2: address of the source
94
802.11 frame: Addressing
Internet
H1 R1 router
AP
802.3 frame
802.11 frame
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
95
802.11 frame
frame seq #
Duration of the reservation (RTS/CTS) (ACK)
2 2 6 6 6 2 6 0 - 2312 4
frame address address address seq address
duration payload CRC
control 1 2 3 control 4
2 2 4 1 1 1 1 1 1 1 1
Protocol To From More Power More
Type Subtype Retry WEP Rsvd
version AP AP frag mgt data
frame type
(RTS, CTS, ACK, data)
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
96
Access networks using
optical fiber
Access networks
• Hub
– Device on the service provider side receiving
data
• Network Interface Unit (NIU)
– Device on the user side connecting an user or an
organization
• Remote Node (RN)
– In broadcasting networks, RN distribute data
from Hub to NIUs
– In switched networks, RN receive data from Hub
and distribute different flows to NIUs
101
Optical access network: FTTx
108
WPON (WDM PON)
• Developed by compagnies and has not been standardized
• Each ONT use a wavelength to transmit data
• Remote note is AWG (arrayed waveguide grating). The AWG is
capable to MUX/DEMUX wavelengths from up and down
streams.