Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame^] | 1 | #ifndef __PORT_COUNTERS_P4__ |
| 2 | #define __PORT_COUNTERS_P4__ |
| 3 | #include "defines.p4" |
| 4 | |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 5 | counter ingress_port_counter { |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame^] | 6 | type : packets; // bmv2 always counts both bytes and packets |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 7 | instance_count : MAX_PORTS; |
| 8 | min_width : 32; |
| 9 | } |
| 10 | |
| 11 | counter egress_port_counter { |
| 12 | type: packets; |
| 13 | instance_count : MAX_PORTS; |
| 14 | min_width : 32; |
| 15 | } |
| 16 | |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame^] | 17 | action count_ingress() { |
| 18 | count(ingress_port_counter, IGR_PORT_FIELD); |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 19 | } |
| 20 | |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame^] | 21 | action count_egress() { |
| 22 | count(egress_port_counter, EGR_PORT_FIELD); |
| 23 | } |
| 24 | |
| 25 | table ingress_port_count_table { |
| 26 | actions { count_ingress; } |
| 27 | default_action: count_ingress; |
| 28 | } |
| 29 | |
| 30 | table egress_port_count_table { |
| 31 | actions { count_egress; } |
| 32 | default_action: count_egress; |
Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | control process_port_counters { |
Carmelo Cascone | 16de6db | 2017-08-22 00:27:57 +0200 | [diff] [blame^] | 36 | if (EGR_PORT_FIELD < MAX_PORTS) { |
| 37 | apply(ingress_port_count_table); |
| 38 | apply(egress_port_count_table); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | #endif |