blob: f432ade7fab3233b1fdae22ceeb50a5346ae16eb [file] [log] [blame]
tom8bf2e6b2014-09-10 20:53:54 -07001package org.onlab.onos.net.trivial.topology.impl;
tom0efbb1d2014-09-09 11:54:28 -07002
tomdc361b62014-09-09 20:36:52 -07003import org.onlab.onos.event.Event;
4import org.onlab.onos.net.ConnectPoint;
5import org.onlab.onos.net.DeviceId;
tom13cb4852014-09-11 12:44:17 -07006import org.onlab.onos.net.Link;
tomdc361b62014-09-09 20:36:52 -07007import org.onlab.onos.net.Path;
tome52ce702014-09-11 00:12:54 -07008import org.onlab.onos.net.provider.ProviderId;
tom13cb4852014-09-11 12:44:17 -07009import org.onlab.onos.net.topology.ClusterId;
tom97937552014-09-11 10:48:42 -070010import org.onlab.onos.net.topology.GraphDescription;
tomdc361b62014-09-09 20:36:52 -070011import org.onlab.onos.net.topology.LinkWeight;
tomdc361b62014-09-09 20:36:52 -070012import org.onlab.onos.net.topology.Topology;
13import org.onlab.onos.net.topology.TopologyCluster;
tomdc361b62014-09-09 20:36:52 -070014import org.onlab.onos.net.topology.TopologyEvent;
tom97937552014-09-11 10:48:42 -070015import org.onlab.onos.net.topology.TopologyGraph;
tomdc361b62014-09-09 20:36:52 -070016
17import java.util.List;
18import java.util.Set;
19
tom0efbb1d2014-09-09 11:54:28 -070020/**
21 * Manages inventory of topology snapshots using trivial in-memory
tomcbff9392014-09-10 00:45:23 -070022 * structures implementation.
tom0efbb1d2014-09-09 11:54:28 -070023 */
tomcbff9392014-09-10 00:45:23 -070024class SimpleTopologyStore {
tomdc361b62014-09-09 20:36:52 -070025
26 private volatile DefaultTopology current;
27
28 /**
29 * Returns the current topology snapshot.
30 *
31 * @return current topology descriptor
32 */
33 Topology currentTopology() {
34 return current;
35 }
36
37 /**
38 * Indicates whether the topology is the latest.
tomcbff9392014-09-10 00:45:23 -070039 *
tomdc361b62014-09-09 20:36:52 -070040 * @param topology topology descriptor
41 * @return true if topology is the most recent one
42 */
43 boolean isLatest(Topology topology) {
tomcbff9392014-09-10 00:45:23 -070044 // Topology is current only if it is the same as our current topology
tomdc361b62014-09-09 20:36:52 -070045 return topology == current;
46 }
47
48 /**
tom13cb4852014-09-11 12:44:17 -070049 * Returns the immutable graph view of the current topology.
50 *
51 * @param topology topology descriptor
52 * @return graph view
53 */
54 TopologyGraph getGraph(DefaultTopology topology) {
55 return topology.getGraph();
56 }
57
58 /**
tomdc361b62014-09-09 20:36:52 -070059 * Returns the set of topology SCC clusters.
60 *
61 * @param topology topology descriptor
62 * @return set of clusters
63 */
tome52ce702014-09-11 00:12:54 -070064 Set<TopologyCluster> getClusters(DefaultTopology topology) {
65 return topology.getClusters();
tomdc361b62014-09-09 20:36:52 -070066 }
67
68 /**
tom13cb4852014-09-11 12:44:17 -070069 * Returns the cluster of the specified topology.
tomdc361b62014-09-09 20:36:52 -070070 *
tom13cb4852014-09-11 12:44:17 -070071 * @param topology topology descriptor
72 * @param clusterId cluster identity
73 * @return topology cluster
tomdc361b62014-09-09 20:36:52 -070074 */
tom13cb4852014-09-11 12:44:17 -070075 TopologyCluster getCluster(DefaultTopology topology, ClusterId clusterId) {
76 return topology.getCluster(clusterId);
77 }
78
79 /**
80 * Returns the cluster of the specified topology.
81 *
82 * @param topology topology descriptor
83 * @param cluster topology cluster
84 * @return set of cluster links
85 */
86 Set<DeviceId> getClusterDevices(DefaultTopology topology, TopologyCluster cluster) {
87 return topology.getClusterDevices(cluster);
88 }
89
90 /**
91 * Returns the cluster of the specified topology.
92 *
93 * @param topology topology descriptor
94 * @param cluster topology cluster
95 * @return set of cluster links
96 */
97 Set<Link> getClusterLinks(DefaultTopology topology, TopologyCluster cluster) {
98 return topology.getClusterLinks(cluster);
tomdc361b62014-09-09 20:36:52 -070099 }
100
101 /**
102 * Returns the set of pre-computed shortest paths between src and dest.
103 *
104 * @param topology topology descriptor
105 * @param src source device
106 * @param dst destination device
107 * @return set of shortest paths
108 */
tome52ce702014-09-11 00:12:54 -0700109 Set<Path> getPaths(DefaultTopology topology, DeviceId src, DeviceId dst) {
110 return topology.getPaths(src, dst);
tomdc361b62014-09-09 20:36:52 -0700111 }
112
113 /**
114 * Computes and returns the set of shortest paths between src and dest.
115 *
116 * @param topology topology descriptor
117 * @param src source device
118 * @param dst destination device
119 * @param weight link weight function
120 * @return set of shortest paths
121 */
tome52ce702014-09-11 00:12:54 -0700122 Set<Path> getPaths(DefaultTopology topology, DeviceId src, DeviceId dst,
tomdc361b62014-09-09 20:36:52 -0700123 LinkWeight weight) {
tom97937552014-09-11 10:48:42 -0700124 return topology.getPaths(src, dst, weight);
tomdc361b62014-09-09 20:36:52 -0700125 }
126
127 /**
128 * Indicates whether the given connect point is part of the network fabric.
129 *
130 * @param topology topology descriptor
131 * @param connectPoint connection point
132 * @return true if infrastructure; false otherwise
133 */
tome52ce702014-09-11 00:12:54 -0700134 boolean isInfrastructure(DefaultTopology topology, ConnectPoint connectPoint) {
135 return topology.isInfrastructure(connectPoint);
tomdc361b62014-09-09 20:36:52 -0700136 }
137
138 /**
139 * Indicates whether the given connect point is part of the broadcast tree.
140 *
141 * @param topology topology descriptor
142 * @param connectPoint connection point
143 * @return true if in broadcast tree; false otherwise
144 */
tome52ce702014-09-11 00:12:54 -0700145 boolean isInBroadcastTree(DefaultTopology topology, ConnectPoint connectPoint) {
146 return topology.isInBroadcastTree(connectPoint);
tomdc361b62014-09-09 20:36:52 -0700147 }
148
149 /**
150 * Generates a new topology snapshot from the specified description.
151 *
tom97937552014-09-11 10:48:42 -0700152 * @param providerId provider identification
153 * @param graphDescription topology graph description
154 * @param reasons list of events that triggered the update
tomdc361b62014-09-09 20:36:52 -0700155 * @return topology update event or null if the description is old
156 */
tome52ce702014-09-11 00:12:54 -0700157 TopologyEvent updateTopology(ProviderId providerId,
tom97937552014-09-11 10:48:42 -0700158 GraphDescription graphDescription,
tomcbff9392014-09-10 00:45:23 -0700159 List<Event> reasons) {
tome52ce702014-09-11 00:12:54 -0700160 // First off, make sure that what we're given is indeed newer than
161 // what we already have.
tom97937552014-09-11 10:48:42 -0700162 if (current != null && graphDescription.timestamp() < current.time()) {
tome52ce702014-09-11 00:12:54 -0700163 return null;
164 }
165
166 // Have the default topology construct self from the description data.
167 DefaultTopology newTopology =
tom97937552014-09-11 10:48:42 -0700168 new DefaultTopology(providerId, graphDescription);
tome52ce702014-09-11 00:12:54 -0700169
170 // Promote the new topology to current and return a ready-to-send event.
tom97937552014-09-11 10:48:42 -0700171 synchronized (this) {
172 current = newTopology;
173 return new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, current);
174 }
tomdc361b62014-09-09 20:36:52 -0700175 }
176
tom0efbb1d2014-09-09 11:54:28 -0700177}