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.Edge;
17 import org.opendaylight.controller.sal.core.Host;
18 import org.opendaylight.controller.sal.core.NodeConnector;
19 import org.opendaylight.controller.sal.core.Property;
20 import org.opendaylight.controller.sal.core.UpdateType;
21 import org.opendaylight.controller.sal.utils.Status;
22 import org.opendaylight.controller.topologymanager.ITopologyManager;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import com.google.common.base.Predicate;
32 import com.google.common.collect.FluentIterable;
34 @SuppressWarnings("all")
35 public class CompatibleTopologyManager extends ConfigurableLinkManager implements ITopologyManager {
36 private AdSalTopologyMapping topologyMapping;
37 private TypeSafeDataReader dataReader;
39 public TypeSafeDataReader getDataReader() {
43 public void setDataReader(final TypeSafeDataReader dataReader) {
44 this.dataReader = dataReader;
47 public AdSalTopologyMapping getTopologyMapping() {
48 return topologyMapping;
51 public void setTopologyMapping(final AdSalTopologyMapping topologyMapping) {
52 this.topologyMapping = topologyMapping;
56 public Map<Edge,Set<Property>> getEdges() {
57 final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
58 return this.topologyMapping.toEdgePropertiesMap(topology.getLink());
62 public Map<org.opendaylight.controller.sal.core.Node, Set<Edge>> getNodeEdges() {
63 final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
64 final HashMap<org.opendaylight.controller.sal.core.Node, Set<Edge>> ret = new HashMap<>();
65 for (final Node node : topology.getNode()) {
66 final org.opendaylight.controller.sal.core.Node adNode = topologyMapping.toAdNode(node);
67 ret.put(adNode, topologyMapping.toEdges(
68 FluentIterable.from(topology.getLink()).filter(new Predicate<Link>() {
70 public boolean apply(final Link input) {
71 final NodeId nodeId = node.getNodeId();
72 if (nodeId.equals(input.getSource().getSourceNode())) {
75 if (nodeId.equals(input.getDestination().getDestNode())) {
87 * Returns true if point is connected to link
89 public boolean isInternal(final TerminationPoint point) {
90 final Topology topology = getDataReader().readConfigurationData(topologyMapping.getTopologyPath());
91 final TpId tpId = point.getKey().getTpId();
92 return FluentIterable.from(topology.getLink()).anyMatch(new Predicate<Link>() {
94 public boolean apply(final Link input) {
95 if (tpId.equals(input.getSource().getSourceTp())) {
98 if (tpId.equals(input.getDestination().getDestTp())) {
107 public Set<NodeConnector> getNodeConnectorWithHost() {
112 public Host getHostAttachedToNodeConnector(final NodeConnector p) {
113 final InstanceIdentifier<TerminationPoint> tpPath = topologyMapping.toTerminationPoint(p);
114 throw new UnsupportedOperationException("TODO: auto-generated method stub");
118 public List<Host> getHostsAttachedToNodeConnector(final NodeConnector p) {
119 final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
120 throw new UnsupportedOperationException("Hosts not mapped yet");
124 public Map<org.opendaylight.controller.sal.core.Node, Set<NodeConnector>> getNodesWithNodeConnectorHost() {
125 throw new UnsupportedOperationException("TODO: auto-generated method stub");
129 public boolean isInternal(final NodeConnector p) {
130 final TerminationPoint connector = getDataReader()
131 .readConfigurationData(topologyMapping.toTerminationPoint(p));
132 return this.isInternal(connector);
136 public void updateHostLink(final NodeConnector p, final Host h, final UpdateType t, final Set<Property> props) {
137 // Update app defined topology
141 public Status saveConfig() {
142 // FIXME: commit configuration