10ee47ab6369dd0ed01eb6c0cd2e539eae8fba8f
[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.node.NodeConnector;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
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(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(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(InstanceIdentifier<Node> nodePath,TableKey tableKey) {
54         return InstanceIdentifier.builder(nodePath)
55                 .augmentation(FlowCapableNode.class)
56                 .child(Table.class, tableKey)
57                 .build();
58     }
59
60     /**
61      * Creates a path for particular flow, by appending flow-specific information
62      * to table path.
63      * 
64      * @param tablePath
65      * @param flowKey
66      * @return path to flow
67      */
68     public static InstanceIdentifier<Flow> createFlowPath(InstanceIdentifier<Table> tablePath, FlowKey flowKey) {
69         return InstanceIdentifier.builder(tablePath)
70                 .child(Flow.class, flowKey)
71                 .build();
72     }
73
74     /**
75      * Extract table id from table path.
76      * 
77      * @param tablePath
78      * @return
79      */
80     public static Short getTableId(InstanceIdentifier<Table> tablePath) {
81         return tablePath.firstKeyOf(Table.class, TableKey.class).getId();
82     }
83     
84     /**
85      * Extracts NodeConnectorKey from node connector path.
86      * 
87      */
88     public static NodeConnectorKey getNodeConnectorKey(InstanceIdentifier<?> nodeConnectorPath) {
89         return nodeConnectorPath.firstKeyOf(NodeConnector.class, NodeConnectorKey.class);
90     }
91     
92     
93     //
94     public static final InstanceIdentifier<NodeConnector> createNodeConnectorPath(InstanceIdentifier<Node> nodeKey,NodeConnectorKey nodeConnectorKey) {
95         return InstanceIdentifier.builder(nodeKey)
96                 .child(NodeConnector.class,nodeConnectorKey)
97                 .build();
98     }
99 }