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