Link Layer Fundamentals NWEN302 Computer Network Design
Topics to be covered Link layer services Link layer addressing and address resolution Ethernet Switches © Winston SeahNWEN302 Computer Network Design 1
Network data at different layers The 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 SeahNWEN302 Computer Network Design 2 application transport network link physical
Link Layer: Introduction © Winston SeahNWEN302 Computer Network Design 3 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 on last link each link protocol provides different services –e.g., may or may not provide reliable data transfer over the link © Winston SeahNWEN302 Computer Network Design 4
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 SeahNWEN302 Computer Network Design 5
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 SeahNWEN302 Computer Network Design 6
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 Seah7
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 Seah8
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, card –implements link, physical layer Connects to host’s system buses Combination of hardware, software, and firmware © Winston SeahNWEN302 Computer Network Design 9 controller physical transmission cpu memory host bus (e.g., PCI) network interface card / adaptor host schematic application transport network link physical
Adaptors Communicating © Winston SeahNWEN302 Computer Network Design 10 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 sending host receiving host datagram frame
Error Detection © Winston SeahNWEN302 Computer Network Design 11 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 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 SeahNWEN302 Computer Network Design 13 Goal: detect “errors” (e.g., flipped bits) in transmitted packet (note: used at transport layer only) 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 – exactly divisible by G (modulo 2) –receiver knows G, divides by G. If non-zero remainder error detected! –can detect all burst errors less than r + 1 bits widely used in practice (Ethernet, WiFi, ATM) © Winston SeahNWEN302 Computer Network Design 14
CRC Example Want: D. 2 r XOR R = nG equivalently: D. 2 r = nG XOR R equivalently: if we divide D. 2 r by G, we get remainder R NWEN302 Computer Network Design R = remainder[ ] D.2rGD.2rG © Winston Seah15
Try at home examples G=1001, D=110010, r= ?? Given that with polynomial G(x)= x 5 + x 4 + x 3 + x 2 + x 0 and D = AF1867C (in hexadecimal) the r=0000 (in binary). Find the r, for D= AF1867D. © Winston SeahNWEN302 Computer Network Design 16
Topics to be covered Link layer services Link layer addressing and address resolution Ethernet Switches © Winston SeahNWEN302 Computer Network Design 17
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 SeahNWEN302 Computer Network Design 18
LAN Addresses and ARP © Winston SeahNWEN302 Computer Network Design 19 Each adapter on the LAN has a unique LAN address Broadcast address = FF-FF-FF-FF-FF-FF = adapter 1A-2F-BB AD D7-FA-20-B0 0C-C4-11-6F-E F7-2B LAN (wired or wireless)
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 SeahNWEN302 Computer Network Design 20
ARP: Address Resolution Protocol © Winston SeahNWEN302 Computer Network Design 21 Each IP node (host, router) on LAN has ARP table ARP table: IP/MAC address mappings for some LAN nodes –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 AD D7-FA-20-B0 0C-C4-11-6F-E F7-2B LAN
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 SeahNWEN302 Computer Network Design 22
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 SeahNWEN302 Computer Network Design 23
ARP usage in Routing to another LAN © Winston SeahNWEN302 Computer Network Design 24 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 E6-E BB-4B CC-49-DE-D0-AB-7D A C-E8-FF B2-2F-54-1A-0F B BD-D2-C7-56-2A
ARP usage in Routing to another LAN 1. A creates IP datagram with source A, destination B and A sends IP datagram to next hop (router) R 1. A uses ARP to get R’s MAC address A creates link-layer frame with R's MAC address as destination, frame contains A-to-B IP datagram 3. 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 R creates frame containing A-to-B IP datagram sends to B © Winston SeahNWEN302 Computer Network Design 25
Topics to be covered Link layer services Link layer addressing and address resolution Ethernet Switches © Winston SeahNWEN302 Computer Network Design 26
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 SeahNWEN302 Computer Network Design 27
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 SeahNWEN302 Computer Network Design 28
Ethernet frame structure sending adapter encapsulates IP datagram (or other network layer protocol packet) in Ethernet frame preamble: 7 bytes with pattern followed by one byte with pattern used to synchronize receiver, sender clock rates dest. address source address data (payload) CRC preamble type © Winston SeahNWEN302 Computer Network Design 29
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 source address data (payload) CRC preamble type © Winston SeahNWEN302 Computer Network Design 30
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 SeahNWEN302 Computer Network Design 31
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 application transport network link physical MAC protocol and frame format 100BASE-TX 100BASE-T4 100BASE-FX 100BASE-T2 100BASE-SX 100BASE-BX fiber physical layer copper (twister pair) physical layer © Winston SeahNWEN302 Computer Network Design 32
Topics to be covered Link layer services Link layer addressing and address resolution Ethernet Switches © Winston SeahNWEN302 Computer Network Design 33
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 SeahNWEN302 Computer Network Design 34
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’A’ B B’B’C C’C’ © Winston SeahNWEN302 Computer Network Design 35
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’A’ B B’B’C C’C’ A: 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 SeahNWEN302 Computer Network Design 36
A A’A’ B B’B’C C’C’ 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: A Dest: A’ Switch table (initially empty) MAC addr interface TTL A 1 60 © Winston SeahNWEN302 Computer Network Design 37
Switch: frame filtering/forwarding when frame received at switch 1. record incoming link, MAC address of sending host 2. index switch table using MAC destination address 3. 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 SeahNWEN302 Computer Network Design 38
A A’A’ B B’B’C C’C’ Self-learning, forwarding: example A A’ Source: A Dest: A’ MAC addr interface TTL switch table (initially empty) A 1 60 A A’ frame destination, A’, location unknown: flood A’ A destination A location known: A’A’ 4 60 selectively send on just one link © Winston SeahNWEN302 Computer Network Design 39
Interconnecting switches switches can be connected together Q: sending from A to G - how does S 1 know to forward frame destined to F via S 4 and S 3 ? A: self learning! (works exactly the same as in single-switch case!) A B S1S1 C D E F S2S2 S4S4 S3S3 H I G © Winston SeahNWEN302 Computer Network Design 40
Self-learning multi-switch example Suppose C sends frame to I, I responds to C Q: show switch tables and packet forwarding in S 1, S 2, S 3, S 4 A B S1S1 C D E F S2S2 S4S4 S3S3 H I G © Winston SeahNWEN302 Computer Network Design 41
to external network router IP subnet mail server web server Institutional network © Winston SeahNWEN302 Computer Network Design 5-42
Switches vs. routers both 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 addresses switches: learn forwarding table using flooding, learning, MAC addresses application transport network link physical network link physical link physical switch datagram application transport network link physical frame datagram © Winston SeahNWEN302 Computer Network Design 43
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 SeahNWEN302 Computer Network Design 44