Closed nested JSON writers
[netconf.git] / netconf / netconf-tcp / src / main / java / org / opendaylight / netconf / tcp / NetconfTCPProvider.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;
10
11 import java.net.InetSocketAddress;
12 import org.opendaylight.netconf.tcp.netty.ProxyServer;
13 import org.opendaylight.netconf.util.NetconfConfiguration;
14 import org.osgi.framework.InvalidSyntaxException;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Opens TCP port specified in config.ini, creates bridge between this port and local netconf server.
20  */
21 public class NetconfTCPProvider {
22     private static final Logger LOG = LoggerFactory.getLogger(NetconfTCPProvider.class);
23
24     private final NetconfConfiguration netconfConfiguration;
25     private ProxyServer proxyServer;
26
27     public NetconfTCPProvider(final NetconfConfiguration netconfConfiguration) {
28         this.netconfConfiguration = netconfConfiguration;
29     }
30
31     // Called via blueprint
32     @SuppressWarnings("unused")
33     public void init() throws InvalidSyntaxException {
34         final InetSocketAddress address = netconfConfiguration.getTcpServerAddress();
35
36         if (address.getAddress().isAnyLocalAddress()) {
37             LOG.warn("Unprotected netconf TCP address is configured to ANY "
38                     + "local address. This is a security risk. Consider "
39                     + "changing tcp-address in netconf.cfg to 127.0.0.1");
40         }
41         LOG.info("Starting TCP netconf server at {}", address);
42         proxyServer = new ProxyServer(address, NetconfConfiguration.NETCONF_LOCAL_ADDRESS);
43     }
44
45     // Called via blueprint
46     @SuppressWarnings("unused")
47     public void destroy() {
48         if (proxyServer != null) {
49             proxyServer.close();
50         }
51     }
52 }