Carmelo Cascone | 9ab4061 | 2017-09-19 16:31:55 +0900 | [diff] [blame] | 1 | // 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 | |
| 17 | control ingress_tor(inout parsed_packet_t hdr, |
| 18 | inout local_metadata_t local_metadata, |
| 19 | inout standard_metadata_t standard_metadata) { |
Carmelo Cascone | 821fa52 | 2017-10-04 14:33:28 +0200 | [diff] [blame^] | 20 | // L123-DEMO-HACK: BEGIN |
| 21 | counter(511, CounterType.packets_and_bytes) ingress_port_counter; |
| 22 | // L123-DEMO-HACK: END |
Carmelo Cascone | 9ab4061 | 2017-09-19 16:31:55 +0900 | [diff] [blame] | 23 | apply { |
Carmelo Cascone | 821fa52 | 2017-10-04 14:33:28 +0200 | [diff] [blame^] | 24 | // L123-DEMO-HACK: BEGIN |
| 25 | ingress_port_counter.count((bit<32>) standard_metadata.ingress_port); |
| 26 | // L123-DEMO-HACK: END |
Carmelo Cascone | 9ab4061 | 2017-09-19 16:31:55 +0900 | [diff] [blame] | 27 | 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 | |
| 37 | control egress_tor(inout parsed_packet_t hdr, |
| 38 | inout local_metadata_t local_metadata, |
| 39 | inout standard_metadata_t standard_metadata) { |
Carmelo Cascone | 821fa52 | 2017-10-04 14:33:28 +0200 | [diff] [blame^] | 40 | // L123-DEMO-HACK: BEGIN |
| 41 | counter(511, CounterType.packets_and_bytes) egress_port_counter; |
| 42 | // L123-DEMO-HACK: END |
Carmelo Cascone | 9ab4061 | 2017-09-19 16:31:55 +0900 | [diff] [blame] | 43 | apply { |
Carmelo Cascone | 821fa52 | 2017-10-04 14:33:28 +0200 | [diff] [blame^] | 44 | // L123-DEMO-HACK: BEGIN |
| 45 | egress_port_counter.count((bit<32>) standard_metadata.egress_port); |
| 46 | // L123-DEMO-HACK: END |
Carmelo Cascone | 9ab4061 | 2017-09-19 16:31:55 +0900 | [diff] [blame] | 47 | packetio_egress.apply(hdr, local_metadata, standard_metadata); |
| 48 | spoof_protection.apply(hdr, local_metadata, standard_metadata); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | V1Switch(pkt_parser(), verify_checksum(), ingress_tor(), egress_tor(), |
| 53 | compute_checksum(), pkt_deparser()) main; |