2 * Copyright (c) 2014 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
8 package org.opendaylight.controller.netconf.client;
10 import io.netty.channel.socket.SocketChannel;
11 import io.netty.util.concurrent.Promise;
12 import java.io.IOException;
13 import org.opendaylight.controller.netconf.nettyutil.AbstractChannelInitializer;
14 import org.opendaylight.controller.netconf.nettyutil.handler.ssh.SshHandler;
15 import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
16 import org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.Invoker;
17 import org.opendaylight.protocol.framework.SessionListenerFactory;
19 final class SshClientChannelInitializer extends AbstractChannelInitializer<NetconfClientSession> {
21 private final AuthenticationHandler authenticationHandler;
22 private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
23 private final NetconfClientSessionListener sessionListener;
25 public SshClientChannelInitializer(final AuthenticationHandler authHandler,
26 final NetconfClientSessionNegotiatorFactory negotiatorFactory,
27 final NetconfClientSessionListener sessionListener) {
28 this.authenticationHandler = authHandler;
29 this.negotiatorFactory = negotiatorFactory;
30 this.sessionListener = sessionListener;
34 public void initialize(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
36 final Invoker invoker = Invoker.subsystem("netconf");
37 ch.pipeline().addFirst(new SshHandler(authenticationHandler, invoker));
38 super.initialize(ch,promise);
39 } catch (final IOException e) {
40 throw new RuntimeException(e);
45 protected void initializeSessionNegotiator(final SocketChannel ch,
46 final Promise<NetconfClientSession> promise) {
47 ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
48 negotiatorFactory.getSessionNegotiator(new SessionListenerFactory<NetconfClientSessionListener>() {
50 public NetconfClientSessionListener getSessionListener() {
51 return sessionListener;