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.topologymanager;
10 import java.util.HashMap;
11 import java.util.List;
15 import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader;
16 import org.opendaylight.controller.sal.core.ConstructionException;
17 import org.opendaylight.controller.sal.core.Edge;
18 import org.opendaylight.controller.sal.core.Host;
19 import org.opendaylight.controller.sal.core.NodeConnector;
20 import org.opendaylight.controller.sal.core.Property;
21 import org.opendaylight.controller.sal.core.UpdateType;
22 import org.opendaylight.controller.sal.utils.Status;
23 import org.opendaylight.controller.topologymanager.ITopologyManager;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import com.google.common.base.Predicate;
33 import com.google.common.collect.FluentIterable;
35 @SuppressWarnings("all")
36 public class CompatibleTopologyManager extends ConfigurableLinkManager implements ITopologyManager {
37 private AdSalTopologyMapping topologyMapping;
38 private TypeSafeDataReader dataReader;
40 public TypeSafeDataReader getDataReader() {
44 public void setDataReader(final TypeSafeDataReader dataReader) {
45 this.dataReader = dataReader;
48 public AdSalTopologyMapping getTopologyMapping() {
49 return topologyMapping;
52 public void setTopologyMapping(final AdSalTopologyMapping topologyMapping) {
53 this.topologyMapping = topologyMapping;
57 public Map<Edge,Set<Property>> getEdges() {
58 final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
59 return this.topologyMapping.toEdgePropertiesMap(topology.getLink());
63 public Map<org.opendaylight.controller.sal.core.Node, Set<Edge>> getNodeEdges() {
64 final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
65 final HashMap<org.opendaylight.controller.sal.core.Node, Set<Edge>> ret = new HashMap<>();
66 for (final Node node : topology.getNode()) {
68 ret.put(topologyMapping.toAdNode(node), topologyMapping.toEdges(
69 FluentIterable.from(topology.getLink()).filter(new Predicate<Link>() {
71 public boolean apply(final Link input) {
72 final NodeId nodeId = node.getNodeId();
73 if (nodeId.equals(input.getSource().getSourceNode())) {
76 if (nodeId.equals(input.getDestination().getDestNode())) {
83 } catch (ConstructionException e) {
84 throw new IllegalStateException(String.format("Failed to construct node for {}", node), e);
91 * Returns true if point is connected to link
93 private boolean isInternal(final TerminationPoint point) {
94 final Topology topology = getDataReader().readConfigurationData(topologyMapping.getTopologyPath());
95 final TpId tpId = point.getKey().getTpId();
96 return FluentIterable.from(topology.getLink()).anyMatch(new Predicate<Link>() {
98 public boolean apply(final Link input) {
99 if (tpId.equals(input.getSource().getSourceTp())) {
102 if (tpId.equals(input.getDestination().getDestTp())) {
111 public Set<NodeConnector> getNodeConnectorWithHost() {
116 public Host getHostAttachedToNodeConnector(final NodeConnector p) {
117 final InstanceIdentifier<TerminationPoint> tpPath = topologyMapping.toTerminationPoint(p);
118 throw new UnsupportedOperationException("TODO: auto-generated method stub");
122 public List<Host> getHostsAttachedToNodeConnector(final NodeConnector p) {
123 final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
124 throw new UnsupportedOperationException("Hosts not mapped yet");
128 public Map<org.opendaylight.controller.sal.core.Node, Set<NodeConnector>> getNodesWithNodeConnectorHost() {
129 throw new UnsupportedOperationException("TODO: auto-generated method stub");
133 public boolean isInternal(final NodeConnector p) {
134 final TerminationPoint connector = getDataReader()
135 .readConfigurationData(topologyMapping.toTerminationPoint(p));
136 return this.isInternal(connector);
140 public void updateHostLink(final NodeConnector p, final Host h, final UpdateType t, final Set<Property> props) {
141 // Update app defined topology
145 public Status saveConfig() {
146 // FIXME: commit configuration