Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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_MAIN__ |
| 19 | #define __INT_MAIN__ |
| 20 | |
| 21 | #ifdef WITH_INT_SOURCE |
| 22 | #include "int_source.p4" |
| 23 | #endif // WITH_INT_SOURCE |
| 24 | |
| 25 | #ifdef WITH_INT_TRANSIT |
| 26 | #include "int_transit.p4" |
| 27 | #endif // WITH_INT_TRANSIT |
| 28 | |
| 29 | #ifdef WITH_INT_SINK |
| 30 | #include "int_sink.p4" |
| 31 | #include "int_report.p4" |
| 32 | #endif // WITH_INT_SINK |
| 33 | |
| 34 | control process_set_source_sink ( |
| 35 | inout parsed_headers_t hdr, |
| 36 | inout fabric_metadata_t fabric_metadata, |
| 37 | inout standard_metadata_t standard_metadata) { |
| 38 | |
| 39 | direct_counter(CounterType.packets_and_bytes) counter_set_source; |
| 40 | |
| 41 | action int_set_source () { |
| 42 | fabric_metadata.int_meta.source = _TRUE; |
| 43 | counter_set_source.count(); |
| 44 | } |
| 45 | |
| 46 | table tb_set_source { |
| 47 | key = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 48 | standard_metadata.ingress_port: exact @name("ig_port"); |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 49 | } |
| 50 | actions = { |
| 51 | int_set_source; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 52 | @defaultonly nop(); |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 53 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 54 | const default_action = nop(); |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 55 | counters = counter_set_source; |
| 56 | size = MAX_PORTS; |
| 57 | } |
| 58 | |
| 59 | #ifdef WITH_INT_SINK |
| 60 | direct_counter(CounterType.packets_and_bytes) counter_set_sink; |
| 61 | |
| 62 | action int_set_sink () { |
| 63 | fabric_metadata.int_meta.sink = _TRUE; |
| 64 | counter_set_sink.count(); |
| 65 | } |
| 66 | |
| 67 | table tb_set_sink { |
| 68 | key = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 69 | standard_metadata.egress_spec: exact @name("eg_spec"); |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 70 | } |
| 71 | actions = { |
| 72 | int_set_sink; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 73 | @defaultonly nop(); |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 74 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 75 | const default_action = nop(); |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 76 | counters = counter_set_sink; |
| 77 | size = MAX_PORTS; |
| 78 | } |
| 79 | #endif // WITH_INT_SINK |
| 80 | |
| 81 | apply { |
| 82 | tb_set_source.apply(); |
| 83 | |
| 84 | #ifdef WITH_INT_SINK |
| 85 | tb_set_sink.apply(); |
| 86 | if(fabric_metadata.int_meta.sink == _TRUE) { |
| 87 | // FIXME: this works only on BMv2 |
| 88 | #ifdef __TARGET_BMV2__ |
Sundararajan Renganathan | ac96e5b | 2020-07-10 02:43:40 +0000 | [diff] [blame^] | 89 | clone3(CloneType.I2E, REPORT_MIRROR_SESSION_ID, {standard_metadata.ingress_port}); |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 90 | #endif |
| 91 | } |
| 92 | #endif // WITH_INT_SINK |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | control process_int_main ( |
| 97 | inout parsed_headers_t hdr, |
| 98 | inout fabric_metadata_t fabric_metadata, |
| 99 | inout standard_metadata_t standard_metadata) { |
| 100 | |
| 101 | apply { |
| 102 | if (standard_metadata.ingress_port != CPU_PORT && |
| 103 | standard_metadata.egress_port != CPU_PORT && |
| 104 | (hdr.udp.isValid() || hdr.tcp.isValid())) { |
| 105 | #ifdef WITH_INT_SOURCE |
| 106 | if (fabric_metadata.int_meta.source == _TRUE) { |
| 107 | process_int_source.apply(hdr, fabric_metadata, standard_metadata); |
| 108 | } |
| 109 | #endif // WITH_INT_SOURCE |
| 110 | if(hdr.int_header.isValid()) { |
| 111 | #ifdef WITH_INT_TRANSIT |
| 112 | process_int_transit.apply(hdr, fabric_metadata, standard_metadata); |
| 113 | #endif // WITH_INT_TRANSIT |
| 114 | #ifdef WITH_INT_SINK |
| 115 | if (standard_metadata.instance_type == PKT_INSTANCE_TYPE_INGRESS_CLONE) { |
| 116 | /* send int report */ |
| 117 | process_int_report.apply(hdr, fabric_metadata, standard_metadata); |
| 118 | } |
| 119 | if (fabric_metadata.int_meta.sink == _TRUE) { |
| 120 | // int sink |
| 121 | process_int_sink.apply(hdr, fabric_metadata); |
| 122 | } |
| 123 | #endif // WITH_INT_SINK |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | #endif |