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.netconf.client;
10 import io.netty.channel.Channel;
11 import io.netty.util.concurrent.Promise;
12 import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
13 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
14 import org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
15 import org.opendaylight.protocol.framework.SessionListenerFactory;
17 final class SshClientChannelInitializer extends AbstractChannelInitializer<NetconfClientSession> {
19 private final AuthenticationHandler authenticationHandler;
20 private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
21 private final NetconfClientSessionListener sessionListener;
23 SshClientChannelInitializer(final AuthenticationHandler authHandler,
24 final NetconfClientSessionNegotiatorFactory negotiatorFactory,
25 final NetconfClientSessionListener sessionListener) {
26 this.authenticationHandler = authHandler;
27 this.negotiatorFactory = negotiatorFactory;
28 this.sessionListener = sessionListener;
32 public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) {
33 // ssh handler has to be the first handler in pipeline
34 ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler, promise));
35 super.initialize(ch,promise);
39 protected void initializeSessionNegotiator(final Channel ch,
40 final Promise<NetconfClientSession> promise) {
41 ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
42 negotiatorFactory.getSessionNegotiator(new SessionListenerFactory<NetconfClientSessionListener>() {
44 public NetconfClientSessionListener getSessionListener() {
45 return sessionListener;