Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions p4-16/psa/examples/psa-example-incremental-checksum.p4
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,8 @@ control EgressDeparserImpl(packet_out packet,
});
hdr.ipv4.hdrChecksum = ck.get();
// Update TCP checksum
// This clear() call is necessary for correct behavior, since
// the same instance 'ck' is reused from above for the same
// packet. If a second InternetChecksum instance other than
// 'ck' were used below instead, this clear() call would be
// unnecessary.
ck.clear();
// Subtract the original TCP checksum
ck.subtract(hdr.tcp.checksum);
// Initialize with the original TCP checksum
ck.initialize(hdr.tcp.checksum);
// Subtract the effect of the original IPv4 source address,
// which is part of the TCP 'pseudo-header' for the purposes
// of TCP checksum calculation (see RFC 793), then add the
Expand Down
11 changes: 11 additions & 0 deletions p4-16/psa/psa.p4
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,17 @@ extern InternetChecksum {
/// 16 bits long.
void subtract<T>(in T data);

/// Initialize the InternetChecksum extern object.
/// This method prepares the InternetChecksum object to compute an
/// incremental checksum (e.g. TCP checksum).
/// The primary use case for this method is to initialize the checksum
/// computation with the value extracted from the received packet header.
/// Calling ck.initizalize(chksum) is algorithmically equivalent to calling
/// ck.clear() followed by ck.substract(chksum)
/// @param chksum : The initial checksum value, typically extracted from
/// the packet header.
void initialize(in bit<16> chksum);

/// Get checksum for data added (and not removed) since last clear
@noSideEffects
bit<16> get();
Expand Down