blob: ab86c3932f41bf16e35a53d9feb59da53216183f [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#include <core.p4>
18#include <v1model.p4>
19
20#include "include/headers.p4"
21#include "include/defines.p4"
22#include "include/parsers.p4"
23#include "include/actions.p4"
24#include "include/port_counters.p4"
25#include "include/checksums.p4"
26#include "include/packet_io.p4"
27#include "include/table0.p4"
28
29// FIXME: this program is obsolete and should be removed.
30// The PI ECMP demo app should be refactored to use the WCMP capability of default.p4
31
32// Expected number of ports of an ECMP group.
33// This value is fixed, .i.e. we do not support ECMP over port groups of different
34// size. Due to hardware limitations, this value must be constant and a power of 2.
35
36#define ECMP_GROUP_SIZE 128w2
37
38//------------------------------------------------------------------------------
39// INGRESS PIPELINE
40//------------------------------------------------------------------------------
41
42control ingress(inout headers_t hdr,
43 inout local_metadata_t local_metadata,
44 inout standard_metadata_t standard_metadata) {
45
46 direct_counter(CounterType.packets_and_bytes) ecmp_table_counter;
47
48 table ecmp_table {
49 key = {
50 local_metadata.next_hop_id : exact;
51 local_metadata.selector : exact;
52 }
53 actions = {
54 set_egress_port(standard_metadata);
55 }
56 counters = ecmp_table_counter;
57 }
58
59 action set_ecmp_selector() {
60 hash(local_metadata.selector, HashAlgorithm.crc16, (bit<64>) 0,
61 {
62 hdr.ipv4.src_addr,
63 hdr.ipv4.dst_addr,
64 hdr.ipv4.protocol,
65 local_metadata.l4_src_port,
66 local_metadata.l4_dst_port
67 },
68 ECMP_GROUP_SIZE);
69 }
70
71 apply {
72 port_counters_ingress.apply(hdr, standard_metadata);
73 packetio_ingress.apply(hdr, standard_metadata);
74 table0_control.apply(hdr, local_metadata, standard_metadata);
75 if (local_metadata.next_hop_id > 0) {
76 set_ecmp_selector();
77 ecmp_table.apply();
78 }
79 }
80}
81
82//------------------------------------------------------------------------------
83// EGRESS PIPELINE
84//------------------------------------------------------------------------------
85
86control egress(inout headers_t hdr,
87 inout local_metadata_t local_metadata,
88 inout standard_metadata_t standard_metadata) {
89
90 apply {
91 port_counters_egress.apply(hdr, standard_metadata);
92 packetio_egress.apply(hdr, standard_metadata);
93 }
94}
95
96//------------------------------------------------------------------------------
97// SWITCH INSTANTIATION
98//------------------------------------------------------------------------------
99
100V1Switch(parser_impl(),
101 verify_checksum_control(),
102 ingress(),
103 egress(),
104 compute_checksum_control(),
105 deparser()) main;