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 java.net.InetSocketAddress;
13 import java.util.Objects;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.HostBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
26 import org.opendaylight.yangtools.yang.common.QName;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
30 public final class RemoteDeviceId {
31 private static final String DEFAULT_TOPOLOGY_NAME = TopologyNetconf.QNAME.getLocalName();
32 private static final KeyedInstanceIdentifier<Topology, TopologyKey> DEFAULT_TOPOLOGY_IID =
33 InstanceIdentifier.create(NetworkTopology.class)
34 .child(Topology.class, new TopologyKey(new TopologyId(DEFAULT_TOPOLOGY_NAME)));
35 private static final YangInstanceIdentifier DEFAULT_TOPOLOGY_NODE = YangInstanceIdentifier.builder()
36 .node(NetworkTopology.QNAME).node(Topology.QNAME)
37 .nodeWithKey(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), DEFAULT_TOPOLOGY_NAME)
40 private static final QName NODE_ID_QNAME = QName.create(Node.QNAME, "node-id").intern();
42 private final String name;
43 private final NodeKey key;
44 private final YangInstanceIdentifier topologyPath;
45 private final KeyedInstanceIdentifier<Node, NodeKey> topologyBindingPath;
46 private InetSocketAddress address;
49 private RemoteDeviceId(final String name) {
50 this.name = requireNonNull(name);
51 this.topologyPath = DEFAULT_TOPOLOGY_NODE
52 .node(NodeIdentifierWithPredicates.of(Node.QNAME, NODE_ID_QNAME, name));
53 this.key = new NodeKey(new NodeId(name));
54 this.topologyBindingPath = DEFAULT_TOPOLOGY_IID.child(Node.class, key);
57 public RemoteDeviceId(final String name, final InetSocketAddress address) {
59 this.address = address;
60 this.host = buildHost();
63 private Host buildHost() {
64 return HostBuilder.getDefaultInstance(address.getHostString());
67 public String getName() {
71 public NodeKey getBindingKey() {
75 public InstanceIdentifier<Node> getTopologyBindingPath() {
76 return topologyBindingPath;
79 public YangInstanceIdentifier getTopologyPath() {
83 public InetSocketAddress getAddress() {
87 public Host getHost() {
92 public String toString() {
93 return "RemoteDevice{" + name + '}';
97 public boolean equals(final Object obj) {
101 if (!(obj instanceof RemoteDeviceId)) {
104 final RemoteDeviceId that = (RemoteDeviceId) obj;
105 return name.equals(that.name) && topologyBindingPath.equals(that.topologyBindingPath);
109 public int hashCode() {
110 return Objects.hash(name, topologyBindingPath);