Error Detection
Outline
Parity
Checksum
CRC
Spring 2007
CSE 30264
2-Dimensional Parity
Parity
bits
0101001 1
1101001 0
1011110 1
Data
0001110 1
0110100 1
1011111 0
Parity
byte
Spring 2007
1111011 0
CSE 30264
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);
}
Spring 2007
CSE 30264
Cyclic Redundancy Check
Add k bits of redundant data to an n-bit message
want k << n
e.g., k = 32 and n = 12,000 (1500 bytes)
Represent n-bit message as n-1 degree polynomial
e.g., MSG=10011010 as M(x) = x7 + x4 + x3 + x1
Let k be the degree of some divisor polynomial
e.g., C(x) = x3 + x2 + 1
Spring 2007
CSE 30264
CRC (cont)
Transmit polynomial P(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
Receiver polynomial P(x) + E(x)
E(x) = 0 implies no errors
Divide (P(x) + E(x)) by C(x); remainder zero if:
E(x) was zero (no error), or
E(x) is exactly divisible by C(x)
Spring 2007
CSE 30264
Selecting C(x)
All single-bit errors, as long as the xk and x0 terms have
non-zero coefficients.
All double-bit errors, as long as C(x) contains a factor with
at least three terms
Any odd number of errors, as long as C(x) contains the
factor (x + 1)
Any burst error (i.e., sequence of consecutive error bits)
for which the length of the burst is less than k bits.
Most burst errors of larger than k bits can also be detected
See Table 2.5 on page 96 for common C(x)
Spring 2007
CSE 30264
Hardware Implementation
Message
x0
x 1 XOR gate
Spring 2007
x2
CSE 30264
Acknowledgements & Timeouts
Sender
Receiver
Fram
Sender
Receiver
Fram
ACK
ACK
Fram
ACK
(a)
Sender
(c)
Receiver
Fram
Sender
Receiver
Fram
ACK
Fram
Fram
e
ACK
ACK
(b)
Spring 2007
(d)
CSE 30264
Stop-and-Wait
Sender
Receiver
Fram
e0
0
ACK
Fram
e1
1
ACK
Fram
e0
0
ACK
Spring 2007
CSE 30264
Stop-and-Wait
Sender
Receiver
Problem: keeping the pipe full
Example
1.5Mbps link x 45ms RTT = 67.5Kb (8KB)
1KB frames implies 1/8th link utilization
Spring 2007
CSE 30264
10
Sliding Window
Allow multiple outstanding (un-ACKed) frames
Upper bound on un-ACKed frames, called window
Sender
Spring 2007
Receiver
CSE 30264
11
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
< SWS
LAR
Advance LAR when ACK arrives
Buffer up to SWS frames
Spring 2007
CSE 30264
LFS
12
SW: Receiver
Maintain three state variables
receive window size (RWS)
largest frame acceptable (LFA)
last frame received (LFR)
Maintain invariant: LFA - LFR <= RWS
<
RWS
Frame SeqNum arrives:
LFR
if LFR < SeqNum < = LFA
accept
if SeqNum < = LFR or SeqNum > LFA
LAF
discarded
Send cumulative ACKs
Spring 2007
CSE 30264
13
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
Spring 2007
CSE 30264
14
Concurrent Logical Channels
Multiplex 8 logical channels over a single link
Run stop-and-wait on each logical channel
Maintain three state bits per channel
channel busy
current sequence number out
next sequence number in
Header: 3-bit channel num, 1-bit sequence num
4-bits total
same as sliding window protocol
Separates reliability from order
Spring 2007
CSE 30264
15