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 org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
13 import org.opendaylight.controller.netconf.util.handler.ssh.SshHandler;
14 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.AuthenticationHandler;
15 import org.opendaylight.controller.netconf.util.handler.ssh.client.Invoker;
16 import org.opendaylight.protocol.framework.SessionListenerFactory;
18 import java.io.IOException;
20 final class SshClientChannelInitializer extends AbstractChannelInitializer<NetconfClientSession> {
22 private final AuthenticationHandler authenticationHandler;
23 private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
24 private final NetconfClientSessionListener sessionListener;
26 public SshClientChannelInitializer(final AuthenticationHandler authHandler,
27 final NetconfClientSessionNegotiatorFactory negotiatorFactory,
28 final NetconfClientSessionListener sessionListener) {
29 this.authenticationHandler = authHandler;
30 this.negotiatorFactory = negotiatorFactory;
31 this.sessionListener = sessionListener;
35 public void initialize(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
37 final Invoker invoker = Invoker.subsystem("netconf");
38 ch.pipeline().addFirst(new SshHandler(authenticationHandler, invoker));
39 super.initialize(ch,promise);
40 } catch (final IOException e) {
41 throw new RuntimeException(e);
46 protected void initializeSessionNegotiator(final SocketChannel ch,
47 final Promise<NetconfClientSession> promise) {
48 ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
49 negotiatorFactory.getSessionNegotiator(new SessionListenerFactory<NetconfClientSessionListener>() {
51 public NetconfClientSessionListener getSessionListener() {
52 return sessionListener;