From: Tomas Cere Date: Wed, 29 Apr 2015 11:43:01 +0000 (+0200) Subject: Make TCP netconf endpoint configurable X-Git-Tag: release/beryllium~619^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=c0b54d22478f7b3350ed43375747a4da1b995c64 Make TCP netconf endpoint configurable Allow users to configure netconf endpoint for md-sal to use pure TCP instead/or along with SSH. Change-Id: I03d067322b0c02ba335d554da51c56db77c22bfb Signed-off-by: Maros Marsalek Signed-off-by: Tomas Cere --- diff --git a/features/mdsal/src/main/resources/features.xml b/features/mdsal/src/main/resources/features.xml index a992d2f95e..cd45f09f12 100644 --- a/features/mdsal/src/main/resources/features.xml +++ b/features/mdsal/src/main/resources/features.xml @@ -27,6 +27,8 @@ odl-config-all odl-netconf-all + odl-config-netty + mvn:org.opendaylight.controller/netconf-tcp/${netconf.version} mvn:org.opendaylight.controller/netconf-ssh/${netconf.version} odl-mdsal-broker mvn:org.opendaylight.controller/mdsal-netconf-connector/${netconf.version} diff --git a/features/netconf-connector/src/main/resources/features.xml b/features/netconf-connector/src/main/resources/features.xml index 6805d82063..ea44db97dc 100644 --- a/features/netconf-connector/src/main/resources/features.xml +++ b/features/netconf-connector/src/main/resources/features.xml @@ -112,10 +112,11 @@ mvn:org.opendaylight.controller/netconf-ssh/${netconf.version} - + odl-netconf-impl + odl-config-netty mvn:org.opendaylight.controller/netconf-tcp/${netconf.version} - + odl-netconf-connector 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 index 1982615173..72a3dcf388 100644 --- 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 @@ -112,6 +112,17 @@ admin + + + + + + + + + + + @@ -158,6 +169,7 @@ 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/opendaylight/netconf/netconf-tcp/pom.xml b/opendaylight/netconf/netconf-tcp/pom.xml index 033142ab97..e1e650b4da 100644 --- a/opendaylight/netconf/netconf-tcp/pom.xml +++ b/opendaylight/netconf/netconf-tcp/pom.xml @@ -27,6 +27,14 @@ ${project.groupId} netconf-util + + org.opendaylight.controller + threadpool-config-api + + + org.opendaylight.controller + netty-config-api + org.slf4j slf4j-api @@ -49,6 +57,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-tcp/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/tcp/NetconfNorthboundTcpModule.java b/opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/tcp/NetconfNorthboundTcpModule.java new file mode 100644 index 0000000000..b5492a8139 --- /dev/null +++ b/opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/tcp/NetconfNorthboundTcpModule.java @@ -0,0 +1,76 @@ +package org.opendaylight.controller.config.yang.netconf.northbound.tcp; + +import io.netty.channel.ChannelFuture; +import io.netty.util.concurrent.GenericFutureListener; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import org.opendaylight.controller.netconf.api.NetconfServerDispatcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NetconfNorthboundTcpModule extends org.opendaylight.controller.config.yang.netconf.northbound.tcp.AbstractNetconfNorthboundTcpModule { + + private static final Logger LOG = LoggerFactory.getLogger(NetconfNorthboundTcpModule.class); + + + public NetconfNorthboundTcpModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public NetconfNorthboundTcpModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.netconf.northbound.tcp.NetconfNorthboundTcpModule oldModule, 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 ChannelFuture tcpServer = dispatch.createServer(getInetAddress()); + + tcpServer.addListener(new GenericFutureListener() { + @Override + public void operationComplete(ChannelFuture future) throws Exception { + if (future.isDone() && future.isSuccess()) { + LOG.info("Netconf TCP endpoint started successfully at {}", getInetAddress()); + } else { + LOG.warn("Unable to start TCP netconf server at {}", getInetAddress(), future.cause()); + throw new RuntimeException("Unable to start TCP netconf server", future.cause()); + } + } + }); + + return new NetconfServerCloseable(tcpServer); + } + + 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; + + public NetconfServerCloseable(final ChannelFuture localServer) { + this.localServer = localServer; + } + + @Override + public void close() throws Exception { + if(localServer.isDone()) { + localServer.channel().close(); + } else { + localServer.cancel(true); + } + } + } + +} diff --git a/opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/tcp/NetconfNorthboundTcpModuleFactory.java b/opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/tcp/NetconfNorthboundTcpModuleFactory.java new file mode 100644 index 0000000000..081486ecf4 --- /dev/null +++ b/opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/tcp/NetconfNorthboundTcpModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: netconf-northbound-tcp yang module local name: netconf-northbound-tcp +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Thu Apr 23 16:34:55 CEST 2015 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.netconf.northbound.tcp; +public class NetconfNorthboundTcpModuleFactory extends org.opendaylight.controller.config.yang.netconf.northbound.tcp.AbstractNetconfNorthboundTcpModuleFactory { + +} diff --git a/opendaylight/netconf/netconf-tcp/src/main/yang/netconf-northbound-tcp.yang b/opendaylight/netconf/netconf-tcp/src/main/yang/netconf-northbound-tcp.yang new file mode 100644 index 0000000000..a42fcad147 --- /dev/null +++ b/opendaylight/netconf/netconf-tcp/src/main/yang/netconf-northbound-tcp.yang @@ -0,0 +1,53 @@ +module netconf-northbound-tcp { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:tcp"; + 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 tcp server"; + + revision "2015-04-23" { + description + "Initial revision."; + } + + identity netconf-northbound-tcp { + base config:module-type; + config:java-name-prefix NetconfNorthboundTcp; + } + + augment "/config:modules/config:module/config:configuration" { + case netconf-northbound-tcp { + when "/config:modules/config:module/config:type = 'netconf-northbound-tcp'"; + + leaf port { + type inet:port-number; + default 2831; + } + + leaf binding-address { + type inet:ip-address; + default "0.0.0.0"; + } + + container dispatcher { + uses config:service-ref { + refine type { + config:required-identity nn:netconf-server-dispatcher; + } + } + } + } + } + +} \ No newline at end of file