Carmelo Cascone | c8d3486 | 2017-07-30 00:48:23 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | c8d3486 | 2017-07-30 00:48:23 -0400 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 17 | #include <core.p4> |
| 18 | #include <v1model.p4> |
| 19 | #include "include/defines.p4" |
| 20 | #include "include/headers.p4" |
Carmelo Cascone | 3304fd5 | 2017-07-30 00:43:01 -0400 | [diff] [blame] | 21 | |
| 22 | typedef bit<16> group_id_t; |
| 23 | typedef bit<8> group_size_t; |
| 24 | |
| 25 | struct ecmp_metadata_t { |
| 26 | group_id_t group_id; |
| 27 | bit<16> selector; |
| 28 | } |
| 29 | |
| 30 | struct metadata_t { |
| 31 | ecmp_metadata_t ecmp_metadata; |
| 32 | intrinsic_metadata_t intrinsic_metadata; |
| 33 | } |
| 34 | |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 35 | #include "include/parsers.p4" |
| 36 | #include "include/port_counters.p4" |
| 37 | #include "include/checksums.p4" |
| 38 | #include "include/actions.p4" |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 39 | #include "include/packet_io.p4" |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 40 | |
| 41 | |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 42 | control ingress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) { |
| 43 | |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 44 | direct_counter(CounterType.packets) ecmp_group_table_counter; |
| 45 | direct_counter(CounterType.packets) table0_counter; |
| 46 | |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 47 | action ecmp_group(group_id_t group_id, group_size_t groupSize) { |
| 48 | meta.ecmp_metadata.group_id = group_id; |
| 49 | hash(meta.ecmp_metadata.selector, HashAlgorithm.crc16, (bit<64>)0, |
| 50 | { hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.ipv4.protocol, hdr.tcp.srcPort, hdr.tcp.dstPort, hdr.udp.srcPort, |
| 51 | hdr.udp.dstPort }, |
| 52 | (bit<128>)groupSize); |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | table ecmp_group_table { |
| 56 | actions = { |
| 57 | set_egress_port(standard_metadata); |
| 58 | } |
| 59 | key = { |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 60 | meta.ecmp_metadata.group_id : exact; |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 61 | meta.ecmp_metadata.selector: exact; |
| 62 | } |
| 63 | counters = ecmp_group_table_counter; |
| 64 | } |
| 65 | |
| 66 | table table0 { |
| 67 | support_timeout = true; |
| 68 | actions = { |
| 69 | ecmp_group; |
| 70 | set_egress_port(standard_metadata); |
| 71 | send_to_cpu(standard_metadata); |
| 72 | drop(standard_metadata); |
| 73 | } |
| 74 | key = { |
| 75 | standard_metadata.ingress_port: ternary; |
| 76 | hdr.ethernet.dstAddr : ternary; |
| 77 | hdr.ethernet.srcAddr : ternary; |
| 78 | hdr.ethernet.etherType : ternary; |
| 79 | } |
| 80 | counters = table0_counter; |
| 81 | } |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 82 | |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 83 | PortCountersControl() port_counters_control; |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 84 | PacketIoIngressControl() packet_io_ingress_control; |
| 85 | |
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_ingress_control.apply(hdr, standard_metadata); |
| 88 | if (!hdr.packet_out.isValid()) { |
| 89 | switch (table0.apply().action_run) { |
| 90 | ecmp_group: { |
| 91 | ecmp_group_table.apply(); |
| 92 | } |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 93 | } |
| 94 | } |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 95 | port_counters_control.apply(hdr, meta, standard_metadata); |
| 96 | } |
| 97 | } |
| 98 | |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 99 | control egress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) { |
| 100 | |
| 101 | PacketIoEgressControl() packet_io_egress_control; |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 102 | apply { |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 103 | packet_io_egress_control.apply(hdr, standard_metadata); |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
| 107 | V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; |