blob: a3514b4d646e0dcbf01feea0edfdf3944383bcb8 [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"
Carmelo Cascone16de6db2017-08-22 00:27:57 +02006#include "include/packet_io.p4"
Carmelo Cascone4f011022017-06-05 01:41:02 -04007
Carmelo Casconefc3776d2017-08-21 23:17:22 +02008#define SELECTOR_WIDTH 32
Carmelo Cascone4f011022017-06-05 01:41:02 -04009
10header_type wcmp_meta_t {
11 fields {
12 groupId : 16;
13 numBits: 8;
14 selector : SELECTOR_WIDTH;
15 }
16}
17
18metadata wcmp_meta_t wcmp_meta;
19
20field_list wcmp_hash_fields {
21 ipv4.srcAddr;
22 ipv4.dstAddr;
23 ipv4.protocol;
24 tcp.srcPort;
25 tcp.dstPort;
26 udp.srcPort;
27 udp.dstPort;
28}
29
30field_list_calculation wcmp_hash {
31 input {
32 wcmp_hash_fields;
33 }
Carmelo Casconefc3776d2017-08-21 23:17:22 +020034 algorithm : crc32;
35 output_width : 32;
Carmelo Cascone4f011022017-06-05 01:41:02 -040036}
37
38action wcmp_group(groupId) {
39 modify_field(wcmp_meta.groupId, groupId);
40 modify_field_with_hash_based_offset(wcmp_meta.numBits, 2, wcmp_hash, (SELECTOR_WIDTH - 2));
41}
42
43action wcmp_set_selector() {
44 modify_field(wcmp_meta.selector,
45 (((1 << wcmp_meta.numBits) - 1) << (SELECTOR_WIDTH - wcmp_meta.numBits)));
46}
47
48table table0 {
49 reads {
Carmelo Cascone16de6db2017-08-22 00:27:57 +020050 IGR_PORT_FIELD : ternary;
51 ethernet.dstAddr : ternary;
52 ethernet.srcAddr : ternary;
Carmelo Cascone4f011022017-06-05 01:41:02 -040053 ethernet.etherType : ternary;
54 }
55 actions {
56 set_egress_port;
57 wcmp_group;
58 send_to_cpu;
Carmelo Cascone16de6db2017-08-22 00:27:57 +020059 _drop;
Carmelo Cascone4f011022017-06-05 01:41:02 -040060 }
61 support_timeout: true;
62}
63
64table wcmp_set_selector_table {
65 actions {
66 wcmp_set_selector;
67 }
68}
69
70table wcmp_group_table {
71 reads {
72 wcmp_meta.groupId : exact;
73 wcmp_meta.selector : lpm;
74 }
75 actions {
76 set_egress_port;
77 }
78}
79
80counter table0_counter {
81 type: packets;
82 direct: table0;
83 min_width : 32;
84}
85
86counter wcmp_group_table_counter {
87 type: packets;
88 direct: wcmp_group_table;
89 min_width : 32;
90}
91
92control ingress {
Carmelo Cascone16de6db2017-08-22 00:27:57 +020093 if (not valid(packet_out_hdr)) {
94 apply(table0) {
95 wcmp_group {
96 apply(wcmp_set_selector_table) {
97 wcmp_set_selector {
98 apply(wcmp_group_table);
99 }
Carmelo Cascone4f011022017-06-05 01:41:02 -0400100 }
101 }
102 }
103 }
Carmelo Casconef2ac7202017-09-08 00:57:44 +0200104 ingress_pkt_io_control();
Carmelo Cascone4f011022017-06-05 01:41:02 -0400105 process_port_counters();
Carmelo Casconef2ac7202017-09-08 00:57:44 +0200106}