8-45: Intrductin t Telecmmunicatin Netwrks Lectures 5: Datalink layer Peter Steenkiste Frm Signals t Packets Analg Signal Digital Signal Bit Stream 0 0 0 0 0 0 Spring 05 www.cs.cmu.edu/~prs/nets-ece Packets Packet Transmissin 00000000000000000000000000000000000 Header/Bdy Header/Bdy Header/Bdy Outline Errr Detectin and Crrectin Framing Bit stream t packets Packet lss & crruptin (Errr detectin) Flw cntrl Lss recvery Errr Cntrl Channels intrduce errrs in digital cmmunicatins Applicatins require certain reliability level Data applicatins require errr-ee transfer Vice & vide applicatins tlerate sme errrs Errr cntrl may be needed t meet applicatin requirement Errr cntrl ensures a data stream is transmitted t a certain level f accuracy despite errrs Tw basic appraches: Errr detectin & retransmissin (ARQ) Frward errr crrectin (FEC) 4
Key Idea All transmitted data blcks ( cdewrds ) are chsen s that they satisfy a pattern If received blck desn t satisfy pattern, it is in errr Redundancy: Only a subset f all pssible blcks can be valid cdewrds Undetectable Errr: When channel transms a cdewrd int anther valid cdewrd User inmatin All inputs t channel satisfy pattern r cnditin Encder Channel Channel utput Pattern checking Deliver user inmatin r set errr alarm 5 Single Parity Check Append an parity bit t k inmatin bits Inf Bits: b, b, b,, b k Check Bit: b k+ = b + b + b + + b k mdul Cdewrd: (b, b, b,, b k,, b k+ ) All cdewrds have even # f s checks t see if # f s is even All errr patterns that create an dd # f bits are detectable All even-numbered errr patterns are undetectable ASCII cde is precisely such as cde (7+ bits) Example f Single Parity Cde Inmatin (7 bits): (0,, 0,,, 0, 0) Parity Bit: b 8 = 0 + +0 + + + 0 = Cdewrd (8 bits): (0,, 0,,, 0, 0, ) If single errr in bit : (0,,,,, 0, 0, ) # f s =5, dd Errr detected If errrs in bits and 5: (0,,,, 0, 0, 0, ) # f s =4, even Errr nt detected Parity Checkbits & Errr Detectin Inmatin bits Calculate check bits k bits Sent check bits n k bits Channel Received check bits Received inmatin bits Recalculate check bits Cmpare Inmatin accepted if check bits match 7 8
Hw gd is the single parity check cde? Redundancy: Single parity check cde adds redundant bit per k inmatin bits: verhead = /(k+) Cverage: all errr patterns with dd # f errrs can be detected An errr pattern is a binary (k+)-tuple with s where errrs ccur and 0 s elsewhere Of k+ binary (k+)-tuples, ½ are dd, s 50% f errr patterns can be detected Is it pssible t detect mre errrs if we add mre check bits? Yes, with the right cdes 9 What if bit errrs are randm? Many transmissin channels intrduce bit errrs at randm, independently f each ther, and with prbability p Sme errr patterns are mre prbable than thers: 7 8 p P[0000000 ] p( p) ( p) ( ) and p P[000000 ] p 8 p ( p) ( p) ( ) p In any wrthwhile channel p<0.5, and s (p/(-p))< It fllws that patterns with errr are mre likely than patterns with errrs and s th What is the prbability that an undetectable errr pattern ccurs? 0 Single parity check cde with randm bit errrs Undetectable errr pattern if even # f bit errrs: P[errr detectin failure] P[undetectable errr pattern] P[errr patterns with even number f s] n p ( p) n 4 p n 4 n4 ( p)... Example: Evaluate abve n=, p=0 - P[undetectable errr] (0 ) ( 0 ) 0-49 (0 ) 590(0 4 (0 ) ( 0 ) 4 ) 4.9(0 Fr this example, rughly in 000 transmissins will result in an undetectable errr 4 ) 8 What is a gd cde? Mst channels will have relatively few bit errrs Errneus cdewrds transmitted ver thse channels will map t nearby n-tuples If valid cdewrds are clse t each ther, then detectin failures may ccur Gd cdes shuld maximize separatin between valid cdewrds x x x x x x x x = valid cdewrds = nn-cdewrds x x x x x x x Pr distance prperties Gd distance prperties
Tw-Dimensinal Parity Check Mre parity bits t imprve cverage Arrange inmatin as clumns Add single parity bit t each clumn Add a final parity clumn Used in early errr cntrl systems 0 0 0 0 0 0 0 0 Bttm rw cnsists f check bit each clumn Last clumn cnsists f check bits each rw Errr-detecting capability 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 One errr Three errrs Arrws indicate failed check bits 0 0 0 0 0 Tw errrs 0 0 0 0 0 0 0 0 0 Fur errrs 0 0 0 0 0 0,, r errrs can always be detected; Nt all patterns >4 errrs can be detected 4 Other Errr Detectin Cdes Many applicatins require very lw errr rate Need cdes that detect mre number f errrs Single parity check cdes d nt detect enugh errrs Tw-dimensinal cdes require t many check bits The fllwing errr detecting cdes are widely used in practice: Internet Check Sums CRC Plynmial Cdes Internet Checksum Several Internet prtcls (e.g. IP, TCP, UDP) use check bits t detect errrs in the header A checksum is calculated header cntents and included in a special field. Checksum is ptentially recalculated at every ruter, s algrithm selected ease f implementatin in sftware Let header cnsist f L, -bit wrds, b 0, b, b,..., b L- The algrithm appends a -bit checksum b L 5 4
Checksum Calculatin The checksum b L is calculated as fllws: Treating each -bit wrd as an integer, find x = b 0 + b + b +...+ b L- mdul - The checksum is then given by: b L = - x mdul - Thus, the headers must satisfy the fllwing pattern at the receiver: 0 = b 0 + b + b +...+ b L- + b L mdul - The checksum calculatin is carried ut in sftware using ne s cmplement arithmetic 7 Internet Checksum Example Use Mdul Arithmetic Assume 4-bit wrds Use md 4 - (= 5) arithmetic b 0 =00 = b =00 = 0 b 0 +b =+0=7 md5 b = -7 = 8 md5 Theree b =000 Use Binary Arithmetic Nte = md5 S: 0000 = 000 md5 leading bit wraps arund b 0 + b = 00+00 =00 =0000+00 =000+00 =0 =7 Take s cmplement b = -0 =000 8 Plynmial Cdes Binary Plynmial Arithmetic Plynmials instead f vectrs cdewrds Plynmial arithmetic instead f check sums Implemented using shift-register circuits Als called cyclic redundancy check (CRC) Mst data cmmunicatins standards use plynmial cdes errr detectin Have very simple hardware implementatins Plynmial cdes als basis pwerful errr-crrectin methds 9 Binary vectrs map t plynmials k k ( ik, ik,..., i, i, i0 ) ik x ik x... ix i x i0 Additin: 7 ( x x ) ( x Multiplicatin: ( x )( x 5 7 x ) x x x x 7 7 ( ) x x x x ) x( x x 5 x ( x x x 5 5 since 0 md x ) ( x x) ( x x ) x ) 0 5
Binary Plynmial Divisin Divisin with Decimal Numbers divisr 4 5 ) 05 7 40 Plynmial Divisin divisr qutient dividend remainder Nte: Degree f r(x) is less than degree f divisr dividend = qutient x divisr + remainder x + x x + x + ) x + x 5 = 4 x 5 + + x x + x 4 + x x 5 + x 4 + x x 5 + x + x x 4 + x x 4 + x + x = q(x) qutient x dividend = r(x) remainder Plynmial Cding k inmatin bits define plynmial f degree k- k k i( x) ik x ik x... i x i x i0 Cde has binary generating plynmial f degree n-k nk nk g( x) x g nk x... g x gx Find remainder plynmial f at mst degree n-k- q(x) g(x) ) x n-k i(x) x n-k i(x) = q(x)g(x) + r(x) r(x) Define the cdewrd plynmial f degree n- b(x) = x n-k i(x) + r(x) n bits k bits n-k bits Plynmial example: k=4, n-k= Generatr plynmial: g(x)= x + x + Inmatin: (,,0,0) i(x) = x + x Encding: x i(x) = x + x 5 x + x + x x + x + ) x + x 5 x + x 4 + x x 5 + x 4 + x x 5 + x + x x 4 + x x 4 + x + x x 0 0 ) 00000 0 0 0 00 0 Transmitted cdewrd: b(x) = x + x 5 + x b = (,,0,0,0,,0) 00 The Pattern in Plynmial Cding All cdewrds satisfy the fllwing pattern: b(x) = x n-k i(x) + r(x) = q(x)g(x) + r(x) + r(x) = q(x)g(x) All cdewrds are a multiple f g(x)! shuld divide received n-tuple by g(x) and check if remainder is zer If remainder is nn-zer, then received n-tuple is nt a cdewrd 4
Shift-Register Implementatin. Accept inmatin bits i k-,i k-,,i,i,i 0. Append n-k zers t inmatin bits. Feed sequence t shift-register circuit that perms plynmial divisin 4. After n shifts, the shift register cntains the remainder 5 Feedback-Shift Register Circuit + Encder g (x ) x x g 0 Reg 0 + g 0,0,0,i 0,i,i,i g = 0 Reg Reg Clck Input Reg 0 Reg Reg 0-0 0 0 = i 0 0 = i 0 0 = i 0 4 0 = i 0 5 0 0 0 0 0 7 0 0 0 Check bits: r 0 = 0 r = r = 0 r(x) = x g Undetectable errr patterns Designing gd plynmial cdes (Transmitter) b(x) (Channel) + e(x) () Errr plynmial R(x)=b(x)+e(x) e(x) has s in errr lcatins & 0 s elsewhere divides the received plynmial R(x) by g(x) Undetectable errr: If e(x) is a multiple f g(x), that is, e(x) is a nn-zer cdewrd, then R(x) = b(x) + e(x) = q(x)g(x) + q (x)g(x) The set f undetectable errr plynmials is the set f nnzer cde plynmials Chse the generatr plynmial s that selected errr patterns can be detected. Select generatr plynmial s that likely errr patterns are nt multiples f g(x) Detecting Single Errrs e(x) = x i errr in lcatin i+ If g(x) has mre than term, it cannt divide x i Detecting Duble Errrs e(x) = x i + x j = x i (x j-i +) where j>i If g(x) has mre than term, it cannt divide x i If g(x) is a primitive plynmial, it cannt divide x m + all m< n-k - (Need t keep cdewrd length less than n-k -) Primitive plynmials can be fund by cnsulting cding thery bks 7 8 7
Standard Generatr Plynmials CRC-8: CRC-: CCITT-: CCITT-: CRC = cyclic redundancy check 8 x x x ATM x x 5 x (x )(x 5 x ) Bisync x x x 5 HDLC, XMODEM, V.4 IEEE 80, DD, V.4 x x x x x x x x 0 x 8 x 7 x 5 x 4 x x 9 Hamming Cdes Class f errr-crrecting cdes Capable f crrecting all single-errr patterns Fr each m >, there is a Hamming cde f length n= m - with n-k=m parity check bits m n= m - k=n-m m/n 7 4 /7 4 5 4/5 5 5/ 57 / Redundancy 0 m= Hamming Cde Inmatin bits are b, b, b, b 4 Equatins parity checks b 5, b, b 7 b b b 5 b + 7 b b b b 4 b 4 b b b There are 4 = cdewrds (0,0,0,0,0,0,0) is a cdewrd 4 Hamming (7,4) cde Inmatin Cdewrd Weight b b b b 4 b b b b 4 b 5 b b 7 w(b) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 4 0 0 0 0 0 4 0 0 0 0 4 0 0 0 0 0 7 8
Minimum distance f any Hamming Cde = Frm Signals t Packets Set f n- tuples within distance f b b b Distance Set f n- tuples within distance f b Spheres f distance arund each cdewrd d nt verlap If a single errr ccurs, the resulting n-tuple will be in a unique sphere arund the riginal cdewrd Thus, receiver can crrect errneus receptin back t riginal cdewrd Analg Signal Digital Signal Bit Stream 0 0 0 0 0 0 Packets Packet Transmissin 00000000000000000000000000000000000 Header/Bdy Header/Bdy Header/Bdy 4 Outline Errr Detectin and Crrectin Framing Bit stream t packets Packet lss & crruptin (Errr detectin) Flw cntrl Lss recvery Framing Hw d we break up a stream f bits int ames? 00000000000000000000000000000000000 5 9
Framing A link layer functin, defining which bits have which functin. Minimal functinality: mark the beginning and end f packets (r ames). Sme techniques: Out f band delimiters (e.g. 4B/5B cntrl symbls) Frame delimiter characters with character stuffing Frame delimiter cdes with bit stuffing Synchrnus transmissin (e.g. SONET) Bundaries are based n timing Start delim Out-f-band: E.g., 80.5 80.5/tken ring uses 4b/5b Start delim & end delim are illegal data cdes Access ctrl Frame ctrl Dest adr Src adr Bdy checksum End delim Frame status 7 8 Delimiter Based SYN: sync character SOH: start f header STX: start f text ETX: end f text SYN SYN SOH Header STX Bdy ETX CRC What happens when ETX is in Bdy? Character and Bit Stuffing Mark ames with special character. What happens when the user sends this character? Use escape character when cntrls appear in data: *abc*def *abc\*def Very cmmn n serial lines, in editrs, etc. Mark ames with special bit sequence must ensure data cntaining this sequence can be transmitted example: suppse is a special sequence. transmitter inserts a 0 when this appears in the data: 0 must stuff a zer any time seven s appear: 0 00 receiver unstuffs. 9 40 0
Ethernet Framing Preamble is 7 bytes f 0000 (5 MHz square wave) fllwed by ne byte f 000 Allws receivers t recgnize start f transmissin after idle channel preamble datagram length mre stuff Outline Errr Detectin and Crrectin Framing Bit stream t packets Packet lss & crruptin (Errr detectin) Flw cntrl Lss recvery 4 4 Link Flw Cntrl and Errr Recvery A Naïve Prtcl Dealing with receiver verflw: flw cntrl. Dealing with packet lss and crruptin: errr cntrl. Meta-cmment: these issues are relevant at many layers. Link layer: sender and receiver attached t the same wire End-t-end: transmissin cntrl prtcl (TCP) - sender and receiver are the end pints f a cnnectin Hw can we implement flw cntrl? Yu may send (windws, stp-and-wait, etc.) Please shut up (surce quench, 80.x pause 4 simply sends t the receiver whenever it has packets. Ptential prblem: sender can utrun the receiver. t slw, buffer verflw,.. Nt always a prblem: receiver might be fast enugh. 44
Adding Flw Cntrl Drawback: Permance Stp and wait flw cntrl: sender waits t send the next packet until the previus packet has been acknwledged by the receiver. can pace the receiver RTT Time Max Thrughput = pkt Rundtrip Time 45 4 Windw Flw Cntrl Stp and wait flw cntrl results in pr thrughput lng-delay paths: packet size/ rundtrip-time. Slutin: receiver prvides sender with a windw that it can fill with packets. The windw is backed up by buffer space n receiver acknwledges the a packet every time a packet is cnsumed and a buffer is eed Bandwidth-Delay Prduct RTT Time Max Thrughput = Windw Size Rundtrip Time 47 48
Errr Recvery Tw ms f errr recvery Errr Crrecting Cdes (ECC) Autmatic Repeat Request (ARQ) ECC Send extra redundant data t help repair lsses ARQ sends acknwledgement (ACK) when it receives packet uses ACKs t identify and resend data that was lst 49 Simplest ARQ prtcl Send a packet, stp and wait until acknwledgement arrives Will examine ARQ issues later in semester Stp and Wait Time Timeut 50 Time Timeut Timeut Recvering m Errr Timeut Timeut Timeut Timeut Packet lst ACK lst Early timeut 5 Hw t Recgnize Retransmissins? Use sequence numbers bth packets and acks Sequence # in packet is finite Hw big shuld it be? Fr stp and wait? One bit wn t send seq # until received ACK seq #0 5
Implementatin Issues with Windw-based Prtcl Windw size: # f ttal utstanding packets that sender can send withut acknwledged Hw big a sequence number d we need? Fr m-bit sequence number: W s = m - Reasn: if windw culd be m, then if the first packet in a windw is lst, the receiver cannt nt distinguish a retransmissin m a new packet Maximum Allwable Windw Size is W s = m - A B 0 M = = 4, G-Back - 4: A C K A C K A C K R next 0 0 M = = 4, G-Back-: A 0 0 Transmitter ges back 4 A A A B C C C K K K has R next =, s it 5 R next 0 rejects the ld ame 0-54 0 A C K 0 Transmitter ges back Time has R next = 0, but it des nt knw whether its ACK ame 0 was received, s it des nt knw whether this is the ld ame 0 r a new ame 0 Time What is Used in Practice? N flw r errr cntrl. E.g. regular Ethernet, just uses CRC errr detectin Flw cntrl nly E.g. Gigabit Ethernet Flw and errr cntrl. E.g. X.5 (lder cnnectin-based service at 4 Kbs that guarantees reliable in rder delivery f data) Flw and errr cntrl slutins als 55 4