link layer fundamentals nwen302 computer network design
TRANSCRIPT
Link Layer Fundamentals
NWEN302 Computer Network Design
Topics to be covered
• Link layer services
• Link layer addressing and address resolution
• Ethernet
• Switches
© Winston Seah NWEN302 Computer Network Design
2
Network data at different layersThe generic term for a piece of information at any layer is referred to as a packet.•Message – application layer data; stuff that comes from your application•Segment – transport layer data, typically TCP/UDP segments•Datagram – network layer data blocks moved by routers from source to destination•Frame – block of data transferred between neighboring devices at the link layer•bits – units of binary information “on the wire”
© Winston Seah NWEN302 Computer Network Design
3
application
transport
network
link
physical
Link Layer: Introduction
© Winston Seah NWEN302 Computer Network Design
4
Basic terminology:• hosts and routers are nodes• communication channels that
connect adjacent nodes along communication path are links– wired links– wireless links
• layer-2 packet is a frame, encapsulates datagram
data-link layer has responsibility of transferring datagram from one node to adjacent node over a link
Link layer: context• datagram transferred by different link
protocols over different links:– e.g., Ethernet on first link, frame relay on
intermediate links, IEEE 802.11 on last link
• each link protocol provides different services– e.g., may or may not provide reliable data
transfer over the link
© Winston Seah NWEN302 Computer Network Design
5
Link Layer Services
• Framing, link access: – Encapsulate datagram into frame, adding
header, trailer– Arbitrates channel access if shared medium– “MAC” addresses used in frame headers to
identify source and destination nodes
different from IP address!
© Winston Seah NWEN302 Computer Network Design
6
Link Layer Services• Reliable delivery between adjacent nodes
– Seldom used on low bit-error link (fiber, some twisted pair)
– Very often used on wireless links: high error rates• Q (for the future): why both link-level and
end-end reliability (e.g. TCP)?
© Winston Seah NWEN302 Computer Network Design
7
Link Layer Services
• Flow control: – pacing between adjacent sending and
receiving nodes– Another Q for the future How does this
compare against TCP flow control?
• Half-duplex and full-duplex– with half duplex, nodes at both ends of link
can transmit, but not at same time
NWEN302 Computer Network Design
© Winston Seah 8
Link Layer Services
• Error detection: – Errors caused by signal attenuation, noise, …– receiver detects presence of errors
signals sender for retransmission or drops frame
• Error correction: – receiver identifies and corrects bit error(s)
without resorting to retransmission
NWEN302 Computer Network Design
© Winston Seah 9
Where is the link layer implemented?
• In each and every host• Link layer implemented in
“adaptor” (aka network interface card – NIC)– Ethernet card, PCMCI card,
802.11 card– implements link, physical
layer• Connects to host’s system
buses• Combination of hardware,
software, and firmware
© Winston Seah NWEN302 Computer Network Design
10
controller
physicaltransmission
cpu memory
host bus (e.g., PCI)
network interface card / adaptor
host schematic
applicationtransportnetwork
link
linkphysical
Adaptors Communicating
© Winston Seah NWEN302 Computer Network Design
11
Receiving side:• Error detection, reliable data
transfer, flow control, etc• extracts datagram, passes to
upper layer at receiving side
Sending side:• encapsulates datagram in
frame• adds error checking bits,
reliable data transfer, flow control, etc.
controller controller
sending host receiving host
datagram datagram
datagram
frame
Error Detection
© Winston Seah NWEN302 Computer Network Design
12
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
Parity Checking
NWEN302 Computer Network Design
Single Bit Parity:Detect single bit errors
Two Dimensional Bit Parity:Detect and correct single bit errors
© Winston Seah 13
00 correctable single bit error
Sender:• treat segment contents as
sequence of 16-bit integers• checksum: addition (1’s
complement sum) of segment contents
• sender puts checksum value into UDP checksum field
Internet checksum (more later)
Receiver:• compute checksum of
received segment• check if computed checksum
equals checksum field value:– NO - error detected– YES - no error detected
But maybe errors still exist?
© Winston Seah NWEN302 Computer Network Design
14
Goal: detect “errors” (e.g., flipped bits) in transmitted packet (note: used at transport layer only)
https://www.youtube.com/watch?v=JqEvNxAJtDk
Checksum: 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 (Ethernet, 802.11 WiFi, ATM)
© Winston Seah NWEN302 Computer Network Design
15
CRC ExampleWant:
D.2r XOR R = nGequivalently:
D.2r = nG XOR R equivalently:
if we divide D.2r by G, we get remainder R
NWEN302 Computer Network Design
R = remainder[ ]
D.2r
G
© Winston Seah 16
Try at home examples• G=1001, D=110010, r= ??
• Given that with polynomial
G(x)= x5+ x4+ x3+ x2+ x0
and D = AF1867C (in hexadecimal) the
r=0000 (in binary). Find the r, for
D= AF1867D.
© Winston Seah NWEN302 Computer Network Design
17
Topics to be covered
• Link layer services
• Link layer addressing and address resolution
• Ethernet
• Switches
© Winston Seah NWEN302 Computer Network Design
18
MAC Addresses and ARP• 32-bit IP address:
– network-layer address– used to get datagram to destination IP subnet
• MAC / LAN / physical / Ethernet address: – function: send frame from one interface to
another physically-connected interface (same network)
– 48 bit MAC address (for most LANs)• “burned” in NIC ROM, and sometimes software
configurable
© Winston Seah NWEN302 Computer Network Design
19
LAN Addresses and ARP
© Winston Seah NWEN302 Computer Network Design
20
Each adapter on the LAN has a unique LAN address
Broadcast address =FF-FF-FF-FF-FF-FF
= adapter
1A-2F-BB-76-09-AD
58-23-D7-FA-20-B0
0C-C4-11-6F-E3-98
71-65-F7-2B-08-53
LAN(wired orwireless)
LAN Address (more)• MAC address allocation administered by IEEE• Manufacturer buys portion of MAC address
space (to assure uniqueness) analogy:a) MAC address: like National Student Number (NZ)
and Social Security Number (US)b) IP address: like postal address
• MAC flat address portability ➜– can move LAN card from one LAN to another
• IP hierarchical address NOT portable– address depends on IP subnet to which node is
attached
© Winston Seah NWEN302 Computer Network Design
21
ARP: Address Resolution Protocol
© Winston Seah NWEN302 Computer Network Design
22
• 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)
Q: how to determine MAC addr of B knowing B’s IP addr?
1A-2F-BB-76-09-AD
58-23-D7-FA-20-B0
0C-C4-11-6F-E3-98
71-65-F7-2B-08-53
LAN
137.196.7.23
137.196.7.78
137.196.7.14
137.196.7.88
ARP protocol: Same LAN• Node A wants to send datagram to node B,
and B’s MAC addr not in A’s ARP table.
• A broadcasts ARP query packet, containing B's IP address – dest MAC address = FF-FF-FF-FF-FF-FF– all nodes on LAN receive the ARP query
• B replies to A with its (B's) MAC address– frame sent to A’s MAC address (unicast)
© Winston Seah NWEN302 Computer Network Design
23
ARP protocol: Same LAN• Node A caches (saves) B’s IP-to-MAC
address pair in its ARP table until information becomes old (times out) – soft state: information that times out (goes away)
unless refreshed• ARP is “plug-and-play”:
– nodes create their ARP tables without intervention from net administrator
– “arp” command for displaying and modifying ARP table
© Winston Seah NWEN302 Computer Network Design
24
ARP usage in Routing to another LAN
© Winston Seah NWEN302 Computer Network Design
25
• Objective: send datagram from A to B via R• Assumption: A knows B’s IP address
• Router R maintains two ARP tables in, one for each IP (sub)network (LAN)
R
1A-23-F9-CD-06-9B
222.222.222.220111.111.111.110
E6-E9-00-17-BB-4B
CC-49-DE-D0-AB-7D
111.111.111.112
111.111.111.111
A 74-29-9C-E8-FF-55
222.222.222.221
88-B2-2F-54-1A-0F
B222.222.222.222
49-BD-D2-C7-56-2A
ARP usage in Routing to another LAN1. A creates IP datagram with source A, destination B
and A sends IP datagram to next hop (router) R1. A uses ARP to get R’s MAC address 111.111.111.1102. A creates link-layer frame with R's MAC address as
destination, frame contains A-to-B IP datagram3. A’s NIC sends frame 4. R’s NIC receives frame 5. R removes IP datagram from Ethernet frame, and sees that
it is destined to B (in the same local subnet of its other NIC)6. R uses ARP to get B’s MAC address 222.222.222.2227. R creates frame containing A-to-B IP datagram sends to B
© Winston Seah NWEN302 Computer Network Design
26
Topics to be covered
• Link layer services
• Link layer addressing and address resolution
• Ethernet
• Switches
© Winston Seah NWEN302 Computer Network Design
27
Ethernet“dominant” wired LAN technology: • cheap $20 for NIC• 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
© Winston Seah NWEN302 Computer Network Design
28
Ethernet: physical topology• bus: popular through mid 90s
– all nodes in same collision domain (can collide with each other)
• star: prevails today– active switch in center– each “spoke” runs a (separate) Ethernet protocol
(nodes do not collide with each other)
bus: coaxial cable
switch
star© Winston Seah NWEN302 Computer Network
Design29
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
dest.address
sourceaddress
data (payload) CRCpreamble
type
© Winston Seah NWEN302 Computer Network Design
30
Ethernet frame structure (more)• addresses: 6 byte source, destination MAC
addresses– if adapter receives frame with matching destination
address, or with broadcast address (e.g. ARP packet), it passes data in frame to network layer protocol
– otherwise, adapter discards frame
• type: indicates higher layer protocol (mostly IP but others possible, e.g., Novell IPX, AppleTalk)
• CRC: cyclic redundancy check at receiver– error detected: frame is dropped
dest.address
sourceaddress
data (payload) CRCpreamble
type
© Winston Seah NWEN302 Computer Network Design
31
Ethernet: unreliable, connectionless• connectionless: no handshaking
between sending and receiving NICs • unreliable: receiving NIC doesnt send
acks or nacks to sending NIC– data in dropped frames recovered only if
initial sender uses higher layer rdt (e.g., TCP), otherwise dropped data lost
• Ethernet’s MAC protocol: unslotted CSMA/CD wth binary backoff
© Winston Seah NWEN302 Computer Network Design
32
802.3 Ethernet standards: link & physical layers
• many different Ethernet standards– common MAC protocol and frame format– different speeds: 2 Mbps, 10 Mbps, 100
Mbps, 1Gbps, 10G bps– different physical layer media: fiber, cable
applicationtransportnetwork
linkphysical
MAC protocoland frame format
100BASE-TX
100BASE-T4
100BASE-FX100BASE-T2
100BASE-SX 100BASE-BX
fiber physical layercopper (twisterpair) physical layer
© Winston Seah NWEN302 Computer Network Design
33
Topics to be covered
• Link layer services
• Link layer addressing and address resolution
• Ethernet
• Switches
© Winston Seah NWEN302 Computer Network Design
34
Ethernet switch• link-layer device: takes an active role
– store, forward Ethernet frames– 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
• transparent– hosts are unaware of presence of switches
• plug-and-play, self-learning– switches do not need to be configured
© Winston Seah NWEN302 Computer Network Design
35
Switch: multiple simultaneous transmissions• hosts have dedicated,
direct connection to switch
• switches buffer packets• Ethernet protocol used on
each incoming link, but no collisions; full duplex
– each link is its own collision domain
• switching: A-to-A’ and B-to-B’ can transmit simultaneously, without collisions
switch with six interfaces(1,2,3,4,5,6)
A
A’
B
B’ C
C’
1 2
345
6
© Winston Seah NWEN302 Computer Network Design
36
Switch forwarding table
Q: how does switch know A’ reachable via interface 4, B’ reachable via interface 5?
switch with six interfaces(1,2,3,4,5,6)
A
A’
B
B’ C
C’
1 2
345
6A: each switch has a switch table, each entry:(MAC address of host, interface to reach host, time stamp)looks like a routing table!Q: how are entries created, maintained in switch table?
something like a routing protocol?
© Winston Seah NWEN302 Computer Network Design
37
A
A’
B
B’ C
C’
1 2
345
6
Switch: self-learning• switch learns which
hosts can be reached through which interfaces– when frame received,
switch “learns” location of sender: incoming LAN segment
– records sender/location pair in switch table
A A’
Source: ADest: A’
Switch table (initially empty)
MAC addr interface TTL
A 1 60
© Winston Seah NWEN302 Computer Network Design
38
Switch: frame filtering/forwardingwhen frame received at switch
1. record incoming link, MAC address of sending host2. index switch table using MAC destination address3. if entry found for destination
then { if destination on segment from which frame
arrived then drop frame
else forward frame on interface indicated by entry
} else flood /* forward on all interfaces except
arriving interface */
© Winston Seah NWEN302 Computer Network
Design39
A
A’
B
B’ C
C’
1 2
345
6
Self-learning, forwarding: example
A A’
Source: ADest: A’
MAC addr interface TTL
switch table (initially empty)
A 1 60
A A’A A’A A’A A’A A’
• frame destination, A’, location unknown:flood
A’ A
• destination A location known:
A’ 4 60
selectively send
on just one link
© Winston Seah NWEN302 Computer Network Design
40
Interconnecting switches
• switches can be connected together
Q: sending from A to G - how does S1 know to forward frame destined to F via S4 and S3?A: self learning! (works exactly the same as in single-switch case!)
A
B
S1
C D
E
FS2
S4
S3
H
I
G
© Winston Seah NWEN302 Computer Network Design
41
Self-learning multi-switch exampleSuppose C sends frame to I, I responds to C
Q: show switch tables and packet forwarding in S1, S2, S3, S4
A
B
S1
C D
E
FS2
S4
S3
H
I
G
© Winston Seah NWEN302 Computer Network Design
42
to externalnetwork
router
IP subnet
mail server
web server
Institutional network
© Winston Seah NWEN302 Computer Network Design
5-43
Switches vs. routersboth are store-and-forward: routers: network-layer devices (examine network-layer headers)switches: link-layer devices (examine link-layer headers)
both have forwarding tables:routers: compute tables using routing algorithms, IP addressesswitches: learn forwarding table using flooding, learning, MAC addresses
applicationtransportnetwork
linkphysical
networklink
physical
linkphysical
switch
datagram
applicationtransportnetwork
linkphysical
frame
frame
frame
datagram
© Winston Seah NWEN302 Computer Network Design
44
Link Layer Fundamentals
• Link layer services (Sect 5.1 & 5.2)
• Link layer addressing and address resolution (Sect 5.4.1)
• Ethernet (Sect 5.4.2)
• Switches (Sect 5.4.3)
© Winston Seah NWEN302 Computer Network Design
45