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;
11 import java.net.InetSocketAddress;
12 import java.util.Dictionary;
13 import java.util.Hashtable;
14 import org.osgi.service.cm.ManagedService;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 public class NetconfConfigurationImpl implements NetconfConfiguration, ManagedService {
20 private static final Logger LOG = LoggerFactory.getLogger(NetconfConfigurationImpl.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";
32 private NetconfConfigurationHolder netconfConfiguration;
34 public NetconfConfigurationImpl(final String tcpServerAddress, final String tcpServerPort,
35 final String sshServerAddress, final String sshServerPort,
36 final String privateKeyPath) throws NumberFormatException {
38 // isolate configuration to "updated(...)" instead of repeating logic here
39 final Dictionary<String, String> dictionaryConfig = new Hashtable<>();
40 dictionaryConfig.put(TCP_ADDRESS_PROP, tcpServerAddress);
41 dictionaryConfig.put(TCP_PORT_PROP, tcpServerPort);
42 dictionaryConfig.put(SSH_ADDRESS_PROP, sshServerAddress);
43 dictionaryConfig.put(SSH_PORT_PROP, sshServerPort);
44 dictionaryConfig.put(SSH_PK_PATH_PROP, privateKeyPath);
46 updated(dictionaryConfig);
50 public void updated(final Dictionary<String, ?> dictionaryConfig) {
51 if (dictionaryConfig == null) {
52 LOG.debug("CSS NETCONF server configuration cannot be updated as passed dictionary is null");
55 final InetSocketAddress sshServerAddress =
56 new InetSocketAddress((String) dictionaryConfig.get(SSH_ADDRESS_PROP),
57 Integer.parseInt((String) dictionaryConfig.get(SSH_PORT_PROP)));
58 final InetSocketAddress tcpServerAddress =
59 new InetSocketAddress((String) dictionaryConfig.get(TCP_ADDRESS_PROP),
60 Integer.parseInt((String) dictionaryConfig.get(TCP_PORT_PROP)));
62 netconfConfiguration = new NetconfConfigurationHolder(tcpServerAddress,
64 (String) dictionaryConfig.get(SSH_PK_PATH_PROP));
66 LOG.debug("CSS netconf server configuration was updated: {}", dictionaryConfig.toString());
70 public InetSocketAddress getSshServerAddress() {
71 return netconfConfiguration.getSshServerAddress();
75 public InetSocketAddress getTcpServerAddress() {
76 return netconfConfiguration.getTcpServerAddress();
80 public String getPrivateKeyPath() {
81 return netconfConfiguration.getPrivateKeyPath();