blob: 1086dace755de207e61600e9a9c7788b01933255 [file] [log] [blame]
Yi Tsengbe342052017-11-03 10:21:23 -07001/*
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
20control PacketIoIngress(
21inout parsed_headers_t hdr,
22inout fabric_metadata_t fabric_metadata,
23inout standard_metadata_t standard_metadata) {
24 apply {
25 if (hdr.packet_out.isValid()) {
26 standard_metadata.egress_spec = hdr.packet_out.egress_port;
Yi Tseng1d842672017-11-28 16:06:52 -080027 hdr.packet_out.setInvalid();
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070028 fabric_metadata.is_controller_packet_out = _TRUE;
Yi Tsengbe342052017-11-03 10:21:23 -070029 exit;
30 }
31 }
32}
33
34control PacketIoEgress(
Carmelo Cascone1e8843f2018-07-19 19:01:12 +020035 inout parsed_headers_t hdr,
36 inout fabric_metadata_t fabric_metadata,
37 inout standard_metadata_t standard_metadata) {
Yi Tseng20f9e7b2018-05-24 23:27:39 +080038 action pop_vlan() {
39 hdr.ethernet.ether_type = hdr.vlan_tag.ether_type;
40 hdr.vlan_tag.setInvalid();
41 }
Yi Tsengbe342052017-11-03 10:21:23 -070042 apply {
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070043 if (fabric_metadata.is_controller_packet_out == _TRUE) {
44 // No need to process through the rest of the pipeline.
45 exit;
46 }
Yi Tsengbe342052017-11-03 10:21:23 -070047 if (standard_metadata.egress_port == CPU_PORT) {
Carmelo Cascone35d9b332018-06-15 16:27:22 +020048 if (hdr.vlan_tag.isValid() && fabric_metadata.pop_vlan_when_packet_in == _TRUE) {
Yi Tseng20f9e7b2018-05-24 23:27:39 +080049 pop_vlan();
50 }
Carmelo Cascone1e8843f2018-07-19 19:01:12 +020051 if (fabric_metadata.is_multicast == _TRUE &&
52 fabric_metadata.clone_to_cpu == _FALSE) {
53 // Is multicast but clone was not requested.
54 drop_now();
55 }
Yi Tsengbe342052017-11-03 10:21:23 -070056 hdr.packet_in.setValid();
57 hdr.packet_in.ingress_port = standard_metadata.ingress_port;
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070058 // No need to process through the rest of the pipeline.
59 exit;
Yi Tsengbe342052017-11-03 10:21:23 -070060 }
61 }
62}