<name>OpenDaylight :: Netconf Connector :: SSH</name>
<dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>odl-aaa-netconf-plugin</artifactId>
+ <version>${project.version}</version>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>odl-netconf-util</artifactId>
import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener;
import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration;
import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
-import org.opendaylight.netconf.util.osgi.NetconfConfiguration;
+import org.opendaylight.netconf.util.NetconfConfiguration;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Bundle-Activator>org.opendaylight.netconf.ssh.osgi.NetconfSSHActivator</Bundle-Activator>
- </instructions>
- </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.netconf.ssh.osgi;
+package org.opendaylight.netconf.ssh;
import io.netty.channel.local.LocalAddress;
import io.netty.channel.nio.NioEventLoopGroup;
import org.apache.sshd.common.util.security.SecurityUtils;
import org.apache.sshd.common.util.threads.ThreadUtils;
import org.apache.sshd.server.keyprovider.AbstractGeneratorHostKeyProvider;
-import org.opendaylight.netconf.ssh.SshProxyServer;
-import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder;
-import org.opendaylight.netconf.util.osgi.NetconfConfigUtil;
-import org.opendaylight.netconf.util.osgi.NetconfConfiguration;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
+import org.opendaylight.netconf.auth.AuthProvider;
+import org.opendaylight.netconf.util.NetconfConfiguration;
import org.osgi.framework.InvalidSyntaxException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NetconfSSHActivator implements BundleActivator {
- private static final Logger LOG = LoggerFactory.getLogger(NetconfSSHActivator.class);
+public class NetconfSSHProvider {
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfSSHProvider.class);
private static final java.lang.String ALGORITHM = "RSA";
private static final int KEY_SIZE = 4096;
public static final int POOL_SIZE = 8;
private static final int DEFAULT_IDLE_TIMEOUT = Integer.MAX_VALUE;
+ private final AuthProvider authProvider;
+ private final NetconfConfiguration netconfConfiguration;
+
private ScheduledExecutorService minaTimerExecutor;
private NioEventLoopGroup clientGroup;
private ExecutorService nioExecutor;
- private AuthProviderTracker authProviderTracker;
private SshProxyServer server;
- @Override
- public void start(final BundleContext bundleContext) throws IOException, InvalidSyntaxException {
+ public NetconfSSHProvider(final AuthProvider authProvider,
+ final NetconfConfiguration netconfConfiguration) {
+
+ this.authProvider = authProvider;
+ this.netconfConfiguration = netconfConfiguration;
+ }
+
+ // Called via blueprint
+ @SuppressWarnings("unused")
+ public void init() throws IOException, InvalidSyntaxException {
minaTimerExecutor = Executors.newScheduledThreadPool(POOL_SIZE,
runnable -> new Thread(runnable, "netconf-ssh-server-mina-timers"));
clientGroup = new NioEventLoopGroup();
nioExecutor = ThreadUtils.newFixedThreadPool("netconf-ssh-server-nio-group", POOL_SIZE);
- server = startSSHServer(bundleContext);
+ server = startSSHServer();
}
- @Override
- public void stop(final BundleContext context) throws IOException {
+ // Called via blueprint
+ @SuppressWarnings("unused")
+ public void destroy() throws IOException {
if (server != null) {
server.close();
}
- if (authProviderTracker != null) {
- authProviderTracker.stop();
- }
-
if (nioExecutor != null) {
nioExecutor.shutdownNow();
}
}
}
- private SshProxyServer startSSHServer(final BundleContext bundleContext)
+ private SshProxyServer startSSHServer()
throws IOException, InvalidSyntaxException {
- final NetconfConfiguration netconfConfiguration =
- NetconfConfigUtil.getNetconfConfigurationService(bundleContext);
final InetSocketAddress sshSocketAddress = netconfConfiguration.getSshServerAddress();
LOG.info("Starting netconf SSH server at {}", sshSocketAddress);
final LocalAddress localAddress = NetconfConfiguration.NETCONF_LOCAL_ADDRESS;
- authProviderTracker = new AuthProviderTracker(bundleContext);
final String path = netconfConfiguration.getPrivateKeyPath();
LOG.trace("Starting netconf SSH server with path to ssh private key {}", path);
new SshProxyServerConfigurationBuilder()
.setBindingAddress(sshSocketAddress)
.setLocalAddress(localAddress)
- .setAuthenticator(authProviderTracker)
+ .setAuthenticator(authProvider)
.setKeyPairProvider(keyPairProvider)
.setIdleTimeout(DEFAULT_IDLE_TIMEOUT)
.createSshProxyServerConfiguration());
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.netconf.ssh.osgi;
-
-import org.opendaylight.netconf.auth.AuthProvider;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-final class AuthProviderTracker implements ServiceTrackerCustomizer<AuthProvider, AuthProvider>, AuthProvider {
- private static final Logger LOG = LoggerFactory.getLogger(AuthProviderTracker.class);
-
- private final BundleContext bundleContext;
-
- private final ServiceTracker<AuthProvider, AuthProvider> listenerTracker;
- private volatile AuthProvider authProvider;
-
- AuthProviderTracker(final BundleContext bundleContext) {
- this.bundleContext = bundleContext;
- listenerTracker = new ServiceTracker<>(bundleContext, AuthProvider.class, this);
- listenerTracker.open();
- }
-
- @Override
- public AuthProvider addingService(final ServiceReference<AuthProvider> reference) {
- LOG.trace("Service {} added", reference);
- this.authProvider = bundleContext.getService(reference);
- return authProvider;
- }
-
- @Override
- public void modifiedService(final ServiceReference<AuthProvider> reference, final AuthProvider service) {
- final AuthProvider authService = bundleContext.getService(reference);
- LOG.trace("Replacing modified service {} in netconf SSH.", reference);
- this.authProvider = authService;
- }
-
- @Override
- public void removedService(final ServiceReference<AuthProvider> reference, final AuthProvider service) {
- LOG.trace("Removing service {} from netconf SSH. {}", reference,
- " SSH won't authenticate users until AuthProvider service will be started.");
- this.authProvider = null;
- }
-
- public void stop() {
- listenerTracker.close();
- this.authProvider = null;
- // sshThread should finish normally since sshServer.close stops processing
- }
-
- @Override
- public boolean authenticated(final String username, final String password) {
- if (authProvider == null) {
- LOG.warn("AuthProvider is missing, failing authentication");
- return false;
- }
- return authProvider.authenticated(username, password);
- }
-}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017 Inocybe Technologies Inc. and others. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+
+ <reference id="authProvider"
+ interface="org.opendaylight.netconf.auth.AuthProvider"
+ odl:type="netconf-auth-provider" />
+
+ <reference id="netconfConfiguration"
+ interface="org.opendaylight.netconf.util.NetconfConfiguration" />
+
+ <bean id="netconfSshProvider" class="org.opendaylight.netconf.ssh.NetconfSSHProvider"
+ init-method="init" destroy-method="destroy">
+ <argument ref="authProvider" />
+ <argument ref="netconfConfiguration" />
+ </bean>
+
+</blueprint>
import io.netty.handler.logging.LoggingHandler;
import java.io.BufferedReader;
import java.io.InputStreamReader;
-import org.opendaylight.netconf.util.osgi.NetconfConfiguration;
+import org.opendaylight.netconf.util.NetconfConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import java.net.InetSocketAddress;
-import org.opendaylight.netconf.util.osgi.NetconfConfiguration;
+import org.opendaylight.netconf.util.NetconfConfiguration;
public class ProxyServer implements Runnable {
private final ProxyHandlerFactory proxyHandlerFactory;
import org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
import org.opendaylight.netconf.ssh.SshProxyServer;
import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder;
-import org.opendaylight.netconf.util.osgi.NetconfConfiguration;
+import org.opendaylight.netconf.util.NetconfConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.mockito.MockitoAnnotations;
import org.opendaylight.netconf.ssh.SshProxyServer;
import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder;
-import org.opendaylight.netconf.util.osgi.NetconfConfiguration;
+import org.opendaylight.netconf.util.NetconfConfiguration;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Bundle-Activator>org.opendaylight.netconf.tcp.osgi.NetconfTCPActivator</Bundle-Activator>
- </instructions>
- </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.netconf.tcp.osgi;
+package org.opendaylight.netconf.tcp;
import java.net.InetSocketAddress;
import org.opendaylight.netconf.tcp.netty.ProxyServer;
-import org.opendaylight.netconf.util.osgi.NetconfConfigUtil;
-import org.opendaylight.netconf.util.osgi.NetconfConfiguration;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
+import org.opendaylight.netconf.util.NetconfConfiguration;
import org.osgi.framework.InvalidSyntaxException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Opens TCP port specified in config.ini, creates bridge between this port and local netconf server.
*/
-public class NetconfTCPActivator implements BundleActivator {
- private static final Logger LOG = LoggerFactory.getLogger(NetconfTCPActivator.class);
+public class NetconfTCPProvider {
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfTCPProvider.class);
+
+ private final NetconfConfiguration netconfConfiguration;
private ProxyServer proxyServer;
- @Override
- public void start(BundleContext context) throws InvalidSyntaxException {
- final NetconfConfiguration netconfConfiguration = NetconfConfigUtil.getNetconfConfigurationService(context);
+ public NetconfTCPProvider(final NetconfConfiguration netconfConfiguration) {
+ this.netconfConfiguration = netconfConfiguration;
+ }
+ // Called via blueprint
+ @SuppressWarnings("unused")
+ public void init() throws InvalidSyntaxException {
final InetSocketAddress address = netconfConfiguration.getTcpServerAddress();
if (address.getAddress().isAnyLocalAddress()) {
- LOG.warn("Unprotected netconf TCP address is configured to ANY local address. This is a security risk. "
- + "Consider changing tcp-address in netconf.cfg to 127.0.0.1");
+ LOG.warn("Unprotected netconf TCP address is configured to ANY "
+ + "local address. This is a security risk. Consider "
+ + "changing tcp-address in netconf.cfg to 127.0.0.1");
}
LOG.info("Starting TCP netconf server at {}", address);
proxyServer = new ProxyServer(address, NetconfConfiguration.NETCONF_LOCAL_ADDRESS);
}
- @Override
- public void stop(BundleContext context) {
+ // Called via blueprint
+ @SuppressWarnings("unused")
+ public void destroy() {
if (proxyServer != null) {
proxyServer.close();
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017 Inocybe Technologies Inc. and others. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+
+ <reference id="netconfConfiguration"
+ interface="org.opendaylight.netconf.util.NetconfConfiguration" />
+
+ <bean id="netconfTcpProvider" class="org.opendaylight.netconf.tcp.NetconfTCPProvider"
+ init-method="init" destroy-method="destroy">
+ <argument ref="netconfConfiguration" />
+ </bean>
+
+</blueprint>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Bundle-Activator>org.opendaylight.netconf.util.osgi.NetconfConfigurationActivator</Bundle-Activator>
- </instructions>
- </configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
--- /dev/null
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.netconf.util;
+
+import io.netty.channel.local.LocalAddress;
+import java.net.InetSocketAddress;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Configuration for NETCONF northbound.
+ */
+public interface NetconfConfiguration {
+
+ /**
+ * LocalAddress constant for NETCONF northbound.
+ */
+ LocalAddress NETCONF_LOCAL_ADDRESS = new LocalAddress("netconf");
+
+ /**
+ * Default timeout for NETCONF northbound connections.
+ */
+ long DEFAULT_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(30);
+
+ /**
+ * NETCONF SSH server address.
+ *
+ * @return NETCONF SSH server address
+ */
+ InetSocketAddress getSshServerAddress();
+
+ /**
+ * NETCONF TCP server address.
+ *
+ * @return NETCONF TCP server address.
+ */
+ InetSocketAddress getTcpServerAddress();
+
+ /**
+ * Private key path for NETCONF.
+ *
+ * @return Private key path for NETCONF.
+ */
+ String getPrivateKeyPath();
+}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.netconf.util.osgi;
+package org.opendaylight.netconf.util;
import java.net.InetSocketAddress;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.netconf.util.osgi;
+package org.opendaylight.netconf.util;
-import io.netty.channel.local.LocalAddress;
import java.net.InetSocketAddress;
import java.util.Dictionary;
-import java.util.concurrent.TimeUnit;
+import java.util.Hashtable;
import org.osgi.service.cm.ManagedService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NetconfConfiguration implements ManagedService {
- private static final Logger LOG = LoggerFactory.getLogger(NetconfConfiguration.class);
+public class NetconfConfigurationImpl implements NetconfConfiguration, ManagedService {
- /**
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfConfigurationImpl.class);
+
+ /*
* Props to access information within the dictionary.
*/
private static final String TCP_PORT_PROP = "tcp-port";
private static final String SSH_PK_PATH_PROP = "ssh-pk-path";
- /**
- * Default values used if no dictionary is provided.
- */
-
- public static final LocalAddress NETCONF_LOCAL_ADDRESS = new LocalAddress("netconf");
- public static final long DEFAULT_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(30);
+ private NetconfConfigurationHolder netconfConfiguration;
- private static final String LOCAL_HOST = "127.0.0.1";
- private static final String INADDR_ANY = "0.0.0.0";
- private static final String DEFAULT_PRIVATE_KEY_PATH = "./configuration/RSA.pk";
- private static final InetSocketAddress DEFAULT_TCP_SERVER_ADRESS = new InetSocketAddress(LOCAL_HOST, 8383);
- private static final InetSocketAddress DEFAULT_SSH_SERVER_ADRESS = new InetSocketAddress(INADDR_ANY, 1830);
+ public NetconfConfigurationImpl(final String tcpServerAddress, final String tcpServerPort,
+ final String sshServerAddress, final String sshServerPort,
+ final String privateKeyPath) throws NumberFormatException {
- private NetconfConfigurationHolder netconfConfiguration;
+ // isolate configuration to "updated(...)" instead of repeating logic here
+ final Dictionary<String, String> dictionaryConfig = new Hashtable<>();
+ dictionaryConfig.put(TCP_ADDRESS_PROP, tcpServerAddress);
+ dictionaryConfig.put(TCP_PORT_PROP, tcpServerPort);
+ dictionaryConfig.put(SSH_ADDRESS_PROP, sshServerAddress);
+ dictionaryConfig.put(SSH_PORT_PROP, sshServerPort);
+ dictionaryConfig.put(SSH_PK_PATH_PROP, privateKeyPath);
- NetconfConfiguration() {
- netconfConfiguration = new NetconfConfigurationHolder(DEFAULT_TCP_SERVER_ADRESS,
- DEFAULT_SSH_SERVER_ADRESS, DEFAULT_PRIVATE_KEY_PATH);
+ updated(dictionaryConfig);
}
@Override
public void updated(final Dictionary<String, ?> dictionaryConfig) {
if (dictionaryConfig == null) {
- LOG.debug("CSS netconf server configuration cannot be updated as passed dictionary is null");
+ LOG.debug("CSS NETCONF server configuration cannot be updated as passed dictionary is null");
return;
}
final InetSocketAddress sshServerAddress =
LOG.debug("CSS netconf server configuration was updated: {}", dictionaryConfig.toString());
}
+ @Override
public InetSocketAddress getSshServerAddress() {
return netconfConfiguration.getSshServerAddress();
}
+ @Override
public InetSocketAddress getTcpServerAddress() {
return netconfConfiguration.getTcpServerAddress();
}
+ @Override
public String getPrivateKeyPath() {
return netconfConfiguration.getPrivateKeyPath();
}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.netconf.util.osgi;
-
-import java.util.Collection;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ManagedService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class NetconfConfigUtil {
- private static final Logger LOG = LoggerFactory.getLogger(NetconfConfigUtil.class);
-
- private NetconfConfigUtil() {
- throw new AssertionError("Utility class should not be instantiated");
- }
-
- public static NetconfConfiguration getNetconfConfigurationService(BundleContext bundleContext)
- throws InvalidSyntaxException {
- LOG.debug("Trying to retrieve netconf configuration service");
- final Collection<ServiceReference<ManagedService>> serviceReferences
- = bundleContext.getServiceReferences(ManagedService.class, null);
- for (final ServiceReference<ManagedService> serviceReference : serviceReferences) {
- ManagedService service = bundleContext.getService(serviceReference);
- if (service instanceof NetconfConfiguration) {
- LOG.debug("Netconf configuration service found");
- return (NetconfConfiguration) service;
- }
- }
-
- throw new IllegalStateException("Netconf configuration service not found");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.netconf.util.osgi;
-
-import java.util.Hashtable;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ManagedService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class NetconfConfigurationActivator implements BundleActivator {
- private static final Logger LOG = LoggerFactory.getLogger(NetconfConfigurationActivator.class);
-
- // This has to match netconf config filename without .cfg suffix
- private static final String CONFIG_PID = "netconf";
- private static final Hashtable<String, String> PROPS = new Hashtable<>(1);
-
- static {
- PROPS.put(Constants.SERVICE_PID, CONFIG_PID);
- }
-
- private ServiceRegistration<?> configService;
-
- @Override
- public void start(final BundleContext bundleContext) {
- LOG.debug("Starting netconf configuration service");
- configService = bundleContext.registerService(ManagedService.class,
- new NetconfConfiguration(), PROPS);
- }
-
- @Override
- public void stop(final BundleContext bundleContext) {
- if (configService != null) {
- LOG.debug("Unregistering netconf configuration service");
- configService.unregister();
- configService = null;
- }
- }
-}
# netconf-tcp:
-
-tcp-address=127.0.0.1
-tcp-port=8383
+#tcp-address=127.0.0.1
+#tcp-port=8383
# netconf-ssh:
+#ssh-address=0.0.0.0
+#ssh-port=1830
-ssh-address=0.0.0.0
-ssh-port=1830
# Use Linux style path
-ssh-pk-path = ./configuration/RSA.pk
\ No newline at end of file
+#ssh-pk-path = ./configuration/RSA.pk
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017 Inocybe Technologies Inc. and others. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
+ odl:use-default-for-reference-types="true">
+
+ <!-- The PID "netconf" is used for backwards-compatibility even though it is
+ an ambiguous name. -->
+ <cm:property-placeholder persistent-id="netconf" update-strategy="reload">
+ <cm:default-properties>
+ <cm:property name="tcp-address" value="127.0.0.1" />
+ <cm:property name="tcp-port" value="8383" />
+ <cm:property name="ssh-address" value="0.0.0.0" />
+ <cm:property name="ssh-port" value="1830" />
+ <cm:property name="ssh-pk-path" value="./configuration/RSA.pk" />
+ </cm:default-properties>
+ </cm:property-placeholder>
+
+ <bean id="netconfConfiguration" class="org.opendaylight.netconf.util.NetconfConfigurationImpl">
+ <argument value="${tcp-address}" />
+ <argument value="${tcp-port}" />
+ <argument value="${ssh-address}" />
+ <argument value="${ssh-port}" />
+ <argument value="${ssh-pk-path}" />
+ </bean>
+ <service ref="netconfConfiguration" interface="org.opendaylight.netconf.util.NetconfConfiguration" />
+
+</blueprint>
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.netconf.util.osgi;
+package org.opendaylight.netconf.util;
import java.net.InetSocketAddress;
import java.util.Dictionary;
import org.junit.Assert;
import org.junit.Test;
-public class NetconfConfigurationTest {
+public class NetconfConfigurationImplTest {
@Test
public void testUpdated() throws Exception {
- final NetconfConfiguration config = new NetconfConfiguration();
+ final NetconfConfigurationImpl config = new NetconfConfigurationImpl("127.0.0.1", "8383",
+ "0.0.0.0", "1830",
+ "./configuration/RSA.pk");
Assert.assertEquals(new InetSocketAddress("0.0.0.0", 1830), config.getSshServerAddress());
Assert.assertEquals(new InetSocketAddress("127.0.0.1", 8383), config.getTcpServerAddress());
Assert.assertEquals("./configuration/RSA.pk", config.getPrivateKeyPath());
@Test
public void testUpdatedNull() throws Exception {
- final NetconfConfiguration config = new NetconfConfiguration();
+ final NetconfConfigurationImpl config = new NetconfConfigurationImpl("127.0.0.1", "8383",
+ "0.0.0.0", "1830",
+ "./configuration/RSA.pk");
Assert.assertEquals(new InetSocketAddress("0.0.0.0", 1830), config.getSshServerAddress());
Assert.assertEquals(new InetSocketAddress("127.0.0.1", 8383), config.getTcpServerAddress());
Assert.assertEquals("./configuration/RSA.pk", config.getPrivateKeyPath());
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.netconf.util.osgi;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ManagedService;
-
-public class NetconfConfigUtilTest {
-
- @Mock
- private ServiceReference<ManagedService> serviceRef;
-
- @Mock
- private ServiceReference<ManagedService> netconfConfigurationRef;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void testGetNetconfConfigurationService() throws Exception {
- final Collection<ServiceReference<ManagedService>> services = new ArrayList<>();
- services.add(serviceRef);
- services.add(netconfConfigurationRef);
- final BundleContext context = mock(BundleContext.class);
- doReturn(services).when(context).getServiceReferences(ManagedService.class, null);
- final ManagedService service = mock(ManagedService.class);
- doReturn(service).when(context).getService(serviceRef);
- NetconfConfiguration netconfConfiguration = new NetconfConfiguration();
- doReturn(netconfConfiguration).when(context).getService(netconfConfigurationRef);
- final NetconfConfiguration actualNetconfConfiguration =
- NetconfConfigUtil.getNetconfConfigurationService(context);
- Assert.assertEquals(netconfConfiguration, actualNetconfConfiguration);
-
- }
-
- @Test
- public void testGetNetconfConfigurationServiceAbsent() throws Exception {
- final Collection<ServiceReference<ManagedService>> services = new ArrayList<>();
- services.add(serviceRef);
- final BundleContext context = mock(BundleContext.class);
- doReturn(services).when(context).getServiceReferences(ManagedService.class, null);
- final ManagedService service = mock(ManagedService.class);
- doReturn(service).when(context).getService(serviceRef);
- try {
- NetconfConfigUtil.getNetconfConfigurationService(context);
- Assert.fail(IllegalStateException.class + "exception expected");
- } catch (IllegalStateException e) {
- assertTrue(e.getMessage().startsWith("Netconf configuration service not found"));
- }
- }
-
- @Test
- public void testGetNetconfConfigurationServiceInvalidSyntax() throws Exception {
- final BundleContext context = mock(BundleContext.class);
- final InvalidSyntaxException exception = new InvalidSyntaxException("Invalid syntax", "filter");
- doThrow(exception).when(context).getServiceReferences(ManagedService.class, null);
- try {
- NetconfConfigUtil.getNetconfConfigurationService(context);
- Assert.fail(InvalidSyntaxException.class + "exception expected");
- } catch (InvalidSyntaxException e) {
- return;
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.netconf.util.osgi;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ManagedService;
-
-public class NetconfConfigurationActivatorTest {
-
- @Mock
- private BundleContext context;
- @Mock
- private ServiceRegistration<?> registration;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- doReturn(registration).when(context)
- .registerService(eq(ManagedService.class), any(NetconfConfiguration.class), any());
- doNothing().when(registration).unregister();
- }
-
- @Test
- public void testStartStop() throws Exception {
- final NetconfConfigurationActivator activator = new NetconfConfigurationActivator();
- activator.start(context);
- final Dictionary<String, String> props = new Hashtable<>();
- props.put(Constants.SERVICE_PID, "netconf");
- verify(context).registerService(eq(ManagedService.class), any(NetconfConfiguration.class), eq(props));
- activator.stop(context);
- verify(registration).unregister();
- }
-
-}
\ No newline at end of file