blob: 99310907a9a0456d8c7c4c9b8000978e42350ac2 [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
20control FabricComputeChecksum(inout parsed_headers_t hdr,
21 inout fabric_metadata_t meta)
22{
23 apply {
24 update_checksum(hdr.ipv4.isValid(),
25 {
26 hdr.ipv4.version,
27 hdr.ipv4.ihl,
28 hdr.ipv4.diffserv,
29 hdr.ipv4.total_len,
30 hdr.ipv4.identification,
31 hdr.ipv4.flags,
32 hdr.ipv4.frag_offset,
33 hdr.ipv4.ttl,
34 hdr.ipv4.protocol,
35 hdr.ipv4.src_addr,
36 hdr.ipv4.dst_addr
37 },
38 hdr.ipv4.hdr_checksum,
39 HashAlgorithm.csum16
40 );
41 update_checksum(hdr.icmp.isValid(),
42 {
43 hdr.icmp.icmp_type,
44 hdr.icmp.icmp_code
45 },
46 hdr.icmp.checksum,
47 HashAlgorithm.csum16
48 );
49 }
50}
51
52control FabricVerifyChecksum(inout parsed_headers_t hdr,
53 inout fabric_metadata_t meta)
54{
55 apply {
56 verify_checksum(hdr.ipv4.isValid(),
57 {
58 hdr.ipv4.version,
59 hdr.ipv4.ihl,
60 hdr.ipv4.diffserv,
61 hdr.ipv4.total_len,
62 hdr.ipv4.identification,
63 hdr.ipv4.flags,
64 hdr.ipv4.frag_offset,
65 hdr.ipv4.ttl,
66 hdr.ipv4.protocol,
67 hdr.ipv4.src_addr,
68 hdr.ipv4.dst_addr
69 },
70 hdr.ipv4.hdr_checksum,
71 HashAlgorithm.csum16
72 );
73 verify_checksum(hdr.icmp.isValid(),
74 {
75 hdr.icmp.icmp_type,
76 hdr.icmp.icmp_code
77 },
78 hdr.icmp.checksum,
79 HashAlgorithm.csum16
80 );
81 }
82}
83
84#endif