More improvements and bugfixes in P4Runtime subsystem

Most notably, we fix a bug in which some nodes were not able to find
pipeconf-specific behaviors for a given device. The problem is not
completelly solved but it's mitigated.

There's a race condition caused by the fact that the GDP updates the cfg
with the merged driver name before advertising the device to the core.
Some nodes might receive the cfg update after the device has been
advertised. We mitigate the problem by performing the pipeline deploy
(slow operation) after the cfg update, giving more time for nodes
to catch up. Perhaps we should listen for cfg update events before
advertising the device to the core?

Also:
- NPE when getting P4Runtime client
- Detect if a base driver is already merged in pipeconf manager
- Longer timeouts in P4Runtime driver and protocol (for slow networks)
- Configurable timeout in P4Runtime driver and GDP
- NPE when adding/removing device agent listeners in P4Rtunime handshaker
- Various exceptions due to race conditions in GDP when disconnecting
devices (by serializing disconnect tasks per device)
- NPE when cancelling polling tasks in GDP
- Refactored PipeconfService to distinguish between driver merge,
pipeconf map update, and cfg update (now performed in the GDP)
- Fixed PipeconfManagerTest, not testing driver behaviours
- Use Guava striped locks when possible (more memory-efficient than maps,
and with strict atomicity guarantees w.r.t. to caches).

Change-Id: I30f3887541ba0fd44439a86885e9821ac565b64c
diff --git a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java
index 4362501..464cb85 100644
--- a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java
+++ b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java
@@ -18,7 +18,7 @@
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
+import com.google.common.util.concurrent.Striped;
 import io.grpc.CallOptions;
 import io.grpc.Channel;
 import io.grpc.ClientCall;
@@ -60,7 +60,6 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
@@ -86,7 +85,7 @@
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     private Map<GrpcChannelId, ManagedChannel> channels;
-    private final Map<GrpcChannelId, Lock> channelLocks = Maps.newConcurrentMap();
+    private final Striped<Lock> channelLocks = Striped.lock(30);
 
     @Activate
     public void activate() {
@@ -120,7 +119,7 @@
         checkNotNull(channelId);
         checkNotNull(channelBuilder);
 
-        Lock lock = channelLocks.computeIfAbsent(channelId, k -> new ReentrantLock());
+        Lock lock = channelLocks.get(channelId);
         lock.lock();
 
         try {
@@ -156,7 +155,7 @@
     public boolean isChannelOpen(GrpcChannelId channelId) {
         checkNotNull(channelId);
 
-        Lock lock = channelLocks.computeIfAbsent(channelId, k -> new ReentrantLock());
+        Lock lock = channelLocks.get(channelId);
         lock.lock();
 
         try {
@@ -182,7 +181,7 @@
     public void disconnectChannel(GrpcChannelId channelId) {
         checkNotNull(channelId);
 
-        Lock lock = channelLocks.computeIfAbsent(channelId, k -> new ReentrantLock());
+        Lock lock = channelLocks.get(channelId);
         lock.lock();
 
         try {
@@ -201,7 +200,6 @@
             }
 
             channels.remove(channelId);
-            channelLocks.remove(channelId);
         } finally {
             lock.unlock();
         }
@@ -229,7 +227,7 @@
     public Optional<ManagedChannel> getChannel(GrpcChannelId channelId) {
         checkNotNull(channelId);
 
-        Lock lock = channelLocks.computeIfAbsent(channelId, k -> new ReentrantLock());
+        Lock lock = channelLocks.get(channelId);
         lock.lock();
 
         try {