Annex C Algorithms for PDU Header Error Detection Function
ANNEX C. ALGORITHMS FOR PDU HEADER ERROR DETECTION FUNCTION
This Annex describes algorithm which may be used to computer, check and
update the checksum field of the PDU Header in order to provide the PDU
Header Error Detection function described in Section 6.11.
C.1 Symbols used in algorithms
CO,C1 variables used in the algorithms
i number (i.e., position) of an octet within the header
n number (i.e., position) of the first octet of the checksum
parameter (n=8)
L length of the PDU header in octets
X value of octet one of the checksum parameter
Y value of octet two of the checksum parameter
a octet occupying position i of the PDU header
C.2 Arithmetic Conventions
Addition is performed in one of the two following modes:
a) modulo 255 arithmetic;
b) eight-bit one's complement arithmetic in which, if any of the
variables has the value minus zero (i.e., 255) it shall be
regarded as though it was plus zero (i.e., 0).
C.3 Algorithm for Generating Checksum Parameters
A: Construct the complete PDU header with the value of the checksum
parameter field set to zero;
B: Initialize C0 and C1 to zero;
C: Process each octet of the PDU header sequentially from i = 1 to L
by
a) adding the value of the octet to C0; then
b) adding the value of C0 to C1;
D: Calculate X = (L-8)C0 - C1 (modulo 255) and Y = (L-7) (-C0) + C1
(modulo 255)
E: If X = 0, set X = 255;
F: If Y = 0, set Y = 255;
G: Place the values X and Y in octets 8 and 9 respectively.
C.4 Algorithm for Checking Checksum Parameters
A: If octets 8 and 9 of PDU header both contain 0 (all bits off),
then the checksum calculation has succeeded; otherwise initialize
C1 = 0, C0 - 0 and proceed;
B: process each octet of the PDU header sequentially from i = 1 to L
by
a) adding the value of the octet to C0; then
b) adding the value of C0 to C1;
C: If, when all the octets have been processed, C0 = C1 = 0 (modulo
255) then the checksum calculation has succeeded; otherwise, the
checksum calculation has failed.
C.5 Algorithm to adjust checksum parameter when an octet is altered
This algorithm adjusts the checksum when an octet (such as the
lifetime field) is altered. Suppose the value in octet k is changed by
Z = new_value - old_value.
If X and Y denote the checksum values held in octets n and n+1,
respectively, then adjust X and Y as follows:
If X = 0 and Y = 0 do nothing, else;
X := (k-n-1)Z + X (modulo 255) and
Y := (n-k)Z + Y (modulo 255).
If X is equal to zero, then set it to 255; and
similarly for Y.
For this Protocol, n = 8. If the octet being altered is the lifetime
field, k = 4. For the case where the lifetime is decreased by 1 unit
(Z = -1), the results simplify to
X := X + 5 (modulo 255) and
Y := Y - 4 (modulo 255).
Note:
To derive this result, assume that when octet k has the value Z
added to it then X and Y have values ZX and ZY added to them. For
the checksum parameters to satisfy the conditions of Section 6.11
both before and after the values are added, the following is
required:
Z + ZX + ZY = 0 (modulo 255) and
(L-k+1)Z + (L-n+1)ZX + (L-n)ZY = 0 (modulo 255).
Solving these equations simultaneously yields ZX = (k-n-1)Z and ZY +
(m-k)Z.