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.socket.SocketChannel;
14 import io.netty.util.concurrent.Promise;
15 import org.opendaylight.controller.netconf.api.NetconfSession;
16 import org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
17 import org.opendaylight.controller.netconf.util.AbstractSslChannelInitializer;
18 import org.opendaylight.protocol.framework.AbstractDispatcher;
20 import javax.net.ssl.SSLContext;
21 import javax.net.ssl.SSLEngine;
22 import java.net.InetSocketAddress;
24 public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession, NetconfServerSessionListener> {
26 private final ServerSslChannelInitializer initializer;
28 public NetconfServerDispatcher(final Optional<SSLContext> maybeContext,
29 NetconfServerSessionNegotiatorFactory serverNegotiatorFactory,
30 NetconfServerSessionListenerFactory listenerFactory) {
31 this.initializer = new ServerSslChannelInitializer(maybeContext, serverNegotiatorFactory, listenerFactory);
34 // FIXME change headers for all new source code files
36 // TODO test create server with same address twice
37 public ChannelFuture createServer(InetSocketAddress address) {
39 return super.createServer(address, new PipelineInitializer<NetconfSession>() {
41 public void initializeChannel(final SocketChannel ch, final Promise<NetconfSession> promise) {
42 initializer.initialize(ch, promise);
47 private static class ServerSslChannelInitializer extends AbstractSslChannelInitializer {
49 private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
50 private final NetconfServerSessionListenerFactory listenerFactory;
52 private ServerSslChannelInitializer(Optional<SSLContext> maybeContext,
53 NetconfServerSessionNegotiatorFactory negotiatorFactory,
54 NetconfServerSessionListenerFactory listenerFactory) {
56 this.negotiatorFactory = negotiatorFactory;
57 this.listenerFactory = listenerFactory;
61 protected void initializeAfterDecoder(SocketChannel ch, Promise<? extends NetconfSession> promise) {
62 ch.pipeline().addLast("deserializerExHandler", new DeserializerExceptionHandler());
63 ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
67 protected void initSslEngine(SSLEngine sslEngine) {
68 sslEngine.setUseClientMode(false);