+ private void startSSHServer() throws Exception {
+ logger.info("Creating SSH server");
+ StubUserManager um = new StubUserManager(USERNAME, PASSWORD);
+ String pem;
+ try (InputStream is = getClass().getResourceAsStream("/RSA.pk")) {
+ pem = IOUtils.toString(is);
+ }
+ AuthProvider ap = new AuthProvider(um, pem);
+ Thread sshServerThread = new Thread(NetconfSSHServer.start(10830, tcpAddress, ap));
+ sshServerThread.setDaemon(true);
+ sshServerThread.start();
+ logger.info("SSH server on");
+ }
+
+ @Test
+ public void sshTest() throws Exception {
+ startSSHServer();
+ logger.info("creating connection");
+ Connection conn = new Connection(sshAddress.getHostName(), sshAddress.getPort());
+ Assert.assertNotNull(conn);
+ logger.info("connection created");
+ conn.connect();
+ boolean isAuthenticated = conn.authenticateWithPassword(USERNAME, PASSWORD);
+ assertTrue(isAuthenticated);
+ logger.info("user authenticated");
+ final Session sess = conn.openSession();
+ sess.startSubSystem("netconf");
+ logger.info("user authenticated");
+ sess.getStdin().write(XmlUtil.toString(this.getConfig.getDocument()).getBytes());
+
+ new Thread() {
+ @Override
+ public void run() {
+ while (true) {
+ byte[] bytes = new byte[1024];
+ int c = 0;
+ try {
+ c = sess.getStdout().read(bytes);
+ } catch (IOException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ logger.info("got data:" + bytes);
+ if (c == 0) {
+ break;
+ }
+ }
+ }
+ }.join();
+ }
+
+