Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 82

Data Link Layer

Lecture#33-42

02/13/24 Data Link Layer 1


Link Layer Services(Design Issues)
• Framing, link access:
– encapsulate datagram into frame, adding header, trailer
– channel access if shared medium

• Flow Control:
– pacing between adjacent sending and receiving nodes

• Error Detection:
– errors caused by signal attenuation, noise, and receiver detects presence of errors:

• Error Correction:
– receiver identifies and corrects bit error(s) without resorting to retransmission
• Half-duplex and full-duplex
– with half duplex, nodes at both ends of link can transmit, but not at same time

02/13/24 Data Link Layer 5-2


Error Detection
• Error are likely to occur even when there is a sufficient
SNR to provide a low bit error rate
• To control error and improve the reliability of a
communication line, first we must be able to detect the
errors
• CRC one of the best techniques to detect the error
• Bit Error Rate(BER): It is the ratio of number Ne of errors
appearing over a certain time interval t to the number Nt
of 1 and 0 pulses transmitted during this interval. BER =
Ne/ Nt = Ne / R*t

02/13/24 Data Link Layer 3


Types of Error

• Single Bit Error: In a single-bit error, only one


bit in the data unit has changed

02/13/24 Data Link Layer 4


Burst Error
• A burst error means that 2 or more bits in the
data unit have changed

02/13/24 Data Link Layer 5


Detection

Redundancy: adding extra bits for detecting


errors at the destination.
- Parity Check: a parity bit is added to every data
unit so that the total number of 1s is even
(or odd for odd-parity).
- Cyclic Redundancy Check (CRC)
- Checksum

02/13/24 Data Link Layer 6


Error Detection
EDC= Error Detection and Correction bits (redundancy)
D = Data protected by error checking, may include header fields

• Error detection not 100% reliable!


• protocol may miss some errors, but rarely
• larger EDC field yields better detection and correction

02/13/24 Data Link Layer 5-7


10.3 Redundancy

02/13/24 Data Link Layer 8


10.5 Even-parity concept

02/13/24 Data Link Layer 9


Example 1
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

02/13/24 Data Link Layer 10


Example 2
Now suppose the word world in Example 1 is received by
the receiver without being corrupted in transmission.
11101110 11011110 11100100 11011000
11001001
The receiver counts the 1s in each character and comes up
with even numbers (6, 6, 4, 4, 4). The data are accepted.

02/13/24 Data Link Layer 11


Example 3
Now suppose the word world in Example 1 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.
Note: Simple parity check can detect all single-bit
errors. It can detect burst errors only if the total
number of errors in each data unit is odd
02/13/24 Data Link Layer 12
Parity Checking
Single Bit Parity: Two Dimensional Bit Parity:
Detect single bit errors Detect and correct single bit errors

0 0

02/13/24 Data Link Layer 5-13


10.6 Two-dimensional parity

02/13/24 Data Link Layer 14


Example 4

Suppose the following block is sent:


10101001 00111001 11011101 11100111 10101010

However, it is hit by a burst noise of length 8, and some bits are


corrupted.
10100011 10001001 11011101 11100111 10101010

When the receiver checks the parity bits, some of the bits do not follow
the even-parity rule and the whole block is discarded.
10100011 10001001 11011101 11100111 10101010

02/13/24 Data Link Layer 15


Note:

In two-dimensional parity check, a


block of bits is divided into rows and
a redundant row of bits is added to
the whole block.

02/13/24 Data Link Layer 16


Checksumming: Cyclic Redundancy Check
• view data bits, D, as a binary number
• choose r+1 bit pattern (generator), G
• goal: choose r CRC bits, R, such that
– <D,R> exactly divisible by G (modulo 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 (ATM, HDCL)

02/13/24 Data Link Layer 5-17


10.7 CRC generator and checker

02/13/24 Data Link Layer 18


CRC Example
Want:
D.2r XOR R = nG
equivalently:
D.2r = nG XOR R
equivalently:
if we divide D.2r by G,
want remainder R

D.2r
R = remainder[ ]
G

02/13/24 Data Link Layer 5-19


10.8 Binary division in a CRC generator

02/13/24 Data Link Layer 20


10.9 Binary division in CRC checker

02/13/24 Data Link Layer 21


10.11 A polynomial representing a divisor

02/13/24 Data Link Layer 22


Table 10.1 Standard polynomials
Name Polynomial Application

CRC-8 x 8 + x2 + x + 1 ATM header


CRC-10 x10 + x9 + x5 + x4 + x 2 + 1 ATM AAL
ITU-16 x16 + x12 + x5 + 1 HDLC
x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10
ITU-32 LANs
+ x 8 + x7 + x5 + x4 + x2 + x + 1

02/13/24 Data Link Layer 23


Example 5
Polynomial Properties(Divisor):
1. It should not be divisible by x
2. It should be divisible by x+1
It is obvious that we cannot choose x (binary 10) or x2 + x
(binary 110) as the polynomial because both are divisible
by x. However, we can choose x + 1 (binary 11) because it
is not divisible by x, but is divisible by x + 1. We can also
choose x2 + 1 (binary 101) because it is divisible by x + 1
(binary division).

02/13/24 Data Link Layer 24


Example 6
The CRC-12

x12 + x11 + x3 + x + 1
which has a degree of 12, will detect all burst errors
affecting an odd number of bits, will detect all burst
errors with a length less than or equal to 12, and will
detect, 99.97 percent of the time, burst errors with a
length of 12 or more.

02/13/24 Data Link Layer 25


Internet checksum
Goal: detect “errors” (e.g., flipped bits) in transmitted
segment (note: used at transport layer only)

Sender: Receiver:
• compute checksum of received
• treat segment contents as
segment
sequence of 16-bit integers
• check if computed checksum equals
• checksum: addition (1’s checksum field value:
complement sum) of segment – NO - error detected
contents – YES - no error detected. But
• sender puts checksum value maybe errors nonetheless? More
into UDP checksum field later ….

02/13/24 Data Link Layer 5-26


10.12 Checksum

02/13/24 Data Link Layer 27


10.13 Data unit and checksum

02/13/24 Data Link Layer 28


Note:

The sender follows these steps:


•The unit is divided into k sections, each of n bits.

•All sections are added using one’s complement to get the sum.

•The sum is complemented and becomes the checksum.

•The checksum is sent with the data.

02/13/24 Data Link Layer 29


Note:

The receiver follows these steps:


•The unit is divided into k sections, each of n bits.

•All sections are added using one’s complement to get the sum.

•The sum is complemented.

•If the result is zero, the data are accepted: otherwise, rejected.

02/13/24 Data Link Layer 30


Example 7
Suppose the following block of 16 bits is to be sent using a
checksum of 8 bits.
10101001 00111001
The numbers are added using one’s complement
10101001
00111001
------------
Sum 11100010
Checksum 00011101
The pattern sent is 10101001 00111001 00011101

02/13/24 Data Link Layer 31


Example 8
Now suppose the receiver receives the pattern sent in Example 7
and there is no error.
10101001 00111001 00011101
When the receiver adds the three sections, it will get all 1s, which,
after complementing, is all 0s and shows that there is no error.
10101001
00111001
00011101
Sum 11111111
Complement 00000000 means that the pattern is OK.
02/13/24 Data Link Layer 32
Example 9
Now suppose there is a burst error of length 5 that affects 4 bits.
10101111 11111001 00011101
When the receiver adds the three sections, it gets
10101111
11111001
00011101
Partial Sum 1 11000101
Carry 1
Sum 11000110
Complement 00111001 the pattern is corrupted.
02/13/24 Data Link Layer 33
Error Correction

Retransmission

Forward Error Correction(FEC)

Burst Error Correction

02/13/24 Data Link Layer 34


Table 10.2 Data and redundancy bits

Number of Number of Total


data bits redundancy bits bits
m r m+r
1 2 3
2 3 5
3 3 6

4 3 7

5 4 9

6 4 10

7 4 11

02/13/24 Data Link Layer 35


FEC
10.14 Positions of redundancy bits in Hamming code
Each r bit is the parity bit for one combination of data bits

02/13/24 Data Link Layer 36


10.15 Redundancy bits calculation

02/13/24 Data Link Layer 37


10.16 Example of redundancy bit calculation

02/13/24 Data Link Layer 38


10.17 Error detection using Hamming code

02/13/24 Data Link Layer 39


10.18 Burst error correction example

02/13/24 Data Link Layer 40


MAC Protocols: a taxonomy
Three broad classes:
• Channel Partitioning
– divide channel into smaller “pieces” (time slots, frequency, code)
– allocate piece to node for exclusive use
• Random Access
– channel not divided, allow collisions
– “recover” from collisions
• “Taking turns”
– Nodes take turns, but nodes with more to send can take longer
turns

02/13/24 Data Link Layer 5-41


Channel Partitioning MAC protocols: TDMA
TDMA: time division multiple access
• access to channel in "rounds"
• each station gets fixed length slot (length = pkt trans time) in each round
• unused slots go idle
• example: 6-station LAN, 1,3,4 have pkt, slots 2,5,6 idle

• TDM (Time Division Multiplexing): channel divided into N time slots, one per user;
inefficient with low duty cycle users and at light load.
• FDM (Frequency Division Multiplexing): frequency subdivided.

02/13/24 Data Link Layer 5-42


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 pkt, frequency bands 2,5,6 idle

time
frequency bands

• TDM (Time Division Multiplexing): channel divided into N time slots, one per user;
inefficient with low duty cycle users and at light load.
• FDM (Frequency Division Multiplexing): frequency subdivided.

02/13/24 Data Link Layer 5-43


CDMA
• One channel occupies entire bandwidth of the
link(differs from FDMA)
• All stations can send data simultaneously(differs
from TDMA)
• One channel carries all transmission
simultaneously
• It is based on coding theory
• Each stations is assigned a code , which is a
sequence of numbers called chips
02/13/24 Data Link Layer 44
Rules for encoding
• Suppose we have a sequence of four chips
corresponding to each station

02/13/24 Data Link Layer 45


CDMA multiplexer

02/13/24 Data Link Layer 46


CDMA demultiplexer

02/13/24 Data Link Layer 47


Random Access Protocols
• When node has packet to send
– transmit at full channel data rate R.
– no a priori coordination among nodes
• two or more transmitting nodes ➜ “collision”,
• random access MAC protocol specifies:
– how to detect collisions
– how to recover from collisions (e.g., via delayed retransmissions)
• Examples of random access MAC protocols:
– slotted ALOHA
– ALOHA
– CSMA, CSMA/CD, CSMA/CA

02/13/24 Data Link Layer 5-48


Slotted ALOHA
Assumptions Operation
• all frames same size • when node obtains fresh
• time is divided into equal frame, it transmits in next slot
size slots, time to transmit 1 • no collision, node can send
frame new frame in next slot
• nodes start to transmit • if collision, node retransmits
frames only at beginning of frame in each subsequent slot
slots with prob. p until success
• nodes are synchronized
• if 2 or more nodes transmit
in slot, all nodes detect
collision
02/13/24 Data Link Layer 5-49
Slotted ALOHA

Pros Cons
• single active node can • collisions, wasting slots
continuously transmit at • idle slots
full rate of channel • nodes may be able to
• highly decentralized: only detect collision in less
slots in nodes need to be than time to transmit
packet
in sync
• clock synchronization
• simple
02/13/24 Data Link Layer 5-50
Slotted Aloha efficiency
Efficiency is the long-run • For max efficiency with N
fraction of successful slots nodes, find p* that
when there are many nodes, maximizes
each with many frames to send Np(1-p)N-1
• For many nodes, take
• Suppose N nodes with many limit of Np*(1-p*)N-1 as N
frames to send, each transmits in
goes to infinity, gives 1/e
slot with probability p
• prob that node 1 has success in a
= .37
slot = p(1-p)N-1
• prob that any node has a success = At best: channel
Np(1-p)N-1 used for useful
transmissions 37%
of time!

02/13/24 Data Link Layer 5-51


Pure (unslotted) ALOHA
• unslotted Aloha: simpler, no synchronization
• when frame first arrives
– transmit immediately
• collision probability increases:
– frame sent at t0 collides with other frames sent in [t0-1,t0+1]

02/13/24 Data Link Layer 5-52


Pure Aloha efficiency
P(success by given node) = P(node transmits) .
P(no other node transmits in [t0-1,t0] .
P(no other node transmits in [t0, t0+1]
= p . (1-p)N-1 . (1-p)N-1
= p . (1-p)2(N-1)

… choosing optimum p and then letting n -> infty ...

Even worse= 1/(2e)


! = .18

02/13/24 Data Link Layer 5-53


Throughput Comparison

02/13/24 Data Link Layer 54


Carrier Sense Multiple Access
• To minimize the no. of collision or maximize the
performance, we can use the concept of sensing
the medium
• It is based on the technique listen before talk
or sense before transmit
• But it can not eliminate all the collision
• It is able to reduce the collision and improve the
throughput

02/13/24 Data Link Layer 55


CSMA (Carrier Sense Multiple Access)

CSMA: listen before transmit:


If channel sensed idle: transmit entire frame
• If channel sensed busy, defer transmission

• Human analogy: don’t interrupt others!

02/13/24 Data Link Layer 5-56


Collision in CSMA

02/13/24 Data Link Layer 57


Persistence Technique
• This is technique defined that what should we do
when medium is busy
• Non-persistence:
1. If the medium is idle ,transmit; otherwise ,
go to step 2
2. If the medium is busy , wait an amount of
time drawn from a probability
distribution(retransmission delay) and
repeat step 1

02/13/24 Data Link Layer 58


1-Persistence
• Algorithm:
1. If the medium is idle ,transmit; otherwise ,
go to step 2
2. If the medium is busy , continue to listen until
the channel is sensed idle; then transmit
immediately
• Still, there is a chance of collision, when two
stations senses the medium simultaneously

02/13/24 Data Link Layer 59


p-Persistence
• Algorithm:
1. If the medium is idle ,transmit with probability p, and
delay one time unit with probability (1-p) (The time
unit is typically equal to the maximum propagation
delay)
2. If the medium is busy, continue to listen until the
channel is idle and repeat step 1
3. If the transmission is delayed one time unit, repeat
step 1
• It shows the highest performance among the all
persistence technique
02/13/24 Data Link Layer 60
Throughput Comparison

02/13/24 Data Link Layer 61


“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!
02/13/24 Data Link Layer 5-62
“Taking Turns” MAC protocols
(Controlled Access)
Polling: Token passing:
 control token passed from
• master node “invites”
slave nodes to transmit one node to next sequentially.
in turn  token message
• concerns:  concerns:
– polling overhead  token overhead
– latency  latency
– single point of failure  single point of failure (token)
(master)

02/13/24 Data Link Layer 5-63


Select

02/13/24 Data Link Layer 64


Poll

02/13/24 Data Link Layer 65


Token Passing
• A token circulates around the ring, if no data
are being sent
• The station captures the token and sends one
or more frames
• It will keep capture till they have frame or
allocated time has not expired
• Finally release the token after used

02/13/24 Data Link Layer 66


Figure 13.12 Token-passing network

02/13/24 Data Link Layer 67


Ethernet
“dominant” wired LAN technology:
• cheap $20 for 100Mbs!
• first widely used LAN technology
• Simpler, cheaper than token LANs and ATM
• Kept up with speed race: 10 Mbps – 10 Gbps

Metcalfe’s Ethernet
sketch

02/13/24 Data Link Layer 5-68


Ethernet Frame Structure
Sending adapter encapsulates IP datagram (or other network
layer protocol packet) in Ethernet frame

Preamble:
• 7 bytes with pattern 10101010 followed by one byte with
pattern 10101011
• used to synchronize receiver, sender clock rates

02/13/24 Data Link Layer 5-69


Ethernet Frame Structure (more)
• Addresses: 6 bytes
– if adapter receives frame with matching destination address, or with
broadcast address (eg ARP packet), it passes data in frame to net-layer
protocol
– otherwise, adapter discards frame
• Type: indicates the higher layer protocol (mostly IP but others
may be supported such as Novell IPX and AppleTalk)
• CRC: checked at receiver, if error is detected, the frame is
simply dropped

02/13/24 Data Link Layer 5-70


Bit Stuffing
• Delimit frame at both ends 01111110
• May close one frame and open another
• Receiver hunts for flag sequence to synchronize
• Bit stuffing used to avoid confusion with data
containing 01111110
– 0 inserted after every sequence of five 1s
– If receiver detects five 1s it checks next bit
– If 0, it is deleted
– If 1 and seventh bit is 0, accept as flag
– If sixth and seventh bits 1, sender is indicating abort
02/13/24 Data Link Layer 71
Bit Stuffing
• Example with
possible errors

02/13/24 Data Link Layer 72


Ethernet uses CSMA/CD
• No slots • Before attempting a
• adapter doesn’t transmit if it retransmission, adapter
senses that some other waits a random time, that
adapter is transmitting, that is, random access
is, carrier sense
• transmitting adapter aborts
when it senses that another
adapter is transmitting, that
is, collision detection

02/13/24 Data Link Layer 5-73


Ethernet CSMA/CD algorithm
1. Adaptor receives datagram 4. If adapter detects another
from net layer & creates frame transmission while
2. If adapter senses channel idle transmitting, aborts and
for 96 bit times, it starts to sends jam signal
transmit frame. If it senses 5. After aborting, adapter enters
channel busy, waits until exponential backoff: after the
channel idle plus 96 bit times mth collision, adapter chooses
and then transmits a K at random from
3. If adapter transmits entire {0,1,2,…,2m-1}. Adapter waits
frame without detecting K·512 bit times and returns to
another transmission, the Step 2
adapter is done with frame !

02/13/24 Data Link Layer 5-74


• Truncated Binary Exponential Backoff
– Attempts := 0;
– Attempt Limit is 16 and Backoff Limit 10.
While
{ (Frame NOT Transmitted Successfully)
AND (Attempts < Attempt Limit) }
K : = Min (Attempts, Backoff Limit)
R : = Random (0, 2k-1)
delay : = R * SlotTime;
Wait (delay)
Increment Attempts;
End While
– This algorithm yields a "statistical fairness" in the
sharing of bandwidth.

02/13/24 Data Link Layer 75


CSMA/CD efficiency
• Tprop = max prop between 2 nodes in LAN
• ttrans = time to transmit max-size frame

• Efficiency goes to 1 as t prop goes to 0


• Goes to 1 as ttrans goes to infinity
• Much better than ALOHA, but still decentralized, simple, and cheap

1
efficiency 
1  5t prop / ttrans

02/13/24 Data Link Layer 5-76


Repeater, Hub, Bridge & Switch

Repeater
A repeater receives a signal, regenerates it, and passes it on.
It can regenerate and retime network signals at the bit level
to allow them to travel a longer distance on the media.
It operates at Physical Layer of OSI
The Four Repeater Rule for 10-Mbps Ethernet should be
used as a standard when extending LAN segments.
This rule states that no more than four repeaters can be
used between hosts on a LAN.
This rule is used to limit latency added to frame travel by
each repeater.

02/13/24 Data Link Layer 77


Repeater, Hub, Bridge & Switch

Hub
Hubs are used to connect multiple
nodes to a single physical device,
which connects to the network.
Hubs are actually multiport
repeaters.
Using a hub changes the network
topology from a linear bus, to a
star.
With hubs, data arriving over the
cables to a hub port is electrically
repeated on all the other ports
connected to the same network
segment, except for the port on
which the data was sent.
02/13/24 Data Link Layer 78
Repeater, Hub, Bridge & Switch

Bridge
Bridges are used to logically separate network
segments within the same network.
They operate at the OSI data link layer (Layer
2) and are independent of higher-layer
protocols.
The function of the bridge is to make
intelligent decisions about whether or not to
pass signals on to the next segment of a
network.
When a bridge receives a frame on the
network, the destination MAC address is
looked up in the bridge table to determine
whether to filter, flood, or copy the frame
onto another segment
Broadcast Packets are forwarded
02/13/24 Data Link Layer 79
Repeater, Hub, Bridge & Switch

Switch
Switches are Multiport Bridges.
Switches provide a unique network segment on each port,
thereby separating collision domains.
Today, network designers are replacing hubs in their wiring
closets with switches to increase their network performance
and bandwidth while protecting their existing wiring
investments.
Like bridges, switches learn certain information about the data
packets that are received from various computers on the
network.
Switches use this information to build forwarding tables to
determine the destination of data being sent by one computer
to another computer on Data
02/13/24 theLinknetwork.
Layer 80
Repeater, Hub, Bridge & Switch

Switches: Dedicated Access


Hosts have direct connection to A
switch
C’ B
Full Duplex: No collisions
Switching: A-to-A’ and B-to-B’
simultaneously, no collisions switch

Switches can be cascaded to


expand the network
C

B’ A’

02/13/24 Data Link Layer 81


Thank You

02/13/24 Data Link Layer 82

You might also like