master-thesis/p4src/checksums.p4

61 lines
1.4 KiB
Text
Raw Normal View History

/* -*- P4_16 -*- */
#ifndef CHECKSUMS_P4
#define CHECKSUMS_P4
#include <core.p4>
#include <v1model.p4>
#include "headers.p4"
/*************************************************************************
************* C H E C K S U M V E R I F I C A T I O N *************
*************************************************************************/
control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
apply {}
}
/*************************************************************************
************** C H E C K S U M C O M P U T A T I O N **************
*************************************************************************/
control MyComputeChecksum(inout headers hdr, inout metadata meta) {
apply {
/* 512 bit+ according to
https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_checksum_for_IPv4
*/
update_checksum_with_payload(
hdr.ipv6.isValid(),
{
hdr.ipv6.src_addr, /* 128 */
hdr.ipv6.dst_addr, /* 128 */
meta.tcpLength,
24w0,
hdr.ipv6.next_header,
// TCP header
hdr.tcp.src_port,
hdr.tcp.dst_port,
hdr.tcp.seqNo,
hdr.tcp.ackNo,
hdr.tcp.data_offset,
hdr.tcp.res,
hdr.tcp.cwr,
hdr.tcp.ece,
hdr.tcp.urg,
hdr.tcp.ack,
hdr.tcp.psh,
hdr.tcp.rst,
hdr.tcp.syn,
hdr.tcp.fin,
hdr.tcp.window,
hdr.tcp.urgentPtr
},
hdr.tcp.checksum,
HashAlgorithm.csum16);
}
}
#endif