blob: 7bc533267c41f7b9785bd036f1efbb972cdc1eef [file] [log] [blame]
Carmelo Casconeca94bcf2017-10-27 14:16:59 -07001/*
2 * Copyright 2017-present Open Networking Foundation
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
17#ifndef __WCMP__
18#define __WCMP__
19
20#include "headers.p4"
21#include "defines.p4"
22
23control wcmp_control(inout headers_t hdr,
24 inout local_metadata_t local_metadata,
25 inout standard_metadata_t standard_metadata) {
26
27 direct_counter(CounterType.packets_and_bytes) wcmp_table_counter;
28 action_selector(HashAlgorithm.crc16, 32w64, 32w16) wcmp_selector;
29
Keesjan Karsten23368892018-05-22 10:46:01 +000030 action set_egress_port(port_t port) {
31 standard_metadata.egress_spec = port;
32 }
33
Carmelo Casconeca94bcf2017-10-27 14:16:59 -070034 table wcmp_table {
35 support_timeout = false;
36 key = {
37 local_metadata.next_hop_id : exact;
38 hdr.ipv4.src_addr : selector;
39 hdr.ipv4.dst_addr : selector;
40 hdr.ipv4.protocol : selector;
41 local_metadata.l4_src_port : selector;
42 local_metadata.l4_dst_port : selector;
43 }
44 actions = {
Keesjan Karsten23368892018-05-22 10:46:01 +000045 set_egress_port;
Carmelo Casconeca94bcf2017-10-27 14:16:59 -070046 }
47 implementation = wcmp_selector;
48 counters = wcmp_table_counter;
49 }
50
51 apply {
52 if (local_metadata.next_hop_id != 0) {
53 wcmp_table.apply();
54 }
55 }
56}
57
58#endif