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
8 package org.opendaylight.netconf.util;
10 import java.lang.annotation.Annotation;
11 import java.net.InetSocketAddress;
12 import org.osgi.service.component.annotations.Activate;
13 import org.osgi.service.component.annotations.Component;
14 import org.osgi.service.component.annotations.Deactivate;
15 import org.osgi.service.metatype.annotations.AttributeDefinition;
16 import org.osgi.service.metatype.annotations.Designate;
17 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 @Component(immediate = true, configurationPid = "netconf")
22 @Designate(ocd = NetconfConfigurationImpl.Configuration.class)
23 public class NetconfConfigurationImpl implements NetconfConfiguration {
24 @ObjectClassDefinition
25 public @interface Configuration {
26 @AttributeDefinition(name = "tcp-address")
27 String tcpAddress() default "127.0.0.1";
28 @AttributeDefinition(name = "tcp-port", min = "0", max = "65535")
29 int tcpPort() default 8383;
30 @AttributeDefinition(name = "ssh-address")
31 String sshAddress() default "0.0.0.0";
32 @AttributeDefinition(name = "ssh-port", min = "0", max = "65535")
33 int sshPort() default 1830;
34 @AttributeDefinition(name = "sshpk-path")
35 String sshPrivateKeyPath() default "./configuration/RSA.pk";
38 private static final Logger LOG = LoggerFactory.getLogger(NetconfConfigurationImpl.class);
40 private NetconfConfigurationHolder netconfConfiguration;
42 public NetconfConfigurationImpl() {
46 public NetconfConfigurationImpl(final String tcpServerAddress, final int tcpServerPort,
47 final String sshServerAddress, final int sshServerPort,
48 final String privateKeyPath) {
49 activate(new Configuration() {
51 public Class<? extends Annotation> annotationType() {
52 return Configuration.class;
56 public String tcpAddress() {
57 return tcpServerAddress;
61 public int tcpPort() {
66 public String sshAddress() {
67 return sshServerAddress;
71 public int sshPort() {
76 public String sshPrivateKeyPath() {
77 return privateKeyPath;
83 void activate(final Configuration config) {
84 final InetSocketAddress sshServerAddress = new InetSocketAddress(config.sshAddress(), config.sshPort());
85 final InetSocketAddress tcpServerAddress = new InetSocketAddress(config.tcpAddress(), config.tcpPort());
87 netconfConfiguration = new NetconfConfigurationHolder(tcpServerAddress, sshServerAddress,
88 config.sshPrivateKeyPath());
89 LOG.debug("CSS netconf server configuration was updated");
93 void deactivate(final Configuration config) {
94 netconfConfiguration = null;
98 public InetSocketAddress getSshServerAddress() {
99 return netconfConfiguration.getSshServerAddress();
103 public InetSocketAddress getTcpServerAddress() {
104 return netconfConfiguration.getTcpServerAddress();
108 public String getPrivateKeyPath() {
109 return netconfConfiguration.getPrivateKeyPath();