Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 1 | #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 Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 6 | #include "include/packet_io.p4" |
| 7 | |
| 8 | /* |
Carmelo Cascone | f1d0a42 | 2017-09-07 17:21:46 +0200 | [diff] [blame] | 9 | Make sure to define ECMP_GROUP_SIZE at compile-time. |
| 10 | This is the expected number of ports of an ECMP group. |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 11 | This value is fixed, .i.e. we do not support ECMP over port groups of different size. |
| 12 | Due to hardware limitations, this value must be constant and a power of 2. |
| 13 | */ |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 14 | |
| 15 | header_type ecmp_metadata_t { |
| 16 | fields { |
Carmelo Cascone | 8aa0548 | 2017-09-12 13:21:59 +0200 | [diff] [blame^] | 17 | group_id : 16; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 18 | selector : 16; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | metadata ecmp_metadata_t ecmp_metadata; |
| 23 | |
| 24 | field_list ecmp_hash_fields { |
| 25 | ipv4.srcAddr; |
| 26 | ipv4.dstAddr; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 27 | udp.srcPort; |
| 28 | udp.dstPort; |
| 29 | } |
| 30 | |
| 31 | field_list_calculation ecmp_hash { |
| 32 | input { |
| 33 | ecmp_hash_fields; |
| 34 | } |
Carmelo Cascone | fc3776d | 2017-08-21 23:17:22 +0200 | [diff] [blame] | 35 | algorithm : crc32; |
| 36 | output_width : 32; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 37 | } |
| 38 | |
Carmelo Cascone | 8aa0548 | 2017-09-12 13:21:59 +0200 | [diff] [blame^] | 39 | action ecmp_group(group_id) { |
| 40 | modify_field(ecmp_metadata.group_id, group_id); |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 41 | modify_field_with_hash_based_offset(ecmp_metadata.selector, 0, ecmp_hash, ECMP_GROUP_SIZE); |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 42 | } |
| 43 | |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 44 | #ifdef __TOFINO_BUILD__ |
| 45 | @pragma immediate 0 |
| 46 | #endif |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 47 | table table0 { |
| 48 | reads { |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 49 | IGR_PORT_FIELD : ternary; |
| 50 | ethernet.dstAddr : ternary; |
| 51 | ethernet.srcAddr : ternary; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 52 | ethernet.etherType : ternary; |
| 53 | } |
| 54 | actions { |
| 55 | set_egress_port; |
| 56 | ecmp_group; |
| 57 | send_to_cpu; |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 58 | _drop; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 59 | } |
| 60 | support_timeout: true; |
| 61 | } |
| 62 | |
| 63 | table ecmp_group_table { |
| 64 | reads { |
Carmelo Cascone | 8aa0548 | 2017-09-12 13:21:59 +0200 | [diff] [blame^] | 65 | ecmp_metadata.group_id : exact; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 66 | ecmp_metadata.selector : exact; |
| 67 | } |
| 68 | actions { |
| 69 | set_egress_port; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | counter table0_counter { |
| 74 | type: packets; |
| 75 | direct: table0; |
| 76 | min_width : 32; |
| 77 | } |
| 78 | |
| 79 | counter ecmp_group_table_counter { |
| 80 | type: packets; |
| 81 | direct: ecmp_group_table; |
| 82 | min_width : 32; |
| 83 | } |
| 84 | |
| 85 | control ingress { |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 86 | if (not valid(packet_out_hdr)) { |
| 87 | apply(table0) { |
| 88 | ecmp_group { |
| 89 | apply(ecmp_group_table); |
| 90 | } |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 91 | } |
| 92 | } |
Carmelo Cascone | f2ac720 | 2017-09-08 00:57:44 +0200 | [diff] [blame] | 93 | ingress_pkt_io_control(); |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 94 | process_port_counters(); |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 95 | } |