blob: d24183f5b74f9c7f3f71ef098cc860216aa88bbd [file] [log] [blame]
Carmelo Cascone4f011022017-06-05 01:41:02 -04001#include "include/defines.p4"
2#include "include/headers.p4"
3#include "include/parser.p4"
4#include "include/actions.p4"
5#include "include/port_counters.p4"
6
Carmelo Casconefc3776d2017-08-21 23:17:22 +02007#define SELECTOR_WIDTH 32
Carmelo Cascone4f011022017-06-05 01:41:02 -04008
9header_type wcmp_meta_t {
10 fields {
11 groupId : 16;
12 numBits: 8;
13 selector : SELECTOR_WIDTH;
14 }
15}
16
17metadata wcmp_meta_t wcmp_meta;
18
19field_list wcmp_hash_fields {
20 ipv4.srcAddr;
21 ipv4.dstAddr;
22 ipv4.protocol;
23 tcp.srcPort;
24 tcp.dstPort;
25 udp.srcPort;
26 udp.dstPort;
27}
28
29field_list_calculation wcmp_hash {
30 input {
31 wcmp_hash_fields;
32 }
Carmelo Casconefc3776d2017-08-21 23:17:22 +020033 algorithm : crc32;
34 output_width : 32;
Carmelo Cascone4f011022017-06-05 01:41:02 -040035}
36
37action wcmp_group(groupId) {
38 modify_field(wcmp_meta.groupId, groupId);
39 modify_field_with_hash_based_offset(wcmp_meta.numBits, 2, wcmp_hash, (SELECTOR_WIDTH - 2));
40}
41
42action wcmp_set_selector() {
43 modify_field(wcmp_meta.selector,
44 (((1 << wcmp_meta.numBits) - 1) << (SELECTOR_WIDTH - wcmp_meta.numBits)));
45}
46
47table table0 {
48 reads {
49 standard_metadata.ingress_port : ternary;
50 ethernet.dstAddr : ternary;
51 ethernet.srcAddr : ternary;
52 ethernet.etherType : ternary;
53 }
54 actions {
55 set_egress_port;
56 wcmp_group;
57 send_to_cpu;
Carmelo Casconefc3776d2017-08-21 23:17:22 +020058 drop;
Carmelo Cascone4f011022017-06-05 01:41:02 -040059 }
60 support_timeout: true;
61}
62
63table wcmp_set_selector_table {
64 actions {
65 wcmp_set_selector;
66 }
67}
68
69table wcmp_group_table {
70 reads {
71 wcmp_meta.groupId : exact;
72 wcmp_meta.selector : lpm;
73 }
74 actions {
75 set_egress_port;
76 }
77}
78
79counter table0_counter {
80 type: packets;
81 direct: table0;
82 min_width : 32;
83}
84
85counter wcmp_group_table_counter {
86 type: packets;
87 direct: wcmp_group_table;
88 min_width : 32;
89}
90
91control ingress {
92 apply(table0) {
93 wcmp_group {
94 apply(wcmp_set_selector_table) {
95 wcmp_set_selector {
96 apply(wcmp_group_table);
97 }
98 }
99 }
100 }
101 process_port_counters();
102}