Presentation is loading. Please wait.

Presentation is loading. Please wait.

Flow control and Error control ECS 152A Xin Liu Based on Kurose and Ross.

Similar presentations


Presentation on theme: "Flow control and Error control ECS 152A Xin Liu Based on Kurose and Ross."— Presentation transcript:

1 Flow control and Error control ECS 152A Xin Liu Based on Kurose and Ross

2 The Data Link Layer Our goals: r understand principles behind data link layer services: m Flow control m error detection, correction m reliable data transfer

3 Link Layer: Introduction Some terminology: r hosts and routers are nodes r communication channels that connect adjacent nodes along communication path are links m wired links m wireless links m LANs r layer-2 packet is a frame, encapsulates datagram “link” data-link layer has responsibility of transferring datagram from one node to adjacent node over a link

4 Link layer: context r Datagram transferred by different link protocols over different links: m e.g., Ethernet on first link, frame relay on intermediate links, 802.11 on last link r Each link protocol provides different services m e.g., may or may not provide rdt over link transportation analogy r trip from Princeton to Lausanne m limo: Princeton to JFK m plane: JFK to Geneva m train: Geneva to Lausanne r tourist = datagram r transport segment = communication link r transportation mode = link layer protocol r travel agent = routing algorithm

5 Link Layer Services r Framing, link access: m encapsulate datagram into frame, adding header, trailer m channel access if shared medium m “MAC” addresses used in frame headers to identify source, dest different from IP address! r Reliable delivery between adjacent nodes m we learned how to do this already (chapter 3)! m seldom used on low bit error link (fiber, some twisted pair) m wireless links: high error rates Q: why both link-level and end-end reliability?

6 Link Layer Services (more) r Flow Control: m pacing between adjacent sending and receiving nodes r Error Detection: m errors caused by signal attenuation, noise. m receiver detects presence of errors: signals sender for retransmission or drops frame r Error Correction: m receiver identifies and corrects bit error(s) without resorting to retransmission r Half-duplex and full-duplex m with half duplex, nodes at both ends of link can transmit, but not at same time

7 Adaptors Communicating r link layer implemented in “adaptor” (aka NIC) m Ethernet card, PCMCI card, 802.11 card r sending side: m encapsulates datagram in a frame m adds error checking bits, rdt, flow control, etc. r receiving side m looks for errors, rdt, flow control, etc m extracts datagram, passes to rcving node r adapter is semi- autonomous r link & physical layers sending node frame rcving node datagram frame adapter link layer protocol

8 Flow Control r Ensuring the sending entity does not overwhelm the receiving entity m Preventing buffer overflow r Transmission time m Time taken to emit all bits into medium r Propagation time m Time for a bit to traverse the link

9 Model of Frame Transmission

10 Stop and Wait r Source transmits frame r Destination receives frame and replies with acknowledgement r Source waits for ACK before sending next frame r Destination can stop flow by not send ACK r Works well for a few large frames

11 Fragmentation r Large block of data may be split into small frames m Limited buffer size m Errors detected sooner (when whole frame received) m On error, retransmission of smaller frames is needed m Prevents one station occupying medium for long periods r Stop and wait becomes inadequate

12 Stop and Wait Link Utilization

13 Sliding Windows Flow Control r Allow multiple frames to be in transit r Receiver has buffer W long r Transmitter can send up to W frames without ACK r Each frame is numbered r ACK includes number of next frame expected r Sequence number bounded by size of field (k) m Frames are numbered modulo 2 k

14 Sliding Window Diagram

15 Example Sliding Window

16 Sliding Window Enhancements r Receiver can acknowledge frames without permitting further transmission (Receive Not Ready) r Must send a normal acknowledge to resume r If duplex, use piggybacking m If no data to send, use acknowledgement frame m If data but no acknowledgement to send, send last acknowledgement number again, or have ACK valid flag (TCP) Q: if the size of field is k, what is the maximum window size? A: 2^k -1. Assuming 0,1,…2^k-1 (2^k window size) sent out, need to ack the last 2^k-1.

17 Error Detection and correction

18 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

19 Parity Checking Single Bit Parity: Detect single bit errors Two Dimensional Bit Parity: Detect and correct single bit errors 0 0

20 UDP checksum Sender: r treat segment contents as sequence of 16-bit integers r checksum: addition (1’s complement sum) of segment contents r sender puts checksum value into UDP checksum field Receiver: r compute checksum of received segment r check if computed checksum equals checksum field value: m NO - error detected m YES - no error detected. But maybe errors nonetheless? More later …. Goal: detect “errors” (e.g., flipped bits) in transmitted segment

21 Internet Checksum Example r Note m When adding numbers, a carryout from the most significant bit needs to be added to the result r Example: add two 16-bit integers 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1 wraparound sum checksum

22 Cyclic Redundancy Check r view data bits, D, as a binary number r choose r+1 bit pattern (generator), G r goal: choose r CRC bits, R, such that m exactly divisible by G (modulo 2) m receiver knows G, divides by G. If non-zero remainder: error detected! m can detect all burst errors less than r+1 bits r widely used in practice (ATM, HDCL)

23 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, want remainder R R = remainder[ ] D.2rGD.2rG

24 Cyclic Redundancy Check r For a block of k bits transmitter generates n bit sequence r Transmit k+n bits which is exactly divisible by some number r Receive divides frame by that number m If no remainder, assume no error

25 Addition: Multiplication: Division: x 3 + x + 1 ) x 6 + x 5 x 3 + x 2 + x x 6 + x 4 + x 3 x 5 + x 4 + x 3 x 5 + x 3 + x 2 x 4 + x 2 x 4 + x 2 + x x = q(x) quotient = r(x) remainder divisor dividend 35 ) 122 3 105 17 Figure 3.55 Cyclic Redunancy check

26 Steps: 1) Multiply i(x) by x n-k (puts zeros in (n-k) low order positions) 2) Divide x n-k i(x) by g(x) 3) Add remainder r(x) to x n-k i(x) (puts check bits in the n-k low order positions): quotientremainder transmitted codeword b(x) = x n-k i(x) + r(x) x n-k i(x) = g(x) q(x) + r(x) Cyclic Redundancy Check

27 Generator polynomial: g(x)= x 3 + x + 1 Information: (1,1,0,0) i(x) = x 3 + x 2 Encoding: x 3 i(x) = x 6 + x 5 1011 ) 1100000 1110 1011 1110 1011 1010 1011 010 x 3 + x + 1 ) x 6 + x 5 x 3 + x 2 + x x 6 + x 4 + x 3 x 5 + x 4 + x 3 x 5 + x 3 + x 2 x 4 + x 2 x 4 + x 2 + x x Transmitted codeword: b(x) = x 6 + x 5 + x b = (1,1,0,0,0,1,0)

28 Capability of CRC r An error E(X) is undetectable if it is divisible by P(x). The following can be detected. m All single-bit errors if P(x) has more than one nonzero term m All double-bit errors if P(x) has a factor with three terms m Any odd number of errors, if P(x) contain a factor x+1 m Any burst with length less or equal to n-k m A fraction of error burst of length n-k+1; the fraction is 1-2^(-(-n-k-1)). m A fraction of error burst of length greater than n-k+1; the fraction is 1-2^(-(n-k)). r Powerful error detection; more computation complexity compared to Internet checksum

29 Error Correction r Correction of detected errors usually requires data block to be retransmitted Not appropriate for wireless applications m Bit error rate is high Lots of retransmissions m Propagation delay can be long (satellite) compared with frame transmission time Would result in retransmission of frame in error plus many subsequent frames r Need to correct errors on basis of bits received r Basic idea: redundancy

30 Error Correction r Hamming distance: d(v1,v2) between two n-bit binary sequences v1 and v2 is the # of bits in which v1 and v2 disagree. r (n,k) block code: map each k-bit sequence into a unique n-bit codeword (n>k). r K=2,n=5 Datacode 0000000 0100111 1011001 1111110 Consider one bit of error, say 00000->00001. d(00000,00001)=1; d(00111,00001)=2; d(11001,00001)=2; d(11110,00001)=4;

31 Error Control r Detection and correction of errors r Lost frames r Damaged frames r Automatic repeat request m Error detection m Positive acknowledgement m Retransmission after timeout m Negative acknowledgement

32 Automatic Repeat Request (ARQ) r Stop and wait r Go back N r Selective reject (selective retransmission)

33 Stop and Wait r Source transmits single frame r Wait for ACK r If received frame damaged, discard it m Transmitter has timeout m If no ACK within timeout, retransmit r If ACK damaged,transmitter will not recognize it m Transmitter will retransmit m Receive gets two copies of frame m Use ACK0 and ACK1

34 Stop and Wait - Diagram

35 Stop and Wait - Pros and Cons r Simple r Inefficient

36 Go Back N (1) r Based on sliding window r If no error, ACK as usual with next frame expected r Use window to control number of outstanding frames r If error, reply with rejection m Discard that frame and all future frames until error frame received correctly m Transmitter must go back and retransmit that frame and all subsequent frames

37 Go Back N - Damaged Frame r Receiver detects error in frame i r Receiver sends rejection-i r Transmitter gets rejection-i r Transmitter retransmits frame i and all subsequent

38 Go Back N - Lost Frame (1) r Frame i lost r Transmitter sends i+1 r Receiver gets frame i+1 out of sequence r Receiver send reject i r Transmitter goes back to frame i and retransmits

39 Go Back N - Lost Frame (2) r Frame i lost and no additional frame sent r Receiver gets nothing and returns neither acknowledgement nor rejection r Transmitter times out and sends acknowledgement frame with P bit set to 1 r Receiver interprets this as command which it acknowledges with the number of the next frame it expects (frame i ) r Transmitter then retransmits frame i

40 Go Back N - Damaged Acknowledgement r Receiver gets frame i and send acknowledgement (i+1) which is lost r Acknowledgements are cumulative, so next acknowledgement (i+n) may arrive before transmitter times out on frame i r If transmitter times out, it sends acknowledgement with P bit set as before r This can be repeated a number of times before a reset procedure is initiated

41 Go Back N - Damaged Rejection r As for lost frame (2)

42 Go Back N - Diagram

43 Selective Repeat r receiver individually acknowledges all correctly received pkts m buffers pkts, as needed, for eventual in-order delivery to upper layer r sender only resends pkts for which ACK not received m sender timer for each unACKed pkt r sender window m N consecutive seq #’s m again limits seq #s of sent, unACKed pkts

44 Selective repeat: sender, receiver windows

45 Selective repeat data from above : r if next available seq # in window, send pkt timeout(n): r resend pkt n, restart timer ACK(n) in [sendbase,sendbase+N]: r mark pkt n as received r if n smallest unACKed pkt, advance window base to next unACKed seq # sender pkt n in [rcvbase, rcvbase+N-1] r send ACK(n) r out-of-order: buffer r in-order: deliver (also deliver buffered, in-order pkts), advance window to next not-yet-received pkt pkt n in [rcvbase-N,rcvbase-1] r ACK(n) otherwise: r ignore receiver

46 Selective repeat in action

47 Selective repeat: dilemma Example: r seq #’s: 0, 1, 2, 3 r window size=3 r receiver sees no difference in two scenarios! r incorrectly passes duplicate data as new in (a) Q: what relationship between seq # size and window size?


Download ppt "Flow control and Error control ECS 152A Xin Liu Based on Kurose and Ross."

Similar presentations


Ads by Google