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" |
| 6 | |
| 7 | header_type ecmp_metadata_t { |
| 8 | fields { |
| 9 | groupId : 16; |
| 10 | selector : 16; |
Carmelo Cascone | fc3776d | 2017-08-21 23:17:22 +0200 | [diff] [blame] | 11 | groupSize : 32; // Not used. Workaround to avoid p4c complaining about inferring type to groupSize. |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 12 | } |
| 13 | } |
| 14 | |
| 15 | metadata ecmp_metadata_t ecmp_metadata; |
| 16 | |
| 17 | field_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 | |
| 27 | field_list_calculation ecmp_hash { |
| 28 | input { |
| 29 | ecmp_hash_fields; |
| 30 | } |
Carmelo Cascone | fc3776d | 2017-08-21 23:17:22 +0200 | [diff] [blame] | 31 | algorithm : crc32; |
| 32 | output_width : 32; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | action ecmp_group(groupId, groupSize) { |
| 36 | modify_field(ecmp_metadata.groupId, groupId); |
Carmelo Cascone | fc3776d | 2017-08-21 23:17:22 +0200 | [diff] [blame] | 37 | modify_field(ecmp_metadata.groupSize, groupSize); |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 38 | modify_field_with_hash_based_offset(ecmp_metadata.selector, 0, ecmp_hash, groupSize); |
| 39 | } |
| 40 | |
| 41 | table 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 Cascone | fc3776d | 2017-08-21 23:17:22 +0200 | [diff] [blame] | 52 | drop; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 53 | } |
| 54 | support_timeout: true; |
| 55 | } |
| 56 | |
| 57 | table 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 | |
| 67 | counter table0_counter { |
| 68 | type: packets; |
| 69 | direct: table0; |
| 70 | min_width : 32; |
| 71 | } |
| 72 | |
| 73 | counter ecmp_group_table_counter { |
| 74 | type: packets; |
| 75 | direct: ecmp_group_table; |
| 76 | min_width : 32; |
| 77 | } |
| 78 | |
| 79 | control ingress { |
| 80 | apply(table0) { |
| 81 | ecmp_group { |
| 82 | apply(ecmp_group_table); |
| 83 | } |
| 84 | } |
| 85 | process_port_counters(); |
| 86 | } |