Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 1 | /* |
| 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 Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 20 | #ifdef WITH_SPGW |
| 21 | #include "spgw.p4" |
| 22 | #endif // WITH_SPGW |
| 23 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 24 | control 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, |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 32 | hdr.ipv4.dscp, |
| 33 | hdr.ipv4.ecn, |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 34 | hdr.ipv4.total_len, |
| 35 | hdr.ipv4.identification, |
| 36 | hdr.ipv4.flags, |
| 37 | hdr.ipv4.frag_offset, |
| 38 | hdr.ipv4.ttl, |
| 39 | hdr.ipv4.protocol, |
| 40 | hdr.ipv4.src_addr, |
| 41 | hdr.ipv4.dst_addr |
| 42 | }, |
| 43 | hdr.ipv4.hdr_checksum, |
| 44 | HashAlgorithm.csum16 |
| 45 | ); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 46 | #ifdef WITH_SPGW |
Carmelo Cascone | 14cde40 | 2018-01-25 01:57:18 -0800 | [diff] [blame] | 47 | update_gtpu_checksum.apply(hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu, |
| 48 | hdr.ipv4, hdr.udp); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 49 | #endif // WITH_SPGW |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | control FabricVerifyChecksum(inout parsed_headers_t hdr, |
| 54 | inout fabric_metadata_t meta) |
| 55 | { |
| 56 | apply { |
| 57 | verify_checksum(hdr.ipv4.isValid(), |
| 58 | { |
| 59 | hdr.ipv4.version, |
| 60 | hdr.ipv4.ihl, |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 61 | hdr.ipv4.dscp, |
| 62 | hdr.ipv4.ecn, |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 63 | hdr.ipv4.total_len, |
| 64 | hdr.ipv4.identification, |
| 65 | hdr.ipv4.flags, |
| 66 | hdr.ipv4.frag_offset, |
| 67 | hdr.ipv4.ttl, |
| 68 | hdr.ipv4.protocol, |
| 69 | hdr.ipv4.src_addr, |
| 70 | hdr.ipv4.dst_addr |
| 71 | }, |
| 72 | hdr.ipv4.hdr_checksum, |
| 73 | HashAlgorithm.csum16 |
| 74 | ); |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | #endif |