[ONOS-7141][ONOS-7142] Add GnmiClient and GnmiController
Change-Id: I6347da378d9e4b59a38e2efacc27599b96dc1515
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
new file mode 100644
index 0000000..7f43d1f
--- /dev/null
+++ b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiClient.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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.SetRequest;
+import gnmi.Gnmi.SetResponse;
+import org.onosproject.grpc.api.GrpcClient;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Client to control a gNMI server.
+ */
+@Beta
+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.
+ *
+ * @return the capability response
+ */
+ CompletableFuture<CapabilityResponse> capability();
+
+ /**
+ * Retrieve a snapshot of data from the device.
+ *
+ * @param request the get request
+ * @return the snapshot of data from the device
+ */
+ CompletableFuture<GetResponse> get(GetRequest request);
+
+ /**
+ * Modifies the state of data on the device.
+ *
+ * @param request the set request
+ * @return the set result
+ */
+ CompletableFuture<SetResponse> set(SetRequest request);
+
+ // TODO: Support gNMI subscription
+}
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
new file mode 100644
index 0000000..26ce113
--- /dev/null
+++ b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiClientKey.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.gnmi.api;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.grpc.api.GrpcClientKey;
+import org.onosproject.net.DeviceId;
+
+/**
+ * Key that uniquely identifies a gNMI client.
+ */
+@Beta
+public class GnmiClientKey extends GrpcClientKey {
+
+ /**
+ * 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);
+ }
+}
diff --git a/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiController.java b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiController.java
new file mode 100644
index 0000000..f4964ed
--- /dev/null
+++ b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiController.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.gnmi.api;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.grpc.api.GrpcClientController;
+
+/**
+ * Controller of gNMI devices.
+ */
+@Beta
+public interface GnmiController
+ extends GrpcClientController<GnmiClientKey, GnmiClient> {
+}
diff --git a/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiEvent.java b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiEvent.java
new file mode 100644
index 0000000..5129926
--- /dev/null
+++ b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiEvent.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.gnmi.api;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Representation of an event received from a gNMI device.
+ */
+@Beta
+public final class GnmiEvent extends AbstractEvent<GnmiEvent.Type, GnmiEventSubject> {
+
+ /**
+ * Type of gNMI event.
+ */
+ public enum Type {
+ /**
+ * Update.
+ */
+ UPDATE,
+
+ /**
+ * Sync response.
+ */
+ SYNC_RESPONSE
+ }
+
+ protected GnmiEvent(Type type, GnmiEventSubject subject) {
+ super(type, subject);
+ }
+}
diff --git a/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiEventListener.java b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiEventListener.java
new file mode 100644
index 0000000..0fe2fd3
--- /dev/null
+++ b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiEventListener.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.gnmi.api;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.EventListener;
+
+/**
+ * A listener of events received from gNMI devices.
+ */
+@Beta
+public interface GnmiEventListener extends EventListener<GnmiEvent> {
+}
diff --git a/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiEventSubject.java b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiEventSubject.java
new file mode 100644
index 0000000..d1563ed
--- /dev/null
+++ b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/GnmiEventSubject.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.gnmi.api;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.DeviceId;
+
+/**
+ * Information about an event generated by a gNMI device .
+ */
+@Beta
+public interface GnmiEventSubject {
+
+ /**
+ * Returns the deviceId associated to this subject.
+ *
+ * @return the device ID
+ */
+ DeviceId deviceId();
+}
diff --git a/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/package-info.java b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/package-info.java
new file mode 100644
index 0000000..5f07b46
--- /dev/null
+++ b/protocols/gnmi/api/src/main/java/org/onosproject/gnmi/api/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * gNMI protocol API.
+ */
+package org.onosproject.gnmi.api;
\ No newline at end of file