Introduce cfg property to enable/disable read port-id path

Change-Id: Ieaf08c730039cd44af0d60462a3b4b5885322c45
diff --git a/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiDeviceDescriptionDiscovery.java b/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiDeviceDescriptionDiscovery.java
index 5717ffe..ee7ccc5 100644
--- a/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiDeviceDescriptionDiscovery.java
+++ b/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiDeviceDescriptionDiscovery.java
@@ -61,6 +61,10 @@
 
     private static final String UNKNOWN = "unknown";
 
+    // FIXME temporary solution will be removed when the
+    //  transition to p4rt translation is completed
+    public static boolean readPortId = false;
+
     public OpenConfigGnmiDeviceDescriptionDiscovery() {
         super(GnmiController.class);
     }
@@ -118,8 +122,9 @@
             if (!annotationsBuilder.build().keys().contains(LAST_CHANGE)) {
                 annotationsBuilder.set(LAST_CHANGE, String.valueOf(0));
             }
-            // Override port number if /interfaces/interface/state/id is available
-            if (portIds.containsKey(key)) {
+            /* Override port number if read port-id is enabled
+               and /interfaces/interface/state/id is available */
+            if (readPortId && portIds.containsKey(key)) {
                 value.withPortNumber(portIds.get(key));
             }
             DefaultAnnotations annotation = annotations.get(key).build();
diff --git a/providers/general/device/BUILD b/providers/general/device/BUILD
index 511201a..6e1d53e 100644
--- a/providers/general/device/BUILD
+++ b/providers/general/device/BUILD
@@ -3,6 +3,7 @@
     "//protocols/gnmi/api:onos-protocols-gnmi-api",
     "//deps:com_google_protobuf_protobuf_java",
     "//protocols/grpc/api:onos-protocols-grpc-api",
+    "//drivers/gnmi:onos-drivers-gnmi",
 ]
 
 osgi_jar_with_tests(
diff --git a/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java b/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java
index b892460..c91cfb2 100644
--- a/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java
+++ b/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java
@@ -27,6 +27,7 @@
 import org.onosproject.cluster.ClusterService;
 import org.onosproject.cluster.NodeId;
 import org.onosproject.core.CoreService;
+import org.onosproject.drivers.gnmi.OpenConfigGnmiDeviceDescriptionDiscovery;
 import org.onosproject.gnmi.api.GnmiController;
 import org.onosproject.mastership.MastershipInfo;
 import org.onosproject.mastership.MastershipService;
@@ -97,6 +98,8 @@
 import static org.onlab.util.Tools.groupedThreads;
 import static org.onosproject.provider.general.device.impl.OsgiPropertyConstants.CHECKUP_INTERVAL;
 import static org.onosproject.provider.general.device.impl.OsgiPropertyConstants.CHECKUP_INTERVAL_DEFAULT;
+import static org.onosproject.provider.general.device.impl.OsgiPropertyConstants.READ_PORT_ID;
+import static org.onosproject.provider.general.device.impl.OsgiPropertyConstants.READ_PORT_ID_DEFAULT;
 import static org.onosproject.provider.general.device.impl.OsgiPropertyConstants.STATS_POLL_INTERVAL;
 import static org.onosproject.provider.general.device.impl.OsgiPropertyConstants.STATS_POLL_INTERVAL_DEFAULT;
 import static org.slf4j.LoggerFactory.getLogger;
@@ -111,6 +114,7 @@
         property = {
                 CHECKUP_INTERVAL + ":Integer=" + CHECKUP_INTERVAL_DEFAULT,
                 STATS_POLL_INTERVAL + ":Integer=" + STATS_POLL_INTERVAL_DEFAULT,
+                READ_PORT_ID + ":Boolean=" + READ_PORT_ID_DEFAULT,
         })
 public class GeneralDeviceProvider extends AbstractProvider
         implements DeviceProvider {
@@ -174,6 +178,11 @@
      */
     private int statsPollInterval = STATS_POLL_INTERVAL_DEFAULT;
 
+    /**
+     * Configure read port-id for gnmi drivers; default is false.
+     */
+    private boolean readPortId = READ_PORT_ID_DEFAULT;
+
     private final Map<DeviceId, DeviceHandshaker> handshakersWithListeners = Maps.newConcurrentMap();
     private final Map<DeviceId, Long> lastCheckups = Maps.newConcurrentMap();
     private final InternalPipeconfWatchdogListener pipeconfWatchdogListener = new InternalPipeconfWatchdogListener();
@@ -233,6 +242,11 @@
                 properties, STATS_POLL_INTERVAL, STATS_POLL_INTERVAL_DEFAULT);
         log.info("Configured. {} is configured to {} seconds",
                  STATS_POLL_INTERVAL, statsPollInterval);
+        final boolean oldReaPortId = readPortId;
+        String strReadPortId = Tools.get(properties, READ_PORT_ID);
+        readPortId = Boolean.parseBoolean(strReadPortId);
+        log.info("Configured. {} is configured to {}",
+                READ_PORT_ID, readPortId);
 
         if (oldCheckupInterval != checkupInterval) {
             startOrReschedulePeriodicCheckupTasks();
@@ -241,6 +255,12 @@
         if (oldStatsPollFrequency != statsPollInterval) {
             statsPoller.reschedule(statsPollInterval);
         }
+
+        if (oldReaPortId != readPortId) {
+            // FIXME temporary solution will be removed when the
+            //  transition to p4rt translation is completed
+            OpenConfigGnmiDeviceDescriptionDiscovery.readPortId = readPortId;
+        }
     }
 
     @Deactivate
diff --git a/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/OsgiPropertyConstants.java b/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/OsgiPropertyConstants.java
index f2f2d08..ce18b0f 100644
--- a/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/OsgiPropertyConstants.java
+++ b/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/OsgiPropertyConstants.java
@@ -29,4 +29,7 @@
     public static final String CHECKUP_INTERVAL = "checkupInterval";
     public static final int CHECKUP_INTERVAL_DEFAULT = 10;
 
+    public static final String READ_PORT_ID = "readPortId";
+    public static final boolean READ_PORT_ID_DEFAULT = false;
+
 }