tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.trivial.impl; |
| 2 | |
| 3 | import com.google.common.collect.ImmutableSet; |
| 4 | import com.google.common.collect.Multimap; |
| 5 | import org.onlab.graph.Graph; |
| 6 | import org.onlab.graph.GraphPathSearch; |
| 7 | import org.onlab.onos.net.DeviceId; |
| 8 | import org.onlab.onos.net.Link; |
| 9 | import org.onlab.onos.net.topology.ClusterId; |
| 10 | import org.onlab.onos.net.topology.TopoEdge; |
| 11 | import org.onlab.onos.net.topology.TopoVertex; |
| 12 | import org.onlab.onos.net.topology.TopologyCluster; |
| 13 | import org.onlab.onos.net.topology.TopologyDescription; |
| 14 | |
| 15 | import java.util.Map; |
| 16 | import java.util.Set; |
| 17 | |
| 18 | /** |
| 19 | * Default implementation of an immutable topology data carrier. |
| 20 | */ |
| 21 | public class DefaultTopologyDescription implements TopologyDescription { |
| 22 | |
| 23 | private final long nanos; |
| 24 | private final Graph<TopoVertex, TopoEdge> graph; |
| 25 | private final Map<DeviceId, GraphPathSearch.Result<TopoVertex, TopoEdge>> results; |
| 26 | private final Map<ClusterId, TopologyCluster> clusters; |
| 27 | private final Multimap<ClusterId, DeviceId> clusterDevices; |
| 28 | private final Multimap<ClusterId, Link> clusterLinks; |
| 29 | private final Map<DeviceId, TopologyCluster> deviceClusters; |
| 30 | |
| 31 | public DefaultTopologyDescription(long nanos, Graph<TopoVertex, TopoEdge> graph, |
| 32 | Map<DeviceId, GraphPathSearch.Result<TopoVertex, TopoEdge>> results, |
| 33 | Map<ClusterId, TopologyCluster> clusters, |
| 34 | Multimap<ClusterId, DeviceId> clusterDevices, |
| 35 | Multimap<ClusterId, Link> clusterLinks, |
| 36 | Map<DeviceId, TopologyCluster> deviceClusters) { |
| 37 | this.nanos = nanos; |
| 38 | this.graph = graph; |
| 39 | this.results = results; |
| 40 | this.clusters = clusters; |
| 41 | this.clusterDevices = clusterDevices; |
| 42 | this.clusterLinks = clusterLinks; |
| 43 | this.deviceClusters = deviceClusters; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public long timestamp() { |
| 48 | return nanos; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public Graph<TopoVertex, TopoEdge> graph() { |
| 53 | return graph; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public GraphPathSearch.Result<TopoVertex, TopoEdge> pathResults(DeviceId srcDeviceId) { |
| 58 | return results.get(srcDeviceId); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public Set<TopologyCluster> clusters() { |
| 63 | return ImmutableSet.copyOf(clusters.values()); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public Set<DeviceId> clusterDevices(TopologyCluster cluster) { |
| 68 | return null; // clusterDevices.get(cluster.id()); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public Set<Link> clusterLinks(TopologyCluster cluster) { |
| 73 | return null; // clusterLinks.get(cluster.id()); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public TopologyCluster clusterFor(DeviceId deviceId) { |
| 78 | return deviceClusters.get(deviceId); |
| 79 | } |
| 80 | } |