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.osgi;
10 import com.google.common.base.Optional;
11 import java.net.InetSocketAddress;
12 import org.opendaylight.controller.netconf.ssh.NetconfSSHServer;
13 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
14 import org.osgi.framework.BundleActivator;
15 import org.osgi.framework.BundleContext;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Activator for netconf SSH bundle which creates SSH bridge between netconf client and netconf server. Activator
21 * starts SSH Server in its own thread. This thread is closed when activator calls stop() method. Server opens socket
22 * and listen for client connections. Each client connection creation is handled in separate
23 * {@link org.opendaylight.controller.netconf.ssh.threads.SocketThread} thread.
24 * This thread creates two additional threads {@link org.opendaylight.controller.netconf.ssh.threads.IOThread}
25 * forwarding data from/to client.IOThread closes servers session and server connection when it gets -1 on input stream.
26 * {@link org.opendaylight.controller.netconf.ssh.threads.IOThread}'s run method waits for -1 on input stream to finish.
27 * All threads are daemons.
29 public class NetconfSSHActivator implements BundleActivator{
31 private NetconfSSHServer server;
32 private static final Logger logger = LoggerFactory.getLogger(NetconfSSHActivator.class);
33 private static final String EXCEPTION_MESSAGE = "Netconf ssh bridge is not available.";
36 public void start(BundleContext context) throws Exception {
38 logger.trace("Starting netconf SSH bridge.");
40 Optional<InetSocketAddress> sshSocketAddressOptional = NetconfConfigUtil.extractSSHNetconfAddress(context,EXCEPTION_MESSAGE);
41 InetSocketAddress tcpSocketAddress = NetconfConfigUtil.extractTCPNetconfAddress(context,
42 EXCEPTION_MESSAGE, true);
44 if (sshSocketAddressOptional.isPresent()){
45 server = NetconfSSHServer.start(sshSocketAddressOptional.get().getPort(),tcpSocketAddress);
46 Thread serverThread = new Thread(server,"netconf SSH server thread");
47 serverThread.setDaemon(true);
49 logger.trace("Netconf SSH bridge up and running.");
51 logger.trace("No valid connection configuration for SSH bridge found.");
52 throw new Exception("No valid connection configuration for SSH bridge found.");
57 public void stop(BundleContext context) throws Exception {
59 logger.trace("Netconf SSH bridge going down ...");
61 logger.trace("Netconf SSH bridge is down ...");