2 * Copyright (c) 2014, 2015 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.openflowplugin.learningswitch;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 public final class InstanceIdentifierUtils {
26 private InstanceIdentifierUtils() {
27 //hiding constructor for util class
31 * Creates an Instance Identifier (path) for node with specified id.
33 * @param nodeId the NodeId
35 public static InstanceIdentifier<Node> createNodePath(final NodeId nodeId) {
36 return InstanceIdentifier.builder(Nodes.class)
37 .child(Node.class, new NodeKey(nodeId))
42 * Shorten's node child path to node path.
44 * @param nodeChild child of node, from which we want node path.
46 public static InstanceIdentifier<Node> getNodePath(final InstanceIdentifier<?> nodeChild) {
47 return nodeChild.firstIdentifierOf(Node.class);
51 * Creates a table path by appending table specific location to node path.
53 * @param nodePath the node path
54 * @param tableKey the table yey
56 public static InstanceIdentifier<Table> createTablePath(final InstanceIdentifier<Node> nodePath,
57 final TableKey tableKey) {
58 return nodePath.augmentation(FlowCapableNode.class).child(Table.class, tableKey);
62 * Creates a path for particular flow, by appending flow-specific information
65 * @param tablePath the table path
66 * @param flowKey the flow key
67 * @return path to flow
69 public static InstanceIdentifier<Flow> createFlowPath(final InstanceIdentifier<Table> tablePath,
70 final FlowKey flowKey) {
71 return tablePath.child(Flow.class, flowKey);
75 * Extract table id from table path.
77 * @param tablePath the table path
79 public static Short getTableId(final InstanceIdentifier<Table> tablePath) {
80 return tablePath.firstKeyOf(Table.class).getId();
84 * Extracts NodeConnectorKey from node connector path.
86 public static NodeConnectorKey getNodeConnectorKey(final InstanceIdentifier<?> nodeConnectorPath) {
87 return nodeConnectorPath.firstKeyOf(NodeConnector.class);
90 public static InstanceIdentifier<NodeConnector> createNodeConnectorPath(final InstanceIdentifier<Node> nodeKey,
91 final NodeConnectorKey nodeConnectorKey) {
92 return nodeKey.child(NodeConnector.class,nodeConnectorKey);