blob: 3e9ea007552c756814b182a3fda023dad2b0567d [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
22control PortCountersControl(inout parsed_headers_t hdr, inout fabric_metadata_t fabric_metadata, inout standard_metadata_t standard_metadata) {
Yi Tseng3d3956d2018-01-31 17:28:05 -080023 counter(MAX_PORTS, CounterType.packets_and_bytes) egress_port_counter;
24 counter(MAX_PORTS, CounterType.packets_and_bytes) ingress_port_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070025
26 apply {
27 if (standard_metadata.egress_spec < MAX_PORTS) {
28 egress_port_counter.count((bit<32>)standard_metadata.egress_spec);
29 }
30 if (standard_metadata.ingress_port < MAX_PORTS) {
31 ingress_port_counter.count((bit<32>)standard_metadata.ingress_port);
32 }
33 }
34}
35#endif