blob: 75b84d88d105f1e52d37e97f7b3474bf9728af85 [file] [log] [blame]
// Copyright (c) 2017, Google Inc.
//
// P4 Modeling of controller Packet-IO behavior.
// Note: This code has not been tested and is expected to contain bugs.
#ifndef P4_SPEC_PACKETIO_P4_
#define P4_SPEC_PACKETIO_P4_
#include "headers.p4"
#include "parser.p4"
//------------------------------------------------------------------------------
// Packet IO
//------------------------------------------------------------------------------
control packetio_ingress(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata,
inout standard_metadata_t standard_metadata) {
apply {
if (hdr.packet_out.submit_to_ingress == 0) {
local_metadata.skip_egress = 1;
standard_metadata.egress_spec = hdr.packet_out.egress_physical_port;
hdr.packet_out.setInvalid();
exit;
}
hdr.packet_out.setInvalid();
}
} // end packetio_ingress
control packetio_egress(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata,
inout standard_metadata_t standard_metadata) {
action encap_packet_in_header() {
hdr.packet_in.setValid();
hdr.packet_in.ingress_physical_port = standard_metadata.ingress_port;
hdr.packet_in.target_egress_port = local_metadata.egress_spec_at_punt_match;
// At this time, ingress_logical_port cannot be set directly from within
// a P4-defined pipeline. It's existance currently serves to define
// this metadata field (as part of packet_in header). The target
// software will figure out the logical-port separately, and populate
// it into the P4Runtime stream message using the field-ID generated
// from the P4 packet_in header.
}
apply {
if (standard_metadata.egress_port == CPU_PORT) {
encap_packet_in_header();
}
if (local_metadata.skip_egress == 1) exit;
}
} // end packetio_egress
#endif // P4_SPEC_PACKETIO_P4_