debug CLI command for NETCONF

Change-Id: I42e25899c42f02c1456580e19d34a4a3ea9e83a7
diff --git a/cli/src/main/java/org/onosproject/cli/net/DeviceConfigGetterCommand.java b/cli/src/main/java/org/onosproject/cli/net/DeviceConfigGetterCommand.java
index 40a17d4..1f7d40d 100644
--- a/cli/src/main/java/org/onosproject/cli/net/DeviceConfigGetterCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/DeviceConfigGetterCommand.java
@@ -29,12 +29,14 @@
  *
  * This is a temporary development tool for use until yang integration is complete.
  * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE.
+ *
+ * @deprecated in 1.10.0
  */
 
 //FIXME this should eventually be removed.
-
+@Deprecated
 @Command(scope = "onos", name = "device-configuration",
-        description = "Gets the configuration of the specified type from the" +
+        description = "[Deprecated]Gets the configuration of the specified type from the" +
                 "specified device.")
 public class DeviceConfigGetterCommand extends AbstractShellCommand {
 
@@ -48,6 +50,7 @@
 
     @Override
     protected void execute() {
+        print("[WARN] This command was marked deprecated in 1.10.0");
         DriverService service = get(DriverService.class);
         deviceId = DeviceId.deviceId(uri);
         DriverHandler h = service.createHandler(deviceId);
diff --git a/cli/src/main/java/org/onosproject/cli/net/DeviceConfigSetterCommand.java b/cli/src/main/java/org/onosproject/cli/net/DeviceConfigSetterCommand.java
index 2156a06..4b88266 100644
--- a/cli/src/main/java/org/onosproject/cli/net/DeviceConfigSetterCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/DeviceConfigSetterCommand.java
@@ -31,13 +31,15 @@
  *
  * This is a temporary development tool for use until yang integration is complete.
  * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE.
+ *
+ * @deprecated in 1.10.0
  */
 //Temporary Developer tool, NOT TO BE USED in production or as example for
 // future commands.
 //FIXME this should eventually be removed.
-
+@Deprecated
 @Command(scope = "onos", name = "device-setconfiguration",
-        description = "Sets the configuration of the specified file to the " +
+        description = "[Deprecated]Sets the configuration of the specified file to the " +
                 "specified device.")
 public class DeviceConfigSetterCommand extends AbstractShellCommand {
 
@@ -51,6 +53,7 @@
 
     @Override
     protected void execute() {
+        print("[WARN] This command was marked deprecated in 1.10.0");
         DriverService service = get(DriverService.class);
         deviceId = DeviceId.deviceId(uri);
         DriverHandler h = service.createHandler(deviceId);
diff --git a/cli/src/main/java/org/onosproject/cli/net/DevicePortGetterCommand.java b/cli/src/main/java/org/onosproject/cli/net/DevicePortGetterCommand.java
index 9956a2a..28018ff 100644
--- a/cli/src/main/java/org/onosproject/cli/net/DevicePortGetterCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/DevicePortGetterCommand.java
@@ -29,10 +29,12 @@
  *
  * This is a temporary development tool for use until yang integration is complete.
  * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE.
+ *
+ * @deprecated in 1.10.0
  */
-
+@Deprecated
 @Command(scope = "onos", name = "device-ports",
-        description = "Gets the ports of the specified device.")
+        description = "[Deprecated]Gets the ports of the specified device.")
 public class DevicePortGetterCommand extends AbstractShellCommand {
 
     @Argument(index = 0, name = "uri", description = "Device ID",
@@ -42,6 +44,7 @@
 
     @Override
     protected void execute() {
+        print("[WARN] This command was marked deprecated in 1.10.0");
         DriverService service = get(DriverService.class);
         deviceId = DeviceId.deviceId(uri);
         DriverHandler h = service.createHandler(deviceId);
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index e5bf7fb..7d58b82 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -157,18 +157,21 @@
             <action class="org.onosproject.cli.net.DeviceConfigGetterCommand"/>
             <completers>
                 <ref component-id="deviceIdCompleter"/>
+                <null/>
             </completers>
         </command>
         <command>
             <action class="org.onosproject.cli.net.DeviceConfigSetterCommand"/>
             <completers>
                 <ref component-id="deviceIdCompleter"/>
+                <null/>
             </completers>
         </command>
         <command>
             <action class="org.onosproject.cli.net.DevicePortGetterCommand"/>
             <completers>
                 <ref component-id="deviceIdCompleter"/>
+                <null/>
             </completers>
         </command>
         <command>
diff --git a/drivers/netconf/pom.xml b/drivers/netconf/pom.xml
index dbada3b..1ae0832 100644
--- a/drivers/netconf/pom.xml
+++ b/drivers/netconf/pom.xml
@@ -54,4 +54,4 @@
         </dependency>
     </dependencies>
 
-</project>
\ No newline at end of file
+</project>
diff --git a/protocols/netconf/ctl/BUCK b/protocols/netconf/ctl/BUCK
index 8271185..9ed9e0c 100644
--- a/protocols/netconf/ctl/BUCK
+++ b/protocols/netconf/ctl/BUCK
@@ -1,7 +1,9 @@
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:ganymed-ssh2',
-    '//protocols/netconf/api:onos-protocols-netconf-api'
+    '//protocols/netconf/api:onos-protocols-netconf-api',
+    '//cli:onos-cli',
+    '//lib:org.apache.karaf.shell.console',
 ]
 
 TEST_DEPS = [
diff --git a/protocols/netconf/ctl/pom.xml b/protocols/netconf/ctl/pom.xml
index 90c77a8..40fa0a2 100644
--- a/protocols/netconf/ctl/pom.xml
+++ b/protocols/netconf/ctl/pom.xml
@@ -67,6 +67,18 @@
             <version>0.14.0</version>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-cli</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+        </dependency>
+
     </dependencies>
 
     <build>
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java
new file mode 100644
index 0000000..fd5a04c
--- /dev/null
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java
@@ -0,0 +1,62 @@
+/*
+ * 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.netconf.cli.impl;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.ConfigGetter;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.driver.DriverService;
+
+/**
+ * Command that gets the configuration of the specified type from the specified
+ * device. If configuration cannot be retrieved it prints an error string.
+ *
+ * This is a temporary development tool for use until yang integration is complete.
+ * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE.
+ */
+
+//FIXME Remove dependency to ConfigGetter.
+
+@Command(scope = "onos", name = "netconf-get-config",
+        description = "Gets the configuration of the specified type from the" +
+                "specified device.")
+public class NetconfConfigGetCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "uri", description = "Device ID",
+            required = true, multiValued = false)
+    String uri = null;
+
+    @Argument(index = 1, name = "cfgType",
+              description = "Configuration datastore name (RUNNING, etc.)",
+              required = true, multiValued = false)
+    String cfgType = null;
+
+
+    private DeviceId deviceId;
+
+    @Override
+    protected void execute() {
+        DriverService service = get(DriverService.class);
+        deviceId = DeviceId.deviceId(uri);
+        DriverHandler h = service.createHandler(deviceId);
+        ConfigGetter config = h.behaviour(ConfigGetter.class);
+        print(config.getConfiguration(cfgType));
+    }
+
+}
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfRpcTestCommand.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfRpcTestCommand.java
new file mode 100644
index 0000000..1f59181
--- /dev/null
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfRpcTestCommand.java
@@ -0,0 +1,63 @@
+/*
+ * 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.netconf.cli.impl;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.ConfigSetter;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.driver.DriverService;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Command that sets the configuration included in the specified file to the
+ * specified device. It prints the response of the device.
+ *
+ * This is a temporary development tool for use until yang integration is complete.
+ * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE.
+ */
+//Temporary Developer tool, NOT TO BE USED in production or as example for
+// future commands.
+//FIXME Remove dependency to ConfigSetter.
+
+@Command(scope = "onos", name = "netconf-rpc-test",
+        description = "Debug tool to send NETCONF RPC request")
+public class NetconfRpcTestCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "uri", description = "Device ID",
+            required = true, multiValued = false)
+    private String uri = null;
+
+    @Argument(index = 1, name = "cfgFile", description = "File path to RPC XML",
+            required = true, multiValued = false)
+    private String cfgFile = null;
+
+    private DeviceId deviceId;
+
+    @Override
+    protected void execute() {
+        DriverService service = get(DriverService.class);
+        deviceId = DeviceId.deviceId(uri);
+        DriverHandler h = service.createHandler(deviceId);
+        ConfigSetter config = h.behaviour(ConfigSetter.class);
+        checkNotNull(cfgFile, "Configuration file cannot be null");
+        print(config.setConfiguration(cfgFile));
+    }
+
+}
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfSubscriptionTestCommand.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfSubscriptionTestCommand.java
new file mode 100644
index 0000000..a15cde9
--- /dev/null
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfSubscriptionTestCommand.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2017-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.netconf.cli.impl;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.cli.net.DeviceIdCompleter;
+import org.onosproject.net.DeviceId;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfDevice;
+import org.onosproject.netconf.NetconfException;
+
+/**
+ * Debug command to start subscription on specified device.
+ */
+@Command(scope = "onos", name = "netconf-subscription-test",
+         description = "Debug command to start subscription on specified device")
+public class NetconfSubscriptionTestCommand extends AbstractShellCommand {
+
+    // for OSGi
+    DeviceIdCompleter uriCompleter;
+
+    @Argument(index = 0, name = "deviceId", description = "Device ID",
+            required = true, multiValued = false)
+    String uri = null;
+
+    @Option(name = "--end",
+            description = "Ends subscription instead of starting",
+            required = false)
+    boolean end = false;
+
+
+    @Override
+    protected void execute() {
+        NetconfController controller = get(NetconfController.class);
+        DeviceId did = DeviceId.deviceId(uri);
+
+        NetconfDevice netconfDevice = controller.getNetconfDevice(did);
+        if (netconfDevice == null) {
+            print("%s not found or not connectoed to this node", did);
+            return;
+        }
+
+        if (!end) {
+            try {
+                netconfDevice.getSession().startSubscription();
+            } catch (NetconfException e) {
+                log.error("Exception thrown", e);
+                print("starting subscription failed (see log for details)");
+            }
+        } else {
+            try {
+                netconfDevice.getSession().endSubscription();
+            } catch (NetconfException e) {
+                log.error("Exception thrown", e);
+                print("ending subscription failed (see log for details)");
+            }
+        }
+    }
+
+}
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/package-info.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/package-info.java
new file mode 100644
index 0000000..dd164b4
--- /dev/null
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-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.
+ */
+/**
+ * NETCONF CLI utilities.
+ */
+package org.onosproject.netconf.cli.impl;
diff --git a/protocols/netconf/ctl/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/protocols/netconf/ctl/src/main/resources/OSGI-INF/blueprint/shell-config.xml
new file mode 100644
index 0000000..72e3087
--- /dev/null
+++ b/protocols/netconf/ctl/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -0,0 +1,48 @@
+<!--
+  ~ Copyright 2017-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.
+  -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+
+        <command>
+            <action class="org.onosproject.netconf.cli.impl.NetconfSubscriptionTestCommand"/>
+            <completers>
+                <ref component-id="deviceIdCompleter"/>
+                <null/>
+            </completers>
+        </command>
+
+        <command>
+            <action class="org.onosproject.netconf.cli.impl.NetconfConfigGetCommand"/>
+            <completers>
+                <ref component-id="deviceIdCompleter"/>
+                <null/>
+            </completers>
+        </command>
+
+        <command>
+            <action class="org.onosproject.netconf.cli.impl.NetconfRpcTestCommand"/>
+            <completers>
+                <ref component-id="deviceIdCompleter"/>
+                <null/>
+            </completers>
+        </command>
+
+    </command-bundle>
+
+    <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/>
+
+</blueprint>