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 VRF classifier. |
| 4 | // Note: This code has not been tested and is expected to contain bugs. |
| 5 | |
| 6 | #ifndef P4_SPEC_VRF_P4_ |
| 7 | #define P4_SPEC_VRF_P4_ |
| 8 | |
| 9 | #include "headers.p4" |
| 10 | #include "parser.p4" |
| 11 | |
| 12 | //------------------------------------------------------------------------------ |
| 13 | // Global defines |
| 14 | //------------------------------------------------------------------------------ |
| 15 | |
| 16 | #define DEFAULT_VRF0 0 |
| 17 | |
| 18 | //------------------------------------------------------------------------------ |
| 19 | // Map traffic to a particular VRF |
| 20 | //------------------------------------------------------------------------------ |
| 21 | |
| 22 | control vrf(inout parsed_packet_t hdr, inout local_metadata_t local_metadata, |
| 23 | inout standard_metadata_t standard_metadata) { |
| 24 | |
| 25 | @proto_package("vrf") |
| 26 | action set_vrf(@proto_tag(1) bit<32> vrf_id) { |
| 27 | local_metadata.vrf_id = vrf_id; |
| 28 | } |
| 29 | |
| 30 | @proto_package("vrf") |
| 31 | table vrf_classifier_table { |
| 32 | key = { |
| 33 | hdr.ethernet.ether_type : exact @proto_tag(1); |
| 34 | hdr.ethernet.src_addr : ternary @proto_tag(2); |
| 35 | hdr.ipv4_base.diffserv : ternary @proto_tag(3); |
| 36 | hdr.ipv4_base.dst_addr : ternary @proto_tag(4); |
| 37 | standard_metadata.ingress_port: exact @proto_tag(5); |
| 38 | hdr.ipv6_base.traffic_class : ternary @proto_tag(6); |
| 39 | hdr.ipv6_base.dst_addr : ternary @proto_tag(7); |
| 40 | } |
| 41 | actions = { |
| 42 | @proto_tag(1) set_vrf; |
| 43 | } |
| 44 | const default_action = set_vrf(DEFAULT_VRF0); |
| 45 | } |
| 46 | |
| 47 | apply { |
| 48 | vrf_classifier_table.apply(); |
| 49 | } |
| 50 | } // end vrf |
| 51 | |
| 52 | #endif // P4_SPEC_VRF_P4_ |