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 = { |
| 48 | standard_metadata.ingress_port: exact; |
| 49 | } |
| 50 | actions = { |
| 51 | int_set_source; |
| 52 | } |
| 53 | counters = counter_set_source; |
| 54 | size = MAX_PORTS; |
| 55 | } |
| 56 | |
| 57 | #ifdef WITH_INT_SINK |
| 58 | direct_counter(CounterType.packets_and_bytes) counter_set_sink; |
| 59 | |
| 60 | action int_set_sink () { |
| 61 | fabric_metadata.int_meta.sink = _TRUE; |
| 62 | counter_set_sink.count(); |
| 63 | } |
| 64 | |
| 65 | table tb_set_sink { |
| 66 | key = { |
| 67 | standard_metadata.egress_spec: exact; |
| 68 | } |
| 69 | actions = { |
| 70 | int_set_sink; |
| 71 | } |
| 72 | counters = counter_set_sink; |
| 73 | size = MAX_PORTS; |
| 74 | } |
| 75 | #endif // WITH_INT_SINK |
| 76 | |
| 77 | apply { |
| 78 | tb_set_source.apply(); |
| 79 | |
| 80 | #ifdef WITH_INT_SINK |
| 81 | tb_set_sink.apply(); |
| 82 | if(fabric_metadata.int_meta.sink == _TRUE) { |
| 83 | // FIXME: this works only on BMv2 |
| 84 | #ifdef __TARGET_BMV2__ |
| 85 | clone(CloneType.I2E, REPORT_MIRROR_SESSION_ID); |
| 86 | #endif |
| 87 | } |
| 88 | #endif // WITH_INT_SINK |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | control process_int_main ( |
| 93 | inout parsed_headers_t hdr, |
| 94 | inout fabric_metadata_t fabric_metadata, |
| 95 | inout standard_metadata_t standard_metadata) { |
| 96 | |
| 97 | apply { |
| 98 | if (standard_metadata.ingress_port != CPU_PORT && |
| 99 | standard_metadata.egress_port != CPU_PORT && |
| 100 | (hdr.udp.isValid() || hdr.tcp.isValid())) { |
| 101 | #ifdef WITH_INT_SOURCE |
| 102 | if (fabric_metadata.int_meta.source == _TRUE) { |
| 103 | process_int_source.apply(hdr, fabric_metadata, standard_metadata); |
| 104 | } |
| 105 | #endif // WITH_INT_SOURCE |
| 106 | if(hdr.int_header.isValid()) { |
| 107 | #ifdef WITH_INT_TRANSIT |
| 108 | process_int_transit.apply(hdr, fabric_metadata, standard_metadata); |
| 109 | #endif // WITH_INT_TRANSIT |
| 110 | #ifdef WITH_INT_SINK |
| 111 | if (standard_metadata.instance_type == PKT_INSTANCE_TYPE_INGRESS_CLONE) { |
| 112 | /* send int report */ |
| 113 | process_int_report.apply(hdr, fabric_metadata, standard_metadata); |
| 114 | } |
| 115 | if (fabric_metadata.int_meta.sink == _TRUE) { |
| 116 | // int sink |
| 117 | process_int_sink.apply(hdr, fabric_metadata); |
| 118 | } |
| 119 | #endif // WITH_INT_SINK |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | #endif |