Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [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 | |
| 21 | control process_int_sink ( |
| 22 | inout parsed_headers_t hdr, |
| 23 | inout fabric_metadata_t fabric_metadata, |
| 24 | inout standard_metadata_t standard_metadata) { |
| 25 | action restore_header () { |
| 26 | hdr.udp.dst_port = hdr.intl4_tail.dest_port; |
| 27 | hdr.ipv4.dscp = (bit<6>)hdr.intl4_tail.dscp; |
| 28 | } |
| 29 | |
| 30 | action int_sink() { |
| 31 | // restore length fields of IPv4 header and UDP header |
| 32 | hdr.ipv4.total_len = hdr.ipv4.total_len - (bit<16>)(hdr.intl4_shim.len << 2); |
| 33 | hdr.udp.len = hdr.udp.len - (bit<16>)(hdr.intl4_shim.len << 2); |
| 34 | // remove all the INT information from the packet |
| 35 | hdr.int_header.setInvalid(); |
| 36 | hdr.int_data.setInvalid(); |
| 37 | hdr.intl4_shim.setInvalid(); |
| 38 | hdr.intl4_tail.setInvalid(); |
| 39 | hdr.int_switch_id.setInvalid(); |
| 40 | hdr.int_port_ids.setInvalid(); |
| 41 | hdr.int_hop_latency.setInvalid(); |
| 42 | hdr.int_q_occupancy.setInvalid(); |
| 43 | hdr.int_ingress_tstamp.setInvalid(); |
| 44 | hdr.int_egress_tstamp.setInvalid(); |
| 45 | hdr.int_q_congestion.setInvalid(); |
| 46 | hdr.int_egress_tx_util.setInvalid(); |
| 47 | } |
| 48 | |
| 49 | apply { |
| 50 | restore_header(); |
| 51 | int_sink(); |
| 52 | } |
| 53 | } |
| 54 | #endif |