Merge "Handle more specific BindException and IOException"
authorEd Warnicke <eaw@cisco.com>
Tue, 2 Dec 2014 16:21:52 +0000 (16:21 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 2 Dec 2014 16:21:52 +0000 (16:21 +0000)
1  2 
opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java

index a45c374eae00ed456fae70ce4cd7c5c0a83ca89a,36e7dca76138095c6bca8796e778084bb5d074cb..c6cad90355705961ca72e6cd64da36ff41780e14
@@@ -30,6 -30,7 +30,7 @@@ import java.io.IOException
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.lang.management.ManagementFactory;
+ import java.net.BindException;
  import java.net.Inet4Address;
  import java.net.InetSocketAddress;
  import java.net.URI;
@@@ -185,10 -186,6 +186,10 @@@ public class NetconfDeviceSimulator imp
          final PEMGeneratorHostKeyProvider keyPairProvider = getPemGeneratorHostKeyProvider();
  
          for (int i = 0; i < params.deviceCount; i++) {
 +            if (currentPort > 65535) {
 +                LOG.warn("Port cannot be greater than 65535, stopping further attempts.");
 +                break;
 +            }
              final InetSocketAddress address = getAddress(currentPort);
  
              final ChannelFuture server;
                      final SshProxyServer sshServer = new SshProxyServer(minaTimerExecutor, nettyThreadgroup, nioExecutor);
                      sshServer.bind(getSshConfiguration(bindingAddress, tcpLocalAddress));
                      sshWrappers.add(sshServer);
-                 } catch (final Exception e) {
-                     LOG.warn("Cannot start simulated device on {}, skipping", address, e);
+                 } catch (final BindException e) {
+                     LOG.warn("Cannot start simulated device on {}, port already in use. Skipping.", address);
                      // Close local server and continue
                      server.cancel(true);
                      if(server.isDone()) {
                          server.channel().close();
                      }
                      continue;
+                 } catch (final IOException e) {
+                     LOG.warn("Cannot start simulated device on {} due to IOException.", address, e);
+                     break;
                  } finally {
                      currentPort++;
                  }
  
          if(openDevices.size() == params.deviceCount) {
              LOG.info("All simulated devices started successfully from port {} to {}", params.startingPort, currentPort - 1);
 +        } else if (openDevices.size() == 0) {
 +            LOG.warn("No simulated devices started.");
          } else {
              LOG.warn("Not all simulated devices started successfully. Started devices ar on ports {}", openDevices);
          }