Merge "Added configuration modules and closeable wrappers for FixedThreadPool, Flexib...
[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
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 = nodeConnectorFromString(components.get(0).split("::"));
33         val head = nodeConnectorFromString(components.get(1).split("::"));
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 nodeConnectorFromString(tpKey.tpId.value.split("::"));
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 nodeFromString(tpKey.nodeId.value.split("::"));
46     }
47     
48
49
50     def NodeKey toTopologyNodeKey(org.opendaylight.controller.sal.core.Node node) {
51         val nodeId = new NodeId('''ad-sal:«node.type»::«node.nodeIDString»''')
52         return new NodeKey(nodeId);
53     }
54
55     def TerminationPointKey toTopologyTerminationPointKey(NodeConnector nc) {
56         val node = nc.node;
57         val nodeId = new TpId('''ad-sal:«node.type»::«node.nodeIDString»::«nc.nodeConnectorIDString»''')
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
68     def NodeConnector nodeConnectorFromString(String[] string) {
69         val node = nodeFromString(string.subList(0,1));
70         return NodeConnector.fromStringNoNode(string.get(2),node);
71     }
72     
73     def org.opendaylight.controller.sal.core.Node nodeFromString(String[] strings) {
74         val type = strings.get(0).substring(6);
75         org.opendaylight.controller.sal.core.Node.fromString(type,strings.get(1))
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.