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 com.google.common.base.Preconditions;
11 import java.net.InetSocketAddress;
12 import java.util.Objects;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.HostBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
29 public final class RemoteDeviceId {
30 private static final String DEFAULT_TOPOLOGY_NAME = TopologyNetconf.QNAME.getLocalName();
31 private static final KeyedInstanceIdentifier<Topology, TopologyKey> DEFAULT_TOPOLOGY_IID =
32 InstanceIdentifier.create(NetworkTopology.class)
33 .child(Topology.class, new TopologyKey(new TopologyId(DEFAULT_TOPOLOGY_NAME)));
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 private final String name;
42 private final NodeKey key;
43 private final YangInstanceIdentifier topologyPath;
44 private final KeyedInstanceIdentifier<Node, NodeKey> topologyBindingPath;
45 private InetSocketAddress address;
48 private RemoteDeviceId(final String name) {
49 this.name = Preconditions.checkNotNull(name);
50 this.topologyPath = DEFAULT_TOPOLOGY_NODE
51 .node(NodeIdentifierWithPredicates.of(Node.QNAME, NODE_ID_QNAME, name));
52 this.key = new NodeKey(new NodeId(name));
53 this.topologyBindingPath = DEFAULT_TOPOLOGY_IID.child(Node.class, key);
56 public RemoteDeviceId(final String name, final InetSocketAddress address) {
58 this.address = address;
59 this.host = buildHost();
62 private Host buildHost() {
63 return HostBuilder.getDefaultInstance(address.getHostString());
66 public String getName() {
70 public NodeKey getBindingKey() {
74 public InstanceIdentifier<Node> getTopologyBindingPath() {
75 return topologyBindingPath;
78 public YangInstanceIdentifier getTopologyPath() {
82 public InetSocketAddress getAddress() {
86 public Host getHost() {
91 public String toString() {
92 return "RemoteDevice{" + name + '}';
96 public boolean equals(final Object obj) {
100 if (!(obj instanceof RemoteDeviceId)) {
103 final RemoteDeviceId that = (RemoteDeviceId) obj;
104 return name.equals(that.name) && topologyBindingPath.equals(that.topologyBindingPath);
108 public int hashCode() {
109 return Objects.hash(name, topologyBindingPath);