blob: 0adb8f5eedbd760f568553f83b0a33029a24d49c [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"
Yi Tsengbe342052017-11-03 10:21:23 -070018
Carmelo Casconeb5324e72018-11-25 02:26:32 -080019control PacketIoIngress(inout parsed_headers_t hdr,
20 inout fabric_metadata_t fabric_metadata,
21 inout standard_metadata_t standard_metadata) {
22
Yi Tsengbe342052017-11-03 10:21:23 -070023 apply {
24 if (hdr.packet_out.isValid()) {
25 standard_metadata.egress_spec = hdr.packet_out.egress_port;
Yi Tseng1d842672017-11-28 16:06:52 -080026 hdr.packet_out.setInvalid();
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070027 fabric_metadata.is_controller_packet_out = _TRUE;
Carmelo Cascone79a3a312018-08-16 17:14:43 -070028 // No need for ingress processing, straight to egress.
Yi Tsengbe342052017-11-03 10:21:23 -070029 exit;
30 }
31 }
32}
33
Carmelo Casconeb5324e72018-11-25 02:26:32 -080034control PacketIoEgress(inout parsed_headers_t hdr,
35 inout fabric_metadata_t fabric_metadata,
36 inout standard_metadata_t standard_metadata) {
37
Yi Tsengbe342052017-11-03 10:21:23 -070038 apply {
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070039 if (fabric_metadata.is_controller_packet_out == _TRUE) {
Carmelo Cascone79a3a312018-08-16 17:14:43 -070040 // Transmit right away.
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070041 exit;
42 }
Yi Tsengbe342052017-11-03 10:21:23 -070043 if (standard_metadata.egress_port == CPU_PORT) {
Yi Tsengbe342052017-11-03 10:21:23 -070044 hdr.packet_in.setValid();
45 hdr.packet_in.ingress_port = standard_metadata.ingress_port;
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070046 // No need to process through the rest of the pipeline.
47 exit;
Yi Tsengbe342052017-11-03 10:21:23 -070048 }
49 }
50}