Chapter 5 Data Link Layer

5: DataLink Layer


Chapter 5 outline
Ì 5.1 Introduction and services Ì 5.2 Error detection and correction Ì 5.3Multiple access protocols Ì 5.4 LAN addresses and ARP Ì 5.5 Ethernet Ì 5.6 Hubs, bridges, and switches

5: DataLink Layer


Link Layer: Introduction
Some terminology:
Ì hosts and routers are nodes


(bridges and switches too) Ì communication channels that connect adjacent nodes along communication path are links
r r r

wired links wireless links LANs

data-link layer has responsibility of transferring datagram from one node to adjacent node over a link

5: DataLink Layer


Link layer: context
Ì Datagram transferred by

transportation analogy
Ì trip from Murshidabad to Goa

different link protocols over different links:

e.g., Ethernet on first link, frame relay on intermediate links, 802.11 on last link

r r

car: Murshidabad to Kolkata plane: Kolkata to Mumbai train: Mumbai to Goa

Ì Each link protocol

Ì tourist = datagram Ì transport segment =

provides different services

e.g., may or may not provide rdt over link

communication link Ì transportation mode = link layer protocol Ì travel agent = routing algorithm
5: DataLink Layer 5a-4

Link Layer Services
Ì Framing, link access:
r r r

encapsulate datagram into frame, adding header, trailer channel access if shared medium ‘physical addresses’ used in frame headers to identify source, dest • different from IP address!

Ì Reliable delivery between adjacent nodes r we learned how to do this already (chapter 3)! r seldom used on low bit error link (fiber, some twisted pair) r wireless links: high error rates

5: DataLink Layer


Link Layer Services (more)

Flow Control:

pacing between adjacent sending and receiving nodes errors caused by signal attenuation, noise. receiver detects presence of errors: • signals sender for retransmission or drops frame

Error Detection:
r r

Ì Error Correction: r 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
5: DataLink Layer 5a-6

Adaptors Communicating
datagram sending node link layer protocol frame adapter rcving node frame adapter

Ì link layer implemented in Ì receiving side r looks for errors, rdt, flow “adaptor” (aka NIC) control, etc r Ethernet card, PCMCI r extracts datagram, passes card, 802.11 card to rcving node Ì

sending side:


encapsulates datagram in a frame adds error checking bits, rdt, flow control, etc.

Ì adapter is semi-

autonomous Ì link & physical layers
5: DataLink Layer 5a-7

Chapter 5 outline
Ì 5.1 Introduction and Ì Ì Ì Ì

services 5.2 Error detection and correction 5.3Multiple access protocols 5.4 LAN addresses and ARP 5.5 Ethernet

Ì 5.6 Hubs, bridges, and


5: DataLink Layer


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

5: DataLink Layer


Parity Checking
Single Bit Parity:
Detect single bit errors

Two Dimensional Bit Parity:
Detect and correct single bit errors



5: DataLink Layer 5a-10

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

compute checksum of received segment Ì check if computed checksum equals checksum field value: r NO - error detected r YES - no error detected.

sequence of 16-bit integers Ì checksum: addition (1’s complement sum) of segment contents Ì sender puts checksum value into UDP checksum field

5: DataLink Layer 5a-11

Chapter 5 outline
Ì 5.1 Introduction and Ì Ì Ì Ì

services 5.2 Error detection and correction 5.3Multiple access protocols 5.4 LAN addresses and ARP 5.5 Ethernet

Ì 5.6 Hubs, bridges, and


5: DataLink Layer 5a-12

Multiple Access Links and Protocols
Two types of “links”:
Ì point-to-point r PPP for dial-up access r point-to-point link between Ethernet switch and host Ì broadcast (shared wire or medium) r traditional Ethernet r upstream HFC r 802.11 wireless LAN

5: DataLink Layer 5a-13

Multiple Access protocols
Ì single shared broadcast channel Ì two or more simultaneous transmissions by

nodes: interference

multiple access protocol Ì distributed algorithm that determines how nodes share channel, i.e., determine when node can transmit Ì communication about channel sharing must use channel itself!
5: DataLink Layer 5a-14

only one node can send successfully at a time

Ideal Multiple Access Protocol
Broadcast channel of rate R bps 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:
r r

no special node to coordinate transmissions no synchronization of clocks, slots

4. Simple

5: DataLink Layer 5a-15

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 r channel not divided, allow collisions r “recover” from collisions Ì “Taking turns” r tightly coordinate shared access to avoid collisions

5: DataLink Layer 5a-16

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

5: DataLink Layer 5a-17

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

frequency bands


5: DataLink Layer 5a-18

Channel Partitioning (CDMA)
CDMA (Code Division Multiple Access)
Ì unique “code” assigned to each user; i.e., code set partitioning Ì used mostly in wireless broadcast channels (cellular, satellite, Ì Ì Ì Ì

etc) all users share same frequency, but each user has own “chipping” sequence (i.e., code) to encode data encoded signal = (original data) X (chipping sequence) decoding: inner-product of encoded signal and chipping sequence allows multiple users to “coexist” and transmit simultaneously with minimal interference

5: DataLink Layer 5a-19

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

Slotted ALOHA
Assumptions Ì all frames same size Ì time is divided into equal size slots, time to transmit 1 frame Ì nodes start to transmit frames only at beginning of slots Ì nodes are synchronized Ì if 2 or more nodes transmit in slot, all nodes detect collision Operation Ì when node obtains fresh frame, it transmits in next slot Ì no collision, node can send new frame in next slot Ì if collision, node retransmits frame in each subsequent slot with problem until success

5: DataLink Layer 5a-21

Slotted ALOHA

Pros Ì single active node can continuously transmit at full rate of channel Ì highly decentralized: only slots in nodes need to be in sync Ì simple

Cons Ì collisions, wasting slots Ì idle slots Ì nodes may be able to detect collision in less than time to transmit packet
5: DataLink Layer 5a-22

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!

5: DataLink Layer 5a-23

CSMA collisions
collisions can still occur:
propagation delay means two nodes may not hear each other’s transmission

spatial layout of nodes

collision: note:

entire packet transmission time wasted role of distance & propagation delay in determining collision probability

5: DataLink Layer 5a-24

CSMA/CD (Collision Detection)
CSMA/CD: carrier sensing, deferral as in CSMA
collisions detected within short time r colliding transmissions aborted, reducing channel wastage

Ì collision detection: r easy in wired LANs: measure signal strengths, compare transmitted, received signals r difficult in wireless LANs: receiver shut off while transmitting Ì human analogy: the polite conversationalist
5: DataLink Layer 5a-25

CSMA/CD collision detection

5: DataLink Layer 5a-26

“Taking Turns” MAC protocols
channel partitioning MAC protocols: r share channel efficiently and fairly at high load r inefficient at low load: delay in channel access, 1/N bandwidth allocated even if only 1 active node! Random access MAC protocols r efficient at low load: single node can fully utilize channel r high load: collision overhead “taking turns” protocols look for best of both worlds!
5: DataLink Layer 5a-27

“Taking Turns” MAC protocols
Token passing: Polling: Ì control token passed from Ì master node one node to next “invites” slave nodes sequentially. to transmit in turn Ì token message Ì concerns: Ì concerns: r polling overhead
r r

latency single point of failure (master)

r r r

token overhead latency single point of failure (token)

5: DataLink Layer 5a-28

Summary of MAC protocols
Ì What do you do with a shared media? r Channel Partitioning, by time, frequency or code
• Time Division,Code Division, Frequency Division

Random partitioning (dynamic),
• ALOHA, S-ALOHA, CSMA, CSMA/CD • carrier sensing: easy in some technologies (wire), hard in others (wireless) • CSMA/CD used in Ethernet


Taking Turns
• polling from a central site, token passing

5: DataLink Layer 5a-29

LAN technologies
Data link layer so far:

services, error detection/correction, multiple access

Next: LAN technologies
addressing r Ethernet r hubs, bridges, switches r 802.11 r PPP r ATM
5: DataLink Layer 5a-30

LAN Addresses and ARP
32-bit IP address:
network-layer address Ì used to get datagram to destination IP network (recall IP network definition)

LAN (or MAC or physical or Ethernet) address:
Ì used to get datagram from one interface to another

physically-connected interface (same network) Ì 48 bit MAC address (for most LANs) burned in the adapter ROM

5: DataLink Layer 5a-31

LAN Addresses and ARP
Each adapter on LAN has unique LAN address

5: DataLink Layer 5a-32

LAN Address (more)
Ì MAC address allocation administered by IEEE Ì manufacturer buys portion of MAC address space

(to assure uniqueness) Ì Analogy: (a) MAC address: like Social Security Number (b) IP address: like postal address Ì MAC flat address => portability

can move LAN card from one LAN to another

Ì IP hierarchical address NOT portable r depends on IP network to which node is attached
5: DataLink Layer 5a-33

Recall earlier routing discussion
Starting at A, given IP datagram addressed to B:
Ì look up net. address of B, find B


on same net. as A Ì link layer send datagram to B inside link-layer frame
frame source, dest address B’s MAC A’s MAC addr addr



datagram source, dest address A’s IP addr frame B’s IP addr datagram

IP payload

5: DataLink Layer 5a-34

ARP: Address Resolution Protocol
Question: how to determine MAC address of B knowing B’s IP address?
Ì Each IP node (Host,

Router) on LAN has ARP table Ì ARP Table: IP/MAC address mappings for some LAN nodes
< IP address; MAC address; TTL>

TTL (Time To Live): time after which address mapping will be forgotten (typically 20 min)

5: DataLink Layer 5a-35

ARP protocol
Ì A wants to send datagram

to B, and A knows B’s IP address. Ì Suppose B’s MAC address is not in A’s ARP table. Ì A broadcasts ARP query packet, containing B's IP address r all machines on LAN receive ARP query Ì B receives ARP packet, replies to A with its (B's) MAC address

Ì A caches (saves) IP-to-

MAC address pair in its ARP table until information becomes old (times out) r soft state: information that times out (goes away) unless refreshed

Ì ARP is “plug-and-play”: r nodes create their ARP tables without intervention from net administrator

frame sent to A’s MAC address (unicast)

5: DataLink Layer 5a-36

“dominant” LAN technology: Ì cheap ! Ì first widely used LAN technology Ì Simpler, cheaper than token LANs and ATM Ì Kept up with speed race: 10, 100, 1000 Mbps

Metcalfe’s Ethernet sketch

5: DataLink Layer 5a-37

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

5: DataLink Layer 5a-38

Ethernet Frame Structure (more)
Ì Addresses: 6 bytes r if adapter receives frame with matching destination address, or with broadcast address (eg ARP packet), it passes data in frame to net-layer protocol r 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

5: DataLink Layer 5a-39

Unreliable, connectionless service
Ì Connectionless: No handshaking between sending

and receiving adapter. Ì Unreliable: receiving adapter doesn’t send acks or nacks to sending adapter

r r

stream of datagrams passed to network layer can have gaps gaps will be filled if app is using TCP otherwise, app will see the gaps

5: DataLink Layer 5a-40

Ethernet uses CSMA/CD
Ì No slots Ì adapter doesn’t transmit Ì Before attempting a

if it senses that some other adapter is transmitting, that is, carrier sense Ì transmitting adapter aborts when it senses that another adapter is transmitting, that is, collision detection

retransmission, adapter waits a random time, that is, random access

5: DataLink Layer 5a-41

Ethernet Technologies: 10Base2
Ì 10: 10Mbps; 2: under 200 meters max cable length Ì thin coaxial cable in a bus topology

Ì repeaters used to connect up to multiple segments Ì repeater repeats bits it hears on one interface to

its other interfaces: physical layer device only! Ì has become a legacy technology

5: DataLink Layer 5a-42

10BaseT and 100BaseT
Ì 10/100 Mbps rate; latter called “fast ethernet” Ì T stands for Twisted Pair Ì Nodes connect to a hub: “star topology”; 100 m

max distance between nodes and hub
nodes hub

Ì Hubs are essentially physical-layer repeaters:

bits coming in one link go out all other links r no frame buffering r no CSMA/CD at hub: adapters detect collisions r provides net management functionality
5: DataLink Layer 5a-43

Chapter 5 outline
Ì 5.1 Introduction and Ì Ì Ì Ì

services 5.2 Error detection and correction 5.3Multiple access protocols 5.4 LAN addresses and ARP 5.5 Ethernet

Ì 5.6 Hubs, bridges, and


5: DataLink Layer 5a-44

Interconnecting LAN segments
Ì Hubs Ì Bridges Ì Switches r Remark: switches are essentially multi-port bridges. r What we say about bridges also holds for switches!

5: DataLink Layer 5a-45

Interconnecting with hubs
Ì Backbone hub interconnects LAN segments Ì Extends max distance between nodes Ì But individual segment collision domains become one

large collision domain

if a node in CS and a node EE transmit at same time: collision

Ì Can’t interconnect 10BaseT & 100BaseT

5: DataLink Layer 5a-46

Ì Link layer device

stores and forwards Ethernet frames r examines frame header and selectively forwards frame based on MAC dest address r when frame is to be forwarded on segment, uses CSMA/CD to access segment Ì transparent r hosts are unaware of presence of bridges Ì plug-and-play, self-learning r bridges do not need to be configured

5: DataLink Layer 5a-47

Bridges: traffic isolation
Ì Bridge installation breaks LAN into LAN segments Ì bridges filter packets:

same-LAN-segment frames not usually forwarded onto other LAN segments r segments become separate collision domains
r collision domain collision domain = hub = host


LAN segment

LAN segment

LAN (IP network)
5: DataLink Layer 5a-48


How do determine to which LAN segment to forward frame? • Looks like a routing problem...
5: DataLink Layer 5a-49

Self learning
Ì A bridge has a bridge table Ì entry in bridge table:

(Node LAN Address, Bridge Interface, Time Stamp) r stale entries in table dropped (TTL can be 60 min) Ì bridges learn which hosts can be reached through which interfaces r when frame received, bridge “learns” location of sender: incoming LAN segment r records sender/location pair in bridge table

5: DataLink Layer 5a-50

Bridge example
Suppose C sends frame to D and D replies back with frame to C.

Ì Bridge receives frame from from C r notes in bridge table that C is on interface 1 r because D is not in table, bridge sends frame into interfaces 2 and 3 Ì frame received by D
5: DataLink Layer 5a-51

Bridge Learning: example

Ì D generates frame for C, sends Ì bridge receives frame
r r

notes in bridge table that D is on interface 2 bridge knows C is on interface 1, so selectively forwards frame to interface 1
5: DataLink Layer 5a-52

Interconnection without backbone

Ì Not recommended for two reasons: - single point of failure at Computer Science hub - all traffic between EE and SE must path over CS segment
5: DataLink Layer 5a-53

Backbone configuration

Recommended !

5: DataLink Layer 5a-54

Bridges Spanning Tree
Ì for increased reliability, desirable to have

redundant, alternative paths from source to dest Ì with multiple paths, cycles result - bridges may multiply and forward frame forever Ì solution: organize bridges in a spanning tree by disabling subset of interfaces

5: DataLink Layer 5a-55

Some bridge features
Ì Isolates collision domains resulting in higher total

max throughput Ì limitless number of nodes and geographical coverage Ì Can connect different Ethernet types Ì Transparent (“plug-and-play”): no configuration necessary

5: DataLink Layer 5a-56

Bridges vs. Routers
Ì both store-and-forward devices r routers: network layer devices (examine network layer headers) r bridges are link layer devices Ì routers maintain routing tables, implement routing

algorithms Ì bridges maintain bridge tables, implement filtering, learning and spanning tree algorithms

5: DataLink Layer 5a-57

Routers vs. Bridges
Bridges + and + Bridge operation is simpler requiring less packet processing + Bridge tables are self learning - All traffic confined to spanning tree, even when alternative bandwidth is available - Bridges do not offer protection from broadcast storms

5: DataLink Layer 5a-58

Routers vs. Bridges
Routers + and + arbitrary topologies can be supported, cycling is

limited by TTL counters (and good routing protocols) + provide protection against broadcast storms - require IP address configuration (not plug and play) - require higher packet processing
Ì bridges do well in small (few hundred hosts) while

routers used in large networks (thousands of hosts)

5: DataLink Layer 5a-59

Ethernet Switches
Ì Essentially a multiÌ



interface bridge layer 2 (frame) forwarding, filtering using LAN addresses Switching: A-to-A’ and Bto-B’ simultaneously, no collisions large number of interfaces often: individual hosts, star-connected into switch r Ethernet, but no collisions!
5: DataLink Layer 5a-60

Ethernet Switches
Ì cut-through switching: frame forwarded

from input to output port without awaiting for assembly of entire frame r slight reduction in latency Ì combinations of shared/dedicated, 10/100/1000 Mbps interfaces

5: DataLink Layer 5a-61

Not an atypical LAN (IP network)


5: DataLink Layer 5a-62

Summary comparison
hubs traffic isolation plug & play optimal routing cut through no yes no yes bridges yes yes no no routers yes no yes no switches yes yes no yes
5: DataLink Layer 5a-63