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 class InstanceIdentifierUtils {
34 * Creates an Instance Identifier (path) for node with specified id
39 public static final InstanceIdentifier<Node> createNodePath(NodeId nodeId) {
40 return InstanceIdentifier.builder(Nodes.class) //
41 .child(Node.class, new NodeKey(nodeId)) //
46 * Shorten's node child path to node path.
48 * @param nodeChild child of node, from which we want node path.
51 public static final InstanceIdentifier<Node> getNodePath(InstanceIdentifier<?> nodeChild) {
52 return nodeChild.firstIdentifierOf(Node.class);
57 * Creates a table path by appending table specific location to node path
63 public static final InstanceIdentifier<Table> createTablePath(InstanceIdentifier<Node> nodePath, TableKey tableKey) {
64 return InstanceIdentifier.builder(nodePath)
65 .augmentation(FlowCapableNode.class)
66 .child(Table.class, tableKey)
71 * Creates a path for particular flow, by appending flow-specific information
78 public static InstanceIdentifier<Flow> createFlowPath(InstanceIdentifier<Table> table, FlowKey flowKey) {
79 return InstanceIdentifier.builder(table)
80 .child(Flow.class, flowKey)
85 * Extract table id from table path.
90 public static Short getTableId(InstanceIdentifier<Table> tablePath) {
91 return tablePath.firstKeyOf(Table.class, TableKey.class).getId();
95 * Extracts NodeConnectorKey from node connector path.
97 public static NodeConnectorKey getNodeConnectorKey(InstanceIdentifier<?> nodeConnectorPath) {
98 return nodeConnectorPath.firstKeyOf(NodeConnector.class, NodeConnectorKey.class);
102 * Extracts NodeKey from node path.
104 public static NodeKey getNodeKey(InstanceIdentifier<?> nodePath) {
105 return nodePath.firstKeyOf(Node.class, NodeKey.class);
110 public static final InstanceIdentifier<NodeConnector> createNodeConnectorIdentifier(String nodeIdValue,
111 String nodeConnectorIdValue) {
112 return InstanceIdentifier.builder(createNodePath(new NodeId(nodeIdValue))) //
113 .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId(nodeConnectorIdValue))) //
118 * @param nodeConnectorRef
121 public static InstanceIdentifier<Node> generateNodeInstanceIdentifier(NodeConnectorRef nodeConnectorRef) {
122 return nodeConnectorRef.getValue().firstIdentifierOf(Node.class);
126 * @param nodeConnectorRef
127 * @param flowTableKey
130 public static InstanceIdentifier<Table> generateFlowTableInstanceIdentifier(NodeConnectorRef nodeConnectorRef, TableKey flowTableKey) {
131 return InstanceIdentifier.builder(generateNodeInstanceIdentifier(nodeConnectorRef))
132 .augmentation(FlowCapableNode.class)
133 .child(Table.class, flowTableKey)
138 * @param nodeConnectorRef
139 * @param flowTableKey
143 public static InstanceIdentifier<Flow> generateFlowInstanceIdentifier(NodeConnectorRef nodeConnectorRef,
144 TableKey flowTableKey,
146 return InstanceIdentifier.builder(generateFlowTableInstanceIdentifier(nodeConnectorRef, flowTableKey))
147 .child(Flow.class, flowKey)
151 public static InstanceIdentifier<Topology> generateTopologyInstanceIdentifier(String topologyId) {
152 return InstanceIdentifier.builder(NetworkTopology.class)
153 .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))