2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.compatibility.topology
10 import org.opendaylight.controller.switchmanager.ISwitchManager
11 import org.opendaylight.controller.topologymanager.ITopologyManager
12 import org.opendaylight.controller.md.sal.common.api.data.DataReader
13 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
14 import org.opendaylight.yangtools.yang.binding.DataObject
15 import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology
22 import org.opendaylight.controller.md.compatibility.topology.TopologyMapping
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder
26 import java.util.ArrayList
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey
29 import org.opendaylight.controller.sal.core.NodeConnector
30 import org.opendaylight.controller.sal.topology.TopoEdgeUpdate
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId
32 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder
33 import org.opendaylight.controller.sal.core.Edge
34 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder
35 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder
37 class TopologyReader implements RuntimeDataProvider {
40 var ISwitchManager switchManager;
43 var ITopologyManager topologyManager;
46 val TopologyKey topologyKey;
49 val InstanceIdentifier<Topology> topologyPath;
52 val extension TopologyMapping mapping;
55 _topologyKey = new TopologyKey(new TopologyId("compatibility:ad-sal"));
56 _topologyPath = InstanceIdentifier.builder().node(NetworkTopology).child(Topology, topologyKey).toInstance;
57 _mapping = new TopologyMapping(topologyKey, topologyPath);
60 override readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
62 // Topology and Inventory are operational only
66 override readOperationalData(InstanceIdentifier<? extends DataObject> path) {
67 val type = path.targetType;
68 var DataObject data = null;
69 if (false == topologyPath.contains(path)) {
74 data = readTopology(path as InstanceIdentifier<Topology>)
76 data = readNode(path as InstanceIdentifier<Node>)
77 case TerminationPoint:
78 data = readTerminationPoint(path as InstanceIdentifier<TerminationPoint>)
80 data = readLink(path as InstanceIdentifier<Link>)
85 def DataObject readLink(InstanceIdentifier<Link> identifier) {
86 val edge = identifier.toAdTopologyEdge();
87 val properties = topologyManager?.edges?.get(edge);
89 return constructLink(edge);
92 def DataObject readTerminationPoint(InstanceIdentifier<TerminationPoint> identifier) {
93 val nodeConnector = identifier.toAdTopologyNodeConnector();
94 return constructTerminationPoint(nodeConnector)
97 def DataObject readNode(InstanceIdentifier<Node> identifier) {
98 val node = identifier.toAdTopologyNode();
99 return constructNode(node);
102 def DataObject readTopology(InstanceIdentifier<Topology> identifier) {
104 //val nodeConnectors = switchManager.
105 val nodes = switchManager.nodes
106 val edges = topologyManager.edges
108 val nodeList = new ArrayList<Node>(nodes.size)
110 nodeList.add(constructNode(node))
113 val linkList = new ArrayList<Link>(edges.size)
114 for (edge : edges.keySet) {
115 linkList.add(constructLink(edge))
118 val it = new TopologyBuilder();
125 def constructLink(Edge edge) {
126 val sourceNc = edge.tailNodeConnector
127 val destNc = edge.headNodeConnector
129 val it = new LinkBuilder()
130 key = edge.toTopologyLinkKey();
131 source = new SourceBuilder().setSourceNode(sourceNc.node.toTopologyNodeKey.nodeId).setSourceTp(
132 sourceNc.toTopologyTerminationPointKey.tpId).build()
133 destination = new DestinationBuilder().setDestNode(destNc.node.toTopologyNodeKey.nodeId).setDestTp(
134 destNc.toTopologyTerminationPointKey.tpId).build
138 def Node constructNode(org.opendaylight.controller.sal.core.Node node) {
139 val connectors = switchManager.getNodeConnectors(node)
141 val tpList = new ArrayList<TerminationPoint>(connectors.size)
142 for (connector : connectors) {
143 tpList.add(constructTerminationPoint(connector));
146 val it = new NodeBuilder()
147 key = node.toTopologyNodeKey();
148 terminationPoint = tpList
152 def TerminationPoint constructTerminationPoint(NodeConnector connector) {
153 val it = new TerminationPointBuilder()
154 key = connector.toTopologyTerminationPointKey