Make TCP netconf endpoint configurable 81/18981/8
authorTomas Cere <tcere@cisco.com>
Wed, 29 Apr 2015 11:43:01 +0000 (13:43 +0200)
committerTomas Cere <tcere@cisco.com>
Thu, 30 Apr 2015 11:45:52 +0000 (13:45 +0200)
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 <mmarsale@cisco.com>
Signed-off-by: Tomas Cere <tcere@cisco.com>
features/mdsal/src/main/resources/features.xml
features/netconf-connector/src/main/resources/features.xml
opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml
opendaylight/netconf/netconf-tcp/pom.xml
opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/tcp/NetconfNorthboundTcpModule.java [new file with mode: 0644]
opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/config/yang/netconf/northbound/tcp/NetconfNorthboundTcpModuleFactory.java [new file with mode: 0644]
opendaylight/netconf/netconf-tcp/src/main/yang/netconf-northbound-tcp.yang [new file with mode: 0644]

index a992d2f95e19b497f81ae90641a269214095221c..cd45f09f124172d01eaac4d6153f9b055253710d 100644 (file)
@@ -27,6 +27,8 @@
     <feature name='odl-netconf-mdsal' version='${project.version}' description="OpenDaylight :: Netconf :: Mdsal">
         <feature version='${config.version}'>odl-config-all</feature>
         <feature version='${netconf.version}'>odl-netconf-all</feature>
     <feature name='odl-netconf-mdsal' version='${project.version}' description="OpenDaylight :: Netconf :: Mdsal">
         <feature version='${config.version}'>odl-config-all</feature>
         <feature version='${netconf.version}'>odl-netconf-all</feature>
+        <feature version='${config.version}'>odl-config-netty</feature>
+        <bundle>mvn:org.opendaylight.controller/netconf-tcp/${netconf.version}</bundle>
         <bundle>mvn:org.opendaylight.controller/netconf-ssh/${netconf.version}</bundle>
         <feature version='${mdsal.version}'>odl-mdsal-broker</feature>
         <bundle>mvn:org.opendaylight.controller/mdsal-netconf-connector/${netconf.version}</bundle>
         <bundle>mvn:org.opendaylight.controller/netconf-ssh/${netconf.version}</bundle>
         <feature version='${mdsal.version}'>odl-mdsal-broker</feature>
         <bundle>mvn:org.opendaylight.controller/mdsal-netconf-connector/${netconf.version}</bundle>
index 6805d82063ab83ab5b2aa540a8f11aa767f2e1c0..ea44db97dc5cc30426f243fbae38ce985508f9ea 100644 (file)
         <!-- feature version='${aaa.version}'>odl-aaa-netconf-plugin</feature -->
         <bundle>mvn:org.opendaylight.controller/netconf-ssh/${netconf.version}</bundle>
       </feature>
         <!-- feature version='${aaa.version}'>odl-aaa-netconf-plugin</feature -->
         <bundle>mvn:org.opendaylight.controller/netconf-ssh/${netconf.version}</bundle>
       </feature>
-      <feature name='odl-netconf-tcp' version='${netconf.version}' description="OpenDaylight :: Netconf Connector :: TCP">
+    <feature name='odl-netconf-tcp' version='${netconf.version}' description="OpenDaylight :: Netconf Connector :: TCP">
         <feature version='${netconf.version}'>odl-netconf-impl</feature>
         <feature version='${netconf.version}'>odl-netconf-impl</feature>
+        <feature version='${config.version}'>odl-config-netty</feature>
         <bundle>mvn:org.opendaylight.controller/netconf-tcp/${netconf.version}</bundle>
         <bundle>mvn:org.opendaylight.controller/netconf-tcp/${netconf.version}</bundle>
-      </feature>
+    </feature>
 
     <feature name='odl-message-bus' version='${project.version}'>
         <feature version='${project.version}'>odl-netconf-connector</feature>
 
     <feature name='odl-message-bus' version='${project.version}'>
         <feature version='${project.version}'>odl-netconf-connector</feature>
index 1982615173ec2aa7d36a39b7eb0733f759d55299..72a3dcf3885165aad54083ad4774d62e4fe29f8d 100644 (file)
               <password>admin</password>
           </module>
 
               <password>admin</password>
           </module>
 
+
+          <!--TCP endpoint for MD-SAL netconf server -->
+          <!--<module>-->
+              <!--<type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:tcp">prefix:netconf-northbound-tcp</type>-->
+              <!--<name>netconf-mdsal-tcp-server</name>-->
+              <!--<dispatcher xmlns="urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:tcp">-->
+                  <!--<type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:netconf:northbound">prefix:netconf-server-dispatcher</type>-->
+                  <!--<name>netconf-mdsal-server-dispatcher</name>-->
+              <!--</dispatcher>-->
+          <!--</module>-->
+
       </modules>
 
         <services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
       </modules>
 
         <services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
       <capability>urn:opendaylight:params:xml:ns:yang:controller:netconf:mdsal:mapper?module=netconf-mdsal-mapper&amp;revision=2015-01-14</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:netconf:mdsal:monitoring?module=netconf-mdsal-monitoring&amp;revision=2015-02-18</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:ssh?module=netconf-northbound-ssh&amp;revision=2015-01-14</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:netconf:mdsal:mapper?module=netconf-mdsal-mapper&amp;revision=2015-01-14</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:netconf:mdsal:monitoring?module=netconf-mdsal-monitoring&amp;revision=2015-02-18</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:ssh?module=netconf-northbound-ssh&amp;revision=2015-01-14</capability>
+      <capability>urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:tcp?module=netconf-northbound-tcp&amp;revision=2015-04-23</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:config:netconf:northbound:impl?module=netconf-northbound-impl&amp;revision=2015-01-12</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl:scheduled?module=threadpool-impl-scheduled&amp;revision=2013-12-01</capability>
   </required-capabilities>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:config:netconf:northbound:impl?module=netconf-northbound-impl&amp;revision=2015-01-12</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl:scheduled?module=threadpool-impl-scheduled&amp;revision=2013-12-01</capability>
   </required-capabilities>
index 033142ab9756caa272662911019692bb4d701a34..e1e650b4da3c8ff06f98ac8747b89865814ef1d2 100644 (file)
       <groupId>${project.groupId}</groupId>
       <artifactId>netconf-util</artifactId>
     </dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>netconf-util</artifactId>
     </dependency>
+      <dependency>
+          <groupId>org.opendaylight.controller</groupId>
+          <artifactId>threadpool-config-api</artifactId>
+      </dependency>
+      <dependency>
+          <groupId>org.opendaylight.controller</groupId>
+          <artifactId>netty-config-api</artifactId>
+      </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
           </instructions>
         </configuration>
       </plugin>
           </instructions>
         </configuration>
       </plugin>
+        <plugin>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-maven-plugin</artifactId>
+            <executions>
+                <execution>
+                    <id>config</id>
+                    <goals>
+                        <goal>generate-sources</goal>
+                    </goals>
+                    <configuration>
+                        <codeGenerators>
+                            <generator>
+                                <codeGeneratorClass>org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator</codeGeneratorClass>
+                                <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
+                                <additionalConfiguration>
+                                    <namespaceToPackage1>urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang</namespaceToPackage1>
+                                </additionalConfiguration>
+                            </generator>
+                            <generator>
+                                <codeGeneratorClass>org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl</codeGeneratorClass>
+                                <outputBaseDir>${salGeneratorPath}</outputBaseDir>
+                            </generator>
+                        </codeGenerators>
+                        <inspectDependencies>true</inspectDependencies>
+                    </configuration>
+                </execution>
+            </executions>
+            <dependencies>
+                <dependency>
+                    <groupId>org.opendaylight.controller</groupId>
+                    <artifactId>yang-jmx-generator-plugin</artifactId>
+                    <version>${config.version}</version>
+                </dependency>
+            </dependencies>
+        </plugin>
     </plugins>
   </build>
 
     </plugins>
   </build>
 
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 (file)
index 0000000..b5492a8
--- /dev/null
@@ -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<ChannelFuture>() {
+            @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 (file)
index 0000000..081486e
--- /dev/null
@@ -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 (file)
index 0000000..a42fcad
--- /dev/null
@@ -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