Added Inventory Reader for SwitchManager
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / InventoryMapping.xtend
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.compatibility
9
10 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef
20
21 class InventoryMapping {
22
23     static def org.opendaylight.controller.sal.core.NodeConnector toAdNodeConnector(
24         InstanceIdentifier<NodeConnector> identifier) {
25         val tpKey = (identifier.path.last as IdentifiableItem<NodeConnector,NodeConnectorKey>).key;
26         return nodeConnectorFromId(tpKey.id.value);
27     }
28
29     static def org.opendaylight.controller.sal.core.Node toAdNode(InstanceIdentifier<Node> identifier) {
30         val tpKey = (identifier.path.last as IdentifiableItem<Node,NodeKey>).key;
31         return nodeFromNodeId(tpKey.id.value);
32     }
33     
34     
35      static def NodeRef toNodeRef(org.opendaylight.controller.sal.core.Node node) {
36         val nodeId = new NodeKey(new NodeId(node.toNodeId))
37         val path = InstanceIdentifier.builder().node(Nodes).child(Node,nodeId).toInstance;
38         return new NodeRef(path);
39     }
40
41     static def NodeKey toNodeKey(org.opendaylight.controller.sal.core.Node node) {
42         val nodeId = new NodeId(node.toNodeId)
43         return new NodeKey(nodeId);
44     }
45
46     static def NodeConnectorKey toNodeConnectorKey(org.opendaylight.controller.sal.core.NodeConnector nc) {
47         val nodeId = new NodeConnectorId(nc.toNodeConnectorId)
48         return new NodeConnectorKey(nodeId);
49     }
50
51     static def String toNodeId(org.opendaylight.controller.sal.core.Node node) {
52         '''ad-sal:«node.type»::«node.nodeIDString»'''
53     }
54
55     static def String toNodeConnectorId(org.opendaylight.controller.sal.core.NodeConnector nc) {
56         '''«nc.node.toNodeId»::«nc.nodeConnectorIDString»'''
57     }
58
59     static def org.opendaylight.controller.sal.core.Node nodeFromNodeId(String nodeId) {
60         return nodeFromString(nodeId.split("::"))
61     }
62
63     static def nodeConnectorFromId(String invId) {
64         return nodeConnectorFromString(invId.split("::"));
65     }
66
67     private static def org.opendaylight.controller.sal.core.NodeConnector nodeConnectorFromString(String[] string) {
68         val node = nodeFromString(string.subList(0, 1));
69         return org.opendaylight.controller.sal.core.NodeConnector.fromStringNoNode(string.get(2), node);
70     }
71
72     private static def org.opendaylight.controller.sal.core.Node nodeFromString(String[] strings) {
73         val type = strings.get(0).substring(6);
74         org.opendaylight.controller.sal.core.Node.fromString(type, strings.get(1))
75     }
76
77 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.