184c06eb70f37613a67a0b96953aed81e8c096f4
[controller.git] / opendaylight / md-sal / compatibility / inventory-topology-compatibility / src / main / java / org / opendaylight / controller / md / compatibility / topologymanager / CompatibleTopologyManager.java
1 /**
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.compatibility.topologymanager;
9
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13 import java.util.Set;
14
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;
30
31 import com.google.common.base.Predicate;
32 import com.google.common.collect.FluentIterable;
33
34 @SuppressWarnings("all")
35 public class CompatibleTopologyManager extends ConfigurableLinkManager implements ITopologyManager {
36     private AdSalTopologyMapping topologyMapping;
37     private TypeSafeDataReader dataReader;
38
39     public TypeSafeDataReader getDataReader() {
40         return dataReader;
41     }
42
43     public void setDataReader(final TypeSafeDataReader dataReader) {
44         this.dataReader = dataReader;
45     }
46
47     public AdSalTopologyMapping getTopologyMapping() {
48         return topologyMapping;
49     }
50
51     public void setTopologyMapping(final AdSalTopologyMapping topologyMapping) {
52         this.topologyMapping = topologyMapping;
53     }
54
55     @Override
56     public Map<Edge,Set<Property>> getEdges() {
57         final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
58         return this.topologyMapping.toEdgePropertiesMap(topology.getLink());
59     }
60
61     @Override
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>() {
69                         @Override
70                         public boolean apply(final Link input) {
71                             final NodeId nodeId = node.getNodeId();
72                             if (nodeId.equals(input.getSource().getSourceNode())) {
73                                 return true;
74                             }
75                             if (nodeId.equals(input.getDestination().getDestNode())) {
76                                 return true;
77                             }
78
79                             return false;
80                         }
81                     })));
82         }
83         return ret;
84     }
85
86     /**
87      * Returns true if point is connected to link
88      */
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>() {
93             @Override
94             public boolean apply(final Link input) {
95                 if (tpId.equals(input.getSource().getSourceTp())) {
96                     return true;
97                 }
98                 if (tpId.equals(input.getDestination().getDestTp())) {
99                     return true;
100                 }
101                 return false;
102             }
103         });
104     }
105
106     @Override
107     public Set<NodeConnector> getNodeConnectorWithHost() {
108         return null;
109     }
110
111     @Override
112     public Host getHostAttachedToNodeConnector(final NodeConnector p) {
113         final InstanceIdentifier<TerminationPoint> tpPath = topologyMapping.toTerminationPoint(p);
114         throw new UnsupportedOperationException("TODO: auto-generated method stub");
115     }
116
117     @Override
118     public List<Host> getHostsAttachedToNodeConnector(final NodeConnector p) {
119         final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
120         throw new UnsupportedOperationException("Hosts not mapped yet");
121     }
122
123     @Override
124     public Map<org.opendaylight.controller.sal.core.Node, Set<NodeConnector>> getNodesWithNodeConnectorHost() {
125         throw new UnsupportedOperationException("TODO: auto-generated method stub");
126     }
127
128     @Override
129     public boolean isInternal(final NodeConnector p) {
130         final TerminationPoint connector = getDataReader()
131                 .readConfigurationData(topologyMapping.toTerminationPoint(p));
132         return this.isInternal(connector);
133     }
134
135     @Override
136     public void updateHostLink(final NodeConnector p, final Host h, final UpdateType t, final Set<Property> props) {
137         // Update app defined topology
138     }
139
140     @Override
141     public Status saveConfig() {
142         // FIXME: commit configuration
143         return null;
144     }
145 }

©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.