From: Alexis de Talhouët Date: Wed, 12 Oct 2016 02:10:27 +0000 (-0400) Subject: Add blueprint wiring for netconf-ssh X-Git-Tag: release/carbon~146^2~7 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=dc17c0dd822a2ec436c65fed06eaaf970239fa0c;p=netconf.git Add blueprint wiring for netconf-ssh - create mdsal-netconf-ssh bundle containing the blueprint xml file to start-up the md-sal netconf server ssh. Change-Id: I20d3d22f8c58b8b28a113f3969c9da0e7d84b028 Signed-off-by: Alexis de Talhouët --- diff --git a/features/netconf/pom.xml b/features/netconf/pom.xml index b413f6b838..3db7d602a4 100644 --- a/features/netconf/pom.xml +++ b/features/netconf/pom.xml @@ -240,6 +240,10 @@ ${project.groupId} netconf-monitoring + + org.opendaylight.netconf + mdsal-netconf-ssh + ${project.groupId} mdsal-netconf-monitoring diff --git a/features/netconf/src/main/features/features.xml b/features/netconf/src/main/features/features.xml index b43653d2a0..41df465ff1 100644 --- a/features/netconf/src/main/features/features.xml +++ b/features/netconf/src/main/features/features.xml @@ -135,6 +135,7 @@ odl-netconf-ssh odl-netconf-client odl-mdsal-broker + mvn:org.opendaylight.netconf/mdsal-netconf-ssh/{{VERSION}} mvn:org.opendaylight.netconf/mdsal-netconf-notification/{{VERSION}} mvn:org.opendaylight.netconf/mdsal-netconf-connector/{{VERSION}} mvn:org.opendaylight.netconf/mdsal-netconf-monitoring/{{VERSION}} diff --git a/netconf/mdsal-netconf-ssh/pom.xml b/netconf/mdsal-netconf-ssh/pom.xml new file mode 100644 index 0000000000..82c329224c --- /dev/null +++ b/netconf/mdsal-netconf-ssh/pom.xml @@ -0,0 +1,59 @@ + + + + 4.0.0 + + + org.opendaylight.controller + config-parent + 0.6.0-SNAPSHOT + + + + org.opendaylight.netconf + mdsal-netconf-ssh + 1.2.0-SNAPSHOT + ${project.artifactId} + bundle + + + + + org.opendaylight.netconf + netconf-subsystem + ${project.version} + pom + import + + + + + + + ${project.groupId} + netconf-ssh + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + netconf-ssh + + + + + + diff --git a/netconf/mdsal-netconf-ssh/src/main/resources/org/opendaylight/blueprint/netconf-ssh.xml b/netconf/mdsal-netconf-ssh/src/main/resources/org/opendaylight/blueprint/netconf-ssh.xml new file mode 100755 index 0000000000..9d5d3ed409 --- /dev/null +++ b/netconf/mdsal-netconf-ssh/src/main/resources/org/opendaylight/blueprint/netconf-ssh.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/netconf/netconf-artifacts/pom.xml b/netconf/netconf-artifacts/pom.xml index 7102db1cb2..2a35046dc4 100644 --- a/netconf/netconf-artifacts/pom.xml +++ b/netconf/netconf-artifacts/pom.xml @@ -233,6 +233,11 @@ mdsal-netconf-notification ${project.version} + + ${project.groupId} + mdsal-netconf-ssh + ${project.version} + ${project.groupId} netconf-topology diff --git a/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml b/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml index 48260353a9..f80e2cdeba 100644 --- a/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml +++ b/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml @@ -96,32 +96,6 @@ 6 - - 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 - - - prefix:netconf-auth-provider - default-auth-provider - - - prefix:netconf-notification-manager netconf-notification-manager @@ -243,7 +217,6 @@ 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:mdsal:monitoring?module=netconf-mdsal-monitoring&revision=2015-02-18 - 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:netconf:northbound:tcp?module=netconf-northbound-tcp&revision=2015-04-23 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/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModule.java b/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModule.java deleted file mode 100644 index be457f961d..0000000000 --- a/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModule.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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.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.keyprovider.PEMGeneratorHostKeyProvider; -import org.opendaylight.netconf.api.NetconfServerDispatcher; -import org.opendaylight.netconf.ssh.SshProxyServer; -import org.opendaylight.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(getAuthProviderDependency()); - 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); - } - } - } -} diff --git a/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModuleFactory.java b/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModuleFactory.java deleted file mode 100644 index 88ad64bcf7..0000000000 --- a/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/ssh/NetconfNorthboundSshModuleFactory.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 - */ - -/* -* 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/netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/NetconfNorthboundSshServer.java b/netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/NetconfNorthboundSshServer.java new file mode 100644 index 0000000000..fca99e0b3c --- /dev/null +++ b/netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/NetconfNorthboundSshServer.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2016 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.ssh; + +import io.netty.channel.ChannelFuture; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.local.LocalAddress; +import io.netty.util.concurrent.EventExecutor; +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.keyprovider.PEMGeneratorHostKeyProvider; +import org.opendaylight.netconf.api.NetconfServerDispatcher; +import org.opendaylight.netconf.auth.AuthProvider; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NetconfNorthboundSshServer { + + private static final Logger LOG = LoggerFactory.getLogger(NetconfNorthboundSshServer.class); + + private final ChannelFuture localServer; + private final SshProxyServer sshProxyServer; + + public NetconfNorthboundSshServer(final NetconfServerDispatcher netconfServerDispatcher, + final EventLoopGroup workerGroup, + final EventExecutor eventExecutor, + final String bindingAddress, + final String portNumber, + final AuthProvider authProvider) { + + final LocalAddress localAddress = new LocalAddress(portNumber); + + localServer = netconfServerDispatcher.createLocalServer(localAddress); + sshProxyServer = new SshProxyServer(Executors.newScheduledThreadPool(1), workerGroup, eventExecutor); + + final InetSocketAddress inetAddress = getInetAddress(bindingAddress, portNumber); + final SshProxyServerConfigurationBuilder sshProxyServerConfigurationBuilder = new SshProxyServerConfigurationBuilder(); + sshProxyServerConfigurationBuilder.setBindingAddress(inetAddress); + sshProxyServerConfigurationBuilder.setLocalAddress(localAddress); + sshProxyServerConfigurationBuilder.setAuthenticator(authProvider); + sshProxyServerConfigurationBuilder.setIdleTimeout(Integer.MAX_VALUE); + sshProxyServerConfigurationBuilder.setKeyPairProvider(new PEMGeneratorHostKeyProvider()); + + localServer.addListener(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()); + } + }); + } + + private InetSocketAddress getInetAddress(final String bindingAddress, final String portNumber) { + try { + IpAddress ipAddress= IpAddressBuilder.getDefaultInstance(bindingAddress); + final InetAddress inetAd = InetAddress.getByName(ipAddress.getIpv4Address() == null ? ipAddress.getIpv6Address().getValue() : ipAddress.getIpv4Address().getValue()); + return new InetSocketAddress(inetAd, Integer.valueOf(portNumber)); + } catch (final UnknownHostException e) { + throw new IllegalArgumentException("Unable to bind netconf endpoint to address " + bindingAddress, e); + } + } + + public void close() { + sshProxyServer.close(); + + if (localServer.isDone()) { + localServer.channel().close(); + } else { + localServer.cancel(true); + } + } +} diff --git a/netconf/netconf-ssh/src/main/yang/netconf-northbound-ssh.yang b/netconf/netconf-ssh/src/main/yang/netconf-northbound-ssh.yang deleted file mode 100644 index 0f4da44fbc..0000000000 --- a/netconf/netconf-ssh/src/main/yang/netconf-northbound-ssh.yang +++ /dev/null @@ -1,91 +0,0 @@ -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 2013-07-15; } - import netconf-auth { prefix na; revision-date 2015-07-15; } - - 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; - } - } - } - - container auth-provider { - uses config:service-ref { - refine type { - config:required-identity na:netconf-auth-provider; - } - } - } - - } - } - -} diff --git a/netconf/pom.xml b/netconf/pom.xml index 925488cc63..73e926009d 100644 --- a/netconf/pom.xml +++ b/netconf/pom.xml @@ -28,6 +28,7 @@ netconf-config netconf-impl config-netconf-connector + mdsal-netconf-ssh mdsal-netconf-connector mdsal-netconf-monitoring mdsal-netconf-notification