Added Inventory Reader for SwitchManager
[controller.git] / opendaylight / md-sal / compatibility / inventory-topology-compatibility / src / main / java / org / opendaylight / controller / md / compatibility / topology / TopologyMapping.xtend
1 package org.opendaylight.controller.md.compatibility.topology
2
3 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
4 import org.opendaylight.yangtools.yang.binding.DataObject
5 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.network.topology.TopologyKey
6 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.network.topology.Topology
7 import org.opendaylight.controller.sal.core.Edge
8 import java.util.Set
9 import org.opendaylight.controller.sal.core.Property
10 import org.opendaylight.controller.sal.core.NodeConnector
11
12 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.network.topology.topology.node.TerminationPoint
13 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.network.topology.topology.Link
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.network.topology.topology.node.TerminationPointKey
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.TpId
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.network.topology.topology.NodeKey
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.NodeId
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.network.topology.topology.LinkKey
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.LinkId
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.network.topology.topology.Node
22 import org.opendaylight.controller.sal.compatibility.InventoryMapping
23 class TopologyMapping {
24
25     new(TopologyKey path, InstanceIdentifier<Topology> key) {
26         // NOOP
27     }
28
29     def Edge toAdTopologyEdge(InstanceIdentifier<Link> identifier) {
30         val linkKey = (identifier.path.last as IdentifiableItem<Link,LinkKey>).key;
31         val components = linkKey.linkId.value.split("::::");
32         val tail = InventoryMapping.nodeConnectorFromId(components.get(0));
33         val head = InventoryMapping.nodeConnectorFromId(components.get(1));
34         return new Edge(tail, head);
35     }
36
37     def NodeConnector toAdTopologyNodeConnector(InstanceIdentifier<TerminationPoint> identifier) {
38         val tpKey = (identifier.path.last as IdentifiableItem<TerminationPoint,TerminationPointKey>).key;
39         return InventoryMapping.nodeConnectorFromId(tpKey.tpId.value);
40     }
41
42     def org.opendaylight.controller.sal.core.Node toAdTopologyNode(
43         InstanceIdentifier<Node> identifier) {
44         val tpKey = (identifier.path.last as IdentifiableItem<Node,NodeKey>).key;
45         return InventoryMapping.nodeFromNodeId(tpKey.nodeId.value);
46     }
47     
48
49
50     def NodeKey toTopologyNodeKey(org.opendaylight.controller.sal.core.Node node) {
51         val nodeId = new NodeId(InventoryMapping.toNodeId(node));
52         return new NodeKey(nodeId);
53     }
54
55     def TerminationPointKey toTopologyTerminationPointKey(NodeConnector nc) {
56         val node = nc.node;
57         val nodeId = new TpId(InventoryMapping.toNodeConnectorId(nc))
58         return new TerminationPointKey(nodeId);
59     }
60
61     def LinkKey toTopologyLinkKey(Edge edge) {
62         val sourceTp = edge.tailNodeConnector.toTopologyTerminationPointKey;
63         val destTp = edge.headNodeConnector.toTopologyTerminationPointKey;
64         val linkId = new LinkId('''«sourceTp.tpId»::::«destTp.tpId»''')
65         return new LinkKey(linkId);
66     }
67 }

©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.