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