Chapter5 5th Aug 2009
Chapter5 5th Aug 2009
5: DataLink Layer 2
Link Layer
5: DataLink Layer 3
Link Layer: Introduction
Some terminology:
r hosts and routers are nodes
r communication channels that
connect adjacent nodes along
communication path are links
m wired links
m wireless links
m LANs
r layer-2 packet is a frame,
encapsulates datagram
r datagram transferred by
transportation analogy
r trip from Princeton to
different link protocols
Lausanne
over different links:
m limo: Princeton to JFK
m e.g., Ethernet on first link,
m plane: JFK to Geneva
frame relay on
m train: Geneva to Lausanne
intermediate links, 802.11
on last link r tourist = datagram
r each link protocol r transport segment =
provides different communication link
services r transportation mode =
m e.g., may or may not link layer protocol
provide rdt over link
r travel agent = routing
algorithm
5: DataLink Layer 5
Link Layer Services
r framing, link access:
m encapsulate datagram into frame, adding header, trailer
m channel access if shared medium
m “MAC” addresses used in frame headers to identify
source, dest
• different from IP address!
r reliable delivery between adjacent nodes
m we learned how to do this already (chapter 3)!
m seldom used on low bit-error link (fiber, some twisted
pair)
m wireless links: high error rates
• Q: why both link-level and end-end reliability?
5: DataLink Layer 6
Link Layer Services (more)
r flow control:
m pacing between adjacent sending and receiving nodes
r error detection:
m errors caused by signal attenuation, noise.
m receiver detects presence of errors:
• signals sender for retransmission or drops frame
r error correction:
m receiver identifies and corrects bit error(s) without
resorting to retransmission
r half-duplex and full-duplex
m with half duplex, nodes at both ends of link can transmit,
but not at same time
5: DataLink Layer 7
Where is the link layer implemented?
datagram datagram
controll controll
er er
frame
5: DataLink Layer 10
Error Detection
EDC= Error Detection and Correction bits (redundancy)
D = Data protected by error checking, may include header fields
otherwise
5: DataLink Layer 11
Parity Checking
Single Bit Parity: Two Dimensional Bit Parity:
Detect single bit errors Detect and correct single bit errors
0 0
5: DataLink Layer 12
Internet checksum (review)
Sender: Receiver:
r compute checksum of
r treat segment contents as
received segment
sequence of 16-bit
integers r check if computed checksum
equals checksum field value:
r checksum: addition (1’s
complement sum) of m NO - error detected
5: DataLink Layer 13
Checksumming: Cyclic Redundancy Check
r view data bits, D, as a binary number
r choose r+1 bit pattern (generator), G
r goal: choose r CRC bits, R, such that
m <D,R> exactly divisible by G (modulo 2)
m receiver knows G, divides <D,R> by G. If non-zero remainder:
error detected!
m can detect all burst errors less than r+1 bits
r widely used in practice (Ethernet, 802.11 WiFi, ATM)
5: DataLink Layer 14
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
5: DataLink Layer 15
Link Layer
5: DataLink Layer 16
Multiple Access Links and Protocols
Two types of “links”:
r point-to-point
m PPP for dial-up access
m point-to-point link between Ethernet switch and host
humans at a
shared wire (e.g., shared RF shared RF cocktail party
cabled Ethernet) (e.g., 802.11 WiFi) (satellite) (shared air, acoustical)
5: DataLink Layer 17
Multiple Access protocols
r single shared broadcast channel
r two or more simultaneous transmissions by nodes:
interference
m collision if node receives two or more signals at the same time
multiple access protocol
r distributed algorithm that determines how nodes
share channel, i.e., determine when node can transmit
r communication about channel sharing must use channel
itself!
m no out-of-band channel for coordination
5: DataLink Layer 18
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:
m no special node to coordinate transmissions
m no synchronization of clocks, slots
4. simple
5: DataLink Layer 19
MAC Protocols: a taxonomy
Three broad classes:
r Channel Partitioning
m divide channel into smaller “pieces” (time slots,
frequency, code)
m allocate piece to node for exclusive use
r Random Access
m channel not divided, allow collisions
m “recover” from collisions
r “Taking turns”
m nodes take turns, but nodes with more to send can take
longer turns
5: DataLink Layer 20
Channel Partitioning MAC protocols: TDMA
5: DataLink Layer 21
Channel Partitioning MAC protocols: FDMA
FDMA: frequency division multiple access
r channel spectrum divided into frequency bands
r each station assigned fixed frequency band
r unused transmission time in frequency bands go idle
r example: 6-station LAN, 1,3,4 have pkt, frequency
bands 2,5,6 idle
time
frequency bands
FDM cable
5: DataLink Layer 22
Random Access Protocols
r When node has packet to send
m transmit at full channel data rate R.
m no a priori coordination among nodes
5: DataLink Layer 23
Slotted ALOHA
Assumptions: Operation:
r all frames same size r when node obtains fresh
r time divided into equal frame, transmits in next
size slots (time to slot
transmit 1 frame) m if no collision: node can
r nodes start to transmit send new frame in next
only slot beginning slot
r nodes are synchronized m if collision: node
r if 2 or more nodes retransmits frame in
transmit in slot, all each subsequent slot
nodes detect collision with prob. p until
success
5: DataLink Layer 24
Slotted ALOHA
Pros Cons
r single active node can r collisions, wasting slots
continuously transmit r idle slots
at full rate of channel r nodes may be able to
r highly decentralized: detect collision in less
only slots in nodes than time to transmit
packet
need to be in sync
r clock synchronization
r simple
5: DataLink Layer 25
Slotted Aloha efficiency
Efficiency : long-run r max efficiency: find p*
fraction of successful slots that maximizes
(many nodes, all with many Np(1-p)N-1
frames to send) r for many nodes, take
limit of Np*(1-p*)N-1
r suppose: N nodes with as N goes to infinity,
many frames to send, gives:
each transmits in slot Max efficiency = 1/e = .37
with probability p
r prob that given node At best: channel
has success in a slot =
p(1-p)N-1
r prob that any node has
a success = Np(1-p)N-1
used for useful
transmissions 37%
of time!
!
5: DataLink Layer 26
Pure (unslotted) ALOHA
r unslotted Aloha: simpler, no synchronization
r when frame first arrives
m transmit immediately
5: DataLink Layer 27
Pure Aloha efficiency
.
P(success by given node) = P(node transmits)
.
P(no other node transmits in [p 0-1,p0]
P(no other node transmits in [p 0-1,p0]
. .
= p (1-p)N-1 (1-p)N-1
.
= p (1-p)2(N-1)
= 1/(2e) = .18
even worse than slotted Aloha!
5: DataLink Layer 28
CSMA (Carrier Sense Multiple Access)
5: DataLink Layer 29
CSMA collisions spatial layout of nodes
collision:
entire packet transmission
time wasted
note:
role of distance & propagation
delay in determining collision
probability
5: DataLink Layer 30
CSMA/CD (Collision Detection)
CSMA/CD: carrier sensing, deferral as in CSMA
m collisions detected within short time
m colliding transmissions aborted, reducing channel
wastage
r collision detection:
m easy in wired LANs: measure signal strengths,
compare transmitted, received signals
m difficult in wireless LANs: received signal strength
overwhelmed by local transmission strength
r human analogy: the polite conversationalist
5: DataLink Layer 31
CSMA/CD collision detection
5: DataLink Layer 32
“Taking Turns” MAC protocols
channel partitioning MAC protocols:
m share channel efficiently and fairly at high load
m inefficient at low load: delay in channel access,
1/N bandwidth allocated even if only 1 active
node!
Random access MAC protocols
m efficient at low load: single node can fully
utilize channel
m high load: collision overhead
“taking turns” protocols
look for best of both worlds!
5: DataLink Layer 33
“Taking Turns” MAC protocols
Polling:
r master node
“invites” slave nodes data
to transmit in turn poll
5: DataLink Layer 34
“Taking Turns” MAC protocols
Token passing:
T
r control token passed
from one node to next
sequentially.
r token message (nothing
r concerns: to send)
m token overhead T
m latency
m single point of failure
(token)
data
5: DataLink Layer 35
Summary of MAC protocols
r channel partitioning, by time, frequency or code
m Time Division, Frequency Division
r taking turns
m polling from central site, token passing
m Bluetooth, FDDI, IBM Token Ring
5: DataLink Layer 36
Link Layer
5: DataLink Layer 37
MAC Addresses and ARP
r 32-bit IP address:
m network-layer address
m used to get datagram to destination IP subnet
r MAC (or LAN or physical or Ethernet)
address:
m function: get frame from one interface to another
physically-connected interface (same network)
m 48 bit MAC address (for most LANs)
• burned in NIC ROM, also sometimes software settable
5: DataLink Layer 38
LAN Addresses and ARP
Each adapter on LAN has unique LAN address
LAN
(wired or = adapter
wireless)
71-65-F7-2B-08-53
58-23-D7-FA-20-B0
0C-C4-11-6F-E3-98
5: DataLink Layer 39
LAN Address (more)
r MAC address allocation administered by IEEE
r manufacturer buys portion of MAC address space
(to assure uniqueness)
r analogy:
(a) MAC address: like Social Security Number
(b) IP address: like postal address
r MAC flat address ➜ portability
m can move LAN card from one LAN to another
r IP hierarchical address NOT portable
m address depends on IP subnet to which node is attached
5: DataLink Layer 40
ARP: Address Resolution Protocol
0C-C4-11-6F-E3-98
137.196.7.88
5: DataLink Layer 41
ARP protocol: Same LAN (network)
5: DataLink Layer 42
Addressing: routing to another LAN
walkthrough: send datagram from A to B via R
assume A knows B’s IP address
74-29-9C-E8-FF-55 88-B2-2F-54-1A-0F
A E6-E9-00-17-BB-4B
222.222.222.221
1A-23-F9-CD-06-9B
111.111.111.111
222.222.222.220 222.222.222.222
111.111.111.110
B
111.111.111.112
R 49-BD-D2-C7-56-2A
CC-49-DE-D0-AB-7D
5: DataLink Layer 43
r A creates IP datagram with source A, destination B
r A uses ARP to get R’s MAC address for 111.111.111.110
r A creates link-layer frame with R's MAC address as dest,
frame contains A-to-B IP datagram
This is a really important
r A’s NIC sends frame example – make sure you
r R’s NIC receives frame understand!
r R removes IP datagram from Ethernet frame, sees its
destined to B
r R uses ARP to get B’s MAC address
r R creates frame containing A-to-B IP datagram sends to B
74-29-9C-E8-FF-55 88-B2-2F-54-1A-0F
A
E6-E9-00-17-BB-4B
222.222.222.221
1A-23-F9-CD-06-9B
111.111.111.111
222.222.222.220 222.222.222.222
111.111.111.110 B
111.111.111.112
R 49-BD-D2-C7-56-2A
CC-49-DE-D0-AB-7D
5: DataLink Layer 44
Link Layer
5: DataLink Layer 45
Ethernet
“dominant” wired LAN technology:
r cheap $20 for NIC
r first widely used LAN technology
r simpler, cheaper than token LANs and ATM
r kept up with speed race: 10 Mbps – 10 Gbps
Metcalfe’s Ethernet
sketch
5: DataLink Layer 46
Star topology
r bus topology popular through mid 90s
m all nodes in same collision domain (can collide with each
other)
r today: star topology prevails
m active switch in center
m each “spoke” runs a (separate) Ethernet protocol (nodes
do not collide with each other)
switch
Preamble:
r 7 bytes with pattern 10101010 followed by one
byte with pattern 10101011
r used to synchronize receiver, sender clock rates
5: DataLink Layer 48
Ethernet Frame Structure (more)
r Addresses: 6 bytes
m if adapter receives frame with matching destination
address, or with broadcast address (eg ARP packet), it
passes data in frame to network layer protocol
m otherwise, adapter discards frame
5: DataLink Layer 49
Ethernet: Unreliable, connectionless
5: DataLink Layer 50
Ethernet CSMA/CD algorithm
5: DataLink Layer 51
Ethernet’s CSMA/CD (more)
5: DataLink Layer 52
CSMA/CD efficiency
r Tprop = max prop delay between 2 nodes in LAN
r ttrans = time to transmit max-size frame
r efficiency goes to 1
m as tprop goes to 0
m as t goes to infinity
trans
r better performance than ALOHA: and simple,
cheap, decentralized!
5: DataLink Layer 53
802.3 Ethernet Standards: Link & Physical Layers
MAC protocol
application and frame format
transport
network 100BASE-TX 100BASE-T2 100BASE-FX
link 100BASE-T4 100BASE-SX 100BASE-BX
physical
r used in 10BaseT
r each bit has a transition
r allows clocks in sending and receiving nodes to
synchronize to each other
m no need for a centralized, global clock among nodes!
r Hey, this is physical-layer stuff!
5: DataLink Layer 55
Link Layer
5: DataLink Layer 56
Hubs
… physical-layer (“dumb”) repeaters:
m bits coming in one link go out all other links at
same rate
m all nodes connected to hub can collide with one
another
m no frame buffering
m no CSMA/CD at hub: host NICs detect
collisions
twisted pair
hub
5: DataLink Layer 57
Switch
r link-layer device: smarter than hubs, take
active role
m store, forward Ethernet frames
m examine incoming frame’s MAC address,
selectively forward frame to one-or-more
outgoing links when frame is to be forwarded on
segment, uses CSMA/CD to access segment
r transparent
m hosts are unaware of presence of switches
r plug-and-play, self-learning
m switches do not need to be configured
5: DataLink Layer 58
Switch: allows multiple simultaneous
transmissions
A
5: DataLink Layer 59
Switch Table
A
r Q: how does switch know that
C’ B
A’ reachable via interface 4,
B’ reachable via interface 5?
1 2
r A: each switch has a switch 6 3
table, each entry: 5 4
m (MAC address of host, interface
to reach host, time stamp) C
r looks like a routing table!
B’ A’
r Q: how are entries created,
maintained in switch table? switch with six interfaces
m something like a routing (1,2,3,4,5,6)
protocol?
5: DataLink Layer 60
Switch: self-learning Source: A
Dest: A’
A A A’
r switch learns which hosts
C’ B
can be reached through
which interfaces
m when frame received, 1 2
6 3
switch “learns” location of
5 4
sender: incoming LAN
segment
C
m records sender/location
pair in switch table B’ A’
5: DataLink Layer 61
Switch: frame filtering/forwarding
When frame received:
forwarding: A A A’
example C’ B
r frame destination 1 2
unknown: flood A6A’ 3
5 4
r destination A
location known: C
A’ A
selective send
B’ A’
5: DataLink Layer 63
Interconnecting switches
r switches can be connected together
S4
S1
S3
A S2
F
D I
B C
G H
E
5: DataLink Layer 64
Self-learning multi-switch example
Suppose C sends frame to I, I responds to C
1 S4
S1 2 S3
A S2
F
D I
B C
G H
E
5: DataLink Layer 65
Institutional network
mail server
to external
network
router web server
IP subnet
5: DataLink Layer 66
Switches vs. Routers
r both store-and-forward devices
m routers: network layer devices (examine network layer
headers)
m switches are link layer devices
5: DataLink Layer 67
VLANs: motivation
5: DataLink Layer 68
Port-based VLAN: switch ports grouped
VLANs (by switch management software) so
that single physical switch ……
1 7 9 15
Virtual Local 2 8 10 16
Area Network
… …
Switch(es) supporting
VLAN capabilities can Electrical Engineering Computer Science
(VLAN ports 1-8) (VLAN ports 9-15)
be configured to
define multiple virtual … operates as multiple virtual switches
LANS over single
physical LAN 1 7 9 15
infrastructure. 2 8 10 16
… …
5: DataLink Layer 69
Port-based VLAN
router
r traffic isolation: frames
to/from ports 1-8 can
only reach ports 1-8
m can also define VLAN based on
MAC addresses of endpoints, 1 7 9 15
2 8 10 16
rather than switch port
r dynamic membership:
… …
ports can be dynamically
assigned among VLANs Electrical Engineering
(VLAN ports 1-8)
Computer Science
(VLAN ports 9-15)
1 7 9 15 1 3 5 7
2 8 10 16 2 4 6 8
… …
5: DataLink Layer 71
802.1Q VLAN frame format
Type
802.1 frame
802.1Q frame
5: DataLink Layer 72
Link Layer
5: DataLink Layer 73
Point to Point Data Link Control
r one sender, one receiver, one link: easier than
broadcast link:
m no Media Access Control
m no need for explicit MAC addressing
m e.g., dialup link, ISDN line
r popular point-to-point DLC protocols:
m PPP (point-to-point protocol)
m HDLC: High level data link control (Data link
used to be considered “high layer” in protocol
stack!
5: DataLink Layer 74
PPP Design Requirements [RFC 1557]
5: DataLink Layer 75
PPP non-requirements
r no error correction/recovery
r no flow control
r out of order delivery OK
r no need to support multipoint links (e.g., polling)
5: DataLink Layer 76
PPP Data Frame
r Flag: delimiter (framing)
r Address: does nothing (only one option)
r Control: does nothing; in the future possible
multiple control fields
r Protocol: upper layer protocol to which frame
delivered (eg, PPP-LCP, IP, IPCP, etc)
5: DataLink Layer 77
PPP Data Frame
r info: upper layer data being carried
r check: cyclic redundancy check for error
detection
5: DataLink Layer 78
Byte Stuffing
r “data transparency” requirement: data field must
be allowed to include flag pattern <01111110>
m Q: is received <01111110> data or flag?
5: DataLink Layer 79
Byte Stuffing
flag byte
pattern
in data
to send
5: DataLink Layer 80
PPP Data Control Protocol
Before exchanging
network-layer data, data link
peers must
r configure PPP link (max.
frame length,
authentication)
r learn/configure network
layer information
m for IP: carry IP Control
Protocol (IPCP) msgs
(protocol field: 8021) to
configure/learn IP
address
5: DataLink Layer 81
Link Layer
5: DataLink Layer 82
Virtualization of networks
5: DataLink Layer 83
The Internet: virtualizing networks
1974: multiple unconnected … differing in:
nets m addressing conventions
m ARPAnet m packet formats
m data-over-cable networks m error recovery
m packet satellite network m routing
(Aloha)
m packet radio network
gateway
5: DataLink Layer 85
Cerf & Kahn’s Internetwork Architecture
What is virtualized?
r two layers of addressing: internetwork and local
network
r new layer (IP) makes everything homogeneous at
internetwork layer
r underlying local network technology
m cable
m satellite
m 56K telephone modem
m today: ATM, MPLS
… “invisible” at internetwork layer. Looks like a link
layer technology to IP!
5: DataLink Layer 86
ATM and MPLS
r ATM, MPLS separate networks in their own
right
m different service models, addressing, routing
from Internet
r viewed by Internet as logical link connecting
IP routers
m just like dialup link is really part of separate
network (telephone network)
r ATM, MPLS: of technical interest in their
own right
5: DataLink Layer 87
Asynchronous Transfer Mode: ATM
r 1990’s/00 standard for high-speed (155Mbps to
622 Mbps and higher) Broadband Integrated
Service Digital Network architecture
r Goal: integrated, end-end transport of carry voice,
video, data
m meeting timing/QoS requirements of voice, video
(versus Internet best-effort model)
m “next generation” telephony: technical roots in
telephone world
m packet-switching (fixed length packets, called
“cells”) using virtual circuits
5: DataLink Layer 88
Multiprotocol label switching (MPLS)
PPP or Ethernet
MPLS header IP header remainder of link-layer frame
header
20 3 1 5
5: DataLink Layer 89
MPLS capable routers
r a.k.a. label-switched router
r forwards packets to outgoing interface based
only on label value (don’t inspect IP address)
m MPLS forwarding table distinct from IP forwarding
tables
r signaling protocol needed to set up forwarding
m RSVP-TE
m forwarding possible along paths that IP alone would
not allow (e.g., source-specific routing) !!
m use MPLS for traffic engineering
r must co-exist with IP-only routers
5: DataLink Layer 90
MPLS forwarding tables
in out out
label label dest interface
10 A 0 in out out
12 D 0 label label dest interface
8 A 1 10 6 A 1
12 9 D 0
R6
0 0
D
1 1
R4 R3
R5
0 0
A
R2 in outR1 out
label label dest interface
in out out
label label dest interface 6 - A 0
8 6 A 0
5: DataLink Layer 91
Link Layer
5: DataLink Layer 92
Synthesis: a day in the life of a web request
r putting-it-all-together: synthesis!
m goal: identify, review, understand protocols (at
all layers) involved in seemingly simple scenario:
requesting www page
m scenario: student attaches laptop to campus
network, requests/receives www.google.com
5: DataLink Layer 93
A day in the life: scenario
browser DNS server
Comcast network
68.80.0.0/13
school network
68.80.2.0/24
web page
5: DataLink Layer 94
A day in the life… connecting to the Internet
DHCP DHCP r connecting laptop needs to
DHCP UDP
DHCP IP get its own IP address,
DHCP Eth addr of first-hop router,
Phy addr of DNS server: use
DHCP
DHCP
r DHCP request encapsulated
DHCP DHCP in UDP, encapsulated in IP,
DHCP UDP encapsulated in 802.1
DHCP IP Ethernet
DHCP Eth router
Phy (runs DHCP) r Ethernet frame broadcast
(dest: FFFFFFFFFFFF) on LAN,
received at router running
DHCP server
r Ethernet demux’ed to IP
demux’ed, UDP demux’ed to
DHCP
5: DataLink Layer 95
A day in the life… connecting to the Internet
DHCP DHCP r DHCP server formulates
DHCP UDP DHCP ACK containing
DHCP IP client’s IP address, IP
DHCP Eth address of first-hop
Phy router for client, name &
IP address of DNS server
r encapsulation at DHCP
server, frame forwarded
DHCP DHCP (switch learning) through
DHCP UDP LAN, demultiplexing at
DHCP IP client
DHCP Eth router r DHCP client receives DHCP
Phy (runs DHCP)
DHCP ACK reply
5: DataLink Layer 96
A day in the life… ARP (before DNS, before HTTP)
DNS DNS r before sending HTTP request,
DNS UDP need IP address of www.google.com:
DNS IP
ARP DNS
ARP query Eth
Phy r DNS query created, encapsulated
in UDP, encapsulated in IP,
encasulated in Eth. In order to
ARP send frame to router, need MAC
ARP reply Eth address of router interface: ARP
Phy
r ARP query broadcast, received
by router, which replies with
ARP reply giving MAC address
of router interface
r client now knows MAC address
of first hop router, so can now
send frame containing DNS
query
5: DataLink Layer 97
A day in the life… using DNS DNS
DNS UDP DNS server
DNS IP
DNS DNS DNS Eth
DNS UDP DNS Phy
DNS IP
DNS Eth
Phy
DNS
Comcast network
68.80.0.0/13
5: DataLink Layer 99
A day in the life… HTTP request/reply
HTTP
r web page finally (!!!)
HTTP HTTP displayed
HTTP
HTTP TCP
HTTP
HTTP IP
HTTP
HTTP Eth
Phy