blob: 326dce7f28bdbb1dd8f89d27c61ebe789ac82bac [file] [log] [blame]
Carmelo Cascone9ab40612017-09-19 16:31:55 +09001// Copyright (c) 2017, Google Inc.
2//
3// P4_16 specification for a Class ID assignment table.
4// Note: This code has not been tested and is expected to contain bugs.
5
6#ifndef P4_SPEC_CLASS_ID_P4_
7#define P4_SPEC_CLASS_ID_P4_
8
9#include "headers.p4"
10#include "parser.p4"
11
12//------------------------------------------------------------------------------
13// Packet Classification
14//------------------------------------------------------------------------------
15
16control class_id(inout parsed_packet_t hdr,
17 inout local_metadata_t local_metadata,
18 inout standard_metadata_t standard_metadata) {
19
20 @proto_package("class_id")
21 action set_class_id(@proto_tag(1) bit<8> class_id_value) {
22 local_metadata.class_id = class_id_value;
23 }
24
25 @proto_package("class_id")
26 table class_id_assignment_table {
27 key = {
28 hdr.ethernet.ether_type: exact @proto_tag(1);
29
30 hdr.ipv4_base.ttl: ternary @proto_tag(2);
31 hdr.ipv6_base.hop_limit: ternary @proto_tag(3);
32 hdr.ipv4_base.dst_addr: ternary @proto_tag(4);
33 hdr.ipv6_base.dst_addr: ternary @proto_tag(5);
34 hdr.ipv4_base.protocol: ternary @proto_tag(6);
35 hdr.ipv6_base.next_header: ternary @proto_tag(7);
36
37 local_metadata.l4_src_port: ternary @proto_tag(8);
38 local_metadata.l4_dst_port: ternary @proto_tag(9);
39
40 hdr.vlan_tag[0].vid: ternary @proto_tag(10);
41 hdr.vlan_tag[0].pcp: ternary @proto_tag(11);
42 }
43 actions = {
44 @proto_tag(1) set_class_id;
45 }
46 const default_action = set_class_id(0);
47 }
48 apply {
49 class_id_assignment_table.apply();
50 }
51
52} // end class_id
53
54#endif // P4_SPEC_CLASS_ID_P4_