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 | |
Yi Tseng | 60ef61d | 2017-08-29 14:20:33 -0700 | [diff] [blame] | 22 | struct ecmp_metadata_t { |
| 23 | ecmp_group_id_t ecmp_group_id; |
| 24 | } |
| 25 | |
Carmelo Cascone | 3304fd5 | 2017-07-30 00:43:01 -0400 | [diff] [blame] | 26 | struct metadata_t { |
| 27 | intrinsic_metadata_t intrinsic_metadata; |
Yi Tseng | 60ef61d | 2017-08-29 14:20:33 -0700 | [diff] [blame] | 28 | ecmp_metadata_t ecmp_metadata; |
Carmelo Cascone | 3304fd5 | 2017-07-30 00:43:01 -0400 | [diff] [blame] | 29 | } |
| 30 | |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 31 | #include "include/parsers.p4" |
| 32 | #include "include/port_counters.p4" |
| 33 | #include "include/checksums.p4" |
| 34 | #include "include/actions.p4" |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 35 | #include "include/packet_io.p4" |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 36 | |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 37 | control ingress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) { |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 38 | direct_counter(CounterType.packets) table0_counter; |
Yi Tseng | b62509b | 2017-08-12 20:01:50 -0700 | [diff] [blame] | 39 | direct_counter(CounterType.packets) ecmp_counter; |
| 40 | |
Carmelo Cascone | b605cf0 | 2017-08-24 13:27:49 +0200 | [diff] [blame] | 41 | action do_ecmp(ecmp_group_id_t ecmp_group_id) { |
Yi Tseng | 60ef61d | 2017-08-29 14:20:33 -0700 | [diff] [blame] | 42 | meta.ecmp_metadata.ecmp_group_id = ecmp_group_id; |
Yi Tseng | b62509b | 2017-08-12 20:01:50 -0700 | [diff] [blame] | 43 | } |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 44 | |
| 45 | table table0 { |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 46 | /* |
| 47 | Disabling timeout here as P4runtime doesn't allow setting timeouts. |
| 48 | This way the FlowRuleTranslator will produce instances of PiTableEntry without timeout. |
| 49 | */ |
| 50 | support_timeout = false; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 51 | key = { |
| 52 | standard_metadata.ingress_port : ternary; |
| 53 | hdr.ethernet.dstAddr : ternary; |
| 54 | hdr.ethernet.srcAddr : ternary; |
| 55 | hdr.ethernet.etherType : ternary; |
Yi Tseng | b62509b | 2017-08-12 20:01:50 -0700 | [diff] [blame] | 56 | } |
| 57 | actions = { |
| 58 | set_egress_port(standard_metadata); |
| 59 | send_to_cpu(standard_metadata); |
Carmelo Cascone | b605cf0 | 2017-08-24 13:27:49 +0200 | [diff] [blame] | 60 | do_ecmp(); |
Yi Tseng | b62509b | 2017-08-12 20:01:50 -0700 | [diff] [blame] | 61 | drop(standard_metadata); |
| 62 | } |
| 63 | counters = table0_counter; |
Carmelo Cascone | b605cf0 | 2017-08-24 13:27:49 +0200 | [diff] [blame] | 64 | default_action = drop(standard_metadata); |
Yi Tseng | b62509b | 2017-08-12 20:01:50 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | action_selector(HashAlgorithm.crc16, 32w64, 32w16) ecmp_selector; |
| 68 | table ecmp { |
| 69 | support_timeout = false; |
Yi Tseng | b62509b | 2017-08-12 20:01:50 -0700 | [diff] [blame] | 70 | key = { |
Yi Tseng | 60ef61d | 2017-08-29 14:20:33 -0700 | [diff] [blame] | 71 | meta.ecmp_metadata.ecmp_group_id : exact; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 72 | // Not for matching. |
| 73 | // Inputs to the hash function of the action selector. |
Yi Tseng | b62509b | 2017-08-12 20:01:50 -0700 | [diff] [blame] | 74 | hdr.ipv4.srcAddr : selector; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 75 | hdr.ipv4.dstAddr : selector; |
| 76 | hdr.ipv4.protocol : selector; |
| 77 | hdr.tcp.srcPort : selector; |
| 78 | hdr.tcp.dstPort : selector; |
| 79 | hdr.udp.srcPort : selector; |
Yi Tseng | b62509b | 2017-08-12 20:01:50 -0700 | [diff] [blame] | 80 | hdr.udp.dstPort : selector; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 81 | } |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 82 | actions = { |
| 83 | set_egress_port(standard_metadata); |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 84 | } |
Yi Tseng | b62509b | 2017-08-12 20:01:50 -0700 | [diff] [blame] | 85 | implementation = ecmp_selector; |
| 86 | counters = ecmp_counter; |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 87 | } |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 88 | |
| 89 | PacketIoIngressControl() packet_io_ingress_control; |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 90 | PortCountersControl() port_counters_control; |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 91 | |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 92 | apply { |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 93 | packet_io_ingress_control.apply(hdr, standard_metadata); |
| 94 | if (!hdr.packet_out.isValid()) { |
Yi Tseng | b62509b | 2017-08-12 20:01:50 -0700 | [diff] [blame] | 95 | switch(table0.apply().action_run) { |
| 96 | do_ecmp: { |
| 97 | ecmp.apply(); |
| 98 | } |
| 99 | } |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 100 | } |
Yi Tseng | b62509b | 2017-08-12 20:01:50 -0700 | [diff] [blame] | 101 | |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 102 | port_counters_control.apply(hdr, meta, standard_metadata); |
| 103 | } |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 106 | control egress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) { |
| 107 | |
| 108 | PacketIoEgressControl() packet_io_egress_control; |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 109 | apply { |
Carmelo Cascone | 837e645 | 2017-07-19 20:35:22 -0400 | [diff] [blame] | 110 | packet_io_egress_control.apply(hdr, standard_metadata); |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
Yi Tseng | 2162993 | 2017-06-06 11:17:43 -0700 | [diff] [blame] | 114 | V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; |