blob: f751049c0d539f263e6d1a42c6b5e25b8d01beb7 [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
7header_type ecmp_metadata_t {
8 fields {
9 groupId : 16;
10 selector : 16;
Carmelo Casconefc3776d2017-08-21 23:17:22 +020011 groupSize : 32; // Not used. Workaround to avoid p4c complaining about inferring type to groupSize.
Carmelo Cascone4f011022017-06-05 01:41:02 -040012 }
13}
14
15metadata ecmp_metadata_t ecmp_metadata;
16
17field_list ecmp_hash_fields {
18 ipv4.srcAddr;
19 ipv4.dstAddr;
20 ipv4.protocol;
21 tcp.srcPort;
22 tcp.dstPort;
23 udp.srcPort;
24 udp.dstPort;
25}
26
27field_list_calculation ecmp_hash {
28 input {
29 ecmp_hash_fields;
30 }
Carmelo Casconefc3776d2017-08-21 23:17:22 +020031 algorithm : crc32;
32 output_width : 32;
Carmelo Cascone4f011022017-06-05 01:41:02 -040033}
34
35action ecmp_group(groupId, groupSize) {
36 modify_field(ecmp_metadata.groupId, groupId);
Carmelo Casconefc3776d2017-08-21 23:17:22 +020037 modify_field(ecmp_metadata.groupSize, groupSize);
Carmelo Cascone4f011022017-06-05 01:41:02 -040038 modify_field_with_hash_based_offset(ecmp_metadata.selector, 0, ecmp_hash, groupSize);
39}
40
41table table0 {
42 reads {
43 standard_metadata.ingress_port : ternary;
44 ethernet.dstAddr : ternary;
45 ethernet.srcAddr : ternary;
46 ethernet.etherType : ternary;
47 }
48 actions {
49 set_egress_port;
50 ecmp_group;
51 send_to_cpu;
Carmelo Casconefc3776d2017-08-21 23:17:22 +020052 drop;
Carmelo Cascone4f011022017-06-05 01:41:02 -040053 }
54 support_timeout: true;
55}
56
57table ecmp_group_table {
58 reads {
59 ecmp_metadata.groupId : exact;
60 ecmp_metadata.selector : exact;
61 }
62 actions {
63 set_egress_port;
64 }
65}
66
67counter table0_counter {
68 type: packets;
69 direct: table0;
70 min_width : 32;
71}
72
73counter ecmp_group_table_counter {
74 type: packets;
75 direct: ecmp_group_table;
76 min_width : 32;
77}
78
79control ingress {
80 apply(table0) {
81 ecmp_group {
82 apply(ecmp_group_table);
83 }
84 }
85 process_port_counters();
86}