Add some validations and new arguments 48/36248/6
authormiroslav.kovac <miroslav.kovac@pantheon.tech>
Tue, 15 Mar 2016 14:09:24 +0000 (15:09 +0100)
committermiroslav.kovac <miroslav.kovac@pantheon.tech>
Tue, 3 May 2016 10:50:58 +0000 (12:50 +0200)
It validates some new parameters.Also thread pool size
and Ip of socket address is configurable. We can set
them using program arguments.

Change-Id: I4af24500ca0650c0c5a922d41b292c573ac78400
Signed-off-by: miroslav.kovac <miroslav.kovac@pantheon.tech>
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Main.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/NetconfDeviceSimulator.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/ScaleUtil.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/http/perf/Parameters.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/Parameters.java

index bffb6f87e0fbc2e5813b04201d2345b797b47fca..e7c772521cabfe69b8e149bca7397b82cd93c361 100644 (file)
@@ -54,7 +54,7 @@ public final class Main {
         final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
         root.setLevel(params.debug ? Level.DEBUG : Level.INFO);
 
-        final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator();
+        final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator(params.threadPoolSize);
         try {
             final List<Integer> openDevices = netconfDeviceSimulator.start(params);
             if (openDevices.size() == 0) {
index 23d6750896140857b0dc10b9e6b3d36939edc0e3..50cbf2d647785438947860b8604de2126f707570 100644 (file)
@@ -88,11 +88,10 @@ public class NetconfDeviceSimulator implements Closeable {
 
     private boolean sendFakeSchema = false;
 
-    public NetconfDeviceSimulator() {
-        // TODO make pool size configurable
+    public NetconfDeviceSimulator(final int ThreadPoolSize) {
         this(new NioEventLoopGroup(), new HashedWheelTimer(),
-                Executors.newScheduledThreadPool(8, new ThreadFactoryBuilder().setNameFormat("netconf-ssh-server-mina-timers-%d").build()),
-                ThreadUtils.newFixedThreadPool("netconf-ssh-server-nio-group", 8));
+                Executors.newScheduledThreadPool(ThreadPoolSize, new ThreadFactoryBuilder().setNameFormat("netconf-ssh-server-mina-timers-%d").build()),
+                ThreadUtils.newFixedThreadPool("netconf-ssh-server-nio-group", ThreadPoolSize));
     }
 
     private NetconfDeviceSimulator(final NioEventLoopGroup eventExecutors, final HashedWheelTimer hashedWheelTimer, final ScheduledExecutorService minaTimerExecutor, final ExecutorService nioExecutor) {
@@ -122,7 +121,7 @@ public class NetconfDeviceSimulator implements Closeable {
 
         final AggregatedNetconfOperationServiceFactory aggregatedNetconfOperationServiceFactory = new AggregatedNetconfOperationServiceFactory();
         final NetconfOperationServiceFactory operationProvider = mdSal ? new MdsalOperationProvider(idProvider, transformedCapabilities, schemaContext, sourceProvider) :
-            new SimulatedOperationProvider(idProvider, transformedCapabilities, notificationsFile, initialConfigXMLFile);
+                new SimulatedOperationProvider(idProvider, transformedCapabilities, notificationsFile, initialConfigXMLFile);
 
         transformedCapabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0"));
 
@@ -173,7 +172,7 @@ public class NetconfDeviceSimulator implements Closeable {
                 LOG.warn("Port cannot be greater than 65535, stopping further attempts.");
                 break;
             }
-            final InetSocketAddress address = getAddress(currentPort);
+            final InetSocketAddress address = getAddress(params.ip, currentPort);
 
             final ChannelFuture server;
             if(params.ssh) {
@@ -361,10 +360,9 @@ public class NetconfDeviceSimulator implements Closeable {
         }, PotentialSchemaSource.create(sourceId, YangTextSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
     }
 
-    private static InetSocketAddress getAddress(final int port) {
+    private static InetSocketAddress getAddress(final String ip, final int port) {
         try {
-            // TODO make address configurable
-            return new InetSocketAddress(Inet4Address.getByName("0.0.0.0"), port);
+            return new InetSocketAddress(Inet4Address.getByName(ip), port);
         } catch (final UnknownHostException e) {
             throw new RuntimeException(e);
         }
index a8040f95eedb4f90c1ba3e0cef5062130cf84486..555f6833b2b38eb10a96c1d2bc7e6c7225fa5361 100644 (file)
@@ -65,7 +65,7 @@ public class ScaleUtil {
         while (true) {
             root.warn("Starting scale test with {} devices", params.deviceCount);
             timeoutGuardFuture = executor.schedule(new TimeoutGuard(), timeout, TimeUnit.MINUTES);
-            final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator();
+            final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator(params.threadAmount);
             try {
                 final List<Integer> openDevices = netconfDeviceSimulator.start(params);
                 if (openDevices.size() == 0) {
index eb6363227d8d40d08165f86eace8ac72933667b9..0ad0f1831c8d5dd3b4606b518c9d537c55301554 100644 (file)
@@ -101,6 +101,12 @@ public class TesttoolParameters {
     @Arg(dest = "time-out")
     public long timeOut;
 
+    @Arg(dest = "ip")
+    public String ip;
+
+    @Arg(dest = "thread-pool-size")
+    public int threadPoolSize;
+
     static ArgumentParser getParser() {
         final ArgumentParser parser = ArgumentParsers.newArgumentParser("netconf testtool");
 
@@ -118,7 +124,8 @@ public class TesttoolParameters {
         parser.addArgument("--thread-amount")
                 .type(Integer.class)
                 .setDefault(1)
-                .dest("thread-amount");
+                .dest("thread-amount")
+                .help("The number of threads to use for configuring devices.");
 
         parser.addArgument("--throttle")
                 .type(Integer.class)
@@ -226,6 +233,20 @@ public class TesttoolParameters {
                 .help("the maximum time in seconds for executing each PUT request")
                 .dest("time-out");
 
+        parser.addArgument("-ip")
+                .type(String.class)
+                .setDefault("0.0.0.0")
+                .help("Ip address which will be used for creating a socket address." +
+                        "It can either be a machine name, such as " +
+                        "java.sun.com, or a textual representation of its IP address.")
+                .dest("ip");
+
+        parser.addArgument("--thread-pool-size")
+                .type(Integer.class)
+                .setDefault(8)
+                .help("The number of threads to keep in the pool, when creating a device simulator. Even if they are idle.")
+                .dest("thread-pool-size");
+
         return parser;
     }
 
index 6f5736f0112b7cd67e3b24f0f18eeb848c1fab66..53296d408036a57431fefb6a40bdef336ff24848 100644 (file)
@@ -144,8 +144,7 @@ public class Parameters {
         Preconditions.checkArgument(editContent.canRead(), "Edit content file is unreadable");
 
         Preconditions.checkArgument(destination.startsWith("/"), "Destination should start with a '/'");
-
-        // TODO validate
+        Preconditions.checkArgument(threadAmount > 0, "Parameter thread-amount must be greater than 0");
     }
 
     public InetSocketAddress getInetAddress() {
index c7e3dbfdab5c362d3920c8130ca861fd69d0e0f2..77a0a60a301fd66128cf9a31dcf0b6cf4e0f4a68 100644 (file)
@@ -163,9 +163,6 @@ public class Parameters {
                 .setDefault(1)
                 .dest("thread-amount");
 
-        // TODO add get-config option instead of edit + commit
-        // TODO different edit config content
-
         return parser;
     }
 
@@ -181,7 +178,8 @@ public class Parameters {
         Preconditions.checkArgument(editContent.exists(), "Edit content file missing");
         Preconditions.checkArgument(editContent.isDirectory() == false, "Edit content file is a dir");
         Preconditions.checkArgument(editContent.canRead(), "Edit content file is unreadable");
-        // TODO validate
+        Preconditions.checkArgument(threadAmount > 0, "Parameter thread-amount must be greater than 0");
+        Preconditions.checkArgument(msgTimeout >= 0, "Parameter msg-timeout must be greater than 0");
     }
 
     public InetSocketAddress getInetAddress() {