Fixed domain-name usage in NETCONF southbound 22/92422/5
authorMaros Marsalek <mmarsalek@frinx.io>
Tue, 10 Sep 2019 08:29:11 +0000 (10:29 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 20 Dec 2020 17:01:44 +0000 (18:01 +0100)
- 'host' in the NETCONF mount request is described by union
  type - it accepts both IP address and domain-name.
- This domain-name wasn't considered as option during creation
  of connector to remote device - it ended with NPE.

Change-Id: I0f064aced76de3465da88376fcb6c6b589ed545f
Signed-off-by: Maros Marsalek <mmarsalek@frinx.io>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java

index c132a2d9cde6058c6f61c0d6c4974280758dcf72..a66c67198180193399fc9db0655c919fa2845581 100644 (file)
@@ -61,6 +61,7 @@ import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.sal.connect.util.SslHandlerFactoryImpl;
 import org.opendaylight.netconf.topology.api.NetconfTopology;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
+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.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.NetconfNodeAugmentedOptional;
@@ -219,10 +220,16 @@ public abstract class AbstractNetconfTopology implements NetconfTopology {
         final long keepaliveDelay = node.getKeepaliveDelay() == null
                 ? DEFAULT_KEEPALIVE_DELAY : node.getKeepaliveDelay().toJava();
 
-        final IpAddress ipAddress = node.getHost().getIpAddress();
-        final InetSocketAddress address = new InetSocketAddress(ipAddress.getIpv4Address() != null
-                ? ipAddress.getIpv4Address().getValue() : ipAddress.getIpv6Address().getValue(),
-                node.getPort().getValue().toJava());
+        final InetSocketAddress address;
+        final Host host = node.getHost();
+        final IpAddress ipAddress = host.getIpAddress();
+        if (ipAddress != null) {
+            address = new InetSocketAddress(IetfInetUtil.INSTANCE.inetAddressFor(ipAddress),
+                    node.getPort().getValue().toJava());
+        } else {
+            address = new InetSocketAddress(host.getDomainName().getValue(),
+                    node.getPort().getValue().toJava());
+        }
         final RemoteDeviceId remoteDeviceId = new RemoteDeviceId(nodeId.getValue(), address);
 
         RemoteDeviceHandler<NetconfSessionPreferences> salFacade = createSalFacade(remoteDeviceId);