1 package org.opendaylight.controller.md.compatibility.topology
3 import org.opendaylight.controller.switchmanager.ISwitchManager
4 import org.opendaylight.controller.topologymanager.ITopologyManager
5 import org.opendaylight.controller.md.sal.common.api.data.DataReader
6 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
7 import org.opendaylight.yangtools.yang.binding.DataObject
8 import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider
9 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
10 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node
11 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint
12 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
13 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology
15 import org.opendaylight.controller.md.compatibility.topology.TopologyMapping
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder
19 import java.util.ArrayList
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey
22 import org.opendaylight.controller.sal.core.NodeConnector
23 import org.opendaylight.controller.sal.topology.TopoEdgeUpdate
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder
26 import org.opendaylight.controller.sal.core.Edge
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder
30 class TopologyReader implements RuntimeDataProvider {
33 var ISwitchManager switchManager;
36 var ITopologyManager topologyManager;
39 val TopologyKey topologyKey;
42 val InstanceIdentifier<Topology> topologyPath;
45 val extension TopologyMapping mapping;
48 _topologyKey = new TopologyKey(new TopologyId("compatibility:ad-sal"));
49 _topologyPath = InstanceIdentifier.builder().node(NetworkTopology).child(Topology, topologyKey).toInstance;
50 _mapping = new TopologyMapping(topologyKey, topologyPath);
53 override readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
55 // Topology and Inventory are operational only
59 override readOperationalData(InstanceIdentifier<? extends DataObject> path) {
60 val type = path.targetType;
61 var DataObject data = null;
62 if (false == topologyPath.contains(path)) {
67 data = readTopology(path as InstanceIdentifier<Topology>)
69 data = readNode(path as InstanceIdentifier<Node>)
70 case TerminationPoint:
71 data = readTerminationPoint(path as InstanceIdentifier<TerminationPoint>)
73 data = readLink(path as InstanceIdentifier<Link>)
78 def DataObject readLink(InstanceIdentifier<Link> identifier) {
79 val edge = identifier.toAdTopologyEdge();
80 val properties = topologyManager?.edges?.get(edge);
82 return constructLink(edge);
85 def DataObject readTerminationPoint(InstanceIdentifier<TerminationPoint> identifier) {
86 val nodeConnector = identifier.toAdTopologyNodeConnector();
87 return constructTerminationPoint(nodeConnector)
90 def DataObject readNode(InstanceIdentifier<Node> identifier) {
91 val node = identifier.toAdTopologyNode();
92 return constructNode(node);
95 def DataObject readTopology(InstanceIdentifier<Topology> identifier) {
97 //val nodeConnectors = switchManager.
98 val nodes = switchManager.nodes
99 val edges = topologyManager.edges
101 val nodeList = new ArrayList<Node>(nodes.size)
103 nodeList.add(constructNode(node))
106 val linkList = new ArrayList<Link>(edges.size)
107 for (edge : edges.keySet) {
108 linkList.add(constructLink(edge))
111 val it = new TopologyBuilder();
118 def constructLink(Edge edge) {
119 val sourceNc = edge.tailNodeConnector
120 val destNc = edge.headNodeConnector
122 val it = new LinkBuilder()
123 key = edge.toTopologyLinkKey();
124 source = new SourceBuilder().setSourceNode(sourceNc.node.toTopologyNodeKey.nodeId).setSourceTp(
125 sourceNc.toTopologyTerminationPointKey.tpId).build()
126 destination = new DestinationBuilder().setDestNode(destNc.node.toTopologyNodeKey.nodeId).setDestTp(
127 destNc.toTopologyTerminationPointKey.tpId).build
131 def Node constructNode(org.opendaylight.controller.sal.core.Node node) {
132 val connectors = switchManager.getNodeConnectors(node)
134 val tpList = new ArrayList<TerminationPoint>(connectors.size)
135 for (connector : connectors) {
136 tpList.add(constructTerminationPoint(connector));
139 val it = new NodeBuilder()
140 key = node.toTopologyNodeKey();
141 terminationPoint = tpList
145 def TerminationPoint constructTerminationPoint(NodeConnector connector) {
146 val it = new TerminationPointBuilder()
147 key = connector.toTopologyTerminationPointKey