2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.netconf.test.tool;
11 import ch.qos.logback.classic.Level;
12 import com.google.common.base.Stopwatch;
13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.concurrent.ExecutionException;
17 import java.util.concurrent.ExecutorService;
18 import java.util.concurrent.Executors;
19 import java.util.concurrent.Future;
20 import java.util.concurrent.TimeUnit;
21 import org.opendaylight.netconf.test.tool.config.Configuration;
22 import org.opendaylight.netconf.test.tool.config.ConfigurationBuilder;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 @SuppressFBWarnings("DM_DEFAULT_ENCODING")
27 public final class Main {
28 private static final Logger LOG = LoggerFactory.getLogger(Main.class);
34 @SuppressWarnings("checkstyle:IllegalCatch")
35 @SuppressFBWarnings({"UW_UNCOND_WAIT", "WA_NOT_IN_LOOP"})
36 public static void main(final String[] args) {
37 final TesttoolParameters params = TesttoolParameters.parseArgs(args, TesttoolParameters.getParser());
39 final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory
40 .getLogger(Logger.ROOT_LOGGER_NAME);
41 root.setLevel(params.debug ? Level.DEBUG : Level.INFO);
43 final Configuration configuration = new ConfigurationBuilder().from(params).build();
44 final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator(configuration);
46 LOG.debug("Trying to start netconf test-tool with parameters {}", params);
47 final List<Integer> openDevices = netconfDeviceSimulator.start();
48 if (openDevices.size() == 0) {
49 LOG.error("Failed to start any simulated devices, exiting...");
52 //if ODL controller ip is not set NETCONF devices will be started, but not registered at the controller
53 if (params.controllerIp != null) {
54 final ArrayList<ArrayList<Execution.DestToPayload>> allThreadsPayloads = params
55 .getThreadsPayloads(openDevices);
56 final ArrayList<Execution> executions = new ArrayList<>();
57 for (ArrayList<Execution.DestToPayload> payloads : allThreadsPayloads) {
58 executions.add(new Execution(params, payloads));
60 final ExecutorService executorService = Executors.newFixedThreadPool(params.threadAmount);
61 final Stopwatch time = Stopwatch.createStarted();
62 List<Future<Void>> futures = executorService.invokeAll(executions, params.timeOut, TimeUnit.SECONDS);
64 for (Future<Void> future : futures) {
66 if (future.isCancelled()) {
67 LOG.info("{}. thread timed out.",threadNum);
71 } catch (final ExecutionException | InterruptedException e) {
72 LOG.info("{}. thread failed.", threadNum, e);
77 LOG.info("Time spent with configuration of devices: {}.",time);
79 } catch (RuntimeException | InterruptedException e) {
80 LOG.error("Unhandled exception", e);
81 netconfDeviceSimulator.close();
86 synchronized (netconfDeviceSimulator) {
88 netconfDeviceSimulator.wait();
89 } catch (final InterruptedException e) {
90 throw new RuntimeException(e);