Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 1 | #include <core.p4> |
| 2 | #include <v1model.p4> |
| 3 | #include "include/defines.p4" |
| 4 | #include "include/headers.p4" |
Carmelo Cascone | 3304fd5 | 2017-07-30 00:43:01 -0400 | [diff] [blame^] | 5 | |
| 6 | #define SELECTOR_WIDTH 64 |
| 7 | const bit<SELECTOR_WIDTH> ONE = 64w1; |
| 8 | |
| 9 | typedef bit<16> group_id_t; |
| 10 | |
| 11 | struct wcmp_metadata_t { |
| 12 | group_id_t group_id; |
| 13 | bit<8> numBits; |
| 14 | bit<SELECTOR_WIDTH> selector; |
| 15 | } |
| 16 | |
| 17 | struct metadata_t { |
| 18 | wcmp_metadata_t wcmp_metadata; |
| 19 | intrinsic_metadata_t intrinsic_metadata; |
| 20 | } |
| 21 | |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 22 | #include "include/parsers.p4" |
| 23 | #include "include/port_counters.p4" |
| 24 | #include "include/checksums.p4" |
| 25 | #include "include/actions.p4" |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 26 | #include "include/packet_io.p4" |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 27 | |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 28 | control ingress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) { |
| 29 | |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 30 | direct_counter(CounterType.packets) table0_counter; |
| 31 | direct_counter(CounterType.packets) wcmp_group_table_counter; |
| 32 | |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 33 | action wcmp_group(group_id_t group_id) { |
Carmelo Cascone | 3304fd5 | 2017-07-30 00:43:01 -0400 | [diff] [blame^] | 34 | meta.wcmp_metadata.group_id = group_id; |
| 35 | hash(meta.wcmp_metadata.numBits, HashAlgorithm.crc16, (bit<64>)2, |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 36 | { hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.ipv4.protocol, hdr.tcp.srcPort, hdr.tcp.dstPort, hdr.udp.srcPort, |
| 37 | hdr.udp.dstPort }, |
| 38 | (bit<128>)62); |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | action wcmp_set_selector() { |
Carmelo Cascone | 3304fd5 | 2017-07-30 00:43:01 -0400 | [diff] [blame^] | 42 | meta.wcmp_metadata.selector = ((ONE << meta.wcmp_metadata.numBits) - ONE) << (SELECTOR_WIDTH - meta.wcmp_metadata.numBits); |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | table table0 { |
| 46 | support_timeout = true; |
| 47 | actions = { |
| 48 | set_egress_port(standard_metadata); |
| 49 | wcmp_group; |
| 50 | send_to_cpu(standard_metadata); |
| 51 | drop(standard_metadata); |
| 52 | } |
| 53 | key = { |
| 54 | standard_metadata.ingress_port: ternary; |
| 55 | hdr.ethernet.dstAddr : ternary; |
| 56 | hdr.ethernet.srcAddr : ternary; |
| 57 | hdr.ethernet.etherType : ternary; |
| 58 | } |
| 59 | counters = table0_counter; |
| 60 | } |
| 61 | |
| 62 | table wcmp_group_table { |
| 63 | actions = { |
| 64 | set_egress_port(standard_metadata); |
| 65 | } |
| 66 | key = { |
Carmelo Cascone | 3304fd5 | 2017-07-30 00:43:01 -0400 | [diff] [blame^] | 67 | meta.wcmp_metadata.group_id : exact; |
| 68 | meta.wcmp_metadata.selector: lpm; |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 69 | } |
| 70 | counters = wcmp_group_table_counter; |
| 71 | } |
| 72 | |
| 73 | PortCountersControl() port_counters_control; |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 74 | PacketIoIngressControl() packet_io_ingress_control; |
| 75 | |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 76 | apply { |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 77 | packet_io_ingress_control.apply(hdr, standard_metadata); |
| 78 | if (!hdr.packet_out.isValid()) { |
| 79 | switch (table0.apply().action_run) { |
| 80 | wcmp_group: { |
| 81 | wcmp_set_selector(); |
| 82 | wcmp_group_table.apply(); |
| 83 | } |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | port_counters_control.apply(hdr, meta, standard_metadata); |
| 87 | } |
| 88 | } |
| 89 | |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 90 | control egress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) { |
| 91 | |
| 92 | PacketIoEgressControl() packet_io_egress_control; |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 93 | apply { |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 94 | packet_io_egress_control.apply(hdr, standard_metadata); |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; |