blob: fb5d7314328088fc7321d0fc90c67de0f710eff0 [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;
27 exit;
28 }
29 }
30}
31
32control PacketIoEgress(
33inout parsed_headers_t hdr,
34inout fabric_metadata_t fabric_metadata,
35inout standard_metadata_t standard_metadata) {
36 apply {
37 hdr.packet_out.setInvalid();
38 if (standard_metadata.egress_port == CPU_PORT) {
39 hdr.packet_in.setValid();
40 hdr.packet_in.ingress_port = standard_metadata.ingress_port;
41 }
42 }
43}