Download presentation
Presentation is loading. Please wait.
1
Dr. Mozafar Bag-Mohammadi Ilam University
Link Layer Dr. Mozafar Bag-Mohammadi Ilam University
2
Contents Overview Encoding Framing Error detection
Acknowledgements & Timeouts
3
1. Overview: Link Layer
4
Link layer application transport network network link link physical
Communication service between two physically connected devices: host-router, router-router, host-host unit of data: frame implemented in “adapter” e.g., PCMCIA card, Ethernet card typically includes: RAM, DSP chips, host bus interface, and link interface application transport network link physical network link physical M H t n l data link protocol H l H t n M frame phys. link adapter card
5
Link Layer Services Framing, link access:
encapsulate datagram into frame, adding header, trailer implement channel access if shared medium, ‘physical addresses’ used in frame headers to identify source, dest different from IP address! Reliable delivery between two physically connected devices: seldom used on low bit error link (fiber, some twisted pair) wireless links: high error rates
6
Link Layer Services (more)
Flow Control: pacing between sender and receivers 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
7
2.Encoding Encode binary data onto signals
Bits flow is between network adaptors. How to send clock information? Extract from signals or data. The simplest way is 0 as low signal and 1 as high signal. This is known as Non-Return to zero (NRZ) Bits NRZ 1
8
Problem with NRZ Consecutive 0’s or 1’s may create problems.
Synchronization problem because of difference in the sender or receiver clocks. The average of signals which is used to distinguish between low or high may move and make the decoding difficult. This is called baseline wander Unable to recover clock
9
Alternative Encodings
Non-return to Zero Inverted (NRZI) make a transition from current signal to encode a 1; stay at current signal to encode a zero solves the problem of consecutive 1s Manchester encoding transmit XOR of the NRZ encoded data and the clock. 0 is being encoded as a low to high transition and 1 as high to low. It doubles the rate, then, it is only 50% efficient. The rate signal changing is called baud rate.
10
Encodings (cont) Bits NRZ Clock Manchester NRZI 1
11
4B/5B Encoding 4B/5B: The idea is insert extra bits to break the consecutive bit patterns. every 4 bits of data encoded in a 5-bit code
12
4B/5B Encoding (cont) 5-bit codes selected to have no more than one leading 0 and no more than two trailing 0s thus, never get more than three consecutive 0s resulting 5-bit codes are transmitted using NRZI achieves 80% efficiency. Unused code are used for control. I.e is for line is idle or for the line is dead. FDDI is using this scheme.
13
3.Framing How to distinguish between data and garbage.
Break sequence of bits into a frame Typically implemented by network adaptor
14
Byte-oriented Approaches
Sentinel-based delineate frame with special pattern: or STX, ETX, etc characters. e.g., HDLC, SDLC, PPP Header Body 8 16 CRC ASCII character 1 soh (start of header) ASCII character 4 eot (end of transmission) Header Body 8 16 CRC
15
Byte-oriented Approaches
problem: special pattern or characters appear in the payload solution: bit stuffing sender: insert 0 after five consecutive 1s receiver: delete 0 that follows five consecutive 1s
16
Byte stuffing
17
Byte-oriented Approaches (cont)
Counter-based include payload length in the header e.g., DDCMP protocol from DEC. problem: count field corrupted solution: catch when CRC fails
18
4.Error Detection To send extra information to find error in the frame. The simplest form is sending two copies, inefficient. Sending the sum of values (?) in the frame, checksum. In Internet, consider 16 bits sequences and then use one-complement to find the result. Sending parity, odd or even parity. Odd parity of is
19
Error Detection Two dimensional parity, adding one extra bit, parity bit, to code and also find the parity for each bit position for total data
20
Cyclic Redundancy Code (CRC)
Add k bits of redundant data to an n-bit message Where k << n e.g., k = 32 and n = 12,000 (1500 bytes)
21
CRC(cont) Represent n-bit message as n-1 degree polynomial
e.g., MSG= as M(x) = x7 + x4 + x3 + x1 Let k be the degree of some divisor polynomial e.g., C(x) = x3 + x2 + 1 Transmit polynomial T(x) that is evenly divisible by C(x) shift left k bits, i.e., M(x)xk subtract remainder of M(x)xk / C(x) from M(x)xk
22
CRC (cont) Receiver polynomial T(x) + E(x)
E(x) = 0 implies no errors Divide (T(x) + E(x)) by C(x); remainder zero if: E(x) was zero (no error), or E(x) is exactly divisible by C(x) All operation is done in modulo 2 in which there is no carry. Then, the operation can be done by XOR only.
23
CRC(cont) Example: M(x)= 110101, C(x) = 1001
0 1 1 The final transmitted message is: T(x) = R
24
Example
25
Internet Checksum Algorithm
View message as a sequence of 16-bit integers; sum using 16-bit ones-complement arithmetic; take ones-complement of the result. u_short cksum(u_short *buf, int count) { register u_long sum = 0; while (count--) sum += *buf++; if (sum & 0xFFFF0000) /* carry occurred, so wrap around */ sum &= 0xFFFF; sum++; } return ~(sum & 0xFFFF);
26
5.Acknowledgements & Timeouts
27
Stop-and-Wait Problem: keeping the pipe full Example
Sender Receiver Problem: keeping the pipe full Example 1.5Mbps link x 45ms RTT = 67.5Kb (8KB) 1KB frames imples 1/8th link utilization
28
Sliding Window Allow multiple outstanding (un-ACKed) frames
Upper bound on un-ACKed frames, called window Sender Receiver T ime …
29
SW: Sender … Assign sequence number to each frame (SeqNum)
Maintain three state variables: send window size (SWS) last acknowledgment received (LAR) last frame sent (LFS) Maintain invariant: LFS - LAR <= SWS Advance LAR when ACK arrives Buffer up to SWS frames SWS LAR LFS …
30
SW: Receiver … Maintain three state variables
receive window size (RWS) largest frame acceptable (LFA) last frame received (LFR) Maintain invariant: LFA - LFR <= RWS Frame SeqNum arrives: if LFR =< SeqNum < = LFA accept if SeqNum < LFR or SeqNum > LFA discarded Send cumulative ACKs RWS LFR LFA …
31
Sequence Number Space SeqNum field is finite; sequence numbers wrap around Sequence number space must be larger then number of outstanding frames SWS <= MaxSeqNum-1 is not sufficient suppose 3-bit SeqNum field (0..7) SWS=RWS=7 sender transmit frames 0..6 arrive successfully, but ACKs lost sender retransmits 0..6 receiver expecting 7, 0..5, but receives second incarnation of 0..5 SWS < (MaxSeqNum+1)/2 is correct rule Intuitively, SeqNum “slides” between two halves of sequence number space
32
Concurrent Logical Channels
Multiplex 8 logical channels over a single link Run stop-and-wait on each logical channel Header: 3-bit channel num, 1-bit sequence num 4-bits total same as sliding window protocol Maintain three state bits per channel channel busy current sequence number out next sequence number in Separates reliability from order
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.