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.Channel;
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.authentication.AuthenticationHandler;
15 import org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
16 import org.opendaylight.protocol.framework.SessionListenerFactory;
18 final class SshClientChannelInitializer extends AbstractChannelInitializer<NetconfClientSession> {
20 private final AuthenticationHandler authenticationHandler;
21 private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
22 private final NetconfClientSessionListener sessionListener;
24 public SshClientChannelInitializer(final AuthenticationHandler authHandler,
25 final NetconfClientSessionNegotiatorFactory negotiatorFactory,
26 final NetconfClientSessionListener sessionListener) {
27 this.authenticationHandler = authHandler;
28 this.negotiatorFactory = negotiatorFactory;
29 this.sessionListener = sessionListener;
33 public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) {
35 // ssh handler has to be the first handler in pipeline
36 ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler));
37 super.initialize(ch,promise);
38 } catch (final IOException e) {
39 throw new RuntimeException(e);
44 protected void initializeSessionNegotiator(final Channel ch,
45 final Promise<NetconfClientSession> promise) {
46 ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
47 negotiatorFactory.getSessionNegotiator(new SessionListenerFactory<NetconfClientSessionListener>() {
49 public NetconfClientSessionListener getSessionListener() {
50 return sessionListener;