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