blob: 3417ca1bef0ace32818b900d8daffe757ceb1795 [file] [log] [blame]
tom8bf2e6b2014-09-10 20:53:54 -07001package org.onlab.onos.net.trivial.topology.impl;
tomdc361b62014-09-09 20:36:52 -07002
tome52ce702014-09-11 00:12:54 -07003import com.google.common.collect.ImmutableMap;
4import com.google.common.collect.ImmutableSet;
5import com.google.common.collect.ImmutableSetMultimap;
6import org.onlab.graph.Graph;
7import org.onlab.graph.GraphPathSearch;
tomdc361b62014-09-09 20:36:52 -07008import org.onlab.onos.net.AbstractModel;
tome52ce702014-09-11 00:12:54 -07009import org.onlab.onos.net.ConnectPoint;
10import org.onlab.onos.net.DeviceId;
11import org.onlab.onos.net.Link;
12import org.onlab.onos.net.Path;
tomdc361b62014-09-09 20:36:52 -070013import org.onlab.onos.net.provider.ProviderId;
tome52ce702014-09-11 00:12:54 -070014import org.onlab.onos.net.topology.TopoEdge;
15import org.onlab.onos.net.topology.TopoVertex;
tomdc361b62014-09-09 20:36:52 -070016import org.onlab.onos.net.topology.Topology;
tome52ce702014-09-11 00:12:54 -070017import org.onlab.onos.net.topology.TopologyCluster;
18import org.onlab.onos.net.topology.TopologyDescription;
19
20import java.util.Set;
tomdc361b62014-09-09 20:36:52 -070021
22/**
23 * Default implementation of the topology descriptor. This carries the
24 * backing topology data.
25 */
26public class DefaultTopology extends AbstractModel implements Topology {
27
28 private final long time;
tomdc361b62014-09-09 20:36:52 -070029 private final int pathCount;
30
tome52ce702014-09-11 00:12:54 -070031 private final Graph<TopoVertex, TopoEdge> graph;
32 private final ImmutableMap<DeviceId, GraphPathSearch.Result<TopoVertex, TopoEdge>> results;
33
34 private final ImmutableSet<TopologyCluster> clusters;
35 private final ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster;
36 private final ImmutableSetMultimap<TopologyCluster, Link> linksByCluster;
37 private final ImmutableSet connectPoints;
38
tomdc361b62014-09-09 20:36:52 -070039 /**
40 * Creates a topology descriptor attributed to the specified provider.
41 *
tome52ce702014-09-11 00:12:54 -070042 * @param providerId identity of the provider
43 * @param description data describing the new topology
tomdc361b62014-09-09 20:36:52 -070044 */
tome52ce702014-09-11 00:12:54 -070045 DefaultTopology(ProviderId providerId, TopologyDescription description) {
tomdc361b62014-09-09 20:36:52 -070046 super(providerId);
tome52ce702014-09-11 00:12:54 -070047 this.time = description.timestamp();
48 this.graph = description.graph();
49 this.results = description.pathsBySource();
50 this.clusters = description.clusters();
51 this.devicesByCluster = description.devicesByCluster();
52 this.linksByCluster = description.linksByCluster();
53
54 this.connectPoints = ImmutableSet.of();
55 this.pathCount = 0;
tomdc361b62014-09-09 20:36:52 -070056 }
57
58 @Override
59 public long time() {
60 return time;
61 }
62
63 @Override
64 public int clusterCount() {
tome52ce702014-09-11 00:12:54 -070065 return clusters.size();
tomdc361b62014-09-09 20:36:52 -070066 }
67
68 @Override
69 public int deviceCount() {
tome52ce702014-09-11 00:12:54 -070070 return graph.getVertexes().size();
tomdc361b62014-09-09 20:36:52 -070071 }
72
73 @Override
74 public int linkCount() {
tome52ce702014-09-11 00:12:54 -070075 return graph.getEdges().size();
tomdc361b62014-09-09 20:36:52 -070076 }
77
78 @Override
79 public int pathCount() {
80 return pathCount;
81 }
82
tome52ce702014-09-11 00:12:54 -070083 Set<TopologyCluster> getClusters() {
84 return clusters;
85 }
86
87 Graph<TopoVertex, TopoEdge> getGraph() {
88 return graph;
89 }
90
91 boolean isInfrastructure(ConnectPoint connectPoint) {
92 return connectPoints.contains(connectPoint);
93 }
94
95 boolean isInBroadcastTree(ConnectPoint connectPoint) {
96 return false;
97 }
98
99 Set<Path> getPaths(DeviceId src, DeviceId dst) {
100 return null; // pointToPointPaths.get(key(src, dst));
101 }
tomdc361b62014-09-09 20:36:52 -0700102}