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.l2switch.loopremover.util;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 * InstanceIdentifierUtils provides utility functions related to InstanceIdentifiers.
32 public final class InstanceIdentifierUtils {
34 private InstanceIdentifierUtils() {
35 throw new UnsupportedOperationException("Utility class should never be instantiated");
39 * Creates an Instance Identifier (path) for node with specified id.
41 * @param nodeId the node id
42 * @return the node InstanceIdentifier
44 public static InstanceIdentifier<Node> createNodePath(final NodeId nodeId) {
45 return InstanceIdentifier.builder(Nodes.class) //
46 .child(Node.class, new NodeKey(nodeId)) //
51 * Shorten's node child path to node path.
54 * child of node, from which we want node path.
55 * @return the Node InstanceIdentifier
57 public static InstanceIdentifier<Node> getNodePath(final InstanceIdentifier<?> nodeChild) {
58 return nodeChild.firstIdentifierOf(Node.class);
62 * Creates a table path by appending table specific location to node path.
64 * @param nodePath the node path
65 * @param tableKey the table key
66 * @return the table InstanceIdentifier
68 public static InstanceIdentifier<Table> createTablePath(final InstanceIdentifier<Node> nodePath,
69 final TableKey tableKey) {
70 return nodePath.builder().augmentation(FlowCapableNode.class).child(Table.class, tableKey).build();
74 * Creates a path for particular flow, by appending flow-specific
75 * information to table path.
77 * @param table the table path
78 * @param flowKey the floe key
79 * @return the flow InstanceIdentifier
81 public static InstanceIdentifier<Flow> createFlowPath(final InstanceIdentifier<Table> table,
82 final FlowKey flowKey) {
83 return table.child(Flow.class, flowKey);
87 * Extract table id from table path.
89 * @param tablePath the table path
90 * @return the table id
92 public static Short getTableId(final InstanceIdentifier<Table> tablePath) {
93 return tablePath.firstKeyOf(Table.class).getId();
97 * Extracts NodeConnectorKey from node connector path.
99 public static NodeConnectorKey getNodeConnectorKey(final InstanceIdentifier<?> nodeConnectorPath) {
100 return nodeConnectorPath.firstKeyOf(NodeConnector.class);
104 * Extracts NodeKey from node path.
106 public static NodeKey getNodeKey(final InstanceIdentifier<?> nodePath) {
107 return nodePath.firstKeyOf(Node.class);
110 public static InstanceIdentifier<NodeConnector> createNodeConnectorIdentifier(final String nodeIdValue,
111 final String nodeConnectorIdValue) {
112 return createNodePath(new NodeId(nodeIdValue)).child(NodeConnector.class,
113 new NodeConnectorKey(new NodeConnectorId(nodeConnectorIdValue)));
116 public static InstanceIdentifier<Node> generateNodeInstanceIdentifier(final NodeConnectorRef nodeConnectorRef) {
117 return nodeConnectorRef.getValue().firstIdentifierOf(Node.class);
120 public static InstanceIdentifier<Table> generateFlowTableInstanceIdentifier(final NodeConnectorRef nodeConnectorRef,
121 final TableKey flowTableKey) {
122 return generateNodeInstanceIdentifier(nodeConnectorRef).builder().augmentation(FlowCapableNode.class)
123 .child(Table.class, flowTableKey).build();
126 public static InstanceIdentifier<Flow> generateFlowInstanceIdentifier(final NodeConnectorRef nodeConnectorRef,
127 final TableKey flowTableKey, final FlowKey flowKey) {
128 return generateFlowTableInstanceIdentifier(nodeConnectorRef, flowTableKey).child(Flow.class, flowKey);
131 public static InstanceIdentifier<Topology> generateTopologyInstanceIdentifier(final String topologyId) {
132 return InstanceIdentifier.builder(NetworkTopology.class)
133 .child(Topology.class, new TopologyKey(new TopologyId(topologyId))).build();