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 | |
Carmelo Cascone | fc3776d | 2017-08-21 23:17:22 +0200 | [diff] [blame] | 7 | #define SELECTOR_WIDTH 32 |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 8 | |
| 9 | header_type wcmp_meta_t { |
| 10 | fields { |
| 11 | groupId : 16; |
| 12 | numBits: 8; |
| 13 | selector : SELECTOR_WIDTH; |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | metadata wcmp_meta_t wcmp_meta; |
| 18 | |
| 19 | field_list wcmp_hash_fields { |
| 20 | ipv4.srcAddr; |
| 21 | ipv4.dstAddr; |
| 22 | ipv4.protocol; |
| 23 | tcp.srcPort; |
| 24 | tcp.dstPort; |
| 25 | udp.srcPort; |
| 26 | udp.dstPort; |
| 27 | } |
| 28 | |
| 29 | field_list_calculation wcmp_hash { |
| 30 | input { |
| 31 | wcmp_hash_fields; |
| 32 | } |
Carmelo Cascone | fc3776d | 2017-08-21 23:17:22 +0200 | [diff] [blame] | 33 | algorithm : crc32; |
| 34 | output_width : 32; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | action wcmp_group(groupId) { |
| 38 | modify_field(wcmp_meta.groupId, groupId); |
| 39 | modify_field_with_hash_based_offset(wcmp_meta.numBits, 2, wcmp_hash, (SELECTOR_WIDTH - 2)); |
| 40 | } |
| 41 | |
| 42 | action wcmp_set_selector() { |
| 43 | modify_field(wcmp_meta.selector, |
| 44 | (((1 << wcmp_meta.numBits) - 1) << (SELECTOR_WIDTH - wcmp_meta.numBits))); |
| 45 | } |
| 46 | |
| 47 | table table0 { |
| 48 | reads { |
| 49 | standard_metadata.ingress_port : ternary; |
| 50 | ethernet.dstAddr : ternary; |
| 51 | ethernet.srcAddr : ternary; |
| 52 | ethernet.etherType : ternary; |
| 53 | } |
| 54 | actions { |
| 55 | set_egress_port; |
| 56 | wcmp_group; |
| 57 | send_to_cpu; |
Carmelo Cascone | fc3776d | 2017-08-21 23:17:22 +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 wcmp_set_selector_table { |
| 64 | actions { |
| 65 | wcmp_set_selector; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | table wcmp_group_table { |
| 70 | reads { |
| 71 | wcmp_meta.groupId : exact; |
| 72 | wcmp_meta.selector : lpm; |
| 73 | } |
| 74 | actions { |
| 75 | set_egress_port; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | counter table0_counter { |
| 80 | type: packets; |
| 81 | direct: table0; |
| 82 | min_width : 32; |
| 83 | } |
| 84 | |
| 85 | counter wcmp_group_table_counter { |
| 86 | type: packets; |
| 87 | direct: wcmp_group_table; |
| 88 | min_width : 32; |
| 89 | } |
| 90 | |
| 91 | control ingress { |
| 92 | apply(table0) { |
| 93 | wcmp_group { |
| 94 | apply(wcmp_set_selector_table) { |
| 95 | wcmp_set_selector { |
| 96 | apply(wcmp_group_table); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | process_port_counters(); |
| 102 | } |