blob: 6531a179ca15ca7db2757bacf66f24fea1498854 [file] [log] [blame]
Jonghwan Hyuned478dc2018-08-06 15:35:18 +09001/*
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
21control process_int_sink (
22 inout parsed_headers_t hdr,
Carmelo Cascone79a3a312018-08-16 17:14:43 -070023 inout fabric_metadata_t fabric_metadata) {
24
Carmelo Casconeb5324e72018-11-25 02:26:32 -080025 @hidden
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090026 action restore_header () {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080027 hdr.udp.dport = hdr.intl4_tail.dest_port;
Carmelo Cascone79a3a312018-08-16 17:14:43 -070028 hdr.ipv4.dscp = hdr.intl4_tail.dscp;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090029 }
30
Carmelo Casconeb5324e72018-11-25 02:26:32 -080031 @hidden
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090032 action int_sink() {
33 // restore length fields of IPv4 header and UDP header
Carmelo Cascone79a3a312018-08-16 17:14:43 -070034 bit<16> len_bytes = (bit<16>) (hdr.intl4_shim.len_words << 5w2);
35 hdr.ipv4.total_len = hdr.ipv4.total_len - len_bytes;
36 hdr.udp.len = hdr.udp.len - len_bytes;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090037 // remove all the INT information from the packet
38 hdr.int_header.setInvalid();
39 hdr.int_data.setInvalid();
40 hdr.intl4_shim.setInvalid();
41 hdr.intl4_tail.setInvalid();
42 hdr.int_switch_id.setInvalid();
43 hdr.int_port_ids.setInvalid();
44 hdr.int_hop_latency.setInvalid();
45 hdr.int_q_occupancy.setInvalid();
46 hdr.int_ingress_tstamp.setInvalid();
47 hdr.int_egress_tstamp.setInvalid();
48 hdr.int_q_congestion.setInvalid();
49 hdr.int_egress_tx_util.setInvalid();
50 }
51
52 apply {
53 restore_header();
54 int_sink();
55 }
56}
Carmelo Cascone79a3a312018-08-16 17:14:43 -070057#endif