Link Layer PDF
Link Layer PDF
application
Provides a service to the network layer Deals with individual links connecting individual hosts
Data-Link Layer
Why a separate layer? Datagram may be transferred by dierent link protocols over dierent links e.g., Ethernet on rst link, frame relay on intermediate links, 802.11 on nal link Each link protocol provides dierent services e.g., may or may not provide rdt, error detection, over link
Framing, link access encapsulate datagram into frame, add header, trailer channel access if shared medium MAC addresses used in frame headers to identify src, dst dierent from IP addresses Reliable delivery between adjacent nodes using rdt rarely used on low bit-error links (bre) but other links may have high error rates (wireless)
Flow Control
pacing between adjacent
sending/receiving nodes Error Detection signal attenuation/noise receiver detects, signals
sender Error Correction receiver detects and corrects w/o retransmit Half and full-duplex half-duplex - both ends can transmit, but not at
the same time
Adapters
Error detection
EDC = Error Detection & Correction bits D = Data protected by EDC (may include headers)
Parity checks
single-bit parity
count 1s can detect single-bit errors what if even number of errors?
Hamming codes
frame consisting of m data bits and r check bits
n = m + r = n-bit codeword
If two codewords are Hamming distance d apart, it requires d single-bit errors to turn one into the other
to detect d errors, you need a distance d+1 code e.g., single parity bit has distance 2, so it can only detect single (2-1) errors
Hamming distance = 3
Parity checks
2-D bit parity divide bits into rows & cols detect and correct single-bit errors
Internet checksum
Goal: detect errors in transmitted segment
used at transport layer only (checksum cheap in software) treat segment contents as sequence of 16-bit integers checksum: addition (1s complement sum) of segment contents put checksum in UDP checksum eld compute checksum of received segment check if computed checksum equals checksum eld value but even if equal, might still be errors...
Sender:
Receiver:
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. remainder!=0 error can detect a' burst errors less than r+1 bits long
CRCs
use G on D to make R
i.e., G(x)
e.g., PPP (dial-up access) point-to-point link between Ethernet switch and host traditional Ethernet 802.11 wireless LAN
Channel Partitioning
Channel Partitioning
TDM (Time Division Multiplexing)
divide channel into timeslots but bandwidth wasted if only one user divide channel into frequency bands also wastes bandwidth when few users divide channel by assigning each sender a cod" if codes are designed well, senders can transmit over entire frequency spectrum simultaneously people speaking simultaneously in dierent languages commonly used in cellphones (US 2G, US/EU 3G WCDMA) GSM uses TDM (sometimes called TDMA)
Slotted ALOHA
A random-access MAC protocol
Developed to network Hawaiian islands all frames same size, L bits time divided into slots of L/R sec (time to transmit 1 frame) nodes start to transmit frames only at beginning of slot nodes are synchronised if 2 or more nodes transmit in a slot, all nodes detect collision when node obtains fresh frame, transmits in next slot if no collision, frame is sent if collision, node retransmits in each subsequent slot with probability p until success
Assumptions:
Operation:
Slotted ALOHA
Pros single active node can transmit at full rate of channel highly-decentralised: 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 clock synchronisation
prob that node 1 has success in slot = p(1-p)N-1 prob that any node has success = Np(1-p)N-1 for max eciency with N nodes, nd p* that max Np(1-p)N-1 p* = 1/N as N , p* 1/e = 0.37
Carrier Sense, but collisions detected within short time colliding transmissions aborted: reduce channel waste Collision detection easy in wired LAN: measure signal strength, compare transmitted and received signals dicult in half-duplex wireless LANs Human analogy polite conversation
Taking Turns
Polling protocol
Master node invites slave nodes to transmit in turn Polling overhead, delay Single point of failure (master node) Control token passed from one node to next sequentially Token overhead, delay Single point of failure (token)
Token-passing protocol
when node obtains token and sends frame, frame propagates around entire ring ring = virtual broadcast channel destination node reads frame from link-layer medium as frame propagates by sender responsible for removing frame from ring receiver responsible for removing frame from ring
Link-Layer Addressing
Network-layer (IP) address
used to get datagram to destination IP subnet but how to nd destination host once at nal router? used to get datagram from one interface to another physicallyconnected interface on the same network 48-bit MAC address burned into the adapters ROM each NIC has unique MAC address (in theory...) address allocation administered by IEEE rst 24-bits = OUI (standards.ieee.org/regauth/oui/oui.txt) MAC at address portable can move NIC from one LAN to another
How to determine MAC address knowing IP address? Each IP node (host, router) on LAN has ARP table
ARP table: IP/MAC address mapping for some LAN nodes <IP address; MAC address; TTL> TTL (Time To Live): time after which mapping forgotten
A broadcasts ARP query packet containing Bs IP addr B receives ARP packet A saves IP-to-MAC address pair in ARP table ARP is plug-and-play
DHCP (RFC2131)
Dynamic Host Conguration Protocol
Client-server protocol
client - new host that wants network conguration information (IP address, DNS server)
Four-stage process:
1. DHCP server discover
client sends DHCP discover message (UDP port 67, IP broadcast dst 255.255.255.255, src 0.0.0.0) DHCP server responds to discover msg with oer msg proposed IP address, netmask, lease time client chooses from 1 oers, responds with DHCP request server responds to client, conrming parameters
3. DHCP request
4. DHCP ACK
DHCP example
DHCP very useful for one particular link-layer: wireless LANs imagine a sysadmin having to recongure each new wireless client? or every time you changed subnet? Ouch!
Ethernet
First widely-used LAN technology cheap Kept up with speed race
simple
used to synchronise receiver/sender clock rates if NIC receives frame w/o matching or broadcast addr, discards, otherwise, passes data in frame to higher-layer protocol
Type: higher-layer protocol, e.g., IP, AppleTalk CRC: checked at receiver; if error, frame dropped
Byte-stung
Transparency: data eld must be allowed to contain
ag pattern <01111110>
how to distinguish between <01111110> data or ag? $string = the ghost said \boo!\;
How to include a quotation mark () in a string? Sender: adds/escapes/stus extra <01111110> byte
after every <01111110> data byte Receiver:
two <01111110> bytes in a row: discard rst byte, continue data reception single <01111110> = ag byte
Bus topology popular in early 1990s Star topology popular now Connections via hub or switch
stream of datagrams passed to network layer may have gaps gaps may be lled, e.g., if transport layer is TCP otherwise, application will see the gaps
Ethernet MAC
CSMA/CD
no slots NIC doesnt transmit if it senses that some other NIC is transmitting, i.e., carrier sens" Transmitting NIC aborts when it senses that another adapter is transmitting, i.e., co'ision detectio* Before attempting to retransmit, NIC waits a random time, i.e., random access if propagation delay small, eciency NICs measure voltage levels 100%
CSMA/CD eciency
Eciency of Ethernet: long-run fraction of time during
which frames are being transmitted on the channel without collisions when there is a large number of active nodes, each with a large number of frames to send tprop = maximum propagation between 2 nodes in LAN ttrans = time to transmit maximum-sized Ethernet frame
ef f iciency = 1 1 + 5tprop /ttrans
Eciency 1 as tprop 0 Eciency 1 as ttrans Better than ALOHA, but still decentralised, simple and
cheap
Ethernet technologies
IEEE 802.3 most common: 10BaseT/100BaseT 10BaseT = 10Mbps, 100BaseT = 100Mbps, 100m distance T = Twisted Pair 10Base2 = 10Mbps over coax, 185m distance 10Base5 = 10Mbps ocver coax, 500m distance Nodes connect to hub, 100m max distance between nodes and hub 802.3z = GigE backwards-compatible Cat5 and bre
Hubs
Hub = physical-layer repeater
bits coming from one link go out of a' other links at the same rate no frame-buering no CSMA/CD at hub NICs detect collisions may provide some network management functionality
Backbone hub interconnects LAN segments Extends maximum distance between nodes
but individual segment co'ision domains become one big collision domain maximum aggregate throughput limited
Switches
Link-layer device
stores and forwards Ethernet frames examines frame header and selectively forwards frame based on destination MAC address when frame is to be forwarded on a segment, use CSMA/CD hosts are unaware of presence of switches switches do not need to be congured these days both switches and hubs are cheap (but hubs are still cheaper)
Forwarding
How to choose onto which LAN segment to forward frame? Switch has a switch tabl" entries: (MAC address, interface, timestamp) stale entries dropped after TTL (e.g., 60 min) Switch learns which hosts can be reached through which interfaces when frame received, switch learns location of sender (incoming LAN
Filtering/forwarding algorithm
When switch receives a frame:
index switch table using MAC destination address if entry found for destination then { if destination on segment from which frame arrived then drop the frame else forward the frame on interface indicated } else ood ood: forward frame on all interfaces except the interface on which the frame arrived
Forwarding
1 2 3 address interfac" A B
A B D C E F H G I J K L
1 1 2 3
E G
C sends frame to F Switch receives frame from C adds C to switch table - notes that C is on interface 1 because F is not in table, switch forwards frame into interfaces 2 & 3 F receives frame
Forwarding
1 2 3 address interfac" A B
A B D C E F H G I J K L
1 1 2 3 1
E G C
F replies with frame to C Switch receives frame from F adds F to switch table - notes that F is on interface 2 because C is in table, switch forwards frame only into interfaces 1 C receives frame
Switches can have many interfaces e.g., in Sudiko typically 48port switches Hosts have direct connection to switch no collisions full-duplex A can speak to A and B can speak to B simultaneously cut-through switching: frame forwarded from input to output port w/o collecting entire frame
2 1 Switch
Repeaters, bridges
lots of terminology (jargon), often confusing repeater = physical-layer hub
connects two segments, e.g., cable signal appears on one segment, amplied and put on the other typically switch used for connecting computers (dedicated access) bridge used for connecting LANs, i.e., multiple hosts on each port both layer 2 a.k.a., a router (L3 switch is marketing-speak) with faster dedicated hardware, fast as a L2 switch but processing L3 headers
bridge switch
layer 3 switch
IEEE 802.1Q
Summary
hubs trac isolatio* plug & play optimal routing cut-through routers switches
Network measurement
Measuring Ethernet
Place NIC into promiscuous mod"
NIC no longer discards frames not addressed to it NIC will see all frames (since hub forwards frames on all ports) NIC will only see frames addressed to it (+ broadcast/multicast) copy all frames to a dedicated port - plug snier into this port issue spoofed ARP frames to fool other machines into thinking that you have another hoss MAC address a sysadmin shouldnt really need to do this
In an Ethernet LAN with hubs In a switched network Some switches have a monitor mode (port mirroring) ARP poisoning (man in the middle attack)
Measurement software
packet snier programs
e.g., Ethereal, tcpdump, Network General Snier e.g., libpcap
link-layer frames encapsulated in a le format program may be able to decode dierent protocols
protocol analyser e.g., ethereal understands HTTP (and ~600 other protocols)
Packet lters
Network driver sits in kernel Measurement software sits in userspace Packet lter - sits in kernel, passes frames to userspace
Security issues
If someone can sni my data-link frames, they can see
all of my data
e-mail contents, telnet passwords, etc ssh (instead of telnet), SSL (HTTPS), PGP (e-mail) tricks using ICMP possible to attack even passive sniers e.g., Witty worm