blob: 75b84d88d105f1e52d37e97f7b3474bf9728af85 [file] [log] [blame]
Carmelo Cascone9ab40612017-09-19 16:31:55 +09001// Copyright (c) 2017, Google Inc.
2//
3// P4 Modeling of controller Packet-IO behavior.
4// Note: This code has not been tested and is expected to contain bugs.
5
6#ifndef P4_SPEC_PACKETIO_P4_
7#define P4_SPEC_PACKETIO_P4_
8
9#include "headers.p4"
10#include "parser.p4"
11
12//------------------------------------------------------------------------------
13// Packet IO
14//------------------------------------------------------------------------------
15
16control packetio_ingress(inout parsed_packet_t hdr,
17 inout local_metadata_t local_metadata,
18 inout standard_metadata_t standard_metadata) {
19 apply {
20 if (hdr.packet_out.submit_to_ingress == 0) {
21 local_metadata.skip_egress = 1;
22 standard_metadata.egress_spec = hdr.packet_out.egress_physical_port;
23 hdr.packet_out.setInvalid();
24 exit;
25 }
26 hdr.packet_out.setInvalid();
27 }
28} // end packetio_ingress
29
30
31control packetio_egress(inout parsed_packet_t hdr,
32 inout local_metadata_t local_metadata,
33 inout standard_metadata_t standard_metadata) {
34 action encap_packet_in_header() {
35 hdr.packet_in.setValid();
36 hdr.packet_in.ingress_physical_port = standard_metadata.ingress_port;
37 hdr.packet_in.target_egress_port = local_metadata.egress_spec_at_punt_match;
38
39 // At this time, ingress_logical_port cannot be set directly from within
40 // a P4-defined pipeline. It's existance currently serves to define
41 // this metadata field (as part of packet_in header). The target
42 // software will figure out the logical-port separately, and populate
43 // it into the P4Runtime stream message using the field-ID generated
44 // from the P4 packet_in header.
45 }
46
47 apply {
Carmelo Cascone9ab40612017-09-19 16:31:55 +090048 if (standard_metadata.egress_port == CPU_PORT) {
49 encap_packet_in_header();
50 }
51 if (local_metadata.skip_egress == 1) exit;
52 }
53} // end packetio_egress
54
55#endif // P4_SPEC_PACKETIO_P4_