Cherry pick gNMI and Stratum related changes to this branch
Cherry picked commits:
20211 Update gNMI version and build script
20247 [ONOS-7829] Implement AbstractGrpcClient and AbstractGrpcClientControl
20233 [ONOS-7141][ONOS-7142] Add GnmiClient and GnmiController
20234 Refactor OpenConfig gNMI device description descovery
20260 [ONOS-7831] Implement GnmiHandshaker
20270 Add Stratum driver
Change-Id: I81ad8bce45251af5909cfcac0edbcfd11c8ebf1d
diff --git a/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiClient.java b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiClient.java
index 242bc94..5beb238 100644
--- a/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiClient.java
+++ b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiClient.java
@@ -17,10 +17,9 @@
package org.onosproject.gnmi.api;
import com.google.common.annotations.Beta;
-
import gnmi.Gnmi.CapabilityResponse;
-import gnmi.Gnmi.GetResponse;
import gnmi.Gnmi.GetRequest;
+import gnmi.Gnmi.GetResponse;
import gnmi.Gnmi.SetRequest;
import gnmi.Gnmi.SetResponse;
import org.onosproject.grpc.api.GrpcClient;
@@ -34,15 +33,14 @@
public interface GnmiClient extends GrpcClient {
/**
- * Gets capability from a target. This allows device driver behavior
- * to validate the service version and models which gNMI device supported.
+ * Gets capability from a target.
*
* @return the capability response
*/
CompletableFuture<CapabilityResponse> capability();
/**
- * Retrieve a snapshot of data from the device.
+ * Retrieves a snapshot of data from the device.
*
* @param request the get request
* @return the snapshot of data from the device
diff --git a/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiClientKey.java b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiClientKey.java
index 26ce113..bc18b9a 100644
--- a/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiClientKey.java
+++ b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiClientKey.java
@@ -26,15 +26,16 @@
@Beta
public class GnmiClientKey extends GrpcClientKey {
+ private static final String GNMI = "gnmi";
+
/**
* Creates a new gNMI client key.
*
- * @param serviceName gNMI service name of the client
* @param deviceId ONOS device ID
* @param serverAddr gNMI server address
* @param serverPort gNMI server port
*/
- public GnmiClientKey(String serviceName, DeviceId deviceId, String serverAddr, int serverPort) {
- super(serviceName, deviceId, serverAddr, serverPort);
+ public GnmiClientKey(DeviceId deviceId, String serverAddr, int serverPort) {
+ super(GNMI, deviceId, serverAddr, serverPort);
}
}
diff --git a/protocols/gnmi/ctl/src/main/java/org/onosproject/gnmi/ctl/GnmiClientImpl.java b/protocols/gnmi/ctl/src/main/java/org/onosproject/gnmi/ctl/GnmiClientImpl.java
index b8179a9..22b226b 100644
--- a/protocols/gnmi/ctl/src/main/java/org/onosproject/gnmi/ctl/GnmiClientImpl.java
+++ b/protocols/gnmi/ctl/src/main/java/org/onosproject/gnmi/ctl/GnmiClientImpl.java
@@ -27,10 +27,10 @@
import io.grpc.ManagedChannel;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
+import org.onosproject.gnmi.api.GnmiClient;
import org.onosproject.gnmi.api.GnmiClientKey;
import org.onosproject.grpc.ctl.AbstractGrpcClient;
import org.slf4j.Logger;
-import org.onosproject.gnmi.api.GnmiClient;
import java.util.concurrent.CompletableFuture;
@@ -46,8 +46,8 @@
private final Logger log = getLogger(getClass());
private final gNMIGrpc.gNMIBlockingStub blockingStub;
- public GnmiClientImpl(GnmiClientKey clientKey, ManagedChannel managedChannel) {
- super(clientKey, managedChannel);
+ GnmiClientImpl(GnmiClientKey clientKey, ManagedChannel managedChannel) {
+ super(clientKey);
this.blockingStub = gNMIGrpc.newBlockingStub(managedChannel);
}
@@ -101,8 +101,7 @@
private boolean doServiceAvailable() {
try {
- blockingStub.get(DUMMY_REQUEST);
- return true;
+ return blockingStub.get(DUMMY_REQUEST) != null;
} catch (StatusRuntimeException e) {
// This gRPC call should throw INVALID_ARGUMENT status exception
// since "/onos-gnmi-test" path does not exists in any config model
diff --git a/protocols/grpc/api/src/main/java/org/onosproject/grpc/api/GrpcClientController.java b/protocols/grpc/api/src/main/java/org/onosproject/grpc/api/GrpcClientController.java
index 2e3ea5d..3cdbcd1 100644
--- a/protocols/grpc/api/src/main/java/org/onosproject/grpc/api/GrpcClientController.java
+++ b/protocols/grpc/api/src/main/java/org/onosproject/grpc/api/GrpcClientController.java
@@ -20,8 +20,8 @@
import org.onosproject.net.DeviceId;
/**
- * Abstraction of a gRPC controller which controls specific gRPC
- * client {@link C} with specific client key {@link K}.
+ * Abstraction of a gRPC controller which controls specific gRPC client {@link
+ * C} with specific client key {@link K}.
*
* @param <K> the gRPC client key
* @param <C> the gRPC client type
@@ -30,19 +30,19 @@
public interface GrpcClientController<K extends GrpcClientKey, C extends GrpcClient> {
/**
- * Instantiates a new client to operate on a gRPC server identified by
- * the given information. As a result of this method, a client can be later
+ * Instantiates a new client to operate on a gRPC server identified by the
+ * given information. As a result of this method, a client can be later
* obtained by invoking {@link #getClient(DeviceId)}.
- *
- * Only one client can exist for the same device ID. Calls to this method are
- * idempotent fot the same client key, i.e. returns true
- * if such client already exists but a new one is not created.
- * If there exists a client with same device ID but different address and port,
- * removes old one and recreate new one.
+ * <p>
+ * Only one client can exist for the same device ID. Calls to this method
+ * are idempotent fot the same client key, i.e. returns true if such client
+ * already exists but a new one is not created. If there exists a client
+ * with same device ID but different address and port, removes old one and
+ * recreate new one.
*
* @param clientKey the client key
- * @return true if the client was created and the channel to the server is open;
- * false otherwise
+ * @return true if the client was created and the channel to the server is
+ * open; false otherwise
*/
boolean createClient(K clientKey);
@@ -55,8 +55,8 @@
C getClient(DeviceId deviceId);
/**
- * Removes the gRPC client for the given device. If no client
- * exists for the given device, the result is a no-op.
+ * Removes the gRPC client for the given device. If no client exists for the
+ * given device, the result is a no-op.
*
* @param deviceId the device identifier
*/
@@ -64,15 +64,15 @@
/**
* Check reachability of the gRPC server running on the given device.
- * Reachability can be tested only if a client is previously created
- * using {@link #createClient(GrpcClientKey)}.
- * Note that this only checks the reachability instead of checking service
- * availability, different gRPC client checks service availability with
+ * Reachability can be tested only if a client is previously created using
+ * {@link #createClient(GrpcClientKey)}. Note that this only checks the
+ * reachability instead of checking service availability, different
+ * service-specific gRPC clients might check service availability in a
* different way.
*
* @param deviceId the device identifier
- * @return true if client was created and is able to contact the gNMI server;
- * false otherwise
+ * @return true if client was created and is able to contact the gNMI
+ * server; false otherwise
*/
boolean isReachable(DeviceId deviceId);
}
diff --git a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/AbstractGrpcClient.java b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/AbstractGrpcClient.java
index 4764a56..05e2978 100644
--- a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/AbstractGrpcClient.java
+++ b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/AbstractGrpcClient.java
@@ -17,7 +17,6 @@
package org.onosproject.grpc.ctl;
import io.grpc.Context;
-import io.grpc.ManagedChannel;
import io.grpc.StatusRuntimeException;
import org.onlab.util.SharedExecutors;
import org.onosproject.grpc.api.GrpcClient;
@@ -25,7 +24,6 @@
import org.onosproject.net.DeviceId;
import org.slf4j.Logger;
-
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
@@ -45,26 +43,24 @@
public abstract class AbstractGrpcClient implements GrpcClient {
// Timeout in seconds to obtain the request lock.
- protected static final int LOCK_TIMEOUT = 60;
+ private static final int LOCK_TIMEOUT = 60;
private static final int DEFAULT_THREAD_POOL_SIZE = 10;
protected final Logger log = getLogger(getClass());
- protected final Lock requestLock = new ReentrantLock();
- protected final Context.CancellableContext cancellableContext =
+ private final Lock requestLock = new ReentrantLock();
+ private final Context.CancellableContext cancellableContext =
Context.current().withCancellation();
+ private final Executor contextExecutor;
+
protected final ExecutorService executorService;
- protected final Executor contextExecutor;
+ protected final DeviceId deviceId;
- protected ManagedChannel channel;
- protected DeviceId deviceId;
-
- protected AbstractGrpcClient(GrpcClientKey clientKey, ManagedChannel channel) {
+ protected AbstractGrpcClient(GrpcClientKey clientKey) {
this.deviceId = clientKey.deviceId();
this.executorService = Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE, groupedThreads(
"onos-grpc-" + clientKey.serviceName() + "-client-" + deviceId.toString(), "%d"));
this.contextExecutor = this.cancellableContext.fixedContextExecutor(executorService);
- this.channel = channel;
}
@Override
@@ -112,7 +108,7 @@
* @param executor the executor to execute this supplier
* @return CompletableFuture includes the result of supplier
*/
- protected <U> CompletableFuture<U> supplyWithExecutor(
+ private <U> CompletableFuture<U> supplyWithExecutor(
Supplier<U> supplier, String opDescription, Executor executor) {
return CompletableFuture.supplyAsync(() -> {
// TODO: explore a more relaxed locking strategy.
diff --git a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/AbstractGrpcClientController.java b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/AbstractGrpcClientController.java
index 36e453c..bf2bbf1 100644
--- a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/AbstractGrpcClientController.java
+++ b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/AbstractGrpcClientController.java
@@ -21,7 +21,6 @@
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.netty.NettyChannelBuilder;
-
import org.onosproject.event.AbstractListenerManager;
import org.onosproject.event.Event;
import org.onosproject.event.EventListener;
@@ -152,7 +151,7 @@
return withDeviceLock(() -> doGetClient(deviceId), deviceId);
}
- protected C doGetClient(DeviceId deviceId) {
+ private C doGetClient(DeviceId deviceId) {
if (!clientKeys.containsKey(deviceId)) {
return null;
}
@@ -183,7 +182,7 @@
return withDeviceLock(() -> doIsReachable(deviceId), deviceId);
}
- protected boolean doIsReachable(DeviceId deviceId) {
+ private boolean doIsReachable(DeviceId deviceId) {
// Default behaviour checks only the gRPC channel, should
// check according to different gRPC service
if (!clientKeys.containsKey(deviceId)) {
diff --git a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java
index 53f7668..d5080ae 100644
--- a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java
@@ -138,7 +138,7 @@
P4RuntimeClientImpl(P4RuntimeClientKey clientKey, ManagedChannel channel,
P4RuntimeControllerImpl controller) {
- super(clientKey, channel);
+ super(clientKey);
this.p4DeviceId = clientKey.p4DeviceId();
this.controller = controller;