| // Copyright (c) 2017, Google Inc. |
| // |
| // P4_16 specification for a VRF classifier. |
| // Note: This code has not been tested and is expected to contain bugs. |
| |
| #ifndef P4_SPEC_VRF_P4_ |
| #define P4_SPEC_VRF_P4_ |
| |
| #include "headers.p4" |
| #include "parser.p4" |
| |
| //------------------------------------------------------------------------------ |
| // Global defines |
| //------------------------------------------------------------------------------ |
| |
| #define DEFAULT_VRF0 0 |
| |
| //------------------------------------------------------------------------------ |
| // Map traffic to a particular VRF |
| //------------------------------------------------------------------------------ |
| |
| control vrf(inout parsed_packet_t hdr, inout local_metadata_t local_metadata, |
| inout standard_metadata_t standard_metadata) { |
| |
| @proto_package("vrf") |
| action set_vrf(@proto_tag(1) bit<32> vrf_id) { |
| local_metadata.vrf_id = vrf_id; |
| } |
| |
| @proto_package("vrf") |
| table vrf_classifier_table { |
| key = { |
| hdr.ethernet.ether_type : exact @proto_tag(1); |
| hdr.ethernet.src_addr : ternary @proto_tag(2); |
| hdr.ipv4_base.diffserv : ternary @proto_tag(3); |
| hdr.ipv4_base.dst_addr : ternary @proto_tag(4); |
| standard_metadata.ingress_port: exact @proto_tag(5); |
| hdr.ipv6_base.traffic_class : ternary @proto_tag(6); |
| hdr.ipv6_base.dst_addr : ternary @proto_tag(7); |
| } |
| actions = { |
| @proto_tag(1) set_vrf; |
| } |
| const default_action = set_vrf(DEFAULT_VRF0); |
| } |
| |
| apply { |
| vrf_classifier_table.apply(); |
| } |
| } // end vrf |
| |
| #endif // P4_SPEC_VRF_P4_ |