blob: 86ed4eee3bed34bd9c132cd22c47d22414352e79 [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
Yi Tseng21629932017-06-06 11:17:43 -070034 direct_counter(CounterType.packets) table0_counter;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040035 action_selector(HashAlgorithm.crc16, 32w64, 32w16) ecmp_selector;
Yi Tseng21629932017-06-06 11:17:43 -070036
37 table table0 {
38 support_timeout = true;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040039 key = {
40 standard_metadata.ingress_port : ternary;
41 hdr.ethernet.dstAddr : ternary;
42 hdr.ethernet.srcAddr : ternary;
43 hdr.ethernet.etherType : ternary;
44 // Not for matching.
45 // Inputs to the hash function of the action selector.
46 hdr.ipv4.srcAddr : selector;
47 hdr.ipv4.dstAddr : selector;
48 hdr.ipv4.protocol : selector;
49 hdr.tcp.srcPort : selector;
50 hdr.tcp.dstPort : selector;
51 hdr.udp.srcPort : selector;
52 hdr.udp.dstPort : selector;
53 }
Yi Tseng21629932017-06-06 11:17:43 -070054 actions = {
55 set_egress_port(standard_metadata);
56 send_to_cpu(standard_metadata);
57 drop(standard_metadata);
58 }
Yi Tseng21629932017-06-06 11:17:43 -070059 counters = table0_counter;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040060 implementation = ecmp_selector;
Yi Tseng21629932017-06-06 11:17:43 -070061 }
Carmelo Cascone837e6452017-07-19 20:35:22 -040062
63 PacketIoIngressControl() packet_io_ingress_control;
Yi Tseng21629932017-06-06 11:17:43 -070064 PortCountersControl() port_counters_control;
Carmelo Cascone837e6452017-07-19 20:35:22 -040065
Yi Tseng21629932017-06-06 11:17:43 -070066 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -040067 packet_io_ingress_control.apply(hdr, standard_metadata);
68 if (!hdr.packet_out.isValid()) {
69 table0.apply();
70 }
Yi Tseng21629932017-06-06 11:17:43 -070071 port_counters_control.apply(hdr, meta, standard_metadata);
72 }
73
74}
75
Carmelo Cascone837e6452017-07-19 20:35:22 -040076control egress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) {
77
78 PacketIoEgressControl() packet_io_egress_control;
Yi Tseng21629932017-06-06 11:17:43 -070079 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -040080 packet_io_egress_control.apply(hdr, standard_metadata);
Yi Tseng21629932017-06-06 11:17:43 -070081 }
82}
83
Yi Tseng21629932017-06-06 11:17:43 -070084V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;