2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.impl;
11 import com.google.common.base.Optional;
12 import io.netty.channel.ChannelFuture;
13 import io.netty.channel.EventLoopGroup;
14 import io.netty.channel.socket.SocketChannel;
15 import io.netty.util.concurrent.Promise;
16 import org.opendaylight.controller.netconf.api.NetconfSession;
17 import org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
18 import org.opendaylight.controller.netconf.util.AbstractSslChannelInitializer;
19 import org.opendaylight.protocol.framework.AbstractDispatcher;
21 import javax.net.ssl.SSLContext;
22 import javax.net.ssl.SSLEngine;
23 import java.net.InetSocketAddress;
25 public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession, NetconfServerSessionListener> {
27 private final ServerSslChannelInitializer initializer;
29 public NetconfServerDispatcher(ServerSslChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
30 EventLoopGroup workerGroup) {
31 super(bossGroup, workerGroup);
32 this.initializer = serverChannelInitializer;
35 // TODO test create server with same address twice
36 public ChannelFuture createServer(InetSocketAddress address) {
38 return super.createServer(address, new PipelineInitializer<NetconfSession>() {
40 public void initializeChannel(final SocketChannel ch, final Promise<NetconfSession> promise) {
41 initializer.initialize(ch, promise);
46 public static class ServerSslChannelInitializer extends AbstractSslChannelInitializer {
48 private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
49 private final NetconfServerSessionListenerFactory listenerFactory;
51 public ServerSslChannelInitializer(Optional<SSLContext> maybeContext,
52 NetconfServerSessionNegotiatorFactory negotiatorFactory,
53 NetconfServerSessionListenerFactory listenerFactory) {
55 this.negotiatorFactory = negotiatorFactory;
56 this.listenerFactory = listenerFactory;
60 protected void initializeAfterDecoder(SocketChannel ch, Promise<? extends NetconfSession> promise) {
61 ch.pipeline().addLast("deserializerExHandler", new DeserializerExceptionHandler());
62 ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
66 protected void initSslEngine(SSLEngine sslEngine) {
67 sslEngine.setUseClientMode(false);