blob: 4d1782da58079efad21870199645d20757406c74 [file] [log] [blame]
Yi Tsengbe342052017-11-03 10:21:23 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __CHECKSUM__
18#define __CHECKSUM__
19
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080020#ifdef WITH_SPGW
21#include "spgw.p4"
22#endif // WITH_SPGW
23
Yi Tsengbe342052017-11-03 10:21:23 -070024control FabricComputeChecksum(inout parsed_headers_t hdr,
25 inout fabric_metadata_t meta)
26{
27 apply {
28 update_checksum(hdr.ipv4.isValid(),
29 {
30 hdr.ipv4.version,
31 hdr.ipv4.ihl,
32 hdr.ipv4.diffserv,
33 hdr.ipv4.total_len,
34 hdr.ipv4.identification,
35 hdr.ipv4.flags,
36 hdr.ipv4.frag_offset,
37 hdr.ipv4.ttl,
38 hdr.ipv4.protocol,
39 hdr.ipv4.src_addr,
40 hdr.ipv4.dst_addr
41 },
42 hdr.ipv4.hdr_checksum,
43 HashAlgorithm.csum16
44 );
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080045#ifdef WITH_SPGW
46 update_gtpu_checksum.apply(hdr.gtpu_ipv4);
47#endif // WITH_SPGW
Yi Tsengbe342052017-11-03 10:21:23 -070048 }
49}
50
51control FabricVerifyChecksum(inout parsed_headers_t hdr,
52 inout fabric_metadata_t meta)
53{
54 apply {
55 verify_checksum(hdr.ipv4.isValid(),
56 {
57 hdr.ipv4.version,
58 hdr.ipv4.ihl,
59 hdr.ipv4.diffserv,
60 hdr.ipv4.total_len,
61 hdr.ipv4.identification,
62 hdr.ipv4.flags,
63 hdr.ipv4.frag_offset,
64 hdr.ipv4.ttl,
65 hdr.ipv4.protocol,
66 hdr.ipv4.src_addr,
67 hdr.ipv4.dst_addr
68 },
69 hdr.ipv4.hdr_checksum,
70 HashAlgorithm.csum16
71 );
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080072#ifdef WITH_SPGW
73 verify_gtpu_checksum.apply(hdr.gtpu_ipv4);
74#endif // WITH_SPGW
Yi Tsengbe342052017-11-03 10:21:23 -070075 }
76}
77
78#endif