P4 source files for BMv2 demo
Change-Id: I3adc57eb346e3cb34f17d54b82505d2d9e89b4ad
diff --git a/tools/test/p4src/include/port_counters.p4 b/tools/test/p4src/include/port_counters.p4
new file mode 100644
index 0000000..06cba4f
--- /dev/null
+++ b/tools/test/p4src/include/port_counters.p4
@@ -0,0 +1,29 @@
+counter ingress_port_counter {
+ type : packets; // bmv2 always counts both bytes and packets
+ instance_count : MAX_PORTS;
+ min_width : 32;
+}
+
+counter egress_port_counter {
+ type: packets;
+ instance_count : MAX_PORTS;
+ min_width : 32;
+}
+
+table port_count_table {
+ actions {
+ count_packet;
+ }
+}
+
+action count_packet() {
+ count(ingress_port_counter, standard_metadata.ingress_port);
+ count(egress_port_counter, standard_metadata.egress_spec);
+}
+
+control process_port_counters {
+ // Avoid counting logical ports, such as drop and cpu
+ if (standard_metadata.egress_spec < MAX_PORTS) {
+ apply(port_count_table);
+ }
+}
\ No newline at end of file