blob: 1971a298d76938d32ea8f8f49ca3d69386228f34 [file] [log] [blame]
/*
* Copyright 2017-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __CHECKSUMS__
#define __CHECKSUMS__
#include "headers.p4"
control verify_checksum_control(inout headers_t hdr,
inout local_metadata_t local_metadata) {
apply {
// Assume checksum is always correct.
}
}
control compute_checksum_control(inout headers_t hdr,
inout local_metadata_t local_metadata) {
apply {
update_checksum(hdr.ipv4.isValid(),
{
hdr.ipv4.version,
hdr.ipv4.ihl,
hdr.ipv4.dscp,
hdr.ipv4.ecn,
hdr.ipv4.len,
hdr.ipv4.identification,
hdr.ipv4.flags,
hdr.ipv4.frag_offset,
hdr.ipv4.ttl,
hdr.ipv4.protocol,
hdr.ipv4.src_addr,
hdr.ipv4.dst_addr
},
hdr.ipv4.hdr_checksum,
HashAlgorithm.csum16
);
// Need to recompute for the cloned packet.
//TODO: https://github.com/p4lang/p4app/issues/43#issuecomment-378061934
#ifdef __INT_HEADERS__
update_checksum(hdr.report_ipv4.isValid(),
{
hdr.report_ipv4.version,
hdr.report_ipv4.ihl,
hdr.report_ipv4.dscp,
hdr.report_ipv4.ecn,
hdr.report_ipv4.len,
hdr.report_ipv4.identification,
hdr.report_ipv4.flags,
hdr.report_ipv4.frag_offset,
hdr.report_ipv4.ttl,
hdr.report_ipv4.protocol,
hdr.report_ipv4.src_addr,
hdr.report_ipv4.dst_addr
},
hdr.report_ipv4.hdr_checksum,
HashAlgorithm.csum16
);
#endif // __INT_HEADERS__
}
}
#endif