| #ifndef __PORT_COUNTERS_P4__ |
| #define __PORT_COUNTERS_P4__ |
| #include "defines.p4" |
| |
| counter ingress_port_counter { |
| type : bytes; // bmv2 always counts both bytes and packets |
| instance_count : MAX_PORTS; |
| min_width : 32; |
| } |
| |
| counter egress_port_counter { |
| type: bytes; |
| instance_count : MAX_PORTS; |
| min_width : 32; |
| } |
| |
| action count_ingress() { |
| count(ingress_port_counter, IGR_PORT_FIELD); |
| } |
| |
| action count_egress() { |
| count(egress_port_counter, EGR_PORT_FIELD); |
| } |
| |
| table ingress_port_count_table { |
| actions { count_ingress; } |
| default_action: count_ingress; |
| } |
| |
| table egress_port_count_table { |
| actions { count_egress; } |
| default_action: count_egress; |
| } |
| |
| control process_port_counters { |
| if (EGR_PORT_FIELD < MAX_PORTS) { |
| apply(ingress_port_count_table); |
| apply(egress_port_count_table); |
| } |
| } |
| |
| #endif |