X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2FAbstractChannelInitializer.java;h=48a45845a4a6fe7f57a722bc5678d8fc8447b54d;hb=1ded3b4311dc761d39c132f9f38fcceb761ea997;hp=317a126bbae392c46b8bd699f8023a03f858d4d0;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;p=controller.git diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java index 317a126bba..48a45845a4 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java @@ -8,69 +8,49 @@ package org.opendaylight.controller.netconf.util; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLEngine; - -import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.api.NetconfSession; -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 com.google.common.base.Optional; - -import io.netty.channel.ChannelHandler; import io.netty.channel.socket.SocketChannel; -import io.netty.handler.ssl.SslHandler; import io.netty.util.concurrent.Promise; -public abstract class AbstractChannelInitializer { - - private final Optional maybeContext; - private final NetconfHandlerFactory handlerFactory; - - public AbstractChannelInitializer(Optional maybeContext) { - this.maybeContext = maybeContext; - this.handlerFactory = new NetconfHandlerFactory(new NetconfMessageFactory()); +import org.opendaylight.controller.netconf.api.NetconfSession; +import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory; +import org.opendaylight.controller.netconf.util.handler.NetconfEOMAggregator; +import org.opendaylight.controller.netconf.util.handler.NetconfHelloMessageToXMLEncoder; +import org.opendaylight.controller.netconf.util.handler.NetconfXMLToHelloMessageDecoder; +import org.opendaylight.controller.netconf.util.messages.FramingMechanism; + +public abstract class AbstractChannelInitializer { + + public static final String NETCONF_MESSAGE_DECODER = "netconfMessageDecoder"; + public static final String NETCONF_MESSAGE_AGGREGATOR = "aggregator"; + public static final String NETCONF_MESSAGE_ENCODER = "netconfMessageEncoder"; + public static final String NETCONF_MESSAGE_FRAME_ENCODER = "frameEncoder"; + public static final String NETCONF_SESSION_NEGOTIATOR = "negotiator"; + + public void initialize(SocketChannel ch, Promise promise) { + ch.pipeline().addLast(NETCONF_MESSAGE_AGGREGATOR, new NetconfEOMAggregator()); + initializeMessageDecoder(ch); + ch.pipeline().addLast(NETCONF_MESSAGE_FRAME_ENCODER, FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM)); + initializeMessageEncoder(ch); + + initializeSessionNegotiator(ch, promise); } - public void initialize(SocketChannel ch, Promise promise) { - if (maybeContext.isPresent()) { - initSsl(ch); - } - - ch.pipeline().addLast("frameDecoder", NetconfMessageFactory.getDelimiterFrameDecoder()); - ch.pipeline().addLast(handlerFactory.getDecoders()); - initializeAfterDecoder(ch, promise); - ch.pipeline().addLast(handlerFactory.getEncoders()); + protected void initializeMessageEncoder(SocketChannel ch) { + // Special encoding handler for hello message to include additional header if available, + // it is thrown away after successful negotiation + ch.pipeline().addLast(NETCONF_MESSAGE_ENCODER, new NetconfHelloMessageToXMLEncoder()); } - protected abstract void initializeAfterDecoder(SocketChannel ch, Promise promise); - - private void initSsl(SocketChannel ch) { - SSLEngine sslEngine = maybeContext.get().createSSLEngine(); - initSslEngine(sslEngine); - final SslHandler handler = new SslHandler(sslEngine); - ch.pipeline().addLast("ssl", handler); + protected void initializeMessageDecoder(SocketChannel ch) { + // Special decoding handler for hello message to parse additional header if available, + // it is thrown away after successful negotiation + ch.pipeline().addLast(NETCONF_MESSAGE_DECODER, new NetconfXMLToHelloMessageDecoder()); } - protected abstract void initSslEngine(SSLEngine sslEngine); - - private static final class NetconfHandlerFactory extends ProtocolHandlerFactory { + /** + * Insert session negotiator into the pipeline. It must be inserted after message decoder + * identified by {@link AbstractChannelInitializer#NETCONF_MESSAGE_DECODER}, (or any other custom decoder processor) + */ + protected abstract void initializeSessionNegotiator(SocketChannel ch, Promise promise); - 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) }; - } - } }