<dependencies>
<dependency>
- <groupId>${project.groupId}</groupId>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-transport</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
+ <artifactId>rfc6991-ietf-inet-types</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.netconf</groupId>
<artifactId>netconf-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.metatype.annotations</artifactId>
+ </dependency>
</dependencies>
-
</project>
package org.opendaylight.netconf.tcp;
import io.netty.channel.ChannelFuture;
-import java.net.InetAddress;
import java.net.InetSocketAddress;
import org.opendaylight.netconf.api.NetconfServerDispatcher;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Create an MD-SAL NETCONF server using TCP.
*/
-public class NetconfNorthboundTcpServer implements AutoCloseable {
+@Component(service = { }, configurationPid = "org.opendaylight.netconf.tcp", enabled = false)
+@Designate(ocd = NetconfNorthboundTcpServer.Configuration.class)
+public final class NetconfNorthboundTcpServer implements AutoCloseable {
+ @ObjectClassDefinition
+ public @interface Configuration {
+ @AttributeDefinition
+ String bindingAddress() default "0.0.0.0";
+ @AttributeDefinition(min = "1", max = "65535")
+ int portNumber() default 2831;
+ }
+
private static final Logger LOG = LoggerFactory.getLogger(NetconfNorthboundTcpServer.class);
private final ChannelFuture tcpServer;
- public NetconfNorthboundTcpServer(final NetconfServerDispatcher netconfServerDispatcher, final String address,
- final String port) {
+ @Activate
+ public NetconfNorthboundTcpServer(
+ @Reference(target = "(type=netconf-server-dispatcher)") final NetconfServerDispatcher serverDispatcher,
+ final Configuration configuration) {
+ this(serverDispatcher, configuration.bindingAddress(), configuration.portNumber());
+ }
+
+ public NetconfNorthboundTcpServer(final NetconfServerDispatcher serverDispatcher, final String address,
+ final int port) {
final InetSocketAddress inetAddress = getInetAddress(address, port);
- tcpServer = netconfServerDispatcher.createServer(inetAddress);
+ tcpServer = serverDispatcher.createServer(inetAddress);
tcpServer.addListener(future -> {
if (future.isDone() && future.isSuccess()) {
LOG.info("Netconf TCP endpoint started successfully at {}", inetAddress);
});
}
- private static InetSocketAddress getInetAddress(final String bindingAddress, final String portNumber) {
- final IpAddress ipAddress = IetfInetUtil.ipAddressFor(bindingAddress);
- final InetAddress inetAd = IetfInetUtil.INSTANCE.inetAddressFor(ipAddress);
- return new InetSocketAddress(inetAd, Integer.parseInt(portNumber));
- }
-
@Override
public void close() {
if (tcpServer.isDone()) {
tcpServer.cancel(true);
}
}
+
+ private static InetSocketAddress getInetAddress(final String bindingAddress, final int portNumber) {
+ final var inetAd = IetfInetUtil.INSTANCE.inetAddressFor(IetfInetUtil.ipAddressFor(bindingAddress));
+ return new InetSocketAddress(inetAd, portNumber);
+ }
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2016 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.3.0"
- odl:restart-dependents-on-updates="true">
-
- <reference id="netconfServerDispatcher"
- interface="org.opendaylight.netconf.api.NetconfServerDispatcher"
- odl:type="netconf-server-dispatcher"/>
-
- <!-- NETCONF TCP server for MD-SAL (listening by default on port 2831)-->
-
- <cm:property-placeholder persistent-id="org.opendaylight.netconf.tcp" update-strategy="none">
- <cm:default-properties>
- <cm:property name="bindingAddress" value="0.0.0.0"/>
- <cm:property name="portNumber" value="2831"/>
- </cm:default-properties>
- </cm:property-placeholder>
-
- <!-- If you need/want to use a TCP NETCONF server to interact with MD-SAL, uncomment bellow bean -->
-
- <!--
- <bean id="netconfMdsalTcpServer"
- class="org.opendaylight.netconf.tcp.NetconfNorthboundTcpServer"
- destroy-method="close">
- <argument ref="netconfServerDispatcher"/>
- <argument value="${bindingAddress}"/>
- <argument value="${portNumber}"/>
- </bean>
- -->
-
-</blueprint>
\ No newline at end of file