[ONOS-4990] NETCONF function for FUJITSU OLT #8
- Add a command to get all configuration from FJ OLT.
e.g. volt-all <netconf: target>
Change-Id: I70b4cf8851ce1911569ca62e59ec40df48913d88
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltNeConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltNeConfig.java
new file mode 100644
index 0000000..2560488
--- /dev/null
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltNeConfig.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.drivers.fujitsu;
+
+import org.onosproject.drivers.fujitsu.behaviour.VoltNeConfig;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.netconf.NetconfController;
+import org.slf4j.Logger;
+
+import java.io.IOException;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Implementation to get all available data in vOLT
+ * through the Netconf protocol.
+ */
+public class FujitsuVoltNeConfig extends AbstractHandlerBehaviour
+ implements VoltNeConfig {
+
+ private final Logger log = getLogger(FujitsuVoltNeConfig.class);
+
+
+ @Override
+ public String getAll() {
+ DriverHandler handler = handler();
+ NetconfController controller = handler.get(NetconfController.class);
+ MastershipService mastershipService = handler.get(MastershipService.class);
+ DeviceId ncDeviceId = handler.data().deviceId();
+ checkNotNull(controller, "Netconf controller is null");
+ String reply = null;
+
+ if (!mastershipService.isLocalMaster(ncDeviceId)) {
+ log.warn("Not master for {} Use {} to execute command",
+ ncDeviceId,
+ mastershipService.getMasterFor(ncDeviceId));
+ return reply;
+ }
+
+ try {
+ StringBuilder request = new StringBuilder();
+ request.append(VOLT_NE_OPEN).append(VOLT_NE_NAMESPACE);
+ request.append(ANGLE_RIGHT).append(NEW_LINE);
+ request.append(VOLT_NE_CLOSE);
+
+ reply = controller.
+ getDevicesMap().get(ncDeviceId).getSession().
+ get(request.toString(), REPORT_ALL);
+ } catch (IOException e) {
+ log.error("Cannot communicate to device {} exception ", ncDeviceId, e);
+ }
+ return reply;
+ }
+
+}
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltNeConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltNeConfig.java
new file mode 100644
index 0000000..b0cdbc2
--- /dev/null
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltNeConfig.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.drivers.fujitsu.behaviour;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.driver.HandlerBehaviour;
+
+/**
+ * Device behaviour to get all available data in vOLT.
+ */
+@Beta
+public interface VoltNeConfig extends HandlerBehaviour {
+
+ /**
+ * Obtain all available data in the device.
+ *
+ * @return response string
+ */
+ String getAll();
+
+}
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetAllCommand.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetAllCommand.java
new file mode 100644
index 0000000..39fde90
--- /dev/null
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetAllCommand.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.drivers.fujitsu.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.drivers.fujitsu.behaviour.VoltNeConfig;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.driver.DriverService;
+
+/**
+ * Gets all available data in vOLT.
+ */
+@Command(scope = "onos", name = "volt-all",
+ description = "Gets all available data in vOLT")
+public class VoltGetAllCommand extends AbstractShellCommand {
+
+ @Argument(index = 0, name = "uri", description = "Device ID",
+ required = true, multiValued = false)
+ String uri = null;
+
+ private DeviceId deviceId;
+
+ @Override
+ protected void execute() {
+ DriverService service = get(DriverService.class);
+ deviceId = DeviceId.deviceId(uri);
+ DriverHandler h = service.createHandler(deviceId);
+ VoltNeConfig volt = h.behaviour(VoltNeConfig.class);
+ String reply = volt.getAll();
+ if (reply != null) {
+ print("%s", reply);
+ } else {
+ print("No reply from %s", deviceId.toString());
+ }
+ }
+
+}
diff --git a/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index e8103cc..e192952 100644
--- a/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -83,6 +83,12 @@
<ref component-id="deviceIdCompleter"/>
</completers>
</command>
+ <command>
+ <action class="org.onosproject.drivers.fujitsu.cli.VoltGetAllCommand"/>
+ <completers>
+ <ref component-id="deviceIdCompleter"/>
+ </completers>
+ </command>
</command-bundle>
<bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/>
diff --git a/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml b/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml
index a1374b9..7a0a237 100644
--- a/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml
+++ b/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml
@@ -34,5 +34,7 @@
impl="org.onosproject.drivers.fujitsu.FujitsuVoltAlertConfig"/>
<behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltFwdlConfig"
impl="org.onosproject.drivers.fujitsu.FujitsuVoltFwdlConfig"/>
+ <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltNeConfig"
+ impl="org.onosproject.drivers.fujitsu.FujitsuVoltNeConfig"/>
</driver>
</drivers>