X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-ssh%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fosgi%2FNetconfSSHActivator.java;h=6626f47b0375e4a7a0e503f78cd862ab647f2f62;hp=b5e86e05c163f04ec9ba9b80951575b3762dd7f0;hb=25ba6b145406b98f8521bcf510bb85bf0167ef72;hpb=d82b96055d2c0d471c85c2b2b3cb30e52fff1c69 diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java index b5e86e05c1..6626f47b03 100644 --- a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java +++ b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java @@ -7,19 +7,56 @@ */ package org.opendaylight.controller.netconf.osgi; +import com.google.common.base.Optional; +import java.net.InetSocketAddress; import org.opendaylight.controller.netconf.ssh.NetconfSSHServer; +import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * Activator for netconf SSH bundle which creates SSH bridge between netconf client and netconf server. Activator + * starts SSH Server in its own thread. This thread is closed when activator calls stop() method. Server opens socket + * and listen for client connections. Each client connection creation is handled in separate + * {@link org.opendaylight.controller.netconf.ssh.threads.SocketThread} thread. + * This thread creates two additional threads {@link org.opendaylight.controller.netconf.ssh.threads.IOThread} + * forwarding data from/to client.IOThread closes servers session and server connection when it gets -1 on input stream. + * {@link org.opendaylight.controller.netconf.ssh.threads.IOThread}'s run method waits for -1 on input stream to finish. + * All threads are daemons. + **/ public class NetconfSSHActivator implements BundleActivator{ + private NetconfSSHServer server; + private static final Logger logger = LoggerFactory.getLogger(NetconfSSHActivator.class); + @Override public void start(BundleContext context) throws Exception { - NetconfSSHServer.start(); + + logger.trace("Starting netconf SSH bridge."); + + Optional sshSocketAddressOptional = NetconfConfigUtil.extractSSHNetconfAddress(context); + Optional tcpSocketAddressOptional = NetconfConfigUtil.extractTCPNetconfAddress(context); + + if (sshSocketAddressOptional.isPresent() && tcpSocketAddressOptional.isPresent()){ + server = NetconfSSHServer.start(sshSocketAddressOptional.get().getPort(),tcpSocketAddressOptional.get()); + Thread serverThread = new Thread(server,"netconf SSH server thread"); + serverThread.setDaemon(true); + serverThread.start(); + logger.trace("Netconf SSH bridge up and running."); + } else { + logger.trace("No valid connection configuration for SSH bridge found."); + throw new Exception("No valid connection configuration for SSH bridge found."); + } } @Override public void stop(BundleContext context) throws Exception { - + if (server != null){ + logger.trace("Netconf SSH bridge going down ..."); + server.stop(); + logger.trace("Netconf SSH bridge is down ..."); + } } }