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 | /* |
| 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 Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 14 | |
| 15 | header_type ecmp_metadata_t { |
| 16 | fields { |
| 17 | groupId : 16; |
| 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; |
| 27 | ipv4.protocol; |
| 28 | tcp.srcPort; |
| 29 | tcp.dstPort; |
| 30 | udp.srcPort; |
| 31 | udp.dstPort; |
| 32 | } |
| 33 | |
| 34 | field_list_calculation ecmp_hash { |
| 35 | input { |
| 36 | ecmp_hash_fields; |
| 37 | } |
Carmelo Cascone | fc3776d | 2017-08-21 23:17:22 +0200 | [diff] [blame] | 38 | algorithm : crc32; |
| 39 | output_width : 32; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 40 | } |
| 41 | |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 42 | action ecmp_group(groupId) { |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 43 | modify_field(ecmp_metadata.groupId, groupId); |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 44 | 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] | 45 | } |
| 46 | |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 47 | #ifdef __TOFINO_BUILD__ |
| 48 | @pragma immediate 0 |
| 49 | #endif |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 50 | table table0 { |
| 51 | reads { |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 52 | IGR_PORT_FIELD : ternary; |
| 53 | ethernet.dstAddr : ternary; |
| 54 | ethernet.srcAddr : ternary; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 55 | ethernet.etherType : ternary; |
| 56 | } |
| 57 | actions { |
| 58 | set_egress_port; |
| 59 | ecmp_group; |
| 60 | send_to_cpu; |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 61 | _drop; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 62 | } |
| 63 | support_timeout: true; |
| 64 | } |
| 65 | |
| 66 | table 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 | |
| 76 | counter table0_counter { |
| 77 | type: packets; |
| 78 | direct: table0; |
| 79 | min_width : 32; |
| 80 | } |
| 81 | |
| 82 | counter ecmp_group_table_counter { |
| 83 | type: packets; |
| 84 | direct: ecmp_group_table; |
| 85 | min_width : 32; |
| 86 | } |
| 87 | |
| 88 | control ingress { |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 89 | ingress_pkt_io(); |
| 90 | if (not valid(packet_out_hdr)) { |
| 91 | apply(table0) { |
| 92 | ecmp_group { |
| 93 | apply(ecmp_group_table); |
| 94 | } |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | process_port_counters(); |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | control egress { |
| 101 | egress_pkt_io(); |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 102 | } |