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 java.net.InetSocketAddress;
12 import java.util.Dictionary;
13 import org.osgi.service.cm.ManagedService;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 public class NetconfConfiguration implements ManagedService {
18 private static final Logger LOG = LoggerFactory.getLogger(NetconfConfiguration.class);
20 private static final NetconfConfiguration instance = new NetconfConfiguration();
21 private NetconfConfigurationHolder netconfConfiguration;
23 public static final String KEY_SSH_ADDRESS = "ssh-address";
24 public static final String KEY_SSH_PORT = "ssh-port";
25 public static final String KEY_TCP_ADDRESS = "tcp-address";
26 public static final String KEY_TCP_PORT = "tcp-port";
27 public static final String KEY_SSH_PK_PATH = "ssh-pk-path";
29 public static NetconfConfiguration getInstance() {
33 private NetconfConfiguration() {
34 netconfConfiguration = new NetconfConfigurationHolder(NetconfConfigUtil.DEFAULT_TCP_SERVER_ADRESS,
35 NetconfConfigUtil.DEFAULT_SSH_SERVER_ADRESS, NetconfConfigUtil.DEFAULT_PRIVATE_KEY_PATH);
39 public void updated(final Dictionary<String, ?> dictionaryConfig) {
40 if (dictionaryConfig == null) {
41 LOG.warn("Netconf configuration cannot be updated.");
44 final InetSocketAddress sshServerAddress = new InetSocketAddress((String) dictionaryConfig.get(KEY_SSH_ADDRESS),
45 Integer.parseInt((String) dictionaryConfig.get(KEY_SSH_PORT)));
46 final InetSocketAddress tcpServerAddress = new InetSocketAddress((String) dictionaryConfig.get(KEY_TCP_ADDRESS),
47 Integer.parseInt((String) dictionaryConfig.get(KEY_TCP_PORT)));
49 netconfConfiguration = new NetconfConfigurationHolder(tcpServerAddress, sshServerAddress,
50 (String) dictionaryConfig.get(KEY_SSH_PK_PATH));
52 LOG.info("Netconf configuration was updated: {}", dictionaryConfig.toString());
55 public InetSocketAddress getSshServerAddress(){
56 return netconfConfiguration.getSshServerAddress();
59 public InetSocketAddress getTcpServerAddress(){
60 return netconfConfiguration.getTcpServerAddress();
63 public String getPrivateKeyPath() {
64 return netconfConfiguration.getPrivateKeyPath();