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