990 likes | 1.18k Views
Communications Technology. Lecture 6: Data Link Layer June 2009. References. Computer Network by A. S. Tanenbaum, Chapter 3 Data & Computer Communications by William Stallings. Learning Objectives. Understand principles behind data link layer services: error detection, correction
E N D
Communications Technology Lecture 6: Data Link Layer June 2009
References • Computer Network by A. S. Tanenbaum, Chapter 3 • Data & Computer Communications by William Stallings
Learning Objectives • Understand principles behind data link layer services: • error detection, correction • sharing a broadcast channel: multiple access • MAC protocols continued
Introduction and services Error detection and correction Multiple/Media access protocols Data Link Layer (L2)
Some terminologies hosts and routers are nodes communication channels that connect adjacent nodes along communication path are links wired links wireless links LANs layer-2 packet is a frame,encapsulates datagram “link” L2 Introduction data-link layer has responsibility of transferring datagram from one node to adjacent node over a link
Datagram transferred by different link protocols over different links: e.g., Ethernet on first link, frame relay on intermediate links, 802.11 on last link Each link protocol provides different services E.g., reliable data transfer (rdt) transportation analogy trip from HCMC to Hanoi limo: HUT to TSN plane: TSN to Noi Bai bus: Noi Bai to Hanoi tourist = datagram transport segment = communication link transportation mode = link layer protocol travel agent = routing algorithm L2: Context
L2 Services • Framing, link access: • encapsulate datagram into frame, adding header, trailer • channel access if shared medium • “MAC” addresses used in frame headers to identify source, dest • different from IP address! • Reliable delivery between adjacent nodes • seldom used on low bit error link (fiber, some twisted pair) • wireless links: high error rates
L2 Services (more) • Flow Control • pacing between adjacent sending and receiving nodes • 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 • Half-duplex and full-duplex • with half duplex, nodes at both ends of link can transmit, but not at same time
link layer implemented in “adaptor” (aka NIC) Ethernet card, modem, 802.11 card adapter is semi-autonomous, implementing link & physical layers sending side encapsulates datagram in a frame adds error checking bits, rdt, flow control, etc. receiving side looks for errors, rdt, flow control, etc extracts datagram, passes to receiving node frame frame Adaptors Communicating datagram receiving node link layer protocol sending node adapter adapter
Introduction and services Error detection and correction Multiple/Media access protocols Data Link Layer (L2)
Error Detection ‘ • D = Data protected by error checking, may include header fields • ED = Error Detection bits (redundancy) • Error detection is not 100% reliable! • a good error detector may miss some errors, but rarely • larger ED field generally yields better detection
Parity Checking Two Dimensional Bit Parity: Detect and correct single bit errors Single Bit Parity: Detect single bit errors 0 0
1 Error Detection: Parity Checking - add a parity bit for every d data bits so that the number of ones of each d+1 data and parity bits is even 0111 0001 1010 1011 1010 1010 0101 0101 Issue: errors generally are bursty, i.e. several consecutive bits are flipped;
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/TCP checksum field Receiver: compute checksum of received segment check if computed checksum equals checksum field value: NO - error detected YES - no error detected. But maybe errors nonetheless? Internet checksum Goal: detect “errors” (e.g., flipped bits) in transmitted segment (note: used at transport layer only)
Checksumming: 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 (ATM, HDCL)
Cyclic Redundancy Check: Background • Widely used in practice, e.g., • Ethernet, FDDI, PKZIP, WinZip, PNG • For a given data D, consider it as a polynomial D(x) • consider the string of 0 and 1 as the coefficients of a polynomial • e.g. consider string 10011 as x4+x+1 • addition and subtraction are modular 2, thus the same as xor • Choose generator polynomial G(x) with r+1 bits, where r is called the degree of G(x)
Cyclic Redundancy Check: Objective • Given data G(x) and D(x), choose R(x) with r bits, such that • D(x)xr+R(x) is exactly divisible by G(x) • The bits correspond to D(x)xr+R(x) are sent to the receiver • Since G(x) is global, when the receiver receives the transmission T’(x), it divides T’(x) by G(x) • if non-zero remainder: error detected! • if zero remainder, assumes no error x +
CRC: Steps and an Example Suppose the degree of G(x) is r Append r zero to D(x), i.e. consider D(x)xr Divide D(x)xr by G(x). Let R(x) denote the reminder Send <D, R> to the receiver
The Power of CRC • Let T(x) denote D(x)xr+R(x), and E(x) the polynomial of the error bits • the received signal is T(x)+E(x) • Since T(x) is divisible by G(x), we only need to consider if E(x) is divisible by G(x) • Examples • a single bit of error: E(x) = xi • if G(x) contains two or more terms, E(x) is not divisible by G(x) • an odd number of errors: E(x) has an odd number of terms: • lemma: if E(x) has an odd number of terms, E(x) cannot be divisible by (x+1) • suppose E(x) = (x+1)F(x), let x=1, the left hand will be 1, while the right hand will be 0 • thus if G(x) contains x+1 as a factor, E(x) will not be divided by G(x) • Many more errors can be detected by designing the right G(x)
Example G(x) • 16 bits CRC: • CRC-16: x16+x15+x2+1, CRC-CCITT: x16+x12+x5+1 • both can catch • all single or double bit errors • all odd number of bit errors • all burst errors of length 16 or less • >99.99% of the 17 or 18 bits burst errors • 32 bits CRC: • CRC32: x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 • used by Ethernet, FDDI, PKZIP, WinZip, and PNG • For more details see the link below and further links it contains: • http://en.wikipedia.org/wiki/Cyclic_redundancy_check
Introduction and services Error detection and correction Multiple/Media access protocols Data Link Layer (L2)
Multiple Access Links and Protocols Two types of “links”: • point-to-point • PPP for dial-up access • point-to-point link between Ethernet switch and host • broadcast (shared wire or medium) • traditional Ethernet • upstream HFC • 802.11 wireless LAN
Multiple Access Protocols • Single shared broadcast channel • thus, if two or more simultaneous transmissions by nodes, due to interference, only one node can send successfully at a time (see CDMA later for an exception) multiple access protocol • Protocol that determines how nodes share channel, i.e., determines when nodes can transmit • Communication about channel sharing must use channel itself ! • Discussion: properties of an ideal multiple accessprotocol.
Ideal Multiple Access Protocol Broadcast channel of rate R bps • Efficiency: when one node wants to transmit, it can send at rate R • Fairness: when N nodes want to transmit, each can send at average rate R/N • Decentralized: • no special node to coordinate transmissions • no synchronization of clocks • Simple
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 • channel not divided, allow collisions • “recover” from collisions • “Taking turns” • Nodes take turns, but nodes with more to send can take longer turns
Multiple Access protocols • single shared broadcast channel • two or more simultaneous transmissions by nodes: interference • collision if node receives two or more signals at the same time 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! • no out-of-band channel for coordination
Random Access Protocols • When node has packet to send • transmit at full channel data rate R. • no a priori coordination among nodes • two or more transmitting nodes == “collision”, • random access MAC protocol specifies: • how to detect collisions • how to recover from collisions (e.g., via delayed retransmissions) • Examples of random access MAC protocols: • slotted ALOHA • ALOHA • CSMA, CSMA/CD, CSMA/CA
Evolution of Contention Protocols Aloha Developed in the 1970s for a packet radio network SlottedAloha Improvement: Start transmission only at fixed times (slots) CSMA = Carrier Sense Multiple Access Improvement: Start transmission only if no transmission is ongoing CSMA CD = Collision Detection Improvement: Stop ongoing transmission if a collision is detected (e.g. Ethernet) CSMA/CD
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 prob. p until success Slotted ALOHA
Pure (unslotted) ALOHA • unslotted ALOHA: simpler, no synchronization • when frame first arrives • transmit immediately • collision probability increases: • frame sent at t0 collides with other frames sent in [t0-1,t0+1]
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!
CSMA collisions spatial layout of nodes collisions can still occur: propagation delay means two nodes may not hear each other’s transmission collision: entire packet transmission time wasted note: role of distance & propagation delay in determining collision probability
CSMA/CD (Collision Detection) CSMA/CD: carrier sensing, deferral as in CSMA • collisions detected within short time • colliding transmissions aborted, reducing channel wastage • collision detection: • easy in wired LANs: measure signal strengths, compare transmitted, received signals • difficult in wireless LANs: receiver shut off while transmitting • human analogy: the polite conversationalist
“Taking Turns” MAC protocols channel partitioning MAC protocols: • share channel efficiently and fairly at high load • inefficient at low load: delay in channel access, 1/N bandwidth allocated even if only 1 active node! Random access MAC protocols • efficient at low load: single node can fully utilize channel • high load: collision overhead “taking turns” protocols look for best of both worlds!
“Taking Turns” MAC protocols Token passing: • control token passed from one node to next sequentially. • token message • concerns: • token overhead • latency • single point of failure (token) Polling: • master node “invites” slave nodes to transmit in turn • concerns: • polling overhead • latency • single point of failure (master)
Summary of MAC protocols • What do you do with a shared media? • Channel Partitioning, by time, frequency or code • Time 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 • CSMA/CA used in 802.11 • Taking Turns • polling from a central site, token passing
principles behind data link layer services: error detection, correction sharing a broadcast channel: multiple access MAC protocols Chapter Summary
Overview • Ethernet and Wi-Fi are both “multi-access” technologies • Broadcast medium, shared by many hosts • Simultaneous transmissions will result in collisions • Media Access Control (MAC) protocol required • Rules on how to share medium
Media Access Control Protocols • Channel partitioning • Divide channel into smaller “pieces” (e.g., time slots, frequency) • Allocate a piece to node for exclusive use • E.g. Time-Division-Multi-Access (TDMA) cellular network • Taking-turns • Tightly coordinate shared access to avoid collisions • E.g. Token ring network • Contention • Allow collisions • “recover” from collisions • E.g. Ethernet, Wi-Fi
Contention Media Access Control Goals • Share medium • If two users send at the same time, collision results in no packet being received (interference) • If no users send, channel goes idle • Thus, want to have only one user send at a time • Want high network utilization • TDMA doesn’t give high utilization • Want simple distributed algorithm • no fancy token-passing schemes that avoid collisions
Evolution of Contention Protocols Aloha Developed in the 1970s for a packet radio network SlottedAloha Improvement: Start transmission only at fixed times (slots) CSMA = Carrier Sense Multiple Access Improvement: Start transmission only if no transmission is ongoing CSMA CD = Collision Detection Improvement: Stop ongoing transmission if a collision is detected (e.g. Ethernet) CSMA/CD
(Pure) ALOHA • Topology: Broadcast medium with multiple stations • Aloha Protocol: • Whenever a station has data, it transmits immediately • Receivers ACK all packets • No ACK = collision. Wait a random time and retransmit
Simple, but Radical • Previous attempts all partitioned channel • TDMA, FDMA, etc. • Aloha optimized the common case (few senders) and dealt with collisions through retries
Trade-off Compared to TDMA • In TDMA, you always have to wait your turn • delay proportional to number of sites • In Aloha, can send immediately • Aloha gives much lower delays, at the price of lower utilization (as we will see)
Performance of (Pure) ALOHA • Performance questions: • What is the collision probability? • What is the maximum throughput? • Notation: C : link capacity in (bits/sec) s : packet size (bits/packet) F : packet transmission time (sec)
Collisions and Vulnerable Period • A frame (red frame) will be in a collision if and only if another transmission begins in the vulnerable period of the frame • Vulnerable period has the length of 2 frame times
Traffic Model Poisson rate from all stations (Poisson Process’s are additive) Inter-arrival time is exponentially distributed