Allow for arbitrary counter IDs in DefaultP4PortStatisticsDiscovery

Change-Id: Ia840848506c362229eb0fcba9270a78eca1cb782
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4PortStatisticsDiscovery.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4PortStatisticsDiscovery.java
index 081e0f1..b2b3760 100644
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4PortStatisticsDiscovery.java
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4PortStatisticsDiscovery.java
@@ -46,16 +46,29 @@
     // With P4_14, counter names in the generated P4Info won't have any scope.
     // A solution could be that of dynamically building counter IDs based on the P4Info (as in DefaultP4Interpreter).
     private static final String DEFAULT_SCOPE = "port_counters_control";
-    private static final String INGRESS_COUNTER = "ingress_port_counter";
-    private static final String EGRESS_COUNTER = "egress_port_counter";
+    private static final PiCounterId DEFAULT_INGRESS_COUNTER_ID = PiCounterId.of(DEFAULT_SCOPE,
+                                                                                 "ingress_port_counter",
+                                                                                 INDIRECT);
+    private static final PiCounterId DEFAULT_EGRESS_COUNTER_ID = PiCounterId.of(DEFAULT_SCOPE,
+                                                                                "egress_port_counter",
+                                                                                INDIRECT);
 
     /**
-     * Returns the scope string to be used for the counter IDs.
+     * Returns the ID of the ingress port counter.
      *
-     * @return scope string
+     * @return counter ID
      */
-    public String scope() {
-        return DEFAULT_SCOPE;
+    public PiCounterId ingressCounterId() {
+        return DEFAULT_INGRESS_COUNTER_ID;
+    }
+
+    /**
+     * Returns the ID of the egress port counter.
+     *
+     * @return counter ID
+     */
+    public PiCounterId egressCounterId() {
+        return DEFAULT_EGRESS_COUNTER_ID;
     }
 
     @Override
@@ -65,9 +78,6 @@
             return Collections.emptyList();
         }
 
-        final PiCounterId ingressCounterId = PiCounterId.of(scope(), INGRESS_COUNTER, INDIRECT);
-        final PiCounterId egressCounterId = PiCounterId.of(scope(), EGRESS_COUNTER, INDIRECT);
-
         Map<Long, DefaultPortStatistics.Builder> portStatBuilders = Maps.newHashMap();
 
         deviceService.getPorts(deviceId)
@@ -79,8 +89,8 @@
         Set<PiCounterCellId> counterCellIds = Sets.newHashSet();
         portStatBuilders.keySet().forEach(p -> {
             // Counter cell/index = port number.
-            counterCellIds.add(PiIndirectCounterCellId.of(ingressCounterId, p));
-            counterCellIds.add(PiIndirectCounterCellId.of(egressCounterId, p));
+            counterCellIds.add(PiIndirectCounterCellId.of(ingressCounterId(), p));
+            counterCellIds.add(PiIndirectCounterCellId.of(egressCounterId(), p));
         });
 
         Collection<PiCounterCellData> counterEntryResponse;
@@ -103,10 +113,10 @@
                 return;
             }
             DefaultPortStatistics.Builder statsBuilder = portStatBuilders.get(indCellId.index());
-            if (counterData.cellId().counterId().equals(ingressCounterId)) {
+            if (counterData.cellId().counterId().equals(ingressCounterId())) {
                 statsBuilder.setPacketsReceived(counterData.packets());
                 statsBuilder.setBytesReceived(counterData.bytes());
-            } else if (counterData.cellId().counterId().equals(egressCounterId)) {
+            } else if (counterData.cellId().counterId().equals(egressCounterId())) {
                 statsBuilder.setPacketsSent(counterData.packets());
                 statsBuilder.setBytesSent(counterData.bytes());
             } else {