blob: 9f460477d5c6f435718f88a243d6090aa6fb68bf [file] [log] [blame]
// Copyright (c) 2017, Google Inc.
//
// P4_16 specification for a ToR (top-of-rack) switch.
// Status: WORK IN PROGRESS
// Note: This code has not been tested and is expected to contain bugs.
#include "parser.p4"
#include "class_id.p4"
#include "spoof_protection.p4"
#include "l3_fwd.p4"
#include "packetio.p4"
#include "punt.p4"
#include "vrf.p4"
#include "ipv4_checksum.p4"
control ingress_tor(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata,
inout standard_metadata_t standard_metadata) {
// L123-DEMO-HACK: BEGIN
counter(511, CounterType.packets_and_bytes) ingress_port_counter;
// L123-DEMO-HACK: END
apply {
// L123-DEMO-HACK: BEGIN
ingress_port_counter.count((bit<32>) standard_metadata.ingress_port);
// L123-DEMO-HACK: END
if (hdr.packet_out.isValid()) {
packetio_ingress.apply(hdr, local_metadata, standard_metadata);
}
vrf.apply(hdr, local_metadata, standard_metadata);
class_id.apply(hdr, local_metadata, standard_metadata);
l3_fwd.apply(hdr, local_metadata, standard_metadata);
punt.apply(hdr, local_metadata, standard_metadata);
}
} // end ingress_tor
control egress_tor(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata,
inout standard_metadata_t standard_metadata) {
// L123-DEMO-HACK: BEGIN
counter(511, CounterType.packets_and_bytes) egress_port_counter;
// L123-DEMO-HACK: END
apply {
// L123-DEMO-HACK: BEGIN
egress_port_counter.count((bit<32>) standard_metadata.egress_port);
// L123-DEMO-HACK: END
packetio_egress.apply(hdr, local_metadata, standard_metadata);
spoof_protection.apply(hdr, local_metadata, standard_metadata);
}
}
V1Switch(pkt_parser(), verify_checksum(), ingress_tor(), egress_tor(),
compute_checksum(), pkt_deparser()) main;