Async netconf API + command for netconf troubleshooting
- Added async API for fetching entire config (+ state)
- netconf-get
issue netcong rpc get
- netconf-get-config
Revised to use async API to deal with slow device
Example usage:
onos> netconf-get netconf:192.168.56.1:2022 | ppxml
for ONOS-7481
Change-Id: Id012e984275109c93bdae113f3fec685a7b2211b
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/NetconfGetCommand.java
similarity index 65%
copy from protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java
copy to protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfGetCommand.java
index bac6bef..2d29fcd 100644
--- 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/NetconfGetCommand.java
@@ -16,10 +16,13 @@
package org.onosproject.netconf.cli.impl;
import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.netconf.DatastoreId.datastore;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
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.net.DeviceId;
import org.onosproject.netconf.NetconfController;
@@ -28,29 +31,26 @@
import org.onosproject.netconf.NetconfSession;
/**
- * Command that gets the configuration of the specified type from the specified
- * device. If configuration cannot be retrieved it prints an error string.
+ * Command that retrieves running configuration and device state.
+ * If configuration cannot be retrieved it prints an error string.
*/
-@Command(scope = "onos", name = "netconf-get-config",
- description = "Gets the configuration of the specified type from the" +
- "specified device.")
-public class NetconfConfigGetCommand extends AbstractShellCommand {
+@Command(scope = "onos", name = "netconf-get",
+ description = "Retrieve running configuration and "
+ + "device state information from specified device.")
+public class NetconfGetCommand extends AbstractShellCommand {
- @Argument(index = 0, name = "uri", description = "Device ID",
+ @Argument(index = 0, name = "deviceId", 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;
+ @Option(name = "--timeout",
+ description = "Timeout in seconds",
+ required = false)
+ long timeoutSec = 30;
@Override
protected void execute() {
- deviceId = DeviceId.deviceId(uri);
+ DeviceId deviceId = DeviceId.deviceId(uri);
NetconfController controller = get(NetconfController.class);
checkNotNull(controller, "Netconf controller is null");
@@ -68,9 +68,10 @@
}
try {
- String res = session.getConfig(datastore(cfgType.toLowerCase()));
+ CharSequence res = session.asyncGet()
+ .get(timeoutSec, TimeUnit.SECONDS);
print("%s", res);
- } catch (NetconfException e) {
+ } catch (NetconfException | InterruptedException | ExecutionException | TimeoutException e) {
log.error("Configuration could not be retrieved", e);
print("Error occurred retrieving configuration");
}
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/NetconfGetConfigCommand.java
similarity index 74%
rename from protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java
rename to protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfGetConfigCommand.java
index bac6bef..2aedaa9 100644
--- 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/NetconfGetConfigCommand.java
@@ -18,8 +18,13 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.netconf.DatastoreId.datastore;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
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.net.DeviceId;
import org.onosproject.netconf.NetconfController;
@@ -34,17 +39,21 @@
@Command(scope = "onos", name = "netconf-get-config",
description = "Gets the configuration of the specified type from the" +
"specified device.")
-public class NetconfConfigGetCommand extends AbstractShellCommand {
+public class NetconfGetConfigCommand extends AbstractShellCommand {
- @Argument(index = 0, name = "uri", description = "Device ID",
+ @Argument(index = 0, name = "deviceId", description = "Device ID",
required = true, multiValued = false)
String uri = null;
- @Argument(index = 1, name = "cfgType",
+ @Argument(index = 1, name = "datastore",
description = "Configuration datastore name (running, etc.)",
- required = true, multiValued = false)
- String cfgType = null;
+ required = false, multiValued = false)
+ String datastore = "running";
+ @Option(name = "--timeout",
+ description = "Timeout in seconds",
+ required = false)
+ long timeoutSec = 30;
private DeviceId deviceId;
@@ -68,9 +77,10 @@
}
try {
- String res = session.getConfig(datastore(cfgType.toLowerCase()));
+ CharSequence res = session.asyncGetConfig(datastore(datastore.toLowerCase()))
+ .get(timeoutSec, TimeUnit.SECONDS);
print("%s", res);
- } catch (NetconfException e) {
+ } catch (NetconfException | InterruptedException | ExecutionException | TimeoutException e) {
log.error("Configuration could not be retrieved", e);
print("Error occurred retrieving configuration");
}