The architecture-specific implementation of the Checksum Extern closely follows the PSA/PNA specification (refer to References). It performs a checksum calculation across some specified header/metadata fields, based on a given Hash algorithm. The supported algorithms are:
- CRC32
- CRC16
- ONES_COMPLEMENT16 (One's complement 16-bit sum used for IPv4 headers)
A custom data input type can be provided (scalars, headers, tuples, structs, etc.). All of the input data must be passed to the Checksum Extern in a single “apply” method call and the result of the checksum calculation is then returned. The input data must be in multiples of 16-bits (32-bits for CRC32) and no greater than 1024 bits, or else the compiler will trigger a warning.
The Checksum Extern is defined in xsa.p4 as -
extern Checksum<H>{
/// Constructor
Checksum(HashAlgorithm_t hash);
void apply<T, W>(in T data, out W result);
}
An example of a Checksum Extern being used in an example P4 program is provided in Forward Example Design.