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 | |
| 20 | control FabricComputeChecksum(inout parsed_headers_t hdr, |
| 21 | inout fabric_metadata_t meta) |
| 22 | { |
| 23 | apply { |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 24 | #ifdef TARGET_BMV2 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 25 | update_checksum(hdr.ipv4.isValid(), |
| 26 | { |
| 27 | hdr.ipv4.version, |
| 28 | hdr.ipv4.ihl, |
| 29 | hdr.ipv4.diffserv, |
| 30 | hdr.ipv4.total_len, |
| 31 | hdr.ipv4.identification, |
| 32 | hdr.ipv4.flags, |
| 33 | hdr.ipv4.frag_offset, |
| 34 | hdr.ipv4.ttl, |
| 35 | hdr.ipv4.protocol, |
| 36 | hdr.ipv4.src_addr, |
| 37 | hdr.ipv4.dst_addr |
| 38 | }, |
| 39 | hdr.ipv4.hdr_checksum, |
| 40 | HashAlgorithm.csum16 |
| 41 | ); |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 42 | #endif |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | control FabricVerifyChecksum(inout parsed_headers_t hdr, |
| 47 | inout fabric_metadata_t meta) |
| 48 | { |
| 49 | apply { |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 50 | #ifdef TARGET_BMV2 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 51 | verify_checksum(hdr.ipv4.isValid(), |
| 52 | { |
| 53 | hdr.ipv4.version, |
| 54 | hdr.ipv4.ihl, |
| 55 | hdr.ipv4.diffserv, |
| 56 | hdr.ipv4.total_len, |
| 57 | hdr.ipv4.identification, |
| 58 | hdr.ipv4.flags, |
| 59 | hdr.ipv4.frag_offset, |
| 60 | hdr.ipv4.ttl, |
| 61 | hdr.ipv4.protocol, |
| 62 | hdr.ipv4.src_addr, |
| 63 | hdr.ipv4.dst_addr |
| 64 | }, |
| 65 | hdr.ipv4.hdr_checksum, |
| 66 | HashAlgorithm.csum16 |
| 67 | ); |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 68 | #endif |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | #endif |