blob: a34a7386a6a2fb6fca6e320cf649bf7811271546 [file] [log] [blame]
Yi Tsengbe342052017-11-03 10:21:23 -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 __PORT_COUNTER__
18#define __PORT_COUNTER__
19#include "../define.p4"
20#include "../header.p4"
21
Carmelo Casconeb5324e72018-11-25 02:26:32 -080022control PortCountersControl(inout parsed_headers_t hdr,
23 inout fabric_metadata_t fabric_metadata,
24 inout standard_metadata_t standard_metadata) {
25
Yi Tseng3d3956d2018-01-31 17:28:05 -080026 counter(MAX_PORTS, CounterType.packets_and_bytes) egress_port_counter;
27 counter(MAX_PORTS, CounterType.packets_and_bytes) ingress_port_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070028
29 apply {
30 if (standard_metadata.egress_spec < MAX_PORTS) {
31 egress_port_counter.count((bit<32>)standard_metadata.egress_spec);
32 }
33 if (standard_metadata.ingress_port < MAX_PORTS) {
34 ingress_port_counter.count((bit<32>)standard_metadata.ingress_port);
35 }
36 }
37}
38#endif