blob: 9f460477d5c6f435718f88a243d6090aa6fb68bf [file] [log] [blame]
Carmelo Cascone9ab40612017-09-19 16:31:55 +09001// Copyright (c) 2017, Google Inc.
2//
3// P4_16 specification for a ToR (top-of-rack) switch.
4// Status: WORK IN PROGRESS
5// Note: This code has not been tested and is expected to contain bugs.
6
7#include "parser.p4"
8#include "class_id.p4"
9#include "spoof_protection.p4"
10#include "l3_fwd.p4"
11#include "packetio.p4"
12#include "punt.p4"
13#include "vrf.p4"
14#include "ipv4_checksum.p4"
15
16
17control ingress_tor(inout parsed_packet_t hdr,
18 inout local_metadata_t local_metadata,
19 inout standard_metadata_t standard_metadata) {
Carmelo Cascone821fa522017-10-04 14:33:28 +020020 // L123-DEMO-HACK: BEGIN
21 counter(511, CounterType.packets_and_bytes) ingress_port_counter;
22 // L123-DEMO-HACK: END
Carmelo Cascone9ab40612017-09-19 16:31:55 +090023 apply {
Carmelo Cascone821fa522017-10-04 14:33:28 +020024 // L123-DEMO-HACK: BEGIN
25 ingress_port_counter.count((bit<32>) standard_metadata.ingress_port);
26 // L123-DEMO-HACK: END
Carmelo Cascone9ab40612017-09-19 16:31:55 +090027 if (hdr.packet_out.isValid()) {
28 packetio_ingress.apply(hdr, local_metadata, standard_metadata);
29 }
30 vrf.apply(hdr, local_metadata, standard_metadata);
31 class_id.apply(hdr, local_metadata, standard_metadata);
32 l3_fwd.apply(hdr, local_metadata, standard_metadata);
33 punt.apply(hdr, local_metadata, standard_metadata);
34 }
35} // end ingress_tor
36
37control egress_tor(inout parsed_packet_t hdr,
38 inout local_metadata_t local_metadata,
39 inout standard_metadata_t standard_metadata) {
Carmelo Cascone821fa522017-10-04 14:33:28 +020040 // L123-DEMO-HACK: BEGIN
41 counter(511, CounterType.packets_and_bytes) egress_port_counter;
42 // L123-DEMO-HACK: END
Carmelo Cascone9ab40612017-09-19 16:31:55 +090043 apply {
Carmelo Cascone821fa522017-10-04 14:33:28 +020044 // L123-DEMO-HACK: BEGIN
45 egress_port_counter.count((bit<32>) standard_metadata.egress_port);
46 // L123-DEMO-HACK: END
Carmelo Cascone9ab40612017-09-19 16:31:55 +090047 packetio_egress.apply(hdr, local_metadata, standard_metadata);
48 spoof_protection.apply(hdr, local_metadata, standard_metadata);
49 }
50}
51
52V1Switch(pkt_parser(), verify_checksum(), ingress_tor(), egress_tor(),
53 compute_checksum(), pkt_deparser()) main;