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.nettyutil.handler.ssh.client;
11 import ch.ethz.ssh2.Connection;
12 import ch.ethz.ssh2.Session;
13 import java.io.IOException;
14 import java.util.HashMap;
16 import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
17 import org.opendaylight.controller.netconf.nettyutil.handler.ssh.virtualsocket.VirtualSocket;
20 * Wrapper class around GANYMED SSH java library.
23 private final VirtualSocket socket;
24 private final Map<Integer, SshSession> openSessions = new HashMap<>();
25 private final AuthenticationHandler authenticationHandler;
26 private Connection connection;
28 public SshClient(VirtualSocket socket, AuthenticationHandler authenticationHandler) throws IOException {
30 this.authenticationHandler = authenticationHandler;
33 public SshSession openSession() throws IOException {
34 if (connection == null) {
38 Session session = connection.openSession();
39 SshSession sshSession = new SshSession(session);
40 openSessions.put(openSessions.size(), sshSession);
45 private void connect() throws IOException {
46 connection = new Connection(socket);
49 authenticationHandler.authenticate(connection);
54 for (SshSession session : openSessions.values()){
60 if (connection != null) {
66 public String toString() {