2 * Copyright (c) 2016 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
9 package org.opendaylight.netconf.util.osgi;
11 import io.netty.channel.local.LocalAddress;
12 import java.net.InetSocketAddress;
13 import java.util.Dictionary;
14 import java.util.concurrent.TimeUnit;
15 import org.osgi.service.cm.ManagedService;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public class NetconfConfiguration implements ManagedService {
20 private static final Logger LOG = LoggerFactory.getLogger(NetconfConfiguration.class);
23 * Props to access information within the dictionary.
26 private static final String SSH_ADDRESS_PROP = "ssh-address";
27 private static final String SSH_PORT_PROP = "ssh-port";
28 private static final String TCP_ADDRESS_PROP = "tcp-address";
29 private static final String TCP_PORT_PROP = "tcp-port";
30 private static final String SSH_PK_PATH_PROP = "ssh-pk-path";
33 * Default values used if no dictionary is provided.
36 public static final LocalAddress NETCONF_LOCAL_ADDRESS = new LocalAddress("netconf");
37 public static final long DEFAULT_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(30);
39 private static final String LOCAL_HOST = "127.0.0.1";
40 private static final String INADDR_ANY = "0.0.0.0";
41 private static final String DEFAULT_PRIVATE_KEY_PATH = "./configuration/RSA.pk";
42 private static final InetSocketAddress DEFAULT_TCP_SERVER_ADRESS = new InetSocketAddress(LOCAL_HOST, 8383);
43 private static final InetSocketAddress DEFAULT_SSH_SERVER_ADRESS = new InetSocketAddress(INADDR_ANY, 1830);
45 private NetconfConfigurationHolder netconfConfiguration;
47 NetconfConfiguration() {
48 netconfConfiguration = new NetconfConfigurationHolder(DEFAULT_TCP_SERVER_ADRESS,
49 DEFAULT_SSH_SERVER_ADRESS, DEFAULT_PRIVATE_KEY_PATH);
53 public void updated(final Dictionary<String, ?> dictionaryConfig) {
54 if (dictionaryConfig == null) {
55 LOG.debug("CSS netconf server configuration cannot be updated as passed dictionary is null");
58 final InetSocketAddress sshServerAddress =
59 new InetSocketAddress((String) dictionaryConfig.get(SSH_ADDRESS_PROP),
60 Integer.parseInt((String) dictionaryConfig.get(SSH_PORT_PROP)));
61 final InetSocketAddress tcpServerAddress =
62 new InetSocketAddress((String) dictionaryConfig.get(TCP_ADDRESS_PROP),
63 Integer.parseInt((String) dictionaryConfig.get(TCP_PORT_PROP)));
65 netconfConfiguration = new NetconfConfigurationHolder(tcpServerAddress,
67 (String) dictionaryConfig.get(SSH_PK_PATH_PROP));
69 LOG.debug("CSS netconf server configuration was updated: {}", dictionaryConfig.toString());
72 public InetSocketAddress getSshServerAddress() {
73 return netconfConfiguration.getSshServerAddress();
76 public InetSocketAddress getTcpServerAddress() {
77 return netconfConfiguration.getTcpServerAddress();
80 public String getPrivateKeyPath() {
81 return netconfConfiguration.getPrivateKeyPath();