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
8 package org.opendaylight.controller.netconf.ssh;
10 import ch.ethz.ssh2.Connection;
11 import ch.ethz.ssh2.Session;
12 import java.io.IOException;
13 import junit.framework.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 public class SSHServerTest {
22 private static final String USER = "netconf";
23 private static final String PASSWORD = "netconf";
24 private static final String HOST = "127.0.0.1";
25 private static final int PORT = 830;
26 private static final Logger logger = LoggerFactory.getLogger(SSHServerTest.class);
28 private class TestSSHServer implements Runnable {
31 NetconfSSHServer.start();
32 } catch (Exception e) {
33 logger.info(e.getMessage());
38 public void startSSHServer() throws Exception{
39 logger.info("Creating SSH server");
40 Thread sshServerThread = new Thread(new TestSSHServer());
41 sshServerThread.setDaemon(true);
42 sshServerThread.start();
43 logger.info("SSH server on");
47 public void connect(){
48 Connection conn = new Connection(HOST,PORT);
49 Assert.assertNotNull(conn);
51 logger.info("connecting to SSH server");
53 logger.info("authenticating ...");
54 boolean isAuthenticated = conn.authenticateWithPassword(USER,PASSWORD);
55 Assert.assertTrue(isAuthenticated);
56 logger.info("opening session");
57 Session sess = conn.openSession();
58 logger.info("subsystem netconf");
59 sess.startSubSystem("netconf");
60 // sess.requestPTY("");
61 } catch (IOException e) {