cassini Modulation Driver Impl | ONOS-7979
Change-Id: Iba45f3e41fc39e63c7dc96acf5d2da248dc6bf68
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/util/NetconfSessionUtility.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/util/NetconfSessionUtility.java
new file mode 100644
index 0000000..786c999
--- /dev/null
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/util/NetconfSessionUtility.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2019-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.
+ *
+ * This Work is contributed by Sterlite Technologies
+ */
+
+package org.onosproject.drivers.odtn.util;
+
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
+import org.onosproject.drivers.utilities.XmlConfigParser;
+import org.onosproject.net.DeviceId;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfDevice;
+import org.onosproject.netconf.NetconfException;
+import org.onosproject.netconf.NetconfSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+public final class NetconfSessionUtility {
+
+ private static final Logger log = LoggerFactory.getLogger(NetconfSessionUtility.class);
+
+ private NetconfSessionUtility() {
+ }
+
+ /**
+ * Returns the NetconfSession with the device for which the method was called.
+ *
+ * @param deviceId device identifier
+ * @param controller NetconfController
+ * @return The netconf session or null
+ */
+ public static NetconfSession getNetconfSession(DeviceId deviceId,
+ NetconfController controller) {
+ log.info("Inside getNetconfSession () method for device : {}", deviceId);
+ NetconfDevice ncdev = controller.getDevicesMap().get(deviceId);
+ if (ncdev == null) {
+ log.trace("No netconf device, returning null session");
+ return null;
+ }
+ return ncdev.getSession();
+ }
+
+ /**
+ * Execute RPC request.
+ *
+ * @param session Netconf session
+ * @param message Netconf message in XML format
+ * @return XMLConfiguration object
+ */
+
+ public static XMLConfiguration executeRpc(NetconfSession session, String message) {
+ try {
+ CompletableFuture<String> fut = session.rpc(message);
+ String rpcReply = fut.get();
+ XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
+ xconf.setExpressionEngine(new XPathExpressionEngine());
+ return xconf;
+ } catch (NetconfException ne) {
+ log.error("Exception on Netconf protocol: {}.", ne);
+ } catch (InterruptedException ie) {
+ log.error("Interrupted Exception: {}.", ie);
+ } catch (ExecutionException ee) {
+ log.error("Concurrent Exception while executing Netconf operation: {}.", ee);
+ }
+ return null;
+ }
+
+}
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/util/package-info.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/util/package-info.java
new file mode 100644
index 0000000..7cdbe9f
--- /dev/null
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/util/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2019-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.
+ *
+ * This Work is contributed by Sterlite Technologies
+ */
+/**
+ * Package for Utility classes to be used by odtn-driver.
+ */
+package org.onosproject.drivers.odtn.util;
\ No newline at end of file