blob: 65f073a33399303fce958de8f3c8938c46def72d [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.
}
// L123-DEMO-HACK: BEGIN
#define MAX_PORTS 510
counter(MAX_PORTS, CounterType.bytes) egress_port_counter;
counter(MAX_PORTS, CounterType.bytes) ingress_port_counter;
// L123-DEMO-HACK: END
apply {
// L123-DEMO-HACK: BEGIN
if (standard_metadata.egress_port < MAX_PORTS) {
egress_port_counter.count((bit<32>) standard_metadata.egress_spec);
}
if (standard_metadata.ingress_port < MAX_PORTS) {
ingress_port_counter.count((bit<32> ) standard_metadata.ingress_port);
}
// L123-DEMO-HACK: END
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_