0% found this document useful (0 votes)
9 views

10. CRC ,IP and TCP Checksum Algo

Uploaded by

ayang5355
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

10. CRC ,IP and TCP Checksum Algo

Uploaded by

ayang5355
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Chapter 2

Internet Checksum Algorithm


 Not used at the link level
 Add up all the words that are transmitted and then transmit the
result of that sum
 The result is called the checksum
 The receiver performs the same calculation on the received data
and compares the result with the received checksum
 If any transmitted data, including the checksum itself, is corrupted,
then the results will not match, so the receiver knows that an error
occurred

1
Chapter 2
Internet Checksum Algorithm
 Consider the data being checksummed as a sequence of 16-bit
integers.
 Add them together using 16-bit ones complement arithmetic
(explained next slide) and then take the ones complement of the
result.
 That 16-bit number is the checksum

2
Chapter 2
Internet Checksum Algorithm
 In ones complement arithmetic, a negative integer −x is
represented as the complement of x;
 Each bit of x is inverted.
 When adding numbers in ones complement arithmetic, a carryout
from the most significant bit needs to be added to the result.

3
Chapter 2
Internet Checksum Algorithm
 Consider, for example, the addition of −5 and −3 in ones
complement arithmetic on 4-bit integers
 +5 is 0101, so −5 is 1010; +3 is 0011, so −3 is 1100
 If we add 1010 and 1100 ignoring the carry, we get 0110
 In ones complement arithmetic, the fact that this operation caused
a carry from the most significant bit causes us to increment the
result, giving 0111, which is the ones complement representation
of −8 (obtained by inverting the bits in 1000), as we would expect

4
Figure 15.5 TCP segment format

TCP/IP Protocol Suite 5


TCP Checksum Calculation and the TCP "Pseudo Header"

Instead of computing the checksum over only the actual data fields of the TCP segment, a
12-byte TCP pseudo header is created prior to checksum calculation.
This header contains important information taken from fields in both the TCP header and the
IP datagram into which the TCP segment will be encapsulated. The TCP pseudo header has
the format shown below :
 Once this 96-bit header has been formed, it is placed in a buffer, following which
the TCP segment itself is placed.
 Then, the checksum is computed over the entire set of data (pseudo header plus
TCP segment).
 The value of the checksum is placed into the Checksum field of the TCP header,
and the pseudo header is discarded—it is not an actual part of the TCP segment
and is not transmitted.
Figure 15.7 Pseudoheader added to the TCP segment

Pseudoheader added only for checksum calculation


TCP/IP Protocol Suite 8
Source Port: The 16-bit port number of the process that originated the TCP segment on the source device.
This will normally be an ephemeral (client) port number for a request sent by a client to a server, or a
well-known/registered (server) port number for a reply from a server to a client.

Destination Port: The 16-bit port number of the process that is the ultimate intended recipient of the
message on the destination device. This will usually be a well-known/registered (server) port number for a
client request, or an ephemeral (client) port number for a server reply.

Sequence Number: For normal transmissions, the sequence number of the first byte of data in this segment.
In a connection request (SYN) message, this carries the initial sequence number (ISN) of the source TCP. The
first byte of data will be given the next sequence number after the contents of this field.

Acknowledgment Number: When the ACK bit is set, this segment is serving as an acknowledgment (in
addition to other possible duties) and this field contains the sequence number the source is next expecting
the destination to send.

Window: Indicates the number of octets of data the sender of this segment is willing to accept from the
receiver at one time. This normally corresponds to the current size of the buffer allocated to accept data for
this connection. This field is, in other words, the current receive window size for the device sending this
segment, which is also the send window for the recipient of the segment
( i.e If I am sending tcp segment , “ Window” field will contain the number of octets that can be sent
back to me from the other side )
Checksum: A 16-bit checksum for data integrity protection, computed over the entire TCP datagram plus a
special “pseudo header” of fields. It is used to protect the entire TCP segment against not just errors in
transmission, but also errors in delivery.

Urgent Pointer: Used in conjunction with the URG control bit for priority data transfer. This field contains the
sequence number of the last byte of urgent data.

Control Bits: ( 6 bits ) For control information ( shown in next slides )

Padding: If the Options field is not a multiple of 32 bits in length, enough zeroes are added to pad the header
so it is a multiple of 32 bits.
Chapter 2
Cyclic Redundancy Check (CRC)
 Reduce the number of extra bits and maximize protection
 Given a bit string 110001 we can associate a polynomial on a
single variable x for it.
1.x5+1.x4+0.x3+0.x2+0.x1+1.x0 = x5+x4+1 and the degree is 5.
A k-bit frame has a maximum degree of k-1
 Let M(x) be a message polynomial and C(x) be a generator
polynomial.

11
Chapter 2
Cyclic Redundancy Check (CRC)
 Let M(x)/C(x) leave a remainder of 0.
 When M(x) is sent and M’(x) is received we have M’(x) = M(x)
+E(x)
 The receiver computes M’(x)/C(x) and if the remainder is nonzero,
then an error has occurred.
 The only thing the sender and the receiver should know is C(x).

12
Chapter 2
Cyclic Redundancy Check (CRC)
Polynomial Arithmetic Modulo 2

Any polynomial B(x) can be divided by a divisor polynomial C(x) if B(x) is
of higher degree than C(x).


Any polynomial B(x) can be divided once by a divisor polynomial C(x) if
B(x) is of the same degree as C(x).


The remainder obtained when B(x) is divided by C(x) is obtained by
subtracting C(x) from B(x).


To subtract C(x) from B(x), we simply perform the exclusive-OR (XOR)
operation on each pair of matching coefficients.

13
Chapter 2
Cyclic Redundancy Check (CRC)
 Let M(x) be a frame with m bits and let the generator polynomial
have less than m bits say equal to r.
 Let r be the degree of C(x). Append r zero bits to the low-order
end of the frame, so it now contains m+r bits and corresponds to
the polynomial xrM(x).

14
Chapter 2
Cyclic Redundancy Check (CRC)
 Divide the bit string corresponding to x rM(x) by the bit string
corresponding to C(x) using modulo 2 division.
 Subtract the remainder (which is always r or fewer bits) from the
string corresponding to xrM(x) using modulo 2 subtraction
(addition and subtraction are the same in modulo 2).
 The result is the checksummed frame to be transmitted. Call it
polynomial M’(x).

15
Chapter 2
Cyclic Redundancy Check (CRC)

CRC Calculation using Binary Long Division

16
Chapter 2
Cyclic Redundancy Check (CRC)
 Properties of Generator Polynomial
 Let P(x) represent what the sender sent and P(x) + E(x) is the received string. A 1 in E(x)
represents that in the corresponding position in P(x) the message the bit is flipped.

 We know that P(x)/C(x) leaves a remainder of 0, but if E(x)/C(x) leaves a remainder of 0,


then either E(x) = 0 or C(x) is factor of E(x).

 When C(x) is a factor of E(x) we have problem; errors go unnoticed.

 If there is a single bit error then E(x) = xi, where i determines the bit in error. If C(x)
contains two or more terms it will never divide E(x), so all single bit errors will be
detected.

17
Chapter 2
Cyclic Redundancy Check (CRC)
 Properties of Generator Polynomial
 In general, it is possible to prove that the following types of errors can be
detected by a C(x) with the stated properties

All single-bit errors, as long as the xk and x0 terms have nonzero coefficients.

All double-bit errors, as long as C(x) has 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.)

18
Chapter 2
Cyclic Redundancy Check (CRC)
 Six generator polynomials that have become international
standards are:
 CRC-8 = x8+x2+x+1
 CRC-10 = x10+x9+x5+x4+x+1
 CRC-12 = x12+x11+x3+x2+x+1
 CRC-16 = x16+x15+x2+1
 CRC-CCITT = x16+x12+x5+1
 CRC-32 = x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1

19
Chapter 2
Reliable Transmission
 CRC is used to detect errors.
 Some error codes are strong enough to correct errors.
 The overhead is typically too high.
 Corrupt frames must be discarded.
 A link-level protocol that wants to deliver frames reliably must
recover from these discarded frames.
 This is accomplished using a combination of two fundamental
mechanisms
 Acknowledgements and Timeouts

20

You might also like