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; |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | metadata ecmp_metadata_t ecmp_metadata; |
| 15 | |
| 16 | field_list ecmp_hash_fields { |
| 17 | ipv4.srcAddr; |
| 18 | ipv4.dstAddr; |
| 19 | ipv4.protocol; |
| 20 | tcp.srcPort; |
| 21 | tcp.dstPort; |
| 22 | udp.srcPort; |
| 23 | udp.dstPort; |
| 24 | } |
| 25 | |
| 26 | field_list_calculation ecmp_hash { |
| 27 | input { |
| 28 | ecmp_hash_fields; |
| 29 | } |
| 30 | algorithm : bmv2_hash; |
| 31 | output_width : 64; |
| 32 | } |
| 33 | |
| 34 | action ecmp_group(groupId, groupSize) { |
| 35 | modify_field(ecmp_metadata.groupId, groupId); |
| 36 | modify_field_with_hash_based_offset(ecmp_metadata.selector, 0, ecmp_hash, groupSize); |
| 37 | } |
| 38 | |
| 39 | table table0 { |
| 40 | reads { |
| 41 | standard_metadata.ingress_port : ternary; |
| 42 | ethernet.dstAddr : ternary; |
| 43 | ethernet.srcAddr : ternary; |
| 44 | ethernet.etherType : ternary; |
| 45 | } |
| 46 | actions { |
| 47 | set_egress_port; |
| 48 | ecmp_group; |
| 49 | send_to_cpu; |
| 50 | _drop; |
| 51 | } |
| 52 | support_timeout: true; |
| 53 | } |
| 54 | |
| 55 | table ecmp_group_table { |
| 56 | reads { |
| 57 | ecmp_metadata.groupId : exact; |
| 58 | ecmp_metadata.selector : exact; |
| 59 | } |
| 60 | actions { |
| 61 | set_egress_port; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | counter table0_counter { |
| 66 | type: packets; |
| 67 | direct: table0; |
| 68 | min_width : 32; |
| 69 | } |
| 70 | |
| 71 | counter ecmp_group_table_counter { |
| 72 | type: packets; |
| 73 | direct: ecmp_group_table; |
| 74 | min_width : 32; |
| 75 | } |
| 76 | |
| 77 | control ingress { |
| 78 | apply(table0) { |
| 79 | ecmp_group { |
| 80 | apply(ecmp_group_table); |
| 81 | } |
| 82 | } |
| 83 | process_port_counters(); |
| 84 | } |