tom | 8bf2e6b | 2014-09-10 20:53:54 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.trivial.topology.impl; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 2 | |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 3 | import com.google.common.collect.ImmutableMap; |
| 4 | import com.google.common.collect.ImmutableSet; |
| 5 | import com.google.common.collect.ImmutableSetMultimap; |
| 6 | import org.onlab.graph.Graph; |
| 7 | import org.onlab.graph.GraphPathSearch; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 8 | import org.onlab.onos.net.AbstractModel; |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 9 | import org.onlab.onos.net.ConnectPoint; |
| 10 | import org.onlab.onos.net.DeviceId; |
| 11 | import org.onlab.onos.net.Link; |
| 12 | import org.onlab.onos.net.Path; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 13 | import org.onlab.onos.net.provider.ProviderId; |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 14 | import org.onlab.onos.net.topology.TopoEdge; |
| 15 | import org.onlab.onos.net.topology.TopoVertex; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 16 | import org.onlab.onos.net.topology.Topology; |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 17 | import org.onlab.onos.net.topology.TopologyCluster; |
| 18 | import org.onlab.onos.net.topology.TopologyDescription; |
| 19 | |
| 20 | import java.util.Set; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Default implementation of the topology descriptor. This carries the |
| 24 | * backing topology data. |
| 25 | */ |
| 26 | public class DefaultTopology extends AbstractModel implements Topology { |
| 27 | |
| 28 | private final long time; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 29 | private final int pathCount; |
| 30 | |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 31 | 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 | |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Creates a topology descriptor attributed to the specified provider. |
| 41 | * |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 42 | * @param providerId identity of the provider |
| 43 | * @param description data describing the new topology |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 44 | */ |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 45 | DefaultTopology(ProviderId providerId, TopologyDescription description) { |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 46 | super(providerId); |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 47 | 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; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public long time() { |
| 60 | return time; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public int clusterCount() { |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 65 | return clusters.size(); |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int deviceCount() { |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 70 | return graph.getVertexes().size(); |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public int linkCount() { |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 75 | return graph.getEdges().size(); |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public int pathCount() { |
| 80 | return pathCount; |
| 81 | } |
| 82 | |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame^] | 83 | 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 | } |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 102 | } |