Topic 2 Data Link Layer Part A The majority of the slides in this course are adapted from the accompanying slides to the books by Larry Peterson and Bruce Davie and by Jim Kurose and Keith Ross. Additional slides and/or figures from other sources and from Vasos Vassiliou are also included in this presentation. DataLink Layer
The Data Link Layer Our goals: understand principles behind data link layer services: error detection, correction link layer addressing reliable data transfer, flow control sharing a broadcast channel: multiple access examine various link layer technologies DataLink Layer
Link Layer: Introduction Some terminology: 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 data-link layer has responsibility of transferring a datagram from one node to an adjacent node over a link DataLink Layer
Link layer: context transportation analogy trip from Princeton to Lausanne limo: Princeton to JFK plane: JFK to Geneva train: Geneva to Lausanne tourist = datagram transport segment = communication link transportation mode = link layer protocol travel agent = routing algorithm 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., may or may not provide reliable data transfer over link DataLink Layer
Link Layer Services Framing, link access: Flow Control: 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! Flow Control: pacing between adjacent sending and receiving nodes DataLink Layer
Link Layer Services (more) 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 Reliable delivery between adjacent nodes Retransmissions seldom used on low bit error link (fiber, some twisted pair) wireless links: high error rates Q: why both link-level and end-end reliability? DataLink Layer
Link access link layer implemented in “adaptor” (aka NIC) datagram link layer protocol rcving node sending node frame frame adapter adapter link layer implemented in “adaptor” (aka NIC) Ethernet card, PCMCIA card, 802.11 card sending side: encapsulates datagram in a frame adds error checking bits, rdt, flow control, etc. receiving side looks for errors, reliable data transfer (rdt), flow control, etc extracts datagram, passes to receiving node adapter is semi-autonomous link & physical layers DataLink Layer
Placement of the data link protocol. Link access Placement of the data link protocol. DataLink Layer
Framing A frame also includes: Destination Address (in Header) Error Detection Code (in Trailer) DataLink Layer
A character stream. (a) Without errors. (b) With one error. Framing A character stream. (a) Without errors. (b) With one error. DataLink Layer
Framing (2) (a) A frame delimited by flag bytes. (b) Four examples of byte sequences before and after stuffing. DataLink Layer
Framing (3) Bit stuffing (a) The original data. (b) The data as they appear on the line. (c) The data as they are stored in receiver’s memory after destuffing. DataLink Layer
Flow Control and Error Control Fundamental mechanisms that determine performance Can be implemented at different levels: link, network, or application Difficult to model performance Simplest case: point-to-point link Constant propagation Constant data rate Probabilistic error rate Traffic characteristics DataLink Layer
Error Control Used to recover lost or damaged PDUs Involves error detection and PDU retransmission Implemented together with flow control in a single mechanism Performed at various protocol levels DataLink Layer
Types of Error An error occurs when a bit is altered between transmission and reception Single bit errors One bit altered Adjacent bits not affected White noise Burst errors Length B Contiguous sequence of B bits in which first last and any number of intermediate bits in error Impulse noise Fading in wireless Effect greater at higher data rates DataLink Layer
Error Detection 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 DataLink Layer
Error Detection Process DataLink Layer
Parity Checking Additional bits added by transmitter for error detection code Parity Value of parity bit is such that character has even (even parity) or odd (odd parity) number of ones Even number of bit errors goes undetected DataLink Layer
Parity Checking Single Bit Parity: Two Dimensional Bit Parity: Detect single bit errors Two Dimensional Bit Parity: Detect and correct single bit errors Detect up to 4 bit errors Odd parity example DataLink Layer
Internet checksum Goal: detect “errors” in transmitted segment (note: used at transport layer only) 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? More later …. Sender: treat segment contents as sequence of 16-bit integers checksum: addition (1’s complement sum) of segment contents sender puts checksum value into checksum field DataLink Layer
Cyclic Redundancy Check For a block of k bits transmitter generates n bit sequence Transmit k+n bits which is exactly divisible by some number Receive divides frame by that number If no remainder, assume no error DataLink Layer
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) DataLink Layer
CRC Example Want: D.2r XOR R = nG equivalently: D.2r = nG XOR R if we divide D.2r by G, want remainder R D.2r G R = remainder[ ] DataLink Layer
Error-Detecting Codes Calculation of the polynomial code checksum. DataLink Layer
Framing, Error Control and noise Suppose that we have a frame of size n bits and the bit error probability = p (independent from the bit error probability in any other bit). Probability of correct (no error) transmission of frame = (1-p)n The larger the frame, the larger the error probability! The smaller the frame, the larger the ratio of overhead information trasnmitted If the error probability is “small”, then the receiver can ask for a retransmission. If the error probability is “large”, then the it may be more effective to use a forward error correction code FEC. DataLink Layer
Error Correction Correction of detected errors usually requires a data block to be retransmitted Not appropriate for wireless applications Bit error rate is high Lots of retransmissions Propagation delay can be long (satellite) compared with frame transmission time Would result in retransmission of frame in error plus many subsequent frames Need to correct errors on basis of bits received DataLink Layer
Working of Error Correction Add redundancy to transmitted message Can deduce original in face of certain level of error rate E.g. block error correction code In general, add (n – k ) bits to end of block Gives n bit block (codeword) All of original k bits included in codeword Some FEC map k bit input onto n bit codeword such that original k bits do not appear DataLink Layer
Error Correction Process Each k bit block mapped to an n bit block (n>k) Codeword Forward error correction (FEC) encoder Codeword sent Received bit string similar to transmitted but may contain errors Received code word passed to FEC decoder If no errors, original data block output Some error patterns can be detected and corrected Some error patterns can be detected but not corrected Some (rare) error patterns are not detected Results in incorrect data output from FEC DataLink Layer
Error Correction Process DataLink Layer
Error-Correcting Codes Use of a Hamming code to correct burst errors. DataLink Layer
Κυκλικός Κώδικας Πλεονασμού (Cyclic Redundancy Check CRC). Βασισμένη στη θεωρία των πεπερασμένων πεδίων. Κάθε συρμός (bit stream) αντιπροσωπεύει ένα πολυώνυμο M(x) (n+1)-bit συρμός αντιπροσωπεύει πολυώνυμο βαθμού n. 1001 M(x) = 1x3+0x2+0x1+1x0= x3+x0 Επιλογή διαιρέτη: Πολυώνυμο C(x) βαθμού k το οποίο γνωρίζουν ο αποστολέας και παραλήπτης. Ο αποστολέας στέλνει το πολυώνυμο P(x) το οποίο είναι βαθμού n+k (δηλαδή n+k+1 bits). Το πολυώνυμο P(x) επιλέγεται έτσι ώστε το υπόλοιπο της διαίρεσης P(x) / C(x) να είναι 0. Ο παραλήπτης κάνει τη διαίρεση και αν υπάρχει υπόλοιπο τότε το δεδομένο πλαίσιο έχει κάποιο σφάλμα. Εάν δεν υπάρχει υπόλοιπο, τότε πιθανότατα το πλαίσιο παραλήφθηκε σωστά. DataLink Layer
Ιδιότητες Διαίρεσης Πολυωνύμων Ένα πολυώνυμο Τ(x) διαιρείται από το C(x) εφόσον το Τ(x) είναι μεγαλύτερου βαθμού από το C(x). Ένα πολυώνυμο Τ(x) διαιρείται από το C(x) εφόσον το Τ(x) είναι ίσου βαθμού με το C(x). Το υπόλοιπο της διαίρεσης Τ(x) / C(x) βρίσκεται με την αφαίρεση του C(x) από το Τ(x). Η αφαίρεση του πολυωνύμου C(x) από το Τ(x) βρίσκεται απλά με την πράξη «αποκλειστικό ή» (Exclusive-OR (XOR)) σε κάθε ζεύγος αντίστοιχων συντελεστών. DataLink Layer
Κυκλικός Κώδικας Πλεονασμού Ο αποστολέας θέλει να μεταδώσει τα δεδομένα που αντιστοιχούν στο πολυώνυμο M(x). Αποστολέας και παραλήπτης συμφωνούν τον διαιρέτη C(x) ο οποίος είναι βαθμού k. Ο αποστολέας πολλαπλασιάζει M(x) επί xk για να δημιουργήσει το πολυώνυμο T(x), δηλαδή T(x)= xk M(x). Ο αποστολέας διαιρεί το Τ(x) δια C(x) και βρίσκει το υπόλοιπο R(x). Αφαιρείται το R(x) από το Τ(x) και το αποτέλεσμα P(x) = Τ(x) - R(x) αποτελεί το συρμό ή πλαίσιο που αποστέλλεται στον παραλήπτη. DataLink Layer
Παράδειγμα Ο αποστολέας θέλει να στείλει το συρμό 10011010. Αντίστοιχο πολυώνυμο: Πολυώνυμο Διαίρεσης C(x)= x3+x2+1 Πολλαπλασιάζουμε το M(x) επί x3 με αποτέλεσμα Το οποίο αντιστοιχεί στο συρμό 10011010000 Στη συνέχει εκτελούμε τη διαίρεση DataLink Layer
Η αφαίρεση αντιστοιχεί στην πράξη Exclusive-OR (XOR) Παράδειγμα Η αφαίρεση αντιστοιχεί στην πράξη Exclusive-OR (XOR) Για συντομία οι μεταβλητές x δεν χρησιμοποιούνται αλλά απλά εννοούνται. DataLink Layer
Παράδειγμα 1 0 0 1 1 0 1 0 0 0 0 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 1 1 0 1 Ο αποστολέας θα στείλει τον συρμό 1 0 0 1 1 0 1 0 1 0 1 1 1 0 0 1 1 0 1 Μήνυμα CRC 1 0 0 0 1 1 0 1 1 0 1 DataLink Layer
Παράδειγμα: Επαλήθευση παραλήπτη 1 0 0 1 1 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1 1 1 0 1 Υπόλοιπο =0, οπόταν πιθανότατα δεν υπάρχουν σφάλματα 1 1 0 1 0 0 0 DataLink Layer
Πολυώνυμα Διαίρεσης C(x) CRC Πολυώνυμο CRC-8 CRC-10 CRC-12 x8+x2+x1+1 x10+x9+x5+x4+x1+1 x12+x11+x3+x2+x1+1 CRC-16 CRC-CCITT CRC-32 x16+x15+x2+1 x16+x12+x5+1 x32+x26+x23+x22+x16+x12+ +x11+x10+x8+x7+x5+x4+x2+x1+1 DataLink Layer