blob: 29c85ef028f2ad772a059947b0925f2045bfc8ba [file] [log] [blame]
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -08001/*
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// TODO: implement report logic to external collector
22control process_int_sink (
23 inout headers_t hdr,
24 inout local_metadata_t local_metadata,
25 inout standard_metadata_t standard_metadata) {
26 action int_sink() {
27 // restore length fields of IPv4 header and UDP header
28 hdr.ipv4.len = hdr.ipv4.len - (bit<16>)((hdr.intl4_shim.len - (bit<8>)hdr.int_header.ins_cnt) << 2);
29 hdr.udp.length_ = hdr.udp.length_ - (bit<16>)((hdr.intl4_shim.len - (bit<8>)hdr.int_header.ins_cnt) << 2);
30 // restore original dst port
31 local_metadata.int_meta.origin_port = hdr.intl4_tail.dest_port;
32 // remove all the INT information from the packet
33 hdr.int_header.setInvalid();
34 hdr.int_data.setInvalid();
35 hdr.intl4_shim.setInvalid();
36 hdr.intl4_tail.setInvalid();
37 }
38
39 action restore_port () {
40 hdr.udp.dst_port = local_metadata.int_meta.origin_port;
41 }
42
43 apply {
44 if (local_metadata.int_meta.sink == 1) {
45 int_sink();
46 restore_port();
47 }
48 }
49}
50#endif