Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [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 | /* -*- P4_16 -*- */ |
| 18 | #ifndef __INT_SINK__ |
| 19 | #define __INT_SINK__ |
| 20 | |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 21 | control process_int_sink ( |
| 22 | inout headers_t hdr, |
| 23 | inout local_metadata_t local_metadata, |
| 24 | inout standard_metadata_t standard_metadata) { |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 25 | @hidden |
Jonghwan Hyun | 8be0339 | 2017-12-04 15:48:44 -0800 | [diff] [blame] | 26 | action restore_header () { |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 27 | hdr.ipv4.dscp = hdr.intl4_shim.dscp; |
| 28 | // restore length fields of IPv4 header and UDP header |
| 29 | bit<16> len_bytes = ((bit<16>)hdr.intl4_shim.len) << 2; |
| 30 | hdr.ipv4.len = hdr.ipv4.len - len_bytes; |
| 31 | hdr.udp.length_ = hdr.udp.length_ - len_bytes; |
Jonghwan Hyun | 8be0339 | 2017-12-04 15:48:44 -0800 | [diff] [blame] | 32 | } |
| 33 | |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 34 | @hidden |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 35 | action int_sink() { |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 36 | // remove all the INT information from the packet |
| 37 | hdr.int_header.setInvalid(); |
| 38 | hdr.int_data.setInvalid(); |
| 39 | hdr.intl4_shim.setInvalid(); |
Jonghwan Hyun | 8be0339 | 2017-12-04 15:48:44 -0800 | [diff] [blame] | 40 | hdr.int_switch_id.setInvalid(); |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 41 | hdr.int_level1_port_ids.setInvalid(); |
Jonghwan Hyun | 8be0339 | 2017-12-04 15:48:44 -0800 | [diff] [blame] | 42 | hdr.int_hop_latency.setInvalid(); |
| 43 | hdr.int_q_occupancy.setInvalid(); |
| 44 | hdr.int_ingress_tstamp.setInvalid(); |
| 45 | hdr.int_egress_tstamp.setInvalid(); |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 46 | hdr.int_level2_port_ids.setInvalid(); |
Jonghwan Hyun | 8be0339 | 2017-12-04 15:48:44 -0800 | [diff] [blame] | 47 | hdr.int_egress_tx_util.setInvalid(); |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | apply { |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 51 | restore_header(); |
| 52 | int_sink(); |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 53 | } |
| 54 | } |
Jonghwan Hyun | 6777d53 | 2018-11-18 20:50:16 +0900 | [diff] [blame] | 55 | #endif |