fall 2005 by: h. veisi computer networks course olum-fonoon babol chapter 3 data link layer

Download Fall 2005 By: H. Veisi Computer networks course Olum-fonoon Babol Chapter 3 Data Link Layer

If you can't read please download the document

Upload: dorcas-kelly-martin

Post on 18-Jan-2018

240 views

Category:

Documents


2 download

DESCRIPTION

H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 3 Services Provided to Network Layer (1)  Network layer and DLL should work independent Virtual communication. Actual communication.

TRANSCRIPT

Fall 2005 By: H. Veisi Computer networks course Olum-fonoon Babol Chapter 3 Data Link Layer H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 2 Data Link Layer Design Issues Services Provided to the Network Layer The network layer wants to be able to send packets to its neighbors without worrying about the details of getting it there in one piece. Framing Group the physical layer bit stream into units called frames. Frames are nothing more than "packets" or "messages". By convention, we use the term "frames" when discussing DLL. Error Control Sender checksums the frame and transmits checksum together with data. Receiver re-computes the checksum and compares it with the received value. Flow Control Prevent a fast sender from overwhelming a slower receiver. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 3 Services Provided to Network Layer (1) Network layer and DLL should work independent Virtual communication. Actual communication. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 4 Services Provided to Network Layer (2) Delivery Mechanisms Un-acknowledge connectionless Receiver does not return acknowledgments to the sender, Sender has no way of knowing if a frame has been successfully delivered. Applications: 1. When errors are so infrequent that there is little to be gained by the data link layer performing the recovery (Higher layers can recover from errors with little loss in performance). Example: LAN 2. For real-time applications requiring "better never than late". Old data may be worse than no data. Example: Sound stream H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 5 Services Provided to Network Layer (3) Delivery Mechanisms Acknowledge connectionless Receiver returns an acknowledgment frame to the sender indicating that a data frame was properly received. Each frame is assigned a unique sequence number, which the receiver returns in an acknowledgment frame to indicate which frame the ACK refers to. Sender must retransmit unacknowledged (e.g., lost or damaged) frames. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 6 Services Provided to Network Layer (4) Delivery Mechanisms Reliable Delivery Acknowledge connection-oriented: Reliable Delivery Frames are delivered to the receiver reliably and in the same order as generated by the sender. Connection state keeps track of sending order and which frames require retransmission. For example, receiver state includes which frames have been received, which ones have not, etc. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 7 Framing (1) DLL translates the physical layer's raw bit stream into discrete units (messages) called frames. How can frame be transmitted so the receiver can detect frame boundaries? That is, how can the receiver recognize the start and end of a frame? Character Count Flag byte with Byte Stuffing Starting and ending flag with bite stuffing Encoding Violations H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 8 Framing (2) Character Count First field in the frame's header = the length of the frame. Disadvantage: Receiver loses synchronization when bits become garbled. If the bits in the count become corrupted during transmission, the receiver will think that the frame contains fewer (or more) bits than it actually does. Without errors With one error H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 9 Framing (3) Flag byte with Byte Stuffing Use reserved bit patterns (Flag byte) to indicate the start and end of a frame. Problem: What happens if the reserved delimiter happens to appear in the frame itself? Solution: Use byte stuffing (Character stuffing): insert a special escape byte (ESC) just before accidental flag byte in data. Another problem: if an ESC byte occurs in data Solution: ESC stuff with another ESC byte Major problem: Dependent on 8-bite character H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 10 Framing (4) Flag byte with Byte Stuffing (a) A frame delimited by flag bytes. (b) Four examples of byte sequences before and after stuffing. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 11 Framing (5) Starting and ending flag with bite stuffing Each frame begin and end with a special bite pattern (Flag) like Whenever the sender DLL encounter 5 consecutive 1s in data, a 0 bit stuffs into outgoing stream. If users data contain flag it transmitted as Independent from number of bits in frames and characters The original data. Data as appear on the line. Receivers memory after destuffing. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 12 Framing (6) Encoding Violations Send a signal that doesn't conform to any legal bit representation. Ex. In Manchester encoding, for instance, 1-bits are represented by a high-low sequence, and 0-bits by low-high sequences. The start/end of a frame could be represented by the signal low-low or high-high. The advantage of encoding violations is that no extra bandwidth is required as in bit or character stuffing. The IEEE standard uses this approach. Some systems use a combination of these techniques. IEEE 802.3, for instance, has both a length field and special frame start and frame end patterns. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 13 Error Control Must insure that all frames are eventually delivered (possibly in order) to a destination. Three components are required to do this: Acknowledgments: Receiver returns a special acknowledgment (ACK) frame to the sender indicating the correct receipt of a frame. In some systems, the receiver also returns a negative acknowledgment (NACK) for incorrectly-received frames. Timers: What happens if an ACK or NACK becomes lost? Retransmission timers are used to resend frames that don't produce an ACK. Sequence Numbers: Retransmissions introduce the possibility of duplicate frames. To suppress duplicates, add sequence numbers to each frame, so that a receiver can distinguish between new frames and repeats of old frames. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 14 Error detection and error correction (1) In data communication, line noise is a fact of life (e.g., signal attenuation) There are two types of attacks against errors: Error Detecting Codes: Include enough redundancy bits to detect errors and use ACKs and retransmissions to recover from the errors. Error Correcting Codes: Include enough redundancy to detect and correct errors. Detecting and correcting errors requires redundancy (sending additional information along with the data). redundancyMessages (frames) data m bits n = ( m + r ) bit codeword r bits H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 15 Error detection and error correction (2) how many of the bits differ Hamming Distance. Given any two codewords, we can determine how many of the bits differ. XOR the two words, and count the number of 1 bits in the result d=2 If two codewords are d bits apart, d errors are required to convert one to the other. A code's Hamming Distance is defined as the minimum Hamming Distance between any two of its legal codewords (from all possible codewords). In general, all 2 m possible data words are legal. However, by choosing check bits carefully, the resulting codewords will have a large Hamming Distance. The larger the Hamming distance, the better the codes are able to detect errors. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 16 Error detection and error correction (3) Error detection (1) Parity Bits A single parity bit is appended to each data block (e.g. each character in ASCII systems) so that the number of 1 bits always adds up to an even (odd) number. Ex (1) (0) Can detect any Odd number of errors Probability of detection=0.5 (Not acceptable!) The Hamming Distance for parity is 2, it can detect single- bit errors. To detect d-bit errors requires having a Hamming Distance of at least d+1 bits. Parity bitMessages (frames) data H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 17 Error detection and error correction (4) Error detection (2) CRC (Cyclic Redundancy Check) or Polynomial code K-bits frame is regarded as the coefficient list for a k-term polynomial Ex x 5 +x 4 +x 0 = x 5 +x 4 +1 generator polynomial Sender and receiver agree upon a r-bits generator polynomial G(x), both high and low bits are 1. For a m-bits frame the corresponding poly. =M(x) Checksum Compute Checksum as bellow: CRC bitsMessages (frames) data H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 18 Error detection and error correction (5) Error detection (3) CRC algorithm: 1. Append r zero bits to low-order end of the frame, Frame= m+r bits x r. G(x) poly. 2. Divide the x r. G(x) bit string in to G(x), using modulo 2 3. Subtract the reminder form x r. G(x) result=T(x) Sender: send T(x) Receiver: Divide T(x) in to G(x) if reminder==0, No error H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 19 Error detection and error correction (6) Error detection (4) CRC example Frame= Generator= Transmitted data = H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 20 Error detection and error correction (7) Error detection (4) CRC benefits: Detection of any single error: If G(x) contain two or more terms Detection of any double error: If G(x) dose not divide the poly. [x k +1] for all [k< frame length] Detection of any odd number error: If G(x) has the poly. [x+1] as a factor Detection of all burst errors of length=D+r H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 26 Error detection and error correction (9) Error correction (5) Hamming code example(4) Correct burst errors column Send one column at a time H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 27 Flow control The speed of the sender too match that of the receiver. This is a dynamic process, as the receiving speed depends on such changing factors as the load, and availability of buffer space. Solutions: Feedback-based flow control Receiver send information back to sender (given permission to give more or telling its condition) Rate-based flow control Use a built-in mechanism to limit the rate H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 28 Data Link Layer protocols (1) Definitions #define MAX PKT 1024 /* determines packet size in bytes */ typedef enum {false, true} boolean; /* boolean type */ typedef unsigned int seq_nr; /* sequence or ack numbers */ typedef struct { unsigned char data[MAX PKT]; } packet; /* packet definition */ typedef enum {data, ack, nak} frame_kind; /* frame kind definition */ typedef struct { /* frames are transported in this layer */ frame_kind kind; /* what kind of a frame is it? */ seq_nr seq; /* sequence number */ seq_nr ack; /* acknowledgement number */ packet info; /* the network layer packet */ } frame; H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 29 Data Link Layer protocols (2): Protocol1(Utopia) An Unrestricted Simplex Protocol one direction onlyerror free channel /* Protocol 1 (utopia) provides for data transmission in one direction only, error free channel, and the receiver is assumed to be able to process all the input infinitely fast. */ void sender1 (void){ frame s; /* buffer for an outbound frame */ packet buffer; /* buffer for an outbound packet */ while (true) { from_network_layer(&buffer); /* go get something from network layer to send */ s.info = buffer; /* copy it into s for transmission */ to_physical_layer(&s); /* send it on its way */ } void receiver1 (void){ frame r; event_type event; /* filled in by wait, but not used here */ while (true) { wait_for_event(&event);/* only possibility is frame arrival */ From_physical_layer(&r); /* go get the inbound frame */ To_network_layer(&r.info); /* pass the data to the network layer */ } H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 30 Data Link Layer protocols (3): Protocol2(Stop-and-wait) Stop-and-Wait A Simplex Stop-and-Wait Protocol /* Protocol 2 (stop-and-wait), one-directional flow of data from sender to receiver, error free channel, The receiver has only a finite buffer capacity and a finite processing speed, protocol must prevent the sender from flooding */ void sender2 (void){ frame s; packet buffer; event_type event; /* frame_arrival is the only possibility */ while (true) { from_network_layer(&buffer); s.info = buffer; to_physical_layer(&s); wait_for_event(event(&event); /* do not proceed until given the go ahead */ } void receiver2 (void){ frame r, s; while (true) { wait_for_event(&event); From_physical_layer(&r); To_network_layer(&r.info); to_physical_layer(s); /* send a dummy frame to awaken sender */ } Flow control: Flow control: Drop the ability of receiving from network layer unrestricted H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 31 Data Link Layer protocols (4): Protocol3(ARQ) A Simplex Protocol for a Noisy Channel (1) In Protocol2 if an error occurred, protocol failed (Frame or its ACK) Solutions: Adding a timer: if frame damaged, sender transmit the frame again after a specific time How long should the timer be? Using 3 factors: 1. transmission time 2. Processing time in receiver 3. Receiving ACK time Scenario of a bug that could happen: 1.A transmits frame one 2.B receives A1 3.B generates ACK 4.ACK is lost 5.A times out, retransmits 6.B gets duplicate copy of A1 (and sends it on to network layer.) H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 32 Data Link Layer protocols (5): Protocol3(ARQ) A Simplex Protocol for a Noisy Channel (2) Solutions: If receiver get the frame correctly but ACK damage: Sender re-transmit the previous frame! Adding a sequence number to header of frame Min. No. of bits for Seq. No.? The ambiguity is in frame No. m and m+1 and only concerned about two successive frames 1-bite is sufficient (Seq. 0 and 1) ARQPAR ARQ (Automatic Repeat reQuest) or PAR (Positive Ack. With Re-transmission) : Sender waits for positive acknowledgment before advancing to the next data item. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 33 Data Link Layer protocols (6): Protocol3(ARQ) A Simplex Protocol for a Noisy Channel (3) /* Protocol 3 (PAR) allows unidirectional data flow over an unreliable channel. */ #define MAX_SEQ 1 /* must be 1 for protocol 3 */ void sender3 (void){ seq_nr next_frame_to_send;/* Seq number of next outgoing frame */ frame s; packet buffer; event_type event; next_frame_to_send = 0; from_network_layer(&buffer); /* go get something to send */ while (true) { s.info = buffer; /* copy it into s for transmission */ s.seq = next_frame_to_send;/* insert sequence number in frame */ to_physical_layer(&s); /* send it on its way */ start_timer( s.seq);/* if answer takes too long, time out */ wait_for_event(event(&event); /* frame arrival or cksum err, or timeout */ if ( event == frame_arrival) { from_physical_layers(&s);/* Get the ACK */ if ( s.ack == next_frame_to_send ) { from_network_layer( &buffer ); /* get the next one to send */ inc( next_frame_to_send );/* invert next_frame_to_send */ } H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 34 Data Link Layer protocols (7): Protocol3(ARQ) A Simplex Protocol for a Noisy Channel (4) void receiver3 (void){ seq_nrframe_expected; frame r, s; event_type event; while (true) { wait_for_event(&event);/* only possibility is frame arrival */ if ( frame == event_arrival ) { /* A valid frame has arrived */ from_physical_layer(&r); /* go get the inbound frame */ if ( r.seq == frame_expected ) { /* This is what weve been waiting for */ to_network_layer(&r.info); /* pass the data to the network layer */ inc(frame_expected);/* next time expect the other seq # */ } s.ack = 1 frame_expected; to_physical_layer(&s); /* send a dummy frame to awaken sender */ } H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 35 Sliding Window Protocols (1) Previous protocols was simplex (one-directional) For full-duplex: 1. Using two separate lines (forward and backward) 2. Better way: Same line but in both directions In bi-directional line using kind filed in frames header to show transmission direction Now have two kinds of frames (containing a "kind" field): Data ACK containing (sequence number of last correctly received frame). Piggybacking: add acknowledgment to data frames going in reverse direction. Piggybacking issue: For better use of bandwidth, how long should we wait for outgoing data frame before sending the ACK on its own. (DLL should wait network layer) H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 36 Sliding Window Protocols (2) Sliding Window Protocols A sending window and receiving window Sending window Sending window: maintain a set of seq. no.s corresponding to frames it is permitted to send Receiving window Receiving window: Set of frames it is permitted to accept Sequence numbers are form 0 to MaxSeq, 2 n - 1. Stop-and-wait is a sliding window protocol with n=1 All frames delivered in correct order. These methods provide much more realism! H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 37 Sliding Window Protocols (3) Example: A sliding window of size 1, with a 3-bit sequence number. (a) Initially. (b) After the first frame has been sent. (c) After the first frame has been received. (d) After the first acknowledgement has been received. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 38 Sliding Window Protocols (4) Sending window contains: 1. Frames which their ACK dont received yet 2. Frames should send Sender should have a buffer with size n contained all frames send and dont receive their ACK. Receiving windows has the fix size=No. of frame it can accept, size=1: Always get frames in order Frames should delivered to network layer in order H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 39 Sliding Window Protocols (5) A One-Bit Sliding Window Protocol (1) /* Protocol 4 (sliding window) is bi-directional and is more robust than protocol 3 */ #define MAX-SEQ 1 /* must be 1 for protocol 4 */ typedef enum {frame-arrival, cksum-err, timeout} event-type; #include "protocol.h" void protocol4 (void) { seq-nr next-frame-to-send; /* 0 or 1 only */ seq-nr frame-expected; /* 0 or 1 only */ frame r, s; /* scratch variables */ packet buffer; /* current packet being sent */ event-type event; next-frame-to-send = 0; /* next frame on the outbound stream */ frame-expected = 0; /* number of frame arriving frame expect */ from-network-layer(&buffer); /* fetch a packet from the network layer */ s.info = buffer; /* prepare to send the initial frame */ s.seq = next-frame-to-send; /* insert sequence number into frame */ s.ack = 1 -frame-expected; /* piggybacked ack */ to-physical-layer(&s); /* transmit the frame */ start-timer(s.seq); /* start the timer running */ H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 40 Sliding Window Protocols (6) A One-Bit Sliding Window Protocol (2) while (true) { wait-for-event(&event); /* frame-arrival, cksum-err, or timeout */ if (event == frame-arrival) { /* a frame has arrived undamaged. */ from-physical-layer(&r); /* go get it */ if (r.seq == frame-expected) { /* Handle inbound frame stream. */ to-network-layer(&r.info); /* pass packet to network layer */ inc(frame-expected); /* invert sequence number expected next */ } if (r.ack == next-frame-to-send) { /* handle outbound frame stream. */ from-network-layer(&buffer); /* fetch new pkt from network layer */ inc(next-frame-to-send); /* invert sender's sequence numbe } } // if s.info = buffer; /* construct outbound frame */ s.seq = next-frame-to-send; /* insert sequence number into it */ s.ack = 1 -frame-expected; /* seq number of last received frame */ to-physical-layer(&s); /* transmit a frame */ start-timer(s.seq); /* start the timer running */ } // while } H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 41 Sliding Window Protocols (7) - Stop-and-wait Example: Normal case Host AHost B (seq, ack, packet number) *=Accepted: To network layer H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 42 Sliding Window Protocols (8) - Stop-and-wait Example: Abnormal case: Host A and B initiate communication simultaneously and Timer of Host B is short Host AHost B (seq, ack, packet number) *=Accepted: To network layer Always, frames receive in order H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 43 Sliding Window Protocols (9) - Stop-and-wait Problem with stop and wait protocols, Example: 50 Kbps bandwidth (satellite channel), 1000 bit frames, 500 msec round-trip propagation delay Sender Receiver first packet bit transmitted, t = first packet bit arrives: 500/2=250 ACK arrives: =520 last packet bit transmitted, t = /2= bits/50,000 bps=20 msec Line utilization = 20/520=3.85% !! sender is blocked 96.15% of time ! H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 44 Sliding Window Protocols (10) - Stop-and-wait first packet bit transmitted, t = 0 R last packet bit transmitted, t = L / B first packet bit arrives last packet bit arrives, send ACK ACK arrives, send next packet, t = R + L / B Sender Receiver U sender = L / B R + L / B = L RB + L Reason: sender can only have one unACKed frame outstanding. This cause the problem only when R is more larger than L/B Reason: sender can only have one unACKed frame outstanding. This cause the problem only when R is more larger than L/B H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 45 Sliding Window Protocols (11) Solution for poor channel utilization: Use larger frames, but the maximum size is limited by the bit error rate of the channel. The larger the frame, the higher the probability that it will become damaged during transmission. w Pipelining Allowing the sender to send more than 1 frame, w frames send before blocking ( Pipelining ) Pipelining: In Pipelining: Sender does not wait for each frame to be ACK'ed. Rather it sends many frames with the assumption that they will arrive. Must still get back ACKs for each frame. Provides more efficient use of transmit bandwidth, but error handling is more complex. w Value of w? times equal to round-trip time, For previous example, W=26 (Because 520/20=26) H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 46 Sliding Window Protocols (12) Pipelining: In Pipelining: w Sender after sending the wth frame, will get the ACK of first frame. If error occurred: What if 26 frames transmitted, and the second has an error. Frames 3-26 will be ignored at receiver side? Sender will have to retransmit. What are the possibilities? Two strategies as solutions (depends on receive Window size) Go-Back-N Selective-Repeat H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 47 Sliding Window Protocols (13)- Go-Back-N Go-Back-N: Equivalent to receiver's window size = 1. If receiver sees bad frames or missing sequence numbers, subsequent frames are discarded. No ACKs for discarded frames. H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 48 Sliding Window Protocols (14)- Selective-Repeat Selective-Repeat: Receiver's window size larger than one. Store all received frames after the bad one. ACK only last one received in sequence. Use NAK (Negative ACK) when an error detected: checksum error or out of sequence H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 49 Protocol Verification How do you specify the operation of a protocol and then assure that it is working correctly. Models: Finite State Machined (FSM) Models Petri Net Models H. Veisi Computer networking, Olum-Fonoon Babol H. Veisi Fall 2005 Page 50 Example Data Link Protocols HDLC (High-Level Data Link Control) PPP (Point to Point Protocol): DLL in the Internet