lecture 7: reliable packet transmission. cyclic redundancy check add k bits of extra data (the crc...
TRANSCRIPT
Lecture 7: Reliable Packet Transmission
Cyclic Redundancy Check
• Add k bits of extra data (the CRC field) to an n-bit message to provide error detection function
– For efficiency, want k << n
– e.g., k = 32 for Ethernet and n = 12,000 (1500 bytes)
Header Body
8 16 16 8
CRCBeginningsequence
Endingsequence
CRC strategy
• Sender and Receiver know the “divisor polynomial”– e.g. C(x)=x3+x2+1=1101
• Send MessageCRC with CRC chosen so that the whole thing is evenly divisible by C(x)
• Receiver calculates the remainder of
MessageCRC/C(x) There’s an error if it is not zero
CRC example
• Message=10011010 C=1101(3 rd order)
• MessageCRC=10011010XYZ
• Choose XYZ so that remainder is zero for MessageCRC/C
CRC Example cont.
• 11111001 110110011010XYZ
1101 1001 1101
1000 1101
X=1 1011 Y=0 1101 Z=1 1100
1101 1xyz1101
• MessageCRC=10011010 101
CRC Example cont.• 11111001
110110011010000 1101 1001 1101 1000
1101 1011 1101 1100
1101 1000 1101 101
• MessageCRC=10011010xor) 101
C(x) Examples• CRC-8 x8+x2+x1+1=100000111• CRC-10 11000110011• CRC-12 110000000101• CRC-16 11000000000000101• CRC-CCITT 10001000000100001• CRC-32
1000001001100000010001110110110111
1’s complement addition
• 0=0000 -0=1111
• 1=0001 -1=1110
• 2=0010 -2=1101
• 2+3=0010+0011=0101=5
• 2+(-0)=0010+1111+0001=0010=2
• 3+(-2)=0011+1101+0001=0001
Internet Checksum Strategy
• 0 1010 0001 1001 1100 =0000A19C
• 0 0110 1010 1111 0010 =00006AF2
• 1 0000 1010 1000 1110 =00010A8E
• =>00000A8E
• =>0000 1010 1000 1111=00000A8F
• =>0A8F
• =>F670
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_shortcksum(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);}
Reliable Transmission
• Problem:
• To detect packet loss
• To retransmit lost packets
• Delete duplicates.
• Assure proper order
Stop and Wait
Sequence numbers: 0,1,0,1 etc.
Resend if no Ack before timeout
+ guarantees arrival of all frames in order
-lots of downtime, particularly for long RTTs
Frame sequencing for Stop-and-Wait protocol
Time line for sliding window algorithm
Sliding Window Algorithm-sender
• LAR=last acknowledgement received• LFS=last frame sent• SWS=send window size• LFS-LAR<SWS
Sliding Window Algorithm-receiver
• NFE=next frame expected• LFA=last frame accepted• RWS=receive window size• LFA-NFE<RWS