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;
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();
*/
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();
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;
// TODO change to a specific documented Exception when changed in ClusterSingletonServiceProvider
@SuppressWarnings("checkstyle:IllegalCatch")
private void startNetconfDeviceContext(final InstanceIdentifier<Node> 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()));
private NetconfTopologySetup createSetup(final InstanceIdentifier<Node> 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)
.setIdleTimeout(writeTxIdleTimeout)
.setPrivateKeyPath(privateKeyPath)
.setPrivateKeyPassphrase(privateKeyPassphrase)
- .setEncryptionService(encryptionService);
-
- return builder.build();
+ .setEncryptionService(encryptionService)
+ .build();
}
}
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;
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) {
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,
*/
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;
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) {
* 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");
assertEquals("topologyId", NetconfTopologyUtils.createTopologyNodePath("topologyId")
.firstKeyOf(Topology.class).getTopologyId().getValue());
}
-
}
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;
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;
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<NetconfSessionPreferences> salFacade = createSalFacade(remoteDeviceId);
return new NetconfConnectorDTO(netconfDeviceCommunicator, salFacade, yanglibRegistrations);
}
- private List<SchemaSourceRegistration<?>> registerDeviceSchemaSources(final RemoteDeviceId remoteDeviceId,
+ private static List<SchemaSourceRegistration<?>> registerDeviceSchemaSources(final RemoteDeviceId remoteDeviceId,
final NetconfNode node, final SchemaResourcesDTO resources) {
final YangLibrary yangLibrary = node.getYangLibrary();
if (yangLibrary != null) {
}
return reconnectingClientConfigurationBuilder
- .withAddress(getSocketAddress(node.getHost(), node.getPort().getValue().toJava()))
+ .withAddress(NetconfNodeUtils.toInetSocketAddress(node))
.withConnectionTimeoutMillis(node.requireConnectionTimeoutMillis().toJava())
.withReconnectStrategy(sf.createReconnectStrategy())
.withConnectStrategyFactory(sf)
protected abstract RemoteDeviceHandler<NetconfSessionPreferences> 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<UserPreferences> getUserCapabilities(final NetconfNode node) {
// if none of yang-module-capabilities or non-module-capabilities is specified
// just return absent
--- /dev/null
+/*
+ * 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));
+ }
+}
--- /dev/null
+/*
+ * 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());
+ }
+}