blob: 341e1e1829c18602f0b9b304205301a8eeffedae [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"
7
8/*
9 Expected number of ports of an ECMP group.
10 This value is fixed, .i.e. we do not support ECMP over port groups of different size.
11 Due to hardware limitations, this value must be constant and a power of 2.
12*/
13#define ECMP_GROUP_SIZE 4
Carmelo Cascone4f011022017-06-05 01:41:02 -040014
15header_type ecmp_metadata_t {
16 fields {
17 groupId : 16;
18 selector : 16;
19 }
20}
21
22metadata ecmp_metadata_t ecmp_metadata;
23
24field_list ecmp_hash_fields {
25 ipv4.srcAddr;
26 ipv4.dstAddr;
27 ipv4.protocol;
28 tcp.srcPort;
29 tcp.dstPort;
30 udp.srcPort;
31 udp.dstPort;
32}
33
34field_list_calculation ecmp_hash {
35 input {
36 ecmp_hash_fields;
37 }
Carmelo Casconefc3776d2017-08-21 23:17:22 +020038 algorithm : crc32;
39 output_width : 32;
Carmelo Cascone4f011022017-06-05 01:41:02 -040040}
41
Carmelo Cascone16de6db2017-08-22 00:27:57 +020042action ecmp_group(groupId) {
Carmelo Cascone4f011022017-06-05 01:41:02 -040043 modify_field(ecmp_metadata.groupId, groupId);
Carmelo Cascone16de6db2017-08-22 00:27:57 +020044 modify_field_with_hash_based_offset(ecmp_metadata.selector, 0, ecmp_hash, ECMP_GROUP_SIZE);
Carmelo Cascone4f011022017-06-05 01:41:02 -040045}
46
Carmelo Cascone16de6db2017-08-22 00:27:57 +020047#ifdef __TOFINO_BUILD__
48@pragma immediate 0
49#endif
Carmelo Cascone4f011022017-06-05 01:41:02 -040050table table0 {
51 reads {
Carmelo Cascone16de6db2017-08-22 00:27:57 +020052 IGR_PORT_FIELD : ternary;
53 ethernet.dstAddr : ternary;
54 ethernet.srcAddr : ternary;
Carmelo Cascone4f011022017-06-05 01:41:02 -040055 ethernet.etherType : ternary;
56 }
57 actions {
58 set_egress_port;
59 ecmp_group;
60 send_to_cpu;
Carmelo Cascone16de6db2017-08-22 00:27:57 +020061 _drop;
Carmelo Cascone4f011022017-06-05 01:41:02 -040062 }
63 support_timeout: true;
64}
65
66table ecmp_group_table {
67 reads {
68 ecmp_metadata.groupId : exact;
69 ecmp_metadata.selector : exact;
70 }
71 actions {
72 set_egress_port;
73 }
74}
75
76counter table0_counter {
77 type: packets;
78 direct: table0;
79 min_width : 32;
80}
81
82counter ecmp_group_table_counter {
83 type: packets;
84 direct: ecmp_group_table;
85 min_width : 32;
86}
87
88control ingress {
Carmelo Cascone16de6db2017-08-22 00:27:57 +020089 ingress_pkt_io();
90 if (not valid(packet_out_hdr)) {
91 apply(table0) {
92 ecmp_group {
93 apply(ecmp_group_table);
94 }
Carmelo Cascone4f011022017-06-05 01:41:02 -040095 }
96 }
97 process_port_counters();
Carmelo Cascone16de6db2017-08-22 00:27:57 +020098}
99
100control egress {
101 egress_pkt_io();
Carmelo Cascone4f011022017-06-05 01:41:02 -0400102}