Do not use InstanceIdentifier.builder()
[openflowplugin.git] / samples / learning-switch / src / main / java / org / opendaylight / openflowplugin / learningswitch / InstanceIdentifierUtils.java
1 package org.opendaylight.openflowplugin.learningswitch;
2
3 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
4 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
5 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
14 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
15
16
17 public class InstanceIdentifierUtils {
18
19     private InstanceIdentifierUtils() {
20         //hiding constructor for util class
21     }
22
23     /**
24      * Creates an Instance Identifier (path) for node with specified id
25      *
26      * @param nodeId
27      * @return
28      */
29     public static final InstanceIdentifier<Node> createNodePath(final NodeId nodeId) {
30         return InstanceIdentifier.builder(Nodes.class)
31                 .child(Node.class, new NodeKey(nodeId))
32                 .build();
33     }
34
35     /**
36      * Shorten's node child path to node path.
37      *
38      * @param nodeChild child of node, from which we want node path.
39      * @return
40      */
41     public static final InstanceIdentifier<Node> getNodePath(final InstanceIdentifier<?> nodeChild) {
42         return nodeChild.firstIdentifierOf(Node.class);
43     }
44
45
46     /**
47      * Creates a table path by appending table specific location to node path
48      *
49      * @param nodePath
50      * @param tableKey
51      * @return
52      */
53     public static final InstanceIdentifier<Table> createTablePath(final InstanceIdentifier<Node> nodePath,final TableKey tableKey) {
54         return nodePath.augmentation(FlowCapableNode.class).child(Table.class, tableKey);
55     }
56
57     /**
58      * Creates a path for particular flow, by appending flow-specific information
59      * to table path.
60      *
61      * @param tablePath
62      * @param flowKey
63      * @return path to flow
64      */
65     public static InstanceIdentifier<Flow> createFlowPath(final InstanceIdentifier<Table> tablePath, final FlowKey flowKey) {
66         return tablePath.child(Flow.class, flowKey);
67     }
68
69     /**
70      * Extract table id from table path.
71      *
72      * @param tablePath
73      * @return
74      */
75     public static Short getTableId(final InstanceIdentifier<Table> tablePath) {
76         return tablePath.firstKeyOf(Table.class, TableKey.class).getId();
77     }
78
79     /**
80      * Extracts NodeConnectorKey from node connector path.
81      *
82      */
83     public static NodeConnectorKey getNodeConnectorKey(final InstanceIdentifier<?> nodeConnectorPath) {
84         return nodeConnectorPath.firstKeyOf(NodeConnector.class, NodeConnectorKey.class);
85     }
86
87
88     //
89     public static final InstanceIdentifier<NodeConnector> createNodeConnectorPath(final InstanceIdentifier<Node> nodeKey,final NodeConnectorKey nodeConnectorKey) {
90         return nodeKey.child(NodeConnector.class,nodeConnectorKey);
91     }
92 }