import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import org.apache.sshd.client.SshClient;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
import org.opendaylight.netconf.nettyutil.AbstractNetconfDispatcher;
private static final Logger LOG = LoggerFactory.getLogger(NetconfClientDispatcherImpl.class);
private final Timer timer;
+ private final SshClient sshClient;
public NetconfClientDispatcherImpl(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup,
- final Timer timer) {
+ final Timer timer, @Nullable final SshClient sshClient) {
super(bossGroup, workerGroup);
this.timer = timer;
+ this.sshClient = sshClient;
+ }
+
+ public NetconfClientDispatcherImpl(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup,
+ final Timer timer) {
+ this(bossGroup, workerGroup, timer, null);
}
protected Timer getTimer() {
LOG.debug("Creating SSH client with configuration: {}", currentConfiguration);
return super.createClient(currentConfiguration.getAddress(), currentConfiguration.getReconnectStrategy(),
(ch, sessionPromise) -> new SshClientChannelInitializer(currentConfiguration.getAuthHandler(),
- getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener())
- .initialize(ch, sessionPromise));
+ getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener(),
+ sshClient).initialize(ch, sessionPromise));
}
private Future<Void> createReconnectingSshClient(
final NetconfReconnectingClientConfiguration currentConfiguration) {
LOG.debug("Creating reconnecting SSH client with configuration: {}", currentConfiguration);
final SshClientChannelInitializer init = new SshClientChannelInitializer(currentConfiguration.getAuthHandler(),
- getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener());
+ getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener(), sshClient);
return super.createReconnectingClient(currentConfiguration.getAddress(), currentConfiguration
.getConnectStrategyFactory(), currentConfiguration.getReconnectStrategy(),
import io.netty.channel.Channel;
import io.netty.util.concurrent.Promise;
+import org.apache.sshd.client.SshClient;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
import org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
private final AuthenticationHandler authenticationHandler;
private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
private final NetconfClientSessionListener sessionListener;
+ private final SshClient sshClient;
SshClientChannelInitializer(final AuthenticationHandler authHandler,
- final NetconfClientSessionNegotiatorFactory negotiatorFactory,
- final NetconfClientSessionListener sessionListener) {
+ final NetconfClientSessionNegotiatorFactory negotiatorFactory,
+ final NetconfClientSessionListener sessionListener, @Nullable final SshClient sshClient) {
this.authenticationHandler = authHandler;
this.negotiatorFactory = negotiatorFactory;
this.sessionListener = sessionListener;
+ this.sshClient = sshClient;
+ }
+
+ SshClientChannelInitializer(final AuthenticationHandler authHandler,
+ final NetconfClientSessionNegotiatorFactory negotiatorFactory,
+ final NetconfClientSessionListener sessionListener) {
+ this(authHandler, negotiatorFactory, sessionListener, null);
}
@Override
public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) {
// ssh handler has to be the first handler in pipeline
- ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler, promise));
+ ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler, promise, sshClient));
super.initialize(ch, promise);
}
import org.apache.sshd.client.future.AuthFuture;
import org.apache.sshd.client.future.ConnectFuture;
import org.apache.sshd.client.session.ClientSession;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @return {@code AsyncSshHandler}
*/
public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler,
- final Future<?> negotiationFuture) {
- return new AsyncSshHandler(authenticationHandler, DEFAULT_CLIENT, negotiationFuture);
+ final Future<?> negotiationFuture, @Nullable final SshClient sshClient) {
+ return new AsyncSshHandler(authenticationHandler, sshClient != null ? sshClient : DEFAULT_CLIENT,
+ negotiationFuture);
}
private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) throws IOException {
import io.netty.channel.EventLoopGroup;
import io.netty.util.Timer;
import java.util.Set;
+import org.apache.sshd.client.SshClient;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.netconf.client.NetconfClientDispatcherImpl;
import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
private final Set<String> capabilities;
private ConfigurableClientDispatcher(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup,
- final Timer timer, final Set<String> capabilities) {
- super(bossGroup, workerGroup, timer);
+ final Timer timer, final Set<String> capabilities, @Nullable final SshClient sshClient) {
+ super(bossGroup, workerGroup, timer, sshClient);
this.capabilities = capabilities;
}
* EXI + chunked framing.
*/
public static ConfigurableClientDispatcher createChunkedExi(final EventLoopGroup bossGroup,
- final EventLoopGroup workerGroup, final Timer timer) {
+ final EventLoopGroup workerGroup, final Timer timer, @Nullable final SshClient sshClient) {
return new ConfigurableClientDispatcher(bossGroup, workerGroup, timer,
- NetconfClientSessionNegotiatorFactory.EXI_CLIENT_CAPABILITIES);
+ NetconfClientSessionNegotiatorFactory.EXI_CLIENT_CAPABILITIES, sshClient);
}
/**
* EXI + ]]gt;]]gt; framing.
*/
public static ConfigurableClientDispatcher createLegacyExi(final EventLoopGroup bossGroup,
- final EventLoopGroup workerGroup, final Timer timer) {
+ final EventLoopGroup workerGroup, final Timer timer, @Nullable final SshClient sshClient) {
return new ConfigurableClientDispatcher(bossGroup, workerGroup, timer,
- NetconfClientSessionNegotiatorFactory.LEGACY_EXI_CLIENT_CAPABILITIES);
+ NetconfClientSessionNegotiatorFactory.LEGACY_EXI_CLIENT_CAPABILITIES, sshClient);
}
/**
* Chunked framing.
*/
public static ConfigurableClientDispatcher createChunked(final EventLoopGroup bossGroup,
- final EventLoopGroup workerGroup, final Timer timer) {
+ final EventLoopGroup workerGroup, final Timer timer, @Nullable final SshClient sshClient) {
return new ConfigurableClientDispatcher(bossGroup, workerGroup, timer,
- NetconfClientSessionNegotiatorFactory.DEFAULT_CLIENT_CAPABILITIES);
+ NetconfClientSessionNegotiatorFactory.DEFAULT_CLIENT_CAPABILITIES, sshClient);
}
/**
* ]]gt;]]gt; framing.
*/
public static ConfigurableClientDispatcher createLegacy(final EventLoopGroup bossGroup,
- final EventLoopGroup workerGroup, final Timer timer) {
+ final EventLoopGroup workerGroup, final Timer timer, @Nullable final SshClient sshClient) {
return new ConfigurableClientDispatcher(bossGroup, workerGroup, timer,
- NetconfClientSessionNegotiatorFactory.LEGACY_FRAMING_CLIENT_CAPABILITIES);
+ NetconfClientSessionNegotiatorFactory.LEGACY_FRAMING_CLIENT_CAPABILITIES, sshClient);
}
@Override
final NetconfClientDispatcherImpl netconfClientDispatcher;
if (params.exi) {
if (params.legacyFraming) {
- netconfClientDispatcher = ConfigurableClientDispatcher.createLegacyExi(nioGroup, nioGroup, timer);
+ netconfClientDispatcher = ConfigurableClientDispatcher.createLegacyExi(nioGroup, nioGroup, timer,
+ null);
} else {
- netconfClientDispatcher = ConfigurableClientDispatcher.createChunkedExi(nioGroup, nioGroup, timer);
+ netconfClientDispatcher = ConfigurableClientDispatcher.createChunkedExi(nioGroup, nioGroup, timer,
+ null);
}
} else {
if (params.legacyFraming) {
- netconfClientDispatcher = ConfigurableClientDispatcher.createLegacy(nioGroup, nioGroup, timer);
+ netconfClientDispatcher = ConfigurableClientDispatcher.createLegacy(nioGroup, nioGroup, timer, null);
} else {
- netconfClientDispatcher = ConfigurableClientDispatcher.createChunked(nioGroup, nioGroup, timer);
+ netconfClientDispatcher = ConfigurableClientDispatcher.createChunked(nioGroup, nioGroup, timer, null);
}
}
return netconfClientDispatcher;