2 * Copyright (c) 2016 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
9 package org.opendaylight.netconf.topology.util;
11 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
12 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
13 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
18 import org.opendaylight.yangtools.yang.binding.Identifier;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
22 public final class TopologyUtil {
24 private TopologyUtil() {
25 throw new AssertionError("Instantiating utility class.");
29 * Determines the Netconf Node Node ID, given the node's instance
32 * @param pathArgument Node's path argument
33 * @return NodeId for the node
35 public static NodeId getNodeId(final InstanceIdentifier.PathArgument pathArgument) {
36 if (pathArgument instanceof InstanceIdentifier.IdentifiableItem<?, ?>) {
38 final Identifier key = ((InstanceIdentifier.IdentifiableItem) pathArgument).getKey();
39 if(key instanceof NodeKey) {
40 return ((NodeKey) key).getNodeId();
43 throw new IllegalStateException("Unable to create NodeId from: " + pathArgument);
46 public static KeyedInstanceIdentifier<Topology, TopologyKey> createTopologyListPath(final String topologyId) {
47 final InstanceIdentifier<NetworkTopology> networkTopology = InstanceIdentifier.create(NetworkTopology.class);
48 return networkTopology.child(Topology.class, new TopologyKey(new TopologyId(topologyId)));
51 public static InstanceIdentifier<Node> createTopologyNodeListPath(final NodeKey key, final String topologyId) {
52 return createTopologyListPath(topologyId).child(Node.class, new NodeKey(new NodeId(key.getNodeId().getValue())));
55 public static InstanceIdentifier<Node> createTopologyNodePath(final String topologyId) {
56 return createTopologyListPath(topologyId).child(Node.class);