d95d2b84a2a793bce5f9b10309385e3695bd3c88
[netconf.git] / netconf / netconf-tcp / src / main / java / org / opendaylight / netconf / tcp / osgi / NetconfTCPActivator.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.netconf.tcp.osgi;
10
11 import java.net.InetSocketAddress;
12 import org.opendaylight.netconf.tcp.netty.ProxyServer;
13 import org.opendaylight.netconf.util.osgi.NetconfConfigUtil;
14 import org.opendaylight.netconf.util.osgi.NetconfConfiguration;
15 import org.osgi.framework.BundleActivator;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.InvalidSyntaxException;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * Opens TCP port specified in config.ini, creates bridge between this port and local netconf server.
23  */
24 public class NetconfTCPActivator implements BundleActivator {
25     private static final Logger LOG = LoggerFactory.getLogger(NetconfTCPActivator.class);
26     private ProxyServer proxyServer;
27
28     @Override
29     public void start(BundleContext context) throws InvalidSyntaxException {
30         final NetconfConfiguration netconfConfiguration = NetconfConfigUtil.getNetconfConfigurationService(context);
31
32         final InetSocketAddress address = netconfConfiguration.getTcpServerAddress();
33
34         if (address.getAddress().isAnyLocalAddress()) {
35             LOG.warn("Unprotected netconf TCP address is configured to ANY local address. This is a security risk. "
36                     + "Consider changing tcp-address in netconf.cfg to 127.0.0.1");
37         }
38         LOG.info("Starting TCP netconf server at {}", address);
39         proxyServer = new ProxyServer(address, NetconfConfiguration.NETCONF_LOCAL_ADDRESS);
40     }
41
42     @Override
43     public void stop(BundleContext context) {
44         if (proxyServer != null) {
45             proxyServer.close();
46         }
47     }
48 }