the data link layer - faculty.tarleton.edu · • character count → counter can be garbled (next...
TRANSCRIPT
QUIZ : oversubscriptionA telco provider sells 5 Mpbs DSL service to 50 customers in aneighborhood. The DSLAM connects to the central office via one T3and two T1 lines.What is the oversubscription factor? (Ignore overhead)
Prove that the T1 carrier has a total data rate of1.544 Mbps
(8·24 + 1) · 2 · 4000 = 1.544 Mbps
Solution
Prove that the OC-1 carrier has a total data rateof 51.84 Mbps
(9·90) · 8 · 2 ·4000 = 51.84 Mbps
Solution
The Data Link Layer (L2)fundamental characteristics
A. Whereas L1 is concerned with Tx/Rx of individualbits, L2 works with multi-bit frames.
B. Transmission is over one “wirelike” channel, i.e. achannel which delivers the bits in the same orderin which they are sent.As a consequence, L2 does not have to provide anyreordering function.
Functions of the Data Link Layer
• Provide service interface to L3 (Network)• Deal w/transmission errors on L1 (Physical)
• L2 “hides” the errors that occur in the real transmission, soL3 and higher don’t have to worry about them
• Regulate the flow of data• Slow receivers should not be swamped by fast
senders
L2 Design Issues
• Services Provided to L3 (Network)• Framing• Error Control• Flow Control• Bit reordering
Services Provided by L2 to L3(a) Unacknowledged connectionless:
– Used when error rate is low (e.g. LAN → Ethernet), or whenthere are stringent timing requirements (e.g. VoIP)
– Recovery is left to higher layers Might be bad b/c one L3 pkt. can be mapped to multiple L2 frames.
L3 does not know about it, so it is wasting bandwidth byrequiring entire pkt. to be retransmitted.
Example:
Problem 1/251A L3 pkt. is split into 10 frames, each of which has an 80% chance
of arriving undamaged. L2 does not do any error control. Howmany times on average will L3 send the pkt. before it makes it?
1. Calculate the probability p that one send is successful:
Problem 1/251A L3 pkt. is split into 10 frames, each of which has an 80% chance
of arriving undamaged. L2 does not do any error control. Howmany times on average will L3 send the pkt. before it makes it?
1. Calculate the probability p that one send is successful:
p = 0.8 ∙ 0.8 ∙ … ∙ 0.8 = 0.810 = 0.107
Problem 1/251A L3 pkt. is split into 10 frames, each of which has an 80% chance
of arriving undamaged. L2 does not do any error control. Howmany times on average will L3 send the pkt. before it makes it?
2. What are the possible numbers of sends?P(1 send ) = ?P(2 sends) = ?…P(n sends) = ?…
Problem 1/251A L3 pkt. is split into 10 frames, each of which has an 80% chance
of arriving undamaged. L2 does not do any error control. Howmany times on average will L3 send the pkt. before it makes it?
Conclusion: GEOMETRIC distribution!P(X = k) = (1-p)k-1p
Plot source: https://en.wikipedia.org/wiki/Geometric_distribution
Problem 1/251A L3 pkt. is split into 10 frames, each of which has an 80% chance
of arriving undamaged. L2 does not do any error control. Howmany times on average will L3 send the pkt. before it makes it?
GEOMETRIC distribution: P(X = k) = (1-p)k-1pWhat is the expected value (a.k.a. mean, average) of a
geometric distribution?
Problem 1/251A L3 pkt. is split into 10 frames, each of which has an 80% chance
of arriving undamaged. L2 does not do any error control. Howmany times on average will L3 send the pkt. before it makes it?
GEOMETRIC distribution: P(X = k) = (1-p)k-1pExpected value (a.k.a. mean, average): weight (multiply)
each value of X by the corresponding probability:E[X] = 1∙P(X=1) + 2∙P(X=2) + … k∙P(X=k) + …
Problem 1/251A L3 pkt. is split into 10 frames, each of which has an 80% chance
of arriving undamaged. L2 does not do any error control. Howmany times on average will L3 send the pkt. before it makes it?
GEOMETRIC distribution: P(X = k) = (1-p)k-1pE[X] = 1/p
Problem 1/251A L3 pkt. is split into 10 frames, each of which has an 80% chance
of arriving undamaged. L2 does not do any error control. Howmany times on average will L3 send the pkt. before it makes it?
GEOMETRIC distribution: P(X = k) = (1-p)k-1pE[X] = 1/p
E[X] = 1/0.107 = 9.32 times (What does it mean?)
■
The Network layer of Host 1 receives a 512-Byte packet every 20 ms, to be sent to Host 2.The Data Link layer fragments each packet into k frames for transmission, and sends out the
frames using unacknowledged, connectionless service over a T1 link. This way, errorcorrection is left entirely to Network, who needs toretransmit entire pkts.
The probability for one frame to make it toHost 2 w/o errors is p=0.85 (85%).What is the maximum fragmentation thatcan be used?(Ignore all overhead, e.g. headers, trailers)
QUIZ for individual work: Designing L2fragmentation
Hint: What is the probability that an entirepacket be transmitted without errors?
Services Provided by L2 to L3(b)Acknowledged connectionless:
– Each frame individually ACK-ed, timers, retransmissions– Used when error rate is high (e.g. wireless→802.11 WiFi)
What if the ACK frame itself gets lost?The ghost frame problem.
Services Provided by L2 to L3
(c)Acknowledged and connection-oriented:– Used in long, error-prone links (e.g. satellite)– Connection established, frames are numbered– Eliminates the “ghost packet problem”– Makes an unreliable (error-prone) L1 “look” reliable to L3.
We say that L3 “sees” a reliable bit-stream at L1.
(d) Unacknowledged connection-oriented??
QUIZWhich Data Link type of service should we choose in the 4 cases below?
Longpropagation
delay
Shortpropagation
delay
Low error probability High error probability
QUIZWhich Data Link type of service should we choose in the 4 cases below?
Unacknowledgedconnectionless
Acknowledgedconnectionless
Unacknowledgedconnectionless
Acknowledgedconnection-oriented
Longpropagation
delay
Shortpropagation
delay
Low error probability High error probability
L2 framing
Relationship between packets, frames and bits.Unlike packets, frames usually have a strict max. length (for hardware
optimization).
Stream of bits in L1 (PHYSICAL)
Why framing?To control errors and flow
Unfortunately, framing introduces its own problem:How does the receiver recognize the beginning and end of a
frame?
Framing5 methods for recognizing frames:• Fixed timing (frame-gap-frame-gap …) → hard to sync.• Character count → counter can be garbled (next slide)• Flag bytes w/Byte stuffing• Flag bytes w/bit stuffing• L1 (PHY layer) coding violations → e.g. 1=hi-lo, 0=lo-
hi, use hi-hi or lo-lo as flags• Needs redundancy on L1• Goes against idea of modularity!
Framing with Flag Bytes (e.g. PPP)
(a) A frame delimited by flag bytes.(b) Four examples of byte sequences before and after stuffing.
What to do ifthe flag itselfis inside thedata stream?
“Byte stuffing”
Framing with Flag BytesProblem: Requires 8-bit characters, otherwise the FLAG
boundaries cannot be detected!
What do we do if we want Unicode (16 bit)?
Solution: Have the FLAG byte contain a pattern of bits notencountered anywhere else in the data!
0111 1110
So what if the pattern does occur in the data?
Framing with Bit Stuffing (e.g. HDLC)
Bit stuffing(a) The original data.(b) The data as they are transmitted on the line.(c) The data as they are stored in receiver’s memory after de-stuffing.
Flag is 0111 1110
QUIZProblem 2/252The following character encoding is used in a L2 protocol:A: 0100 0111 B: 1110 0011FLAG:0111 1110 ESC: 1110 0000The payload (actual data) in the frame is: A B ESC FLAG
Show the frame for each of these framing methods:• Byte count• Flag bytes w/byte stuffing• Flag bytes w/bit stuffing
Framing - conclusion
Most existing L2 protocols use a combination of methodsfor reliability, e.g. byte stuffing and count field.
EOL1
QUIZIn a certain dry area in the world, the probability for a
rainy day is 0.01. How many days do we have to waiton the average for the next rainy day?
Hint: Use a Geometric distribution!
Flow Control
Feedback-based: receiver sendsback explicit messages:
• “Send me more”• “Stop sending”
Rate-based:• Mostly used in higher layers
(e.g. L4→TCP)• Modern Ethernet cards can
switch among 10/100/1000Mbps
Does not neednegotiation
Needsnegotiation
Error Control
Simple model for errors: bits are affected independently.Closer to real-life: Errors come in bursts• Good: at the same average error rate, less frames are
affected• Bad:
• Adjacent errors are harder to detect/correct thanisolated ones.
• An entire frame may disappear!
Mathematical treatment of errors → probability theory
Error ControlMathematical treatment of errors → probability theory
Three basic rules:• The probabilities of complementary events add up to 1• The probabilities of mutually exclusive events add up• The probabilities of independent events multiply
Example on p.203:1000 bits in a frame, BER = 10-3 , errors independentWhat is the probability that a frame has errors?
Error ControlThree basic rules:• The probabilities of complementary events add up to 1• The probabilities of mutually exclusive events add up• The probabilities of independent events multiply
1000 bits in a frame, BER = 10-3 , errors independent• P[no errors in a given frame] = ?• P[at least 1 error in a given frame] = ?• Out of many frames (say 10, 000), how many contain errors
on average?
Error ControlThree basic rules:• The probabilities of complementary events add up to 1• The probabilities of mutually exclusive events add up• The probabilities of independent events multiply
1000 bits in a frame, BER = 10-3 , errors independent
Instructive mistake: # of bits x BERResult: ??How can we tell this method is wrong?
QUIZThere are 1000 bits in a frameErrors are independent, with BER = 10-3
Calculate the following:• P[exactly one errror in a given frame] = ?• P[exactly two errrors in a given frame] = ?• Out of many frames (say 10, 000), what fraction
contain:• Exactly one error?• Exactly two errors?
Principles of Error Detection and Correction
Any mechanism for detecting or correcting errors needsredundancy, a.k.a. overhead
m data bits + r redundant bits = n-bit codeword
m + r = n
m + r = n → m < n 2m < 2n
• Hamming distance between two codewords = # ofdifferent bits
• Cubes and hyper-cubes
codeword
Let’s apply probability to codewords!Assume:• Independent errors• BER = 10-3
• The codeword 000 was transmittedCalculate:• P[001 is received]• P[010 is received]• P[100 is received]• P[011 is received]• P[111 is received]
Conclusion (in terms of Hamming distance):
Hamming distance of a code = minimum of theHamming distance between all pairs of legalcodewords.
What is the Hamming distance of the code below?
What is the maximum # of errors that can be detectedwith the code below?
Corrected?
Conclusion: To detect d errors, we need a code withHamming distance at least d+1.
Example:• Select the codewords that have even-parity-bit.• How many data bits does a codeword have?• What is the Hamming distance of this code?• How many errors can be detected?
Conclusion: To detect d errors, we need a code withHamming distance at least d+1.
QUIZ:• Select the codewords that have odd-parity-bit.• How many data bits does a codeword have?• What is the Hamming distance of this code?• How many errors can be detected?
Conclusion: To detect d errors, we need a code withHamming distance at least d+1.
QUIZ:• Select the codewords that are palindromes.• How many data bits does a codeword have?• What is the Hamming distance of this code?• How many errors can be detected?
Error-Correcting Codesa.k.a. forward error correction
To detect d errors, a code with Hamming distanced+1 (or higher) is needed.
New result:To correct c errors, a code with Hamming distance
2·c + 1 (or higher) is needed.
Each of 2m legal messages needs n+1 codewords assigned
Why n+1? B/c each “good” code needs n“insulating” neighbors at Hammingdistance 1 (Basin of attraction).In the image you have an example forn = 7.
3.2.2 Error-Correcting Codes
Mathematical treatment of prev. slide:To correct single errors, each of 2m legal messages needs n+1
codewords assigned
(n+1) 2m ≤ 2n (m+r+1) ≤ 2n-m (m+r+1) ≤ 2r
Take log on both sides log2(m+r+1) ≤ r log2(m) ≤ r
We say that r has a lower bound which is logarithmic in mIn asymptotic notation: r is WWW(log2m)
r is W(log2m)The Hamming code is a method of attaining this bound:• Number the n bits in the codeword starting at 1.• The power-of-two bits (1, 2, 4, 8 …) are check bits, the rest are
data.• A data bit in position k contributes to the check bits corresponding
to the 1s in the binary expansion of k• Usually the check bits implement even parity
At the receiver:• Check the parity of all check bits.• If all parities are OK (even), conclude that no errors have ocurred.• If the parities of some check bits are not OK, add up the values k of
the incorrect check bits. This is the position of the bit in error.Correct that bit, i.e. flip it!
Hamming code redundant bitsInitial message (11 information bits):
Make room for redundant bits in positions that are powers of 2:0 1 0 1 0 0 1 0 1 0 1
0 1 0 1 0 0 1 0 1 0 11 2 3 4 5 6 7 8 9 10 11 12 13 14 15
r1 r2 r4 r8
How to calculate the values of the redundant bitsMessage with check bits 1 2 3 4 567 8 9 …….15 inserted in power-of-two positions: r1 r2 0 r4 101 r8 0010101
Set of bits associated with r1: r1 r2 0 r4 101 r8 0010101To make the set even, r1 is made 1: 1 r2 0 r4 101 r8 0010101Set of bits associated with r2: 1 r2 0 r4 101 r8 0010101To make the set even, r2 is made 1: 1 1 0 r4 101 r8 0010101Set of bits associated with r4: 1 1 0 r4 101 r8 0010101To make the set even, r4 is made 0: 1 1 0 0 101 r8 0010101Set of bits associated with r8: 1 1 0 0 101 r8 0010101To make the set even, r8 is made 1: 1 1 0 0 101 1 0010101
QUIZ Hamming code
The 12 data bits to be coded are: 1110 1010 0100Calculate the codewordHint: Start by inserting theredundant bits
Hamming code error correctionMessage with check bits 1 2 3 4 56 7 8 9 ……. 15 inserted in power-of-two positions: r1 r2 0 r4 101 r8 0010101Codeword transmitted: 1 1 0 0 101 1 0010101
Assume that bit 13 is corrupted in transmission, so the receiver gets:1 1 0 0 101 0 0010001
Perform the parity calculations for all check bits
Which check bits have wrong parity? r8, r4 and r1 → 8+4+0+1 = 13.
What happens if the corrupted bit is one of the check bits?
Hamming code lingo:What is the syndrome?
Perform the parity calculations for all check bits
Which check bits have wrong parity? r8, r4 and r1 → 8+4+1 = 13.
Parity bit r8 r4 r2 r1
Has error? yes yes no yesSyndrome 1 1 0 1
If we convert the syndrome to base 10 we have → 8+4+0+1 = 13.
Hamming code error correctionMessage with check bits 1 2 3 4 56 7 8 9 ……. 15 inserted in power-of-two positions: r1 r2 0 r4 101 r8 0010101Codeword transmitted: 1 1 0 0 101 1 0010101
Assume that bit 13 is corrupted in transmission, so the receiver gets:1 1 0 0 101 0 0010001
Perform the parity calculations for all check bits
Which check bits have wrong parity? r8, r4 and r1 → 8+4+0+1 = 13.
What happens if the corrupted bit is one of the check bits?
Important:Many Hamming Code Calculators are available onthe Web.Their use in this class is not allowed (except forchecking results).All work has to be shown, step by step, in themanner presented in our text and the previousslides.Answers without work receive no credit.