Department of Computer and IT Engineering University of Kurdistan Data Communication Netwotks (Graduate level) Data Link Layer By: Dr. Alireza Abdollahpouri
Data Link Layer 2
Data Link Layer Application Presentation Session Transport Network Data Link Physical Function: Send blocks of data (frames) between physical devices Regulate access to the physical media Key challenge: How to delineate frames? How to detect errors? How to perform media access control (MAC)? How to recover from and avoid collisions? 3
Adaptors Communicating datagram sending node frame adapter link layer protocol frame adapter receiving node link layer implemented in adaptor (NIC) Ethernet card, PCMCI card, 802.11 card 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 adapter is semiautonomous link & physical layers 4
Hop-to-hop delivery 5
Link-Layer Services Service provided by the data link layer for network layer: Unacknowledged connectionless service Acknowledged connectionless service Acknowledged connection-oriented service 6
Link-Layer Duties Framing Encapsulating packet into frame, adding header, trailer Using MAC addresses, rather than IP addresses Error detection and/or correction Errors caused by signal attenuation, noise. Receiver detecting presence of errors Receiver correcting errors without retransmission Flow control Pacing between adjacent sending and receiving nodes Media access control (MAC) Pacing between adjacent sending and receiving nodes 7
Framing 8
Framing Break sequence of bits into a frame Typically implemented by the network adaptor 10110101000011001.1000100110101010101 How to define the borders? 9
Byte Counting (character count) 132 132 Data Sender: insert length of the data in bytes at the beginning of each frame Receiver: extract the length and read that many bytes what if the count field gets corrupted? 10
Byte Oriented: Byte stuffing START DLE DLE Data DLE END END Add START and END sentinels to the data Problem: what if END appear in the data? Add a special DLE (Data Link Escape) character before END What if DLE appears in the data? Add DLE before it. Used by Point-to-Point protocol, e.g. modem, DSL, cellular 11
Bit Oriented: Bit Stuffing 01111110 Data 01111110 Add sentinels to the start and end of data Both sentinels are the same Example: 01111110 in High-level Data Link Protocol (HDLC) Sender: insert a 0 after each 11111 in data Known as bit stuffing Receiver: after seeing 11111 in the data 111110 remove the 0 (it was stuffed) 111111 look at one more bit 1111110 end of frame 1111111 error! Discard the frame Disadvantage: 20% overhead at worst 12
Bit Stuffing- example 13
Physical Layer Coding Violations Only applicable if physical layer coding has some redundancy The combinations of low-low and high-high which are not used for data may be used for marking frame boundaries. e.g., in Manchester coding 14
Error Control 15
Transmission Errors Transmission errors are caused by: Thermal noise {Shannon} impulse noise (e..g, arcing relays) signal distortion during transmission (attenuation) crosstalk voice amplitude signal compression (companding) quantization noise (PCM) jitter (variations in signal timings) receiver and transmitter out of synch. 16
Packet corruption Types of errors: single bit; only 1 bit in the data unit has changed less likely burst error; 2 or more bits in the data unit have changed Example: 0.01 s of burst impulse noise 1200 bps data rate 12 bits of errors 17
Error Detection Error detection Transmit extra (redundant) information Use redundant information to detect errors Extreme case: send two copies of the data Trade-off: accuracy vs. overhead Techniques for detecting errors Parity checking Checksum Cyclic Redundancy Check (CRC) 18
Error detection Redundancy: adding extra bits for detecting errors at the destination 19
Error detection techniques 20
Parity bits Idea: add extra bits to keep the number of 1s even Example: 7-bit ASCII characters + 1 parity bit 0101001 1 1101001 0 1011110 1 0001110 1 0110100 1 Detects 1-bit errors and some 2-bit errors Not reliable against bursty errors 21
Two Dimensional Parity Parity bit for each column 0101001 1101001 1011110 0001110 0110100 1011111 1 0 1 1 1 0 1111011 0 Parity bit for each row Parity bit for the parity byte Can detect all 1-, 2-, and 3-bit errors, some 4-bit errors 14% overhead 22
Two Dimensional Parity Examples 0101001 1101001 1011110 0001110 1 1 0110100 1011111 1 0 1 1 1 0 1111011 0 0101001 1101001 1011110 0001110 1 0110100 1011111 1 0 1 1 1 0 1111011 0 Odd number of 1s Odd Number of 1s Odd number of 1s Odd Number of 1s 23
Two Dimensional Parity Examples 0101001 1101001 1 0 1011110 0001110 1 1 0110100 1011111 1 0 1 1 1 0 1111011 0 0101001 1101001 1 1011110 0001110 1 1 0110100 1011111 1 0 1 1 1 0 1111011 0 Odd number of 1s Cannot be detected Odd number of 1s 24
Error detection techniques 25
Checksums Idea: Add up the bytes in the data Include the sum in the frame START Data Checksum END Use ones-complement arithmetic Lower overhead than parity: 16 bits per frame But, not resilient to errors Why? 0101001 + 1101001= 10010010 1 0 Used in UDP, TCP, and IP 26
Checksum Example: IP header 1. The data unit is divided into k sections, each of n bits 2. All sections are added using 1 s complement 3. The sum is complemented 4. The checksum is sent with data 27
1 s complement Suppose the following block of 16 bits is to be sent using a checksum of 8 bits. 10101001 00111001 The numbers are added using one s complement 10101001 00111001 ------------ Sum 11100010 Checksum 00011101 The pattern sent is 10101001 00111001 00011101 28
Checksum (cnt d) Performance Can we use this technique to detect an error if 2 corresponding opposite bits in 2 data segments become corrupted? An example: Transmitted sequence: 10101001 00111001 00011101 Received sequence: 00101001 10111001 00011101 29
Error detection techniques 30
Cyclic Redundancy Check (CRC) Uses field theory to compute a semi-unique value for a given message Much better performance than previous approaches Fixed size overhead per frame (usually 32-bits) Quick to implement in hardware Only 1 in 2 32 chance of missing an error with 32-bit CRC Details are in the book/on Wikipedia 31
Cyclic Redundancy Check (CRC) Represent a (n+1)-bit message as an n-degree polynomial M(x) E.g., 10101101 M(x) = x 7 + x 5 + x 3 + x 2 + x 0 Choose a divisor k-degree polynomial G(x) Compute reminder R(x) of M(x)*x k / G(x), i.e., compute A(x) such that M(x)*x k = A(x)*G(x) + R(x), where degree(r(x)) < k Let T(x) = M(x)*x k R(x) = A(x)*G(x) Then T(x) is divisible by G(x) 32
CRC check Based on binary division CRC added to the data unit so that the resulting data becomes exactly divisible by a predetermined number CRC exactly 1 less bit than the divisor 1. A string of n zeros added to the data unit 2. New data divided by divisor 3. Replace 0 s by CRC 33
CRC generator Modulo-2 division 34
CRC generator (cnt d) Name Polynomial Application CRC-8 x 8 + x 2 + x + 1 ATM header CRC-10 x 10 + x 9 + x 5 + x 4 + x 2 + 1 ATM AAL ITU-16 x 16 + x 12 + x 5 + 1 HDLC ITU-32 x 32 + x 26 + x 23 + x 22 + x 16 + x 12 + x 11 + x 10 + x 8 + x 7 + x 5 + x 4 + x 2 + x + 1 LANs 35
CRC performance CRC can detect 1. all burst errors that affect odd number of bits 2. all burst errors of length degree of polynomial 3. with high probability burst errors > degree of polynomial Example: CRC-12 (degree of 12) 1. OK 2. OK 3. 99.97 % 36
Error correction 1. By retransmission flow and error control protocols 2. Forward Error Correction (FEC) require more redundancy bits should locate the invalid bit or bits n-bit code word contains m data bits + r redundancy bits n=m+r m r m+r+1 bits discoverable by r bits r Code-word Example: 2 m + r +1 For m=5 data bits can r be 3? 37
Hamming distance The Hamming distance is the number of bits that have to be changed to get from one bit pattern to another. Example: 10010101 & 10010011 have a hamming distance of 2 For any coding whose members have a Hamming distance of two, any one bit error can be detected. Why? 38
Hamming distance (a) A code with poor distance properties (b) A code with good distance properties o o o o x x x x x o o o x x o o o o o x o o o x o x o o x o o x o x o o o x x = codewordso = non-codewords 39
Error detection/correction To detect d single bit errors, you need a d+1 code distance. To correct d single bit errors, you need a 2d+1 code distance. In general, the price for redundant bits is too expensive to do error correction for network messages. Network protocols use error detection and ARQ. 40
Hamming code Example: 7-bit ASCII code + 4 bit redundancy Each r bit is the parity bit for one combination of data bits r1: bits: 1, 3, 5, 7, 9, 11 r2: bits: 2, 3, 6, 7, 10, 11 r3: bits 4, 5, 6, 7 r4: bits 8, 9, 10, 11 2 0 1 1 1 1 1 1 2 1 2 2 2 2 2 2 2 2 4 4 4 4 2 3 8 8 8 8 Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ 1 2 3 4 5 6 7 8 9 10 11 41
Hamming code (cnt d) Example of redundancy bit calculation (even parity) 42
Hamming code (cnt d) Error detection using Hamming code once the bit is identified the receiver can reverse its value 43
Flow Control 44
Flow Control The process of managing the rate of data transmission between two nodes to prevent a fast sender from overwhelming a slow receiver Transmission Link Buffer 45
Categories of Flow Control 46
Stop-and-Wait Automatic Repeat request Simplest flow and error control mechanism The sending device keeps a copy of the last frame transmitted until it receives an acknowledgement identification of duplicate transmission (lost or delayed ACK) A damaged or lost frame is treated in the same way Timers introduced Positive ACK sent only for frames received safe & sound 47
A Simplex Stop-and-Wait ARQ 1. Normal operation 2. The frame is lost 3. The ACK is lost 4. The ACK is delayed 48
Stop-and-Wait ARQ(Normal operation) The sender will not send the next piece of data until it is sure that the current one is correctly received sequence number necessary to check for duplicated packets No NACK when packet is corrupted duplicate ACKs instead 49
Stop-and-Wait ARQ(Lost or damaged frame) roundtrip time + processing in the receiver Should be as short as possible. Why? 50
Stop-and-Wait ARQ (Lost ACK) Importance of frame numbering Numbering frames prevents the retaining of duplicate frames 51
Stop-and-Wait ARQ (Delayed ACK) Importance of ACK numbering Numbered acknowledgments are needed if an acknowledgment is delayed and the next frame is lost. 52
Duplex Stop-and-Wait ARQ Piggybacking combine data with ACK (less overhead saves bandwidth) 53
Performance of Stop-and-wait ARQ RTT d trans = (Frame size)/bandwidth d ptop = (Speed of signal)/ (Channel length) Utilization = d trans /( d trans + 2 d prop ), error free case or Utilization = (1-P E )d trans /( d trans + 2 d prop, ) error case 54
Stop-and-wait operation Example: 1 Gbps link, 15 ms prop. delay, 8000 bit frame: first bit transmitted, t = 0 last bit transmitted, t = L / R sender receiver RTT first bit arrives last bit arrives, send ACK ACK arrives, send next frame, t = RTT + L / R very low d trans = R L = 8000bits 10 bps 9 = 8microseconds U sender = L / R RTT + L / R =.008 30.008 = 0.00027 55
Sliding window (Pipelined) protocols Pipelining: sender allows multiple, in-flight, yet-to-beacknowledged frames range of sequence numbers must be increased buffering at sender and/or receiver Two generic forms of pipelined protocols: Go-Back-N, Selective repeat 56
Sliding Window Protocols Sequence numbers sent frames are numbered sequentially number of frames stored in the header if the number of bits in the header is m than sequence number goes from 0 to 2 m -1 Sliding window to hold the unacknowledged outstanding frames frame sequence number acknowledged frames 57
Question What is the consequence of the window size in the receiver on the order of the received packets? Answer: Window size 1 means that the packets are received in order This is not the case for the larger window size 58
Sliding Window: Retransmission Strategies How to deal with errors? If the ACK is not received then the sender must go back and retransmit earlier frames (from the lost frame) (Go-Back-N) Sender only retransmits frames for which a NAK is received (the lost or corrupted frames) (Selective repeat) 59
Go-back-N (Control variables) S- holds the sequence number of the recently sent frame SF holds sequence number of the first frame in the window SL holds the sequence number of the last frame R sequence number of the frame expected to be received 60
The name of Go-back-N: why? Re-sending frame when the frame is damaged the sender goes back and sends a set of frames starting from the last one ACKn d the number of retransmitted frames is N Example: The window size is 4. A sender has sent frame 6 and the timer expires for frame 3 (frame 3 not ACKn d). The sender goes back and re-sends the frames 3, 4, 5 and 6. 61
Go-back-N (normal operation) How many frames can be transmitted without acknowledgment? ACK1 not necessary if ACK2 is sent expected sequence number 62
Go-back-N (damaged or lost frame) damaged frames are discarded! Why are correctly received packets not buffered? What is the disadvantage of this? 63
Go-back-N (sender window size) sequence number 64
Go-back-N (drawback) Inefficient all out of order received packets are discarded This is a problem in a noisy link many frames must be retransmitted -> bandwidth consuming Solution re-send only the damaged frames Selective Repeat ARQ avoid unnecessary retransmissions 65
Selective Repeat ARQ Processing at the receiver more complex The window size is reduced to 2 m-1 (at most) Both the transmitter and the receiver have the same window size Receiver expects frames within the range of the sequence numbers 66
Selective Repeat ARQ (lost frame) 67
Selective Repeat 68
Selective Repeat ARQ (sender window size) 69
Sliding window- analysis Frame transmission time is normalized to a value of 1; thus, the propagation time is a. 70
Sliding window- analysis The throughput on the line depends on both the window size W and the value of a 71
Sliding window- utilization Error free channel a =d prop /d trans Selective repeat with error Go-back-N with error Assume a frame is in error with probability P 72
Sequence number and window size Transmitter window size Receiver window size How many sequence numbers required? Stop-and-wait ARQ 1 1 2 Go-back-N W 1 1+W Selective repeat W W 2W In SR protocol with the window size of 5, how many bits required to numbering the sequence of frames? 2*5=10 sequence numbers, we need 4 bits 73
Stop-and-wait utilization (example) A channel has a bit rate of 4 kbps and a propagation delay of 20 ms. For what range of frame sizes does Stopand-Wait give an efficiency (link utilization) > 50%? Efficiency will be 50% when the time to transmit the frame equals the roundtrip propagation delay. At a transmission rate of 4 bits/ms, 160 bits takes 40 ms. For frame sizes above 160 bits, stop and wait is reasonably efficient. 74
Sliding window utilization (example) A 3000 km long T1 trunk is used to transmit 64 byte frame s using selective-repeat protocol. If the propagation speed is 6 µsec/km, how many bits should the sequence numbers be? To operate efficiently, the sequence space (actually, the send window size) must be large enough to allow the transmitter to keep transmitting until the first acknowledgement has been received. The propagation time is 18 ms. At T1 speed, which is 1.536 Mbps (excluding the 1 header bit), a 64 byte frame takes 0.300 msec. Therefore, the first frame fully arrives 18.3 msec after its transmission was started. The acknowledgement takes another 18 msec to get back, plus a small (negligible) time for the acknowledgement to arrive fully. In all, this time is 36.3 msec. The transmitter must have enough window space to keep going for 36.3 msec. A frame takes 0.3 ms, so it takes 121 frames to fill the pipe. Seven bit sequence numbers are needed 75
Questions 76