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.controller.sample.l2switch.md.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;
29 /* InstanceIdentifierUtils provides utility functions related to InstanceIdentifiers.
31 public final class InstanceIdentifierUtils {
33 private InstanceIdentifierUtils() {
34 throw new UnsupportedOperationException("Utility class should never be instantiated");
38 * Creates an Instance Identifier (path) for node with specified id
43 public static final InstanceIdentifier<Node> createNodePath(final NodeId nodeId) {
44 return InstanceIdentifier.builder(Nodes.class) //
45 .child(Node.class, new NodeKey(nodeId)) //
50 * Shorten's node child path to node path.
52 * @param nodeChild child of node, from which we want node path.
55 public static final InstanceIdentifier<Node> getNodePath(final InstanceIdentifier<?> nodeChild) {
56 return nodeChild.firstIdentifierOf(Node.class);
61 * Creates a table path by appending table specific location to node path
67 public static final InstanceIdentifier<Table> createTablePath(final InstanceIdentifier<Node> nodePath, final TableKey tableKey) {
68 return nodePath.builder()
69 .augmentation(FlowCapableNode.class)
70 .child(Table.class, tableKey)
75 * Creates a path for particular flow, by appending flow-specific information
82 public static InstanceIdentifier<Flow> createFlowPath(final InstanceIdentifier<Table> table, final FlowKey flowKey) {
83 return table.child(Flow.class, flowKey);
87 * Extract table id from table path.
92 public static Short getTableId(final InstanceIdentifier<Table> tablePath) {
93 return tablePath.firstKeyOf(Table.class, TableKey.class).getId();
97 * Extracts NodeConnectorKey from node connector path.
99 public static NodeConnectorKey getNodeConnectorKey(final InstanceIdentifier<?> nodeConnectorPath) {
100 return nodeConnectorPath.firstKeyOf(NodeConnector.class, NodeConnectorKey.class);
104 * Extracts NodeKey from node path.
106 public static NodeKey getNodeKey(final InstanceIdentifier<?> nodePath) {
107 return nodePath.firstKeyOf(Node.class, NodeKey.class);
112 public static final InstanceIdentifier<NodeConnector> createNodeConnectorIdentifier(final String nodeIdValue,
113 final String nodeConnectorIdValue) {
114 return createNodePath(new NodeId(nodeIdValue))
115 .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId(nodeConnectorIdValue)));
119 * @param nodeConnectorRef
122 public static InstanceIdentifier<Node> generateNodeInstanceIdentifier(final NodeConnectorRef nodeConnectorRef) {
123 return nodeConnectorRef.getValue().firstIdentifierOf(Node.class);
127 * @param nodeConnectorRef
128 * @param flowTableKey
131 public static InstanceIdentifier<Table> generateFlowTableInstanceIdentifier(final NodeConnectorRef nodeConnectorRef, final TableKey flowTableKey) {
132 return generateNodeInstanceIdentifier(nodeConnectorRef).builder()
133 .augmentation(FlowCapableNode.class)
134 .child(Table.class, flowTableKey)
139 * @param nodeConnectorRef
140 * @param flowTableKey
144 public static InstanceIdentifier<Flow> generateFlowInstanceIdentifier(final NodeConnectorRef nodeConnectorRef,
145 final TableKey flowTableKey,
146 final FlowKey flowKey) {
147 return generateFlowTableInstanceIdentifier(nodeConnectorRef, flowTableKey).child(Flow.class, flowKey);
150 public static InstanceIdentifier<Topology> generateTopologyInstanceIdentifier(final String topologyId) {
151 return InstanceIdentifier.builder(NetworkTopology.class)
152 .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))