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 java.net.InetSocketAddress;
14 import junit.framework.Assert;
15 import org.apache.commons.io.IOUtils;
16 import org.junit.Test;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 public class SSHServerTest {
23 private static final String USER = "netconf";
24 private static final String PASSWORD = "netconf";
25 private static final String HOST = "127.0.0.1";
26 private static final int PORT = 1830;
27 private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 8383);
28 private static final Logger logger = LoggerFactory.getLogger(SSHServerTest.class);
31 public void startSSHServer() throws Exception{
32 logger.info("Creating SSH server");
33 NetconfSSHServer server = NetconfSSHServer.start(PORT,tcpAddress);
34 Thread sshServerThread = new Thread(server);
35 sshServerThread.setDaemon(true);
36 sshServerThread.start();
37 logger.info("SSH server on");
41 public void connect(){
42 Connection conn = new Connection(HOST,PORT);
43 Assert.assertNotNull(conn);
45 logger.info("connecting to SSH server");
47 logger.info("authenticating ...");
48 boolean isAuthenticated = conn.authenticateWithPassword(USER,PASSWORD);
49 Assert.assertTrue(isAuthenticated);
50 logger.info("opening session");
51 Session sess = conn.openSession();
52 logger.info("subsystem netconf");
53 sess.startSubSystem("netconf");
54 sess.getStdin().write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><capabilities><capability>urn:ietf:params:netconf:base:1.1</capability></capabilities></hello>]]>]]>".getBytes());
55 IOUtils.copy(sess.getStdout(), System.out);
56 } catch (IOException e) {