blob: c571331d6b76ec17e6a0e6a1ad59e70c62d10737 [file] [log] [blame]
Carmelo Casconec8d34862017-07-30 00:48:23 -04001/*
2 * Copyright 2017-present Open Networking Laboratory
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 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;
24}
25
Yi Tseng21629932017-06-06 11:17:43 -070026#include "include/parsers.p4"
27#include "include/port_counters.p4"
28#include "include/checksums.p4"
29#include "include/actions.p4"
Carmelo Cascone837e6452017-07-19 20:35:22 -040030#include "include/packet_io.p4"
Yi Tseng21629932017-06-06 11:17:43 -070031
Carmelo Cascone837e6452017-07-19 20:35:22 -040032control ingress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) {
33
Carmelo Cascone2cad9ef2017-08-01 21:52:07 +020034 /*
35 FIXME:
36 It seems that with BMv2 it is not possible to use the same indirect table (like table0 with the
37 implementation attribute enabled), with table entries that use direct actions (e.g. send_to_cpu()).
38 A separate table for ECMP should be created.
39 */
40
Yi Tseng21629932017-06-06 11:17:43 -070041 direct_counter(CounterType.packets) table0_counter;
Carmelo Cascone2cad9ef2017-08-01 21:52:07 +020042 // action_selector(HashAlgorithm.crc16, 32w64, 32w16) ecmp_selector;
Yi Tseng21629932017-06-06 11:17:43 -070043
44 table table0 {
Carmelo Cascone2cad9ef2017-08-01 21:52:07 +020045 /*
46 Disabling timeout here as P4runtime doesn't allow setting timeouts.
47 This way the FlowRuleTranslator will produce instances of PiTableEntry without timeout.
48 */
49 support_timeout = false;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040050 key = {
51 standard_metadata.ingress_port : ternary;
52 hdr.ethernet.dstAddr : ternary;
53 hdr.ethernet.srcAddr : ternary;
54 hdr.ethernet.etherType : ternary;
55 // Not for matching.
56 // Inputs to the hash function of the action selector.
Carmelo Cascone2cad9ef2017-08-01 21:52:07 +020057 /* hdr.ipv4.srcAddr : selector;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040058 hdr.ipv4.dstAddr : selector;
59 hdr.ipv4.protocol : selector;
60 hdr.tcp.srcPort : selector;
61 hdr.tcp.dstPort : selector;
62 hdr.udp.srcPort : selector;
Carmelo Cascone2cad9ef2017-08-01 21:52:07 +020063 hdr.udp.dstPort : selector; */
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040064 }
Yi Tseng21629932017-06-06 11:17:43 -070065 actions = {
66 set_egress_port(standard_metadata);
67 send_to_cpu(standard_metadata);
68 drop(standard_metadata);
69 }
Yi Tseng21629932017-06-06 11:17:43 -070070 counters = table0_counter;
Carmelo Cascone2cad9ef2017-08-01 21:52:07 +020071 // implementation = ecmp_selector;
Yi Tseng21629932017-06-06 11:17:43 -070072 }
Carmelo Cascone837e6452017-07-19 20:35:22 -040073
74 PacketIoIngressControl() packet_io_ingress_control;
Yi Tseng21629932017-06-06 11:17:43 -070075 PortCountersControl() port_counters_control;
Carmelo Cascone837e6452017-07-19 20:35:22 -040076
Yi Tseng21629932017-06-06 11:17:43 -070077 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -040078 packet_io_ingress_control.apply(hdr, standard_metadata);
79 if (!hdr.packet_out.isValid()) {
80 table0.apply();
81 }
Yi Tseng21629932017-06-06 11:17:43 -070082 port_counters_control.apply(hdr, meta, standard_metadata);
83 }
84
85}
86
Carmelo Cascone837e6452017-07-19 20:35:22 -040087control egress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) {
88
89 PacketIoEgressControl() packet_io_egress_control;
Yi Tseng21629932017-06-06 11:17:43 -070090 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -040091 packet_io_egress_control.apply(hdr, standard_metadata);
Yi Tseng21629932017-06-06 11:17:43 -070092 }
93}
94
Yi Tseng21629932017-06-06 11:17:43 -070095V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;