X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Ftools%2Fnetconf-testtool%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Ftest%2Ftool%2Fclient%2Fstress%2FStressClientCallable.java;fp=opendaylight%2Fnetconf%2Ftools%2Fnetconf-testtool%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Ftest%2Ftool%2Fclient%2Fstress%2FStressClientCallable.java;h=a37fcd722ad612078ba665f30b22b0ed9584b439;hb=23fe9ca678ada6263fec5dd996f4025e4a32fcf5;hp=0000000000000000000000000000000000000000;hpb=071a641d7c12c0e6112d5ce0afe806b54f116ed2;p=controller.git diff --git a/opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/client/stress/StressClientCallable.java b/opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/client/stress/StressClientCallable.java new file mode 100644 index 0000000000..a37fcd722a --- /dev/null +++ b/opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/client/stress/StressClientCallable.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.test.tool.client.stress; + +import io.netty.util.concurrent.GlobalEventExecutor; +import java.net.InetSocketAddress; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; +import org.opendaylight.controller.netconf.client.NetconfClientSession; +import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; +import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder; +import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.LoginPassword; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader; +import org.opendaylight.controller.sal.connect.api.RemoteDevice; +import org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCommunicator; +import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionPreferences; +import org.opendaylight.controller.sal.connect.util.RemoteDeviceId; +import org.opendaylight.protocol.framework.NeverReconnectStrategy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class StressClientCallable implements Callable{ + + private static final Logger LOG = LoggerFactory.getLogger(StressClientCallable.class); + + private Parameters params; + private final NetconfDeviceCommunicator sessionListener; + private final NetconfClientDispatcherImpl netconfClientDispatcher; + private final NetconfClientConfiguration cfg; + private final NetconfClientSession netconfClientSession; + private final ExecutionStrategy executionStrategy; + + public StressClientCallable(final Parameters params, + final NetconfClientDispatcherImpl netconfClientDispatcher, + final List preparedMessages) { + this.params = params; + this.sessionListener = getSessionListener(params.getInetAddress()); + this.netconfClientDispatcher = netconfClientDispatcher; + cfg = getNetconfClientConfiguration(this.params, this.sessionListener); + + LOG.info("Connecting to netconf server {}:{}", params.ip, params.port); + try { + netconfClientSession = netconfClientDispatcher.createClient(cfg).get(); + } catch (final InterruptedException e) { + throw new RuntimeException(e); + } catch (final ExecutionException e) { + throw new RuntimeException("Unable to connect", e); + } + executionStrategy = getExecutionStrategy(params, preparedMessages, sessionListener); + } + + @Override + public Boolean call() throws Exception { + executionStrategy.invoke(); + netconfClientSession.close(); + return true; + } + + private static ExecutionStrategy getExecutionStrategy(final Parameters params, final List preparedMessages, final NetconfDeviceCommunicator sessionListener) { + if(params.async) { + return new AsyncExecutionStrategy(params, preparedMessages, sessionListener); + } else { + return new SyncExecutionStrategy(params, preparedMessages, sessionListener); + } + } + + private static NetconfDeviceCommunicator getSessionListener(final InetSocketAddress inetAddress) { + final RemoteDevice loggingRemoteDevice = new StressClient.LoggingRemoteDevice(); + return new NetconfDeviceCommunicator(new RemoteDeviceId("secure-test", inetAddress), loggingRemoteDevice); + } + + private static NetconfClientConfiguration getNetconfClientConfiguration(final Parameters params, final NetconfDeviceCommunicator sessionListener) { + final NetconfClientConfigurationBuilder netconfClientConfigurationBuilder = NetconfClientConfigurationBuilder.create(); + netconfClientConfigurationBuilder.withSessionListener(sessionListener); + netconfClientConfigurationBuilder.withAddress(params.getInetAddress()); + if(params.tcpHeader != null) { + final String header = params.tcpHeader.replaceAll("\"", "").trim() + "\n"; + netconfClientConfigurationBuilder.withAdditionalHeader(new NetconfHelloMessageAdditionalHeader(null, null, null, null, null) { + @Override + public String toFormattedString() { + LOG.debug("Sending TCP header {}", header); + return header; + } + }); + } + netconfClientConfigurationBuilder.withProtocol(params.ssh ? NetconfClientConfiguration.NetconfClientProtocol.SSH : NetconfClientConfiguration.NetconfClientProtocol.TCP); + netconfClientConfigurationBuilder.withAuthHandler(new LoginPassword(params.username, params.password)); + netconfClientConfigurationBuilder.withConnectionTimeoutMillis(20000L); + netconfClientConfigurationBuilder.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000)); + return netconfClientConfigurationBuilder.build(); + } +}