You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.9 KiB
94 lines
2.9 KiB
/* -*- 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 { |
|
|
|
update_checksum_with_payload(meta.chk_icmp6 == 1, |
|
{ |
|
hdr.ipv6.src_addr, /* 128 */ |
|
hdr.ipv6.dst_addr, /* 128 */ |
|
meta.cast_length, /* 32 */ |
|
24w0, /* 24 0's */ |
|
PROTO_ICMP6, /* 8 */ |
|
hdr.icmp6.type, /* 8 */ |
|
hdr.icmp6.code /* 8 */ |
|
}, |
|
hdr.icmp6.checksum, |
|
HashAlgorithm.csum16 |
|
); |
|
|
|
/* checksumming for icmp6_na_ns_option */ |
|
update_checksum_with_payload(meta.chk_icmp6_na_ns == 1, |
|
{ |
|
hdr.ipv6.src_addr, /* 128 */ |
|
hdr.ipv6.dst_addr, /* 128 */ |
|
meta.cast_length, /* 32 */ |
|
24w0, /* 24 0's */ |
|
PROTO_ICMP6, /* 8 */ |
|
hdr.icmp6.type, /* 8 */ |
|
hdr.icmp6.code, /* 8 */ |
|
|
|
hdr.icmp6_na_ns.router, |
|
hdr.icmp6_na_ns.solicitated, |
|
hdr.icmp6_na_ns.override, |
|
hdr.icmp6_na_ns.reserved, |
|
hdr.icmp6_na_ns.target_addr, |
|
|
|
hdr.icmp6_option_link_layer_addr.type, |
|
hdr.icmp6_option_link_layer_addr.ll_length, |
|
hdr.icmp6_option_link_layer_addr.mac_addr |
|
}, |
|
hdr.icmp6.checksum, |
|
HashAlgorithm.csum16 |
|
); |
|
|
|
update_checksum_with_payload(meta.chk_icmp == 1, |
|
{ |
|
hdr.icmp.type, |
|
hdr.icmp.code |
|
}, |
|
hdr.icmp.checksum, |
|
HashAlgorithm.csum16 |
|
); |
|
|
|
update_checksum(meta.chk_ipv4 == 1, |
|
{ |
|
hdr.ipv4.version, |
|
hdr.ipv4.ihl, |
|
hdr.ipv4.diff_serv, |
|
hdr.ipv4.ecn, |
|
hdr.ipv4.totalLen, |
|
hdr.ipv4.identification, |
|
hdr.ipv4.flags, |
|
hdr.ipv4.fragOffset, |
|
hdr.ipv4.ttl, |
|
hdr.ipv4.protocol, |
|
hdr.ipv4.src_addr, |
|
hdr.ipv4.dst_addr |
|
}, |
|
hdr.ipv4.hdrChecksum, |
|
HashAlgorithm.csum16); |
|
} |
|
} |
|
|
|
|
|
#endif
|
|
|