blob: b977d915102d4ee5bf5ed9673f23a6d60f13d5ca [file] [log] [blame]
Carmelo Casconec8d34862017-07-30 00:48:23 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Carmelo Casconec8d34862017-07-30 00:48:23 -04003 *
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 Tseng21629932017-06-06 11:17:43 -070017#include <core.p4>
18#include <v1model.p4>
19#include "include/defines.p4"
20#include "include/headers.p4"
Carmelo Cascone3304fd52017-07-30 00:43:01 -040021
22struct metadata_t {
23 intrinsic_metadata_t intrinsic_metadata;
Yi Tsengb62509b2017-08-12 20:01:50 -070024 ecmp_group_id_t ecmp_group_id;
Carmelo Cascone3304fd52017-07-30 00:43:01 -040025}
26
Yi Tseng21629932017-06-06 11:17:43 -070027#include "include/parsers.p4"
28#include "include/port_counters.p4"
29#include "include/checksums.p4"
30#include "include/actions.p4"
Carmelo Cascone837e6452017-07-19 20:35:22 -040031#include "include/packet_io.p4"
Yi Tseng21629932017-06-06 11:17:43 -070032
Carmelo Cascone837e6452017-07-19 20:35:22 -040033control ingress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) {
Yi Tseng21629932017-06-06 11:17:43 -070034 direct_counter(CounterType.packets) table0_counter;
Yi Tsengb62509b2017-08-12 20:01:50 -070035 direct_counter(CounterType.packets) ecmp_counter;
36
Carmelo Casconeb605cf02017-08-24 13:27:49 +020037 action do_ecmp(ecmp_group_id_t ecmp_group_id) {
Yi Tsengb62509b2017-08-12 20:01:50 -070038 meta.ecmp_group_id = ecmp_group_id;
39 }
Yi Tseng21629932017-06-06 11:17:43 -070040
41 table table0 {
Carmelo Cascone2cad9ef2017-08-01 21:52:07 +020042 /*
43 Disabling timeout here as P4runtime doesn't allow setting timeouts.
44 This way the FlowRuleTranslator will produce instances of PiTableEntry without timeout.
45 */
46 support_timeout = false;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040047 key = {
48 standard_metadata.ingress_port : ternary;
49 hdr.ethernet.dstAddr : ternary;
50 hdr.ethernet.srcAddr : ternary;
51 hdr.ethernet.etherType : ternary;
Yi Tsengb62509b2017-08-12 20:01:50 -070052 }
53 actions = {
54 set_egress_port(standard_metadata);
55 send_to_cpu(standard_metadata);
Carmelo Casconeb605cf02017-08-24 13:27:49 +020056 do_ecmp();
Yi Tsengb62509b2017-08-12 20:01:50 -070057 drop(standard_metadata);
58 }
59 counters = table0_counter;
Carmelo Casconeb605cf02017-08-24 13:27:49 +020060 default_action = drop(standard_metadata);
Yi Tsengb62509b2017-08-12 20:01:50 -070061 }
62
63 action_selector(HashAlgorithm.crc16, 32w64, 32w16) ecmp_selector;
64 table ecmp {
65 support_timeout = false;
Yi Tsengb62509b2017-08-12 20:01:50 -070066 key = {
67 meta.ecmp_group_id : exact;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040068 // Not for matching.
69 // Inputs to the hash function of the action selector.
Yi Tsengb62509b2017-08-12 20:01:50 -070070 hdr.ipv4.srcAddr : selector;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040071 hdr.ipv4.dstAddr : selector;
72 hdr.ipv4.protocol : selector;
73 hdr.tcp.srcPort : selector;
74 hdr.tcp.dstPort : selector;
75 hdr.udp.srcPort : selector;
Yi Tsengb62509b2017-08-12 20:01:50 -070076 hdr.udp.dstPort : selector;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040077 }
Yi Tseng21629932017-06-06 11:17:43 -070078 actions = {
79 set_egress_port(standard_metadata);
Yi Tseng21629932017-06-06 11:17:43 -070080 }
Yi Tsengb62509b2017-08-12 20:01:50 -070081 implementation = ecmp_selector;
82 counters = ecmp_counter;
Yi Tseng21629932017-06-06 11:17:43 -070083 }
Carmelo Cascone837e6452017-07-19 20:35:22 -040084
85 PacketIoIngressControl() packet_io_ingress_control;
Yi Tseng21629932017-06-06 11:17:43 -070086 PortCountersControl() port_counters_control;
Carmelo Cascone837e6452017-07-19 20:35:22 -040087
Yi Tseng21629932017-06-06 11:17:43 -070088 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -040089 packet_io_ingress_control.apply(hdr, standard_metadata);
90 if (!hdr.packet_out.isValid()) {
Yi Tsengb62509b2017-08-12 20:01:50 -070091 switch(table0.apply().action_run) {
92 do_ecmp: {
93 ecmp.apply();
94 }
95 }
Carmelo Cascone837e6452017-07-19 20:35:22 -040096 }
Yi Tsengb62509b2017-08-12 20:01:50 -070097
Yi Tseng21629932017-06-06 11:17:43 -070098 port_counters_control.apply(hdr, meta, standard_metadata);
99 }
Yi Tseng21629932017-06-06 11:17:43 -0700100}
101
Carmelo Cascone837e6452017-07-19 20:35:22 -0400102control egress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) {
103
104 PacketIoEgressControl() packet_io_egress_control;
Yi Tseng21629932017-06-06 11:17:43 -0700105 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -0400106 packet_io_egress_control.apply(hdr, standard_metadata);
Yi Tseng21629932017-06-06 11:17:43 -0700107 }
108}
109
Yi Tseng21629932017-06-06 11:17:43 -0700110V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;