Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [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 | #include "../header.p4" |
| 18 | #include "../action.p4" |
| 19 | |
| 20 | control PacketIoIngress( |
| 21 | inout parsed_headers_t hdr, |
| 22 | inout fabric_metadata_t fabric_metadata, |
| 23 | inout standard_metadata_t standard_metadata) { |
| 24 | apply { |
| 25 | if (hdr.packet_out.isValid()) { |
| 26 | standard_metadata.egress_spec = hdr.packet_out.egress_port; |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 27 | hdr.packet_out.setInvalid(); |
Carmelo Cascone | 8d2d1b2 | 2018-08-27 18:33:53 -0700 | [diff] [blame] | 28 | fabric_metadata.is_controller_packet_out = _TRUE; |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 29 | // No need for ingress processing, straight to egress. |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 30 | exit; |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | control PacketIoEgress( |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 36 | inout parsed_headers_t hdr, |
| 37 | inout fabric_metadata_t fabric_metadata, |
| 38 | inout standard_metadata_t standard_metadata) { |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 39 | action pop_vlan() { |
| 40 | hdr.ethernet.ether_type = hdr.vlan_tag.ether_type; |
| 41 | hdr.vlan_tag.setInvalid(); |
| 42 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 43 | apply { |
Carmelo Cascone | 8d2d1b2 | 2018-08-27 18:33:53 -0700 | [diff] [blame] | 44 | if (fabric_metadata.is_controller_packet_out == _TRUE) { |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 45 | // Transmit right away. |
Carmelo Cascone | 8d2d1b2 | 2018-08-27 18:33:53 -0700 | [diff] [blame] | 46 | exit; |
| 47 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 48 | if (standard_metadata.egress_port == CPU_PORT) { |
Carmelo Cascone | 35d9b33 | 2018-06-15 16:27:22 +0200 | [diff] [blame] | 49 | if (hdr.vlan_tag.isValid() && fabric_metadata.pop_vlan_when_packet_in == _TRUE) { |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 50 | pop_vlan(); |
| 51 | } |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 52 | if (fabric_metadata.is_multicast == _TRUE && |
| 53 | fabric_metadata.clone_to_cpu == _FALSE) { |
| 54 | // Is multicast but clone was not requested. |
| 55 | drop_now(); |
| 56 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 57 | hdr.packet_in.setValid(); |
| 58 | hdr.packet_in.ingress_port = standard_metadata.ingress_port; |
Carmelo Cascone | 8d2d1b2 | 2018-08-27 18:33:53 -0700 | [diff] [blame] | 59 | // No need to process through the rest of the pipeline. |
| 60 | exit; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |