2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.sal.connect.util;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.VisibleForTesting;
13 import java.net.InetSocketAddress;
14 import java.util.Objects;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.network.topology.topology.topology.types.TopologyNetconf;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.common.QName;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
31 public final class RemoteDeviceId {
32 // FIXME: extract all of this to users, as they are in control of topology-id
33 private static final String DEFAULT_TOPOLOGY_NAME = TopologyNetconf.QNAME.getLocalName();
34 private static final YangInstanceIdentifier DEFAULT_TOPOLOGY_NODE = YangInstanceIdentifier.builder()
35 .node(NetworkTopology.QNAME).node(Topology.QNAME)
36 .nodeWithKey(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), DEFAULT_TOPOLOGY_NAME)
39 private static final QName NODE_ID_QNAME = QName.create(Node.QNAME, "node-id").intern();
41 // FIXME: extract this into caller and pass to constructor
43 public static final KeyedInstanceIdentifier<Topology, TopologyKey> DEFAULT_TOPOLOGY_IID =
44 InstanceIdentifier.create(NetworkTopology.class)
45 .child(Topology.class, new TopologyKey(new TopologyId(DEFAULT_TOPOLOGY_NAME)));
47 private final @NonNull String name;
48 private final @NonNull YangInstanceIdentifier topologyPath;
50 private InetSocketAddress address;
53 private RemoteDeviceId(final String name) {
54 this.name = requireNonNull(name);
55 topologyPath = DEFAULT_TOPOLOGY_NODE.node(NodeIdentifierWithPredicates.of(Node.QNAME, NODE_ID_QNAME, name));
58 public RemoteDeviceId(final String name, final InetSocketAddress address) {
60 this.address = address;
62 final var addr = address.getAddress();
63 host = addr != null ? new Host(IetfInetUtil.INSTANCE.ipAddressFor(addr))
64 : new Host(new DomainName(address.getHostString()));
67 public @NonNull String getName() {
71 public @NonNull YangInstanceIdentifier getTopologyPath() {
75 public InetSocketAddress getAddress() {
79 public Host getHost() {
84 public String toString() {
85 return "RemoteDevice{" + name + '}';
89 public boolean equals(final Object obj) {
90 return this == obj || obj instanceof RemoteDeviceId other
91 && name.equals(other.name) && topologyPath.equals(other.topologyPath);
95 public int hashCode() {
96 return Objects.hash(name, topologyPath);