From: Maros Marsalek Date: Mon, 9 Feb 2015 14:44:01 +0000 (+0100) Subject: BUG-2634 Config binding for netconf server X-Git-Tag: release/lithium~541^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=c2eb34d0fe909f382bc4d9201d955e471ae1d80a BUG-2634 Config binding for netconf server MD-SAL based netconf northbound is activated using feature: odl-netconf-mdsal Change-Id: I6b0ae0db30bb239fcd073883ffe76ff7c5fc0143 Signed-off-by: Maros Marsalek --- diff --git a/features/mdsal/pom.xml b/features/mdsal/pom.xml index 5e6afd248f..c63b39c74d 100644 --- a/features/mdsal/pom.xml +++ b/features/mdsal/pom.xml @@ -113,6 +113,12 @@ features xml + + org.opendaylight.controller + features-netconf + features + xml + org.opendaylight.controller features-config-persister diff --git a/features/mdsal/src/main/resources/features.xml b/features/mdsal/src/main/resources/features.xml index 8c166e6382..5b9f4a674a 100644 --- a/features/mdsal/src/main/resources/features.xml +++ b/features/mdsal/src/main/resources/features.xml @@ -7,6 +7,7 @@ mvn:org.opendaylight.controller/features-config/${config.version}/xml/features mvn:org.opendaylight.controller/features-config-persister/${config.version}/xml/features mvn:org.opendaylight.controller/features-config-netty/${config.version}/xml/features + mvn:org.opendaylight.controller/features-netconf/${netconf.version}/xml/features mvn:org.opendaylight.controller/features-akka/${commons.opendaylight.version}/xml/features odl-mdsal-broker @@ -21,6 +22,20 @@ mvn:org.opendaylight.controller/sal-common-impl/${mdsal.version} mvn:org.opendaylight.controller/sal-common-util/${mdsal.version} + + + + odl-config-all + odl-netconf-all + mvn:org.opendaylight.controller/netconf-ssh/${netconf.version} + odl-mdsal-broker + mvn:org.opendaylight.controller/mdsal-netconf-connector/${netconf.version} + + mvn:org.opendaylight.controller/netconf-config-dispatcher/${config.version} + mvn:org.opendaylight.controller/netconf-config/${netconf.version}/xml/config + mvn:org.opendaylight.controller/netconf-mdsal-config/${netconf.version}/xml/config + + odl-yangtools-common odl-yangtools-binding diff --git a/features/netconf-connector/pom.xml b/features/netconf-connector/pom.xml index c69ee197be..4e94996634 100644 --- a/features/netconf-connector/pom.xml +++ b/features/netconf-connector/pom.xml @@ -119,6 +119,10 @@ org.opendaylight.controller netconf-config-dispatcher + + org.opendaylight.controller + mdsal-netconf-connector + org.opendaylight.controller netconf-tcp diff --git a/features/netconf-connector/src/main/resources/features.xml b/features/netconf-connector/src/main/resources/features.xml index 863833bcc0..92e6507d21 100644 --- a/features/netconf-connector/src/main/resources/features.xml +++ b/features/netconf-connector/src/main/resources/features.xml @@ -42,6 +42,8 @@ --> odl-netconf-connector odl-netconf-connector-ssh + + + + + 4.0.0 + + org.opendaylight.controller + netconf-subsystem + 0.3.0-SNAPSHOT + + netconf-mdsal-config + Configuration files for netconf for mdsal + jar + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-artifacts + + attach-artifact + + package + + + + ${project.build.directory}/classes/initial/08-netconf-mdsal.xml + xml + config + + + + + + + + + diff --git a/opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml b/opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml new file mode 100644 index 0000000000..042447b1e6 --- /dev/null +++ b/opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml @@ -0,0 +1,103 @@ + + + + + + + + + + + + prefix:netconf-mdsal-mapper + netconf-mdsal-mapper + + dom:schema-service + yang-schema-service + + + dom:dom-async-data-broker + inmemory-data-broker + + + + + prefix:netconf-server-dispatcher-impl + netconf-mdsal-server-dispatcher + + dom:netconf-northbound-mapper + netconf-mdsal-mapper + + + prefix:netty-threadgroup + global-boss-group + + + prefix:netty-threadgroup + global-worker-group + + + prefix:netty-timer + global-timer + + + + + prefix:netconf-northbound-ssh + netconf-mdsal-ssh-server + + + prefix:netty-event-executor + global-event-executor + + + prefix:netty-threadgroup + global-worker-group + + + prefix:threadpool + global-netconf-ssh-scheduled-executor + + + prefix:netconf-server-dispatcher + netconf-mdsal-server-dispatcher + + + admin + admin + + + + + + + prefix:netconf-northbound-mapper + + netconf-mdsal-mapper + /modules/module[type='netconf-mdsal-mapper'][name='netconf-mdsal-mapper'] + + + + prefix:netconf-server-dispatcher + + netconf-mdsal-server-dispatcher + /modules/module[type='netconf-server-dispatcher-impl'][name='netconf-mdsal-server-dispatcher'] + + + + + + + + urn:opendaylight:params:xml:ns:yang:controller:netconf:mdsal:mapper?module=netconf-mdsal-mapper&revision=2015-01-14 + urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:ssh?module=netconf-northbound-ssh&revision=2015-01-14 + urn:opendaylight:params:xml:ns:yang:controller:config:netconf:northbound:impl?module=netconf-northbound-impl&revision=2015-01-12 + urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl:scheduled?module=threadpool-impl-scheduled&revision=2013-12-01 + + diff --git a/opendaylight/netconf/netconf-ssh/pom.xml b/opendaylight/netconf/netconf-ssh/pom.xml index 2371ede577..03f7a2fac2 100644 --- a/opendaylight/netconf/netconf-ssh/pom.xml +++ b/opendaylight/netconf/netconf-ssh/pom.xml @@ -24,9 +24,27 @@ ${project.groupId} netconf-util + + ${project.groupId} + netconf-impl + commons-io commons-io + + + org.opendaylight.controller + threadpool-config-api + + + org.opendaylight.controller + netty-config-api + 0.3.0-SNAPSHOT + + + + org.opendaylight.yangtools.model + ietf-inet-types org.bouncycastle @@ -87,6 +105,41 @@ + + org.opendaylight.yangtools + yang-maven-plugin + + + config + + generate-sources + + + + + org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + ${jmxGeneratorPath} + + urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang + + + + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + ${salGeneratorPath} + + + true + + + + + + org.opendaylight.controller + yang-jmx-generator-plugin + ${config.version} + + + diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModule.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModule.java new file mode 100644 index 0000000000..f17bc3cceb --- /dev/null +++ b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModule.java @@ -0,0 +1,122 @@ +package org.opendaylight.controller.config.yang.netconf.northbound.ssh; + +import io.netty.channel.ChannelFuture; +import io.netty.channel.local.LocalAddress; +import io.netty.util.concurrent.GenericFutureListener; +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.util.concurrent.Executors; +import org.apache.sshd.server.PasswordAuthenticator; +import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider; +import org.apache.sshd.server.session.ServerSession; +import org.opendaylight.controller.netconf.api.NetconfServerDispatcher; +import org.opendaylight.controller.netconf.ssh.SshProxyServer; +import org.opendaylight.controller.netconf.ssh.SshProxyServerConfigurationBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NetconfNorthboundSshModule extends org.opendaylight.controller.config.yang.netconf.northbound.ssh.AbstractNetconfNorthboundSshModule { + + private static final Logger LOG = LoggerFactory.getLogger(NetconfNorthboundSshModule.class); + + public NetconfNorthboundSshModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public NetconfNorthboundSshModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final org.opendaylight.controller.config.yang.netconf.northbound.ssh.NetconfNorthboundSshModule oldModule, final java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + final NetconfServerDispatcher dispatch = getDispatcherDependency(); + + final LocalAddress localAddress = new LocalAddress(getPort().toString()); + final ChannelFuture localServer = dispatch.createLocalServer(localAddress); + + final SshProxyServer sshProxyServer = new SshProxyServer(Executors.newScheduledThreadPool(1), getWorkerThreadGroupDependency(), getEventExecutorDependency()); + + final InetSocketAddress bindingAddress = getInetAddress(); + final SshProxyServerConfigurationBuilder sshProxyServerConfigurationBuilder = new SshProxyServerConfigurationBuilder(); + sshProxyServerConfigurationBuilder.setBindingAddress(bindingAddress); + sshProxyServerConfigurationBuilder.setLocalAddress(localAddress); + sshProxyServerConfigurationBuilder.setAuthenticator(new UserAuthenticator(getUsername(), getPassword())); + sshProxyServerConfigurationBuilder.setIdleTimeout(Integer.MAX_VALUE); + sshProxyServerConfigurationBuilder.setKeyPairProvider(new PEMGeneratorHostKeyProvider()); + + localServer.addListener(new GenericFutureListener() { + + @Override + public void operationComplete(final ChannelFuture future) { + if(future.isDone() && !future.isCancelled()) { + try { + sshProxyServer.bind(sshProxyServerConfigurationBuilder.createSshProxyServerConfiguration()); + LOG.info("Netconf SSH endpoint started successfully at {}", bindingAddress); + } catch (final IOException e) { + throw new RuntimeException("Unable to start SSH netconf server", e); + } + } else { + LOG.warn("Unable to start SSH netconf server at {}", bindingAddress, future.cause()); + throw new RuntimeException("Unable to start SSH netconf server", future.cause()); + } + } + }); + + return new NetconfServerCloseable(localServer, sshProxyServer); + } + + private InetSocketAddress getInetAddress() { + try { + final InetAddress inetAd = InetAddress.getByName(getBindingAddress().getIpv4Address() == null ? getBindingAddress().getIpv6Address().getValue() : getBindingAddress().getIpv4Address().getValue()); + return new InetSocketAddress(inetAd, getPort().getValue()); + } catch (final UnknownHostException e) { + throw new IllegalArgumentException("Unable to bind netconf endpoint to address " + getBindingAddress(), e); + } + } + + private static final class NetconfServerCloseable implements AutoCloseable { + private final ChannelFuture localServer; + private final SshProxyServer sshProxyServer; + + public NetconfServerCloseable(final ChannelFuture localServer, final SshProxyServer sshProxyServer) { + this.localServer = localServer; + this.sshProxyServer = sshProxyServer; + } + + @Override + public void close() throws Exception { + sshProxyServer.close(); + + if(localServer.isDone()) { + localServer.channel().close(); + } else { + localServer.cancel(true); + } + } + } + + + private static final class UserAuthenticator implements PasswordAuthenticator { + + private final String username; + private final String password; + + public UserAuthenticator(final String username, final String password) { + this.username = username; + this.password = password; + } + + @Override + public boolean authenticate(final String username, final String password, final ServerSession session) { + // FIXME use aaa stuff here instead + return this.username.equals(username) && this.password.equals(password); + } + } +} diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModuleFactory.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModuleFactory.java new file mode 100644 index 0000000000..4e107ec24d --- /dev/null +++ b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: netconf-northbound-ssh yang module local name: netconf-northbound-ssh +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Mon Feb 09 14:09:07 CET 2015 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.netconf.northbound.ssh; +public class NetconfNorthboundSshModuleFactory extends org.opendaylight.controller.config.yang.netconf.northbound.ssh.AbstractNetconfNorthboundSshModuleFactory { + +} diff --git a/opendaylight/netconf/netconf-ssh/src/main/yang/netconf-northbound-ssh.yang b/opendaylight/netconf/netconf-ssh/src/main/yang/netconf-northbound-ssh.yang new file mode 100644 index 0000000000..2e9d0b15b4 --- /dev/null +++ b/opendaylight/netconf/netconf-ssh/src/main/yang/netconf-northbound-ssh.yang @@ -0,0 +1,94 @@ +module netconf-northbound-ssh { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:ssh"; + prefix "nni"; + + import netconf-northbound-mapper { prefix nnm; revision-date 2015-01-14; } + import netconf-northbound { prefix nn; revision-date 2015-01-14; } + import config { prefix config; revision-date 2013-04-05; } + import threadpool {prefix th;} + import netty {prefix netty;} + import ietf-inet-types { prefix inet; revision-date 2010-09-24; } + + organization "Cisco Systems, Inc."; + + description + "This module contains the base YANG definitions for + a default implementation of netconf northbound server"; + + revision "2015-01-14" { + description + "Initial revision."; + } + + identity netconf-northbound-ssh { + base config:module-type; + config:java-name-prefix NetconfNorthboundSsh; + } + + augment "/config:modules/config:module/config:configuration" { + case netconf-northbound-ssh { + when "/config:modules/config:module/config:type = 'netconf-northbound-ssh'"; + + leaf port { + type inet:port-number; + default 2830; + } + + leaf binding-address { + type inet:ip-address; + default "0.0.0.0"; + } + + container processing-executor { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity th:scheduled-threadpool; + } + } + + description "Required by the mina-ssh library used in SSH endpoint"; + } + + container event-executor { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity netty:netty-event-executor; + } + } + } + + container worker-thread-group { + uses config:service-ref { + refine type { + config:required-identity netty:netty-threadgroup; + } + } + } + + container dispatcher { + uses config:service-ref { + refine type { + config:required-identity nn:netconf-server-dispatcher; + } + } + } + + // FIXME use auth provider from aaa instead + leaf username { + description "Specifies username credential"; + type string; + } + + leaf password { + description "Specifies password credential"; + type string; + } + + + } + } + +} \ No newline at end of file diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java index 8f24a5741e..30b3076589 100644 --- a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java @@ -58,7 +58,7 @@ import org.apache.sshd.server.session.ServerSession; import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; -import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher; +import org.opendaylight.controller.netconf.impl.NetconfServerDispatcherImpl; import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory; import org.opendaylight.controller.netconf.impl.SessionIdProvider; import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; @@ -125,7 +125,7 @@ public class NetconfDeviceSimulator implements Closeable { this.nioExecutor = nioExecutor; } - private NetconfServerDispatcher createDispatcher(final Map moduleBuilders, final boolean exi, final int generateConfigsTimeout, final Optional notificationsFile) { + private NetconfServerDispatcherImpl createDispatcher(final Map moduleBuilders, final boolean exi, final int generateConfigsTimeout, final Optional notificationsFile) { final Set capabilities = Sets.newHashSet(Collections2.transform(moduleBuilders.keySet(), new Function() { @Override @@ -154,9 +154,9 @@ public class NetconfDeviceSimulator implements Closeable { final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( hashedWheelTimer, simulatedOperationProvider, idProvider, generateConfigsTimeout, commitNotifier, new LoggingMonitoringService(), serverCapabilities); - final NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer( + final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( serverNegotiatorFactory); - return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup); + return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup); } private Map toModuleBuilders(final Map> sources) { @@ -192,7 +192,7 @@ public class NetconfDeviceSimulator implements Closeable { final Map moduleBuilders = parseSchemasToModuleBuilders(params); - final NetconfServerDispatcher dispatcher = createDispatcher(moduleBuilders, params.exi, params.generateConfigsTimeout, Optional.fromNullable(params.notificationFile)); + final NetconfServerDispatcherImpl dispatcher = createDispatcher(moduleBuilders, params.exi, params.generateConfigsTimeout, Optional.fromNullable(params.notificationFile)); int currentPort = params.startingPort; diff --git a/opendaylight/netconf/pom.xml b/opendaylight/netconf/pom.xml index 0f14239686..4566845e4f 100644 --- a/opendaylight/netconf/pom.xml +++ b/opendaylight/netconf/pom.xml @@ -34,6 +34,7 @@ ietf-netconf-notifications ietf-netconf-monitoring-extension netconf-connector-config + netconf-mdsal-config netconf-auth netconf-usermanager netconf-testtool