Fix availability checks in GDP

Checks if the expected pipeline is set and if the pipeline is READY

Change-Id: Ief210c91b44f500eca8d79ebeb4e79766c25fdfe
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeHandshaker.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeHandshaker.java
index e689298..3219a6c 100644
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeHandshaker.java
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeHandshaker.java
@@ -21,12 +21,15 @@
 import org.onosproject.net.MastershipRole;
 import org.onosproject.net.device.DeviceAgentListener;
 import org.onosproject.net.device.DeviceHandshaker;
+import org.onosproject.net.pi.model.PiPipeconf;
+import org.onosproject.net.pi.service.PiPipeconfService;
 import org.onosproject.net.pi.service.PiPipeconfWatchdogService;
 import org.onosproject.net.provider.ProviderId;
 import org.onosproject.p4runtime.api.P4RuntimeClient;
 import org.onosproject.p4runtime.api.P4RuntimeController;
 
 import java.math.BigInteger;
+import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 
 import static java.util.concurrent.CompletableFuture.completedFuture;
@@ -94,7 +97,20 @@
                 !client.isSessionOpen(p4DeviceId)) {
             return completedFuture(false);
         }
-        return client.isAnyPipelineConfigSet(p4DeviceId);
+
+        PiPipeconfService piPipeconfService = handler().get(PiPipeconfService.class);
+        final Optional<PiPipeconf> optionalPiPipeconf = piPipeconfService.getPipeconf(deviceId);
+        if (optionalPiPipeconf.isEmpty()) {
+            return completedFuture(false);
+        }
+
+        if (!PiPipeconfWatchdogService.PipelineStatus.READY.equals(
+                handler().get(PiPipeconfWatchdogService.class)
+                        .getStatus(data().deviceId()))) {
+            return completedFuture(false);
+        }
+
+        return client.isPipelineConfigSet(p4DeviceId, optionalPiPipeconf.get());
     }
 
     @Override