From 90dcdd5d040eb22b74e87baccffd70a30d93bfc0 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 17 May 2022 11:53:23 +0200 Subject: [PATCH] Centralize NetconfNode/InetSocketAddress conversion The process of creating a RemoteDeviceId and/or the target InetSocketAddress is duplicated in a number of places, each slightly different. Centralize conversion in netconf.topology.spi and use it from there, which leads us to topology-singleton being able to use non-IP addresses. JIRA: NETCONF-875 Change-Id: I5c4a610eb4f4b3cd6586198d5e9a4b84b476d351 Signed-off-by: Rohini.Ambika Signed-off-by: Robert Varga --- .../impl/NetconfTopologyContext.java | 9 +++-- .../impl/NetconfTopologyManager.java | 15 +++----- .../impl/RemoteDeviceConnectorImpl.java | 17 +-------- .../impl/utils/NetconfTopologyUtils.java | 13 +------ .../impl/utils/NetconfTopologyUtilTest.java | 24 ------------ .../topology/spi/AbstractNetconfTopology.java | 31 ++------------- .../topology/spi/NetconfNodeUtils.java | 38 +++++++++++++++++++ .../topology/spi/NetconfNodeUtilsTest.java | 35 +++++++++++++++++ 8 files changed, 90 insertions(+), 92 deletions(-) create mode 100644 netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfNodeUtils.java create mode 100644 netconf/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfNodeUtilsTest.java diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyContext.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyContext.java index 56a2ae5c83..0cb78da8aa 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyContext.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyContext.java @@ -27,6 +27,7 @@ import org.opendaylight.netconf.topology.singleton.impl.actors.NetconfNodeActor; import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup; import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils; import org.opendaylight.netconf.topology.singleton.messages.RefreshSetupMasterActorData; +import org.opendaylight.netconf.topology.spi.NetconfNodeUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.slf4j.Logger; @@ -60,8 +61,8 @@ class NetconfTopologyContext implements ClusterSingletonService, AutoCloseable { this.mountService = mountService; this.deviceActionFactory = deviceActionFactory; - remoteDeviceId = NetconfTopologyUtils.createRemoteDeviceId(netconfTopologyDeviceSetup.getNode().getNodeId(), - netconfTopologyDeviceSetup.getNode().augmentation(NetconfNode.class)); + final var node = netconfTopologyDeviceSetup.getNode(); + remoteDeviceId = NetconfNodeUtils.toRemoteDeviceId(node.getNodeId(), node.augmentation(NetconfNode.class)); remoteDeviceConnector = new RemoteDeviceConnectorImpl(netconfTopologyDeviceSetup, remoteDeviceId, deviceActionFactory); netconfNodeManager = createNodeDeviceManager(); @@ -137,8 +138,8 @@ class NetconfTopologyContext implements ClusterSingletonService, AutoCloseable { */ void refresh(final @NonNull NetconfTopologySetup setup) { netconfTopologyDeviceSetup = requireNonNull(setup); - remoteDeviceId = NetconfTopologyUtils.createRemoteDeviceId(netconfTopologyDeviceSetup.getNode().getNodeId(), - netconfTopologyDeviceSetup.getNode().augmentation(NetconfNode.class)); + final var node = netconfTopologyDeviceSetup.getNode(); + remoteDeviceId = NetconfNodeUtils.toRemoteDeviceId(node.getNodeId(), node.augmentation(NetconfNode.class)); if (isMaster) { remoteDeviceConnector.stopRemoteDeviceConnection(); diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManager.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManager.java index 64faa51145..0a0c04f926 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManager.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManager.java @@ -50,6 +50,7 @@ import org.opendaylight.netconf.topology.singleton.api.NetconfTopologySingletonS import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup; import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup.NetconfTopologySetupBuilder; import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils; +import org.opendaylight.netconf.topology.spi.NetconfNodeUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeTopologyService; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.topology.singleton.config.rev170419.Config; @@ -179,10 +180,7 @@ public class NetconfTopologyManager // TODO change to a specific documented Exception when changed in ClusterSingletonServiceProvider @SuppressWarnings("checkstyle:IllegalCatch") private void startNetconfDeviceContext(final InstanceIdentifier instanceIdentifier, final Node node) { - final NetconfNode netconfNode = node.augmentation(NetconfNode.class); - requireNonNull(netconfNode); - requireNonNull(netconfNode.getHost()); - requireNonNull(netconfNode.getHost().getIpAddress()); + final NetconfNode netconfNode = requireNonNull(node.augmentation(NetconfNode.class)); final Timeout actorResponseWaitTime = Timeout.create( Duration.ofSeconds(netconfNode.getActorResponseWaitTime().toJava())); @@ -304,9 +302,9 @@ public class NetconfTopologyManager private NetconfTopologySetup createSetup(final InstanceIdentifier instanceIdentifier, final Node node) { final NetconfNode netconfNode = node.augmentation(NetconfNode.class); - final RemoteDeviceId deviceId = NetconfTopologyUtils.createRemoteDeviceId(node.getNodeId(), netconfNode); + final RemoteDeviceId deviceId = NetconfNodeUtils.toRemoteDeviceId(node.getNodeId(), netconfNode); - final NetconfTopologySetupBuilder builder = NetconfTopologySetupBuilder.create() + return NetconfTopologySetupBuilder.create() .setClusterSingletonServiceProvider(clusterSingletonServiceProvider) .setBaseSchemas(baseSchemas) .setDataBroker(dataBroker) @@ -324,8 +322,7 @@ public class NetconfTopologyManager .setIdleTimeout(writeTxIdleTimeout) .setPrivateKeyPath(privateKeyPath) .setPrivateKeyPassphrase(privateKeyPassphrase) - .setEncryptionService(encryptionService); - - return builder.build(); + .setEncryptionService(encryptionService) + .build(); } } diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java index 2546015548..0de0ea6bc3 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java @@ -53,8 +53,7 @@ import org.opendaylight.netconf.topology.singleton.api.RemoteDeviceConnector; import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup; import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils; import org.opendaylight.netconf.topology.spi.NetconfConnectorDTO; -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.IpAddress; +import org.opendaylight.netconf.topology.spi.NetconfNodeUtils; 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.topology.rev150114.NetconfNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.OdlHelloMessageCapabilities; @@ -257,18 +256,6 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector { return Optional.of(NetconfSessionPreferences.fromStrings(capabilities, CapabilityOrigin.UserDefined)); } - //TODO: duplicate code - private static InetSocketAddress getSocketAddress(final Host host, final int port) { - if (host.getDomainName() != null) { - return new InetSocketAddress(host.getDomainName().getValue(), port); - } else { - final IpAddress ipAddress = host.getIpAddress(); - final String ip = ipAddress.getIpv4Address() != null ? ipAddress.getIpv4Address().getValue() : - ipAddress.getIpv6Address().getValue(); - return new InetSocketAddress(ip, port); - } - } - @VisibleForTesting NetconfReconnectingClientConfiguration getClientConfig(final NetconfClientSessionListener listener, final NetconfNode node) { @@ -286,7 +273,7 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector { final Decimal64 sleepFactor = node.getSleepFactor() == null ? NetconfTopologyUtils.DEFAULT_SLEEP_FACTOR : node.getSleepFactor(); - final InetSocketAddress socketAddress = getSocketAddress(node.getHost(), node.getPort().getValue().toJava()); + final InetSocketAddress socketAddress = NetconfNodeUtils.toInetSocketAddress(node); final ReconnectStrategyFactory sf = new TimedReconnectStrategyFactory(netconfTopologyDeviceSetup.getEventExecutor(), maxConnectionAttempts, diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java index e0341a94c1..eba7cde7c7 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java @@ -7,11 +7,8 @@ */ package org.opendaylight.netconf.topology.singleton.impl.utils; -import java.net.InetSocketAddress; import org.opendaylight.netconf.api.DocumentedException; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; @@ -39,15 +36,7 @@ public final class NetconfTopologyUtils { public static final Decimal64 DEFAULT_SLEEP_FACTOR = Decimal64.valueOf("1.5"); private NetconfTopologyUtils() { - - } - - public static RemoteDeviceId createRemoteDeviceId(final NodeId nodeId, final NetconfNode node) { - final IpAddress ipAddress = node.getHost().getIpAddress(); - final InetSocketAddress address = new InetSocketAddress(ipAddress.getIpv4Address() != null - ? ipAddress.getIpv4Address().getValue() : ipAddress.getIpv6Address().getValue(), - node.getPort().getValue().toJava()); - return new RemoteDeviceId(nodeId.getValue(), address); + // Hidden on purpose } public static String createActorPath(final String masterMember, final String name) { diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtilTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtilTest.java index 9f95da5779..648e38b4e5 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtilTest.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtilTest.java @@ -5,41 +5,18 @@ * 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.topology.singleton.impl.utils; import static org.junit.Assert.assertEquals; import org.junit.Test; -import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; -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.IpAddress; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.Uint16; public class NetconfTopologyUtilTest { - - @Test - public void testCreateRemoteDeviceId() { - final Host host = new Host(new IpAddress(new Ipv4Address("127.0.0.1"))); - final NetconfNode netconfNode = new NetconfNodeBuilder().setHost(host) - .setPort(new PortNumber(Uint16.valueOf(9999))).build(); - final NodeId nodeId = new NodeId("testing-node"); - final RemoteDeviceId id = NetconfTopologyUtils.createRemoteDeviceId(nodeId, netconfNode); - - assertEquals("testing-node", id.getName()); - assertEquals(host, id.getHost()); - assertEquals(9999, id.getAddress().getPort()); - } - @Test public void testCreateActorPath() { final String actorPath = NetconfTopologyUtils.createActorPath("member", "name"); @@ -57,5 +34,4 @@ public class NetconfTopologyUtilTest { assertEquals("topologyId", NetconfTopologyUtils.createTopologyNodePath("topologyId") .firstKeyOf(Topology.class).getTopologyId().getValue()); } - } diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java index 4f0dff3d0b..740ad3a869 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java @@ -18,7 +18,6 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import io.netty.util.concurrent.EventExecutor; -import java.net.InetSocketAddress; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; @@ -60,9 +59,6 @@ import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSc 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; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; @@ -203,17 +199,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { protected NetconfConnectorDTO createDeviceCommunicator(final NodeId nodeId, final NetconfNode node, final NetconfNodeAugmentedOptional nodeOptional) { - final Host host = node.getHost(); - final IpAddress ipAddress = host.getIpAddress(); - final InetSocketAddress address; - 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); + final RemoteDeviceId remoteDeviceId = NetconfNodeUtils.toRemoteDeviceId(nodeId, node); final long keepaliveDelay = node.requireKeepaliveDelay().toJava(); RemoteDeviceHandler salFacade = createSalFacade(remoteDeviceId); @@ -264,7 +250,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { return new NetconfConnectorDTO(netconfDeviceCommunicator, salFacade, yanglibRegistrations); } - private List> registerDeviceSchemaSources(final RemoteDeviceId remoteDeviceId, + private static List> registerDeviceSchemaSources(final RemoteDeviceId remoteDeviceId, final NetconfNode node, final SchemaResourcesDTO resources) { final YangLibrary yangLibrary = node.getYangLibrary(); if (yangLibrary != null) { @@ -340,7 +326,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { } return reconnectingClientConfigurationBuilder - .withAddress(getSocketAddress(node.getHost(), node.getPort().getValue().toJava())) + .withAddress(NetconfNodeUtils.toInetSocketAddress(node)) .withConnectionTimeoutMillis(node.requireConnectionTimeoutMillis().toJava()) .withReconnectStrategy(sf.createReconnectStrategy()) .withConnectStrategyFactory(sf) @@ -377,17 +363,6 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { protected abstract RemoteDeviceHandler createSalFacade(RemoteDeviceId id); - private static InetSocketAddress getSocketAddress(final Host host, final int port) { - if (host.getDomainName() != null) { - return new InetSocketAddress(host.getDomainName().getValue(), port); - } - - final IpAddress ipAddress = host.getIpAddress(); - final String ip = ipAddress.getIpv4Address() != null ? ipAddress.getIpv4Address().getValue() - : ipAddress.getIpv6Address().getValue(); - return new InetSocketAddress(ip, port); - } - private static Optional getUserCapabilities(final NetconfNode node) { // if none of yang-module-capabilities or non-module-capabilities is specified // just return absent diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfNodeUtils.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfNodeUtils.java new file mode 100644 index 0000000000..085680fb6b --- /dev/null +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfNodeUtils.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.topology.spi; + +import java.net.InetSocketAddress; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; +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.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; + +/** + * Utility methods to work with {@link NetconfNode} information. + */ +public final class NetconfNodeUtils { + private NetconfNodeUtils() { + // Hidden on purpose + } + + public static @NonNull InetSocketAddress toInetSocketAddress(final NetconfNode node) { + final Host host = node.requireHost(); + final int port = node.requirePort().getValue().toJava(); + final IpAddress ipAddress = host.getIpAddress(); + return ipAddress != null ? new InetSocketAddress(IetfInetUtil.INSTANCE.inetAddressFor(ipAddress), port) + : new InetSocketAddress(host.getDomainName().getValue(), port); + } + + public static @NonNull RemoteDeviceId toRemoteDeviceId(final NodeId nodeId, final NetconfNode node) { + return new RemoteDeviceId(nodeId.getValue(), toInetSocketAddress(node)); + } +} diff --git a/netconf/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfNodeUtilsTest.java b/netconf/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfNodeUtilsTest.java new file mode 100644 index 0000000000..a779f690bf --- /dev/null +++ b/netconf/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfNodeUtilsTest.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.topology.spi; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; +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.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.common.Uint16; + +public class NetconfNodeUtilsTest { + @Test + public void testCreateRemoteDeviceId() { + final Host host = new Host(new IpAddress(new Ipv4Address("127.0.0.1"))); + final RemoteDeviceId id = NetconfNodeUtils.toRemoteDeviceId(new NodeId("testing-node"), new NetconfNodeBuilder() + .setHost(host) + .setPort(new PortNumber(Uint16.valueOf(9999))) + .build()); + + assertEquals("testing-node", id.getName()); + assertEquals(host, id.getHost()); + assertEquals(9999, id.getAddress().getPort()); + } +} -- 2.36.6