X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fclient%2FNetconfSshClientDispatcher.java;h=5b82ff22156341b8543b59d3c95bd72e6d9b77cd;hp=b19c09263b9fa481c76307da0bb2dbebc310bb85;hb=3176d0fa83a733f1aa0810d7e99217f5aa664931;hpb=110f0a37cb14b8fbf05b87dcb851bd3f026c6d8d diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfSshClientDispatcher.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfSshClientDispatcher.java index b19c09263b..5b82ff2215 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfSshClientDispatcher.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfSshClientDispatcher.java @@ -8,50 +8,48 @@ package org.opendaylight.controller.netconf.client; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.util.HashedWheelTimer; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.Promise; + import java.io.IOException; import java.net.InetSocketAddress; -import javax.net.ssl.SSLContext; - -import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.api.NetconfSession; -import org.opendaylight.controller.netconf.api.NetconfTerminationReason; import org.opendaylight.controller.netconf.util.AbstractChannelInitializer; -import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory; -import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator; import org.opendaylight.controller.netconf.util.handler.ssh.SshHandler; import org.opendaylight.controller.netconf.util.handler.ssh.authentication.AuthenticationHandler; import org.opendaylight.controller.netconf.util.handler.ssh.client.Invoker; -import org.opendaylight.controller.netconf.util.messages.FramingMechanism; -import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory; -import org.opendaylight.protocol.framework.ProtocolHandlerFactory; -import org.opendaylight.protocol.framework.ProtocolMessageDecoder; -import org.opendaylight.protocol.framework.ProtocolMessageEncoder; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader; import org.opendaylight.protocol.framework.ReconnectStrategy; -import org.opendaylight.protocol.framework.SessionListener; +import org.opendaylight.protocol.framework.ReconnectStrategyFactory; import org.opendaylight.protocol.framework.SessionListenerFactory; import com.google.common.base.Optional; -import io.netty.channel.ChannelHandler; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.socket.SocketChannel; -import io.netty.util.HashedWheelTimer; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.Promise; - public class NetconfSshClientDispatcher extends NetconfClientDispatcher { - private AuthenticationHandler authHandler; - private HashedWheelTimer timer; - private NetconfClientSessionNegotiatorFactory negotatorFactory; + private final AuthenticationHandler authHandler; + private final HashedWheelTimer timer; + private final NetconfClientSessionNegotiatorFactory negotiatorFactory; + + public NetconfSshClientDispatcher(AuthenticationHandler authHandler, EventLoopGroup bossGroup, + EventLoopGroup workerGroup, long connectionTimeoutMillis) { + super(bossGroup, workerGroup, connectionTimeoutMillis); + this.authHandler = authHandler; + this.timer = new HashedWheelTimer(); + this.negotiatorFactory = new NetconfClientSessionNegotiatorFactory(timer, + Optional. absent(), connectionTimeoutMillis); + } public NetconfSshClientDispatcher(AuthenticationHandler authHandler, EventLoopGroup bossGroup, - EventLoopGroup workerGroup) { - super(Optional. absent(), bossGroup, workerGroup); + EventLoopGroup workerGroup, NetconfHelloMessageAdditionalHeader additionalHeader, long socketTimeoutMillis) { + super(bossGroup, workerGroup, additionalHeader, socketTimeoutMillis); this.authHandler = authHandler; this.timer = new HashedWheelTimer(); - this.negotatorFactory = new NetconfClientSessionNegotiatorFactory(timer); + this.negotiatorFactory = new NetconfClientSessionNegotiatorFactory(timer, Optional.of(additionalHeader), + socketTimeoutMillis); } @Override @@ -61,15 +59,29 @@ public class NetconfSshClientDispatcher extends NetconfClientDispatcher { @Override public void initializeChannel(SocketChannel arg0, Promise arg1) { - new NetconfSshClientInitializer(authHandler, negotatorFactory, sessionListener).initialize(arg0, arg1); + new NetconfSshClientInitializer(authHandler, negotiatorFactory, sessionListener).initialize(arg0, arg1); } }); } - private static final class NetconfSshClientInitializer extends AbstractChannelInitializer { + @Override + public Future createReconnectingClient(final InetSocketAddress address, + final NetconfClientSessionListener listener, + final ReconnectStrategyFactory connectStrategyFactory, final ReconnectStrategy reestablishStrategy) { + final NetconfSshClientInitializer init = new NetconfSshClientInitializer(authHandler, negotiatorFactory, listener); + + return super.createReconnectingClient(address, connectStrategyFactory, reestablishStrategy, + new PipelineInitializer() { + @Override + public void initializeChannel(final SocketChannel ch, final Promise promise) { + init.initialize(ch, promise); + } + }); + } + + private static final class NetconfSshClientInitializer extends AbstractChannelInitializer { - private final NetconfHandlerFactory handlerFactory; private final AuthenticationHandler authenticationHandler; private final NetconfClientSessionNegotiatorFactory negotiatorFactory; private final NetconfClientSessionListener sessionListener; @@ -77,54 +89,32 @@ public class NetconfSshClientDispatcher extends NetconfClientDispatcher { public NetconfSshClientInitializer(AuthenticationHandler authHandler, NetconfClientSessionNegotiatorFactory negotiatorFactory, final NetconfClientSessionListener sessionListener) { - this.handlerFactory = new NetconfHandlerFactory(new NetconfMessageFactory()); this.authenticationHandler = authHandler; this.negotiatorFactory = negotiatorFactory; this.sessionListener = sessionListener; } @Override - public void initialize(SocketChannel ch, Promise promise) { + public void initialize(SocketChannel ch, Promise promise) { try { Invoker invoker = Invoker.subsystem("netconf"); ch.pipeline().addFirst(new SshHandler(authenticationHandler, invoker)); - ch.pipeline().addLast("aggregator", new NetconfMessageAggregator(FramingMechanism.EOM)); - ch.pipeline().addLast(handlerFactory.getDecoders()); - initializeAfterDecoder(ch, promise); - ch.pipeline().addLast("frameEncoder", - FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM)); - ch.pipeline().addLast(handlerFactory.getEncoders()); + super.initialize(ch,promise); } catch (IOException e) { throw new RuntimeException(e); } } @Override - protected void initializeAfterDecoder(SocketChannel ch, Promise promise) { - ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(new SessionListenerFactory() { + protected void initializeSessionNegotiator(SocketChannel ch, + Promise promise) { + ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR, + negotiatorFactory.getSessionNegotiator(new SessionListenerFactory() { @Override - public SessionListener getSessionListener() { + public NetconfClientSessionListener getSessionListener() { return sessionListener; } }, ch, promise)); - - } - } - - private static final class NetconfHandlerFactory extends ProtocolHandlerFactory { - - public NetconfHandlerFactory(final NetconfMessageFactory msgFactory) { - super(msgFactory); - } - - @Override - public ChannelHandler[] getEncoders() { - return new ChannelHandler[] { new ProtocolMessageEncoder(this.msgFactory) }; - } - - @Override - public ChannelHandler[] getDecoders() { - return new ChannelHandler[] { new ProtocolMessageDecoder(this.msgFactory) }; } } }