The architecture-specific implementation of the InternetChecksum Extern closely follows the PSA/PNA specification (see References). This extern is limited to the ONES_COMPLEMENT16 algorithm and is primarily intended for IPv4 checksum calculations. It can also be used for UDP checksum updates, but not full UDP checksum calculations as the calculation over the packet payload is not supported.
In contrast to the Checksum Extern, the InternetChecksum supports multiple
different method calls and is not limited to a single method call per packet, for
example, subtract(), followed by add() and followed by get().
Input data must be in multiples of 16 bits and no greater than 1024 bits, otherwise the compiler will trigger a warning.
There can be multiple instances of the InternetChecksum Extern in a P4 program. The InternetChecksum Extern is only supported within the Match_Action Engine ‘control’ block of a P4 program. There is no AXI4-Lite control-plane associated with the InternetChecksum Extern.
The InternetChecksum Extern is defined in xsa.p4 as -
// Checksum based on `ONES_COMPLEMENT16` algorithm used in IPv4, TCP, and UDP.
// Supports incremental updating via `subtract` method.
// See IETF RFC 1624.
extern InternetChecksum {
InternetChecksum();
void clear();
/// Add data to checksum. Data must be a multiple of 16 bits long.
void add<T>(in T data);
/// Subtract data from existing checksum. Data must be a multiple of
/// 16 bits long.
void subtract<T>(in T data);
void get<W>(out W result);
}