blob: 44a2b0edb31128a42d09e92c45a7bb8413a92f68 [file] [log] [blame]
Carmelo Cascone16de6db2017-08-22 00:27:57 +02001#ifndef __PORT_COUNTERS_P4__
2#define __PORT_COUNTERS_P4__
3#include "defines.p4"
4
Carmelo Cascone4f011022017-06-05 01:41:02 -04005counter ingress_port_counter {
Carmelo Cascone16de6db2017-08-22 00:27:57 +02006 type : packets; // bmv2 always counts both bytes and packets
Carmelo Cascone4f011022017-06-05 01:41:02 -04007 instance_count : MAX_PORTS;
8 min_width : 32;
9}
10
11counter egress_port_counter {
12 type: packets;
13 instance_count : MAX_PORTS;
14 min_width : 32;
15}
16
Carmelo Cascone16de6db2017-08-22 00:27:57 +020017action count_ingress() {
18 count(ingress_port_counter, IGR_PORT_FIELD);
Carmelo Cascone4f011022017-06-05 01:41:02 -040019}
20
Carmelo Cascone16de6db2017-08-22 00:27:57 +020021action count_egress() {
22 count(egress_port_counter, EGR_PORT_FIELD);
23}
24
25table ingress_port_count_table {
26 actions { count_ingress; }
27 default_action: count_ingress;
28}
29
30table egress_port_count_table {
31 actions { count_egress; }
32 default_action: count_egress;
Carmelo Cascone4f011022017-06-05 01:41:02 -040033}
34
35control process_port_counters {
Carmelo Cascone16de6db2017-08-22 00:27:57 +020036 if (EGR_PORT_FIELD < MAX_PORTS) {
37 apply(ingress_port_count_table);
38 apply(egress_port_count_table);
39 }
40}
41
42#endif