BUG-3335 Disable keepalives in netconf testtool
[controller.git] / opendaylight / netconf / netconf-testtool / src / main / java / org / opendaylight / controller / netconf / test / tool / Main.java
index e36d58591e2ad8a1b2f757ca475ec7f41aa392ae..e273254e0ed3bc8520cdcaf910957b982958f3b9 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.controller.netconf.test.tool;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
 
 import ch.qos.logback.classic.Level;
 import com.google.common.base.Charsets;
@@ -46,7 +45,7 @@ public final class Main {
 
     private static final Logger LOG = LoggerFactory.getLogger(Main.class);
 
-    static class Params {
+    public static class Params {
 
         @Arg(dest = "schemas-dir")
         public File schemasDir;
@@ -78,6 +77,9 @@ public final class Main {
         @Arg(dest = "debug")
         public boolean debug;
 
+        @Arg(dest = "notification-file")
+        public File notificationFile;
+
         static ArgumentParser getParser() {
             final ArgumentParser parser = ArgumentParsers.newArgumentParser("netconf testool");
 
@@ -95,6 +97,11 @@ public final class Main {
                     .help("Directory containing yang schemas to describe simulated devices. Some schemas e.g. netconf monitoring and inet types are included by default")
                     .dest("schemas-dir");
 
+            parser.addArgument("--notification-file")
+                    .type(File.class)
+                    .help("Xml file containing notifications that should be sent to clients after create subscription is called")
+                    .dest("notification-file");
+
             parser.addArgument("--starting-port")
                     .type(Integer.class)
                     .setDefault(17830)
@@ -147,7 +154,7 @@ public final class Main {
 
         void validate() {
             checkArgument(deviceCount > 0, "Device count has to be > 0");
-            checkArgument(startingPort > 1024, "Starting port has to be > 1024");
+            checkArgument(startingPort > 1023, "Starting port has to be > 1023");
 
             if(schemasDir != null) {
                 checkArgument(schemasDir.exists(), "Schemas dir has to exist");
@@ -167,6 +174,10 @@ public final class Main {
         final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator();
         try {
             final List<Integer> openDevices = netconfDeviceSimulator.start(params);
+            if (openDevices.size() == 0) {
+                LOG.error("Failed to start any simulated devices, exiting...");
+                System.exit(1);
+            }
             if(params.distroFolder != null) {
                 final ConfigGenerator configGenerator = new ConfigGenerator(params.distroFolder, openDevices);
                 final List<File> generated = configGenerator.generate(params.ssh, params.generateConfigBatchSize, params.generateConfigsTimeout, params.generateConfigsAddress);
@@ -203,11 +214,7 @@ public final class Main {
     }
 
     private static class ConfigGenerator {
-        public static final String NETCONF_CONNECTOR_XML = "/initial/99-netconf-connector.xml";
-        public static final String NETCONF_CONNECTOR_NAME = "controller-config";
-        public static final String NETCONF_CONNECTOR_PORT = "1830";
-        public static final String NETCONF_CONNECTOR_ADDRESS = "127.0.0.1";
-        public static final String NETCONF_USE_SSH = "false";
+        public static final String NETCONF_CONNECTOR_XML = "/99-netconf-connector-simulated.xml";
         public static final String SIM_DEVICE_SUFFIX = "-sim-device";
 
         private static final String SIM_DEVICE_CFG_PREFIX = "simulated-devices_";
@@ -249,15 +256,6 @@ public final class Main {
                 checkNotNull(stream, "Cannot load %s", NETCONF_CONNECTOR_XML);
                 String configBlueprint = CharStreams.toString(new InputStreamReader(stream, Charsets.UTF_8));
 
-                checkState(configBlueprint.contains(NETCONF_CONNECTOR_NAME));
-                checkState(configBlueprint.contains(NETCONF_CONNECTOR_PORT));
-                checkState(configBlueprint.contains(NETCONF_USE_SSH));
-                checkState(configBlueprint.contains(NETCONF_CONNECTOR_ADDRESS));
-                configBlueprint = configBlueprint.replace(NETCONF_CONNECTOR_NAME, "%s");
-                configBlueprint = configBlueprint.replace(NETCONF_CONNECTOR_ADDRESS, "%s");
-                configBlueprint = configBlueprint.replace(NETCONF_CONNECTOR_PORT, "%s");
-                configBlueprint = configBlueprint.replace(NETCONF_USE_SSH, "%s");
-
                 final String before = configBlueprint.substring(0, configBlueprint.indexOf("<module>"));
                 final String middleBlueprint = configBlueprint.substring(configBlueprint.indexOf("<module>"), configBlueprint.indexOf("</module>"));
                 final String after = configBlueprint.substring(configBlueprint.indexOf("</module>") + "</module>".length());