Committed by
Gerrit Code Review
Refactoring to eliminate duplicate DefaultTopology and DefaultTopologyGraph; eli…
…minating a few fixmes. Change-Id: I4461b6f1c8ae60d39f5da909bf6995294cbfa84d
Showing
8 changed files
with
56 additions
and
618 deletions
... | @@ -15,10 +15,8 @@ | ... | @@ -15,10 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.topology; | 16 | package org.onosproject.net.topology; |
17 | 17 | ||
18 | -import static org.slf4j.LoggerFactory.getLogger; | 18 | +import com.google.common.collect.ImmutableSet; |
19 | - | 19 | +import com.google.common.collect.Maps; |
20 | -import java.util.Map; | ||
21 | - | ||
22 | import org.onosproject.net.AbstractDescription; | 20 | import org.onosproject.net.AbstractDescription; |
23 | import org.onosproject.net.ConnectPoint; | 21 | import org.onosproject.net.ConnectPoint; |
24 | import org.onosproject.net.Device; | 22 | import org.onosproject.net.Device; |
... | @@ -27,14 +25,15 @@ import org.onosproject.net.Link; | ... | @@ -27,14 +25,15 @@ import org.onosproject.net.Link; |
27 | import org.onosproject.net.SparseAnnotations; | 25 | import org.onosproject.net.SparseAnnotations; |
28 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
29 | 27 | ||
30 | -import com.google.common.collect.ImmutableSet; | 28 | +import java.util.Map; |
31 | -import com.google.common.collect.Maps; | 29 | + |
30 | +import static org.slf4j.LoggerFactory.getLogger; | ||
32 | 31 | ||
33 | /** | 32 | /** |
34 | * Default implementation of an immutable topology graph data carrier. | 33 | * Default implementation of an immutable topology graph data carrier. |
35 | */ | 34 | */ |
36 | public class DefaultGraphDescription extends AbstractDescription | 35 | public class DefaultGraphDescription extends AbstractDescription |
37 | -implements GraphDescription { | 36 | + implements GraphDescription { |
38 | 37 | ||
39 | private static final Logger log = getLogger(DefaultGraphDescription.class); | 38 | private static final Logger log = getLogger(DefaultGraphDescription.class); |
40 | 39 | ||
... | @@ -43,19 +42,15 @@ implements GraphDescription { | ... | @@ -43,19 +42,15 @@ implements GraphDescription { |
43 | private final ImmutableSet<TopologyVertex> vertexes; | 42 | private final ImmutableSet<TopologyVertex> vertexes; |
44 | private final ImmutableSet<TopologyEdge> edges; | 43 | private final ImmutableSet<TopologyEdge> edges; |
45 | 44 | ||
46 | - private final Map<DeviceId, TopologyVertex> vertexesById = Maps | 45 | + private final Map<DeviceId, TopologyVertex> vertexesById = Maps.newHashMap(); |
47 | - .newHashMap(); | ||
48 | 46 | ||
49 | /** | 47 | /** |
50 | * Creates a minimal topology graph description to allow core to construct | 48 | * Creates a minimal topology graph description to allow core to construct |
51 | * and process the topology graph. | 49 | * and process the topology graph. |
52 | * | 50 | * |
53 | * @param nanos time in nanos of when the topology description was created | 51 | * @param nanos time in nanos of when the topology description was created |
54 | - * | ||
55 | * @param devices collection of infrastructure devices | 52 | * @param devices collection of infrastructure devices |
56 | - * | ||
57 | * @param links collection of infrastructure links | 53 | * @param links collection of infrastructure links |
58 | - * | ||
59 | * @param annotations optional key/value annotations map | 54 | * @param annotations optional key/value annotations map |
60 | * @deprecated in Cardinal Release | 55 | * @deprecated in Cardinal Release |
61 | */ | 56 | */ |
... | @@ -71,15 +66,10 @@ implements GraphDescription { | ... | @@ -71,15 +66,10 @@ implements GraphDescription { |
71 | * and process the topology graph. | 66 | * and process the topology graph. |
72 | * | 67 | * |
73 | * @param nanos time in nanos of when the topology description was created | 68 | * @param nanos time in nanos of when the topology description was created |
74 | - * | ||
75 | * @param millis time in millis of when the topology description was created | 69 | * @param millis time in millis of when the topology description was created |
76 | - * | ||
77 | * @param devices collection of infrastructure devices | 70 | * @param devices collection of infrastructure devices |
78 | - * | ||
79 | * @param links collection of infrastructure links | 71 | * @param links collection of infrastructure links |
80 | - * | ||
81 | * @param annotations optional key/value annotations map | 72 | * @param annotations optional key/value annotations map |
82 | - * | ||
83 | */ | 73 | */ |
84 | public DefaultGraphDescription(long nanos, long millis, | 74 | public DefaultGraphDescription(long nanos, long millis, |
85 | Iterable<Device> devices, | 75 | Iterable<Device> devices, |
... | @@ -114,8 +104,7 @@ implements GraphDescription { | ... | @@ -114,8 +104,7 @@ implements GraphDescription { |
114 | } | 104 | } |
115 | 105 | ||
116 | // Builds a set of topology vertexes from the specified list of devices | 106 | // Builds a set of topology vertexes from the specified list of devices |
117 | - private ImmutableSet<TopologyVertex> | 107 | + private ImmutableSet<TopologyVertex> buildVertexes(Iterable<Device> devices) { |
118 | - buildVertexes(Iterable<Device> devices) { | ||
119 | ImmutableSet.Builder<TopologyVertex> vertexes = ImmutableSet.builder(); | 108 | ImmutableSet.Builder<TopologyVertex> vertexes = ImmutableSet.builder(); |
120 | for (Device device : devices) { | 109 | for (Device device : devices) { |
121 | TopologyVertex vertex = new DefaultTopologyVertex(device.id()); | 110 | TopologyVertex vertex = new DefaultTopologyVertex(device.id()); | ... | ... |
... | @@ -13,20 +13,14 @@ | ... | @@ -13,20 +13,14 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.store.topology.impl; | 16 | +package org.onosproject.common; |
17 | - | ||
18 | -import static com.google.common.base.MoreObjects.toStringHelper; | ||
19 | -import static org.onlab.graph.GraphPathSearch.ALL_PATHS; | ||
20 | -import static org.onosproject.core.CoreService.CORE_PROVIDER_ID; | ||
21 | -import static org.onosproject.net.Link.State.ACTIVE; | ||
22 | -import static org.onosproject.net.Link.State.INACTIVE; | ||
23 | -import static org.onosproject.net.Link.Type.INDIRECT; | ||
24 | - | ||
25 | -import java.util.ArrayList; | ||
26 | -import java.util.List; | ||
27 | -import java.util.Map; | ||
28 | -import java.util.Set; | ||
29 | 17 | ||
18 | +import com.google.common.base.Supplier; | ||
19 | +import com.google.common.base.Suppliers; | ||
20 | +import com.google.common.collect.ImmutableMap; | ||
21 | +import com.google.common.collect.ImmutableSet; | ||
22 | +import com.google.common.collect.ImmutableSetMultimap; | ||
23 | +import com.google.common.collect.ImmutableSetMultimap.Builder; | ||
30 | import org.onlab.graph.DijkstraGraphSearch; | 24 | import org.onlab.graph.DijkstraGraphSearch; |
31 | import org.onlab.graph.GraphPathSearch; | 25 | import org.onlab.graph.GraphPathSearch; |
32 | import org.onlab.graph.GraphPathSearch.Result; | 26 | import org.onlab.graph.GraphPathSearch.Result; |
... | @@ -50,14 +44,18 @@ import org.onosproject.net.topology.TopologyEdge; | ... | @@ -50,14 +44,18 @@ import org.onosproject.net.topology.TopologyEdge; |
50 | import org.onosproject.net.topology.TopologyGraph; | 44 | import org.onosproject.net.topology.TopologyGraph; |
51 | import org.onosproject.net.topology.TopologyVertex; | 45 | import org.onosproject.net.topology.TopologyVertex; |
52 | 46 | ||
53 | -import com.google.common.base.Supplier; | 47 | +import java.util.ArrayList; |
54 | -import com.google.common.base.Suppliers; | 48 | +import java.util.List; |
55 | -import com.google.common.collect.ImmutableMap; | 49 | +import java.util.Map; |
56 | -import com.google.common.collect.ImmutableSet; | 50 | +import java.util.Set; |
57 | -import com.google.common.collect.ImmutableSetMultimap; | 51 | + |
58 | -import com.google.common.collect.ImmutableSetMultimap.Builder; | 52 | +import static com.google.common.base.MoreObjects.toStringHelper; |
53 | +import static org.onlab.graph.GraphPathSearch.ALL_PATHS; | ||
54 | +import static org.onosproject.core.CoreService.CORE_PROVIDER_ID; | ||
55 | +import static org.onosproject.net.Link.State.ACTIVE; | ||
56 | +import static org.onosproject.net.Link.State.INACTIVE; | ||
57 | +import static org.onosproject.net.Link.Type.INDIRECT; | ||
59 | 58 | ||
60 | -// FIXME: Move to onos-core-common when ready | ||
61 | /** | 59 | /** |
62 | * Default implementation of the topology descriptor. This carries the backing | 60 | * Default implementation of the topology descriptor. This carries the backing |
63 | * topology data. | 61 | * topology data. |
... | @@ -83,12 +81,10 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -83,12 +81,10 @@ public class DefaultTopology extends AbstractModel implements Topology { |
83 | /** | 81 | /** |
84 | * Creates a topology descriptor attributed to the specified provider. | 82 | * Creates a topology descriptor attributed to the specified provider. |
85 | * | 83 | * |
86 | - * @param providerId | 84 | + * @param providerId identity of the provider |
87 | - * identity of the provider | 85 | + * @param description data describing the new topology |
88 | - * @param description | ||
89 | - * data describing the new topology | ||
90 | */ | 86 | */ |
91 | - DefaultTopology(ProviderId providerId, GraphDescription description) { | 87 | + public DefaultTopology(ProviderId providerId, GraphDescription description) { |
92 | super(providerId); | 88 | super(providerId); |
93 | this.time = description.timestamp(); | 89 | this.time = description.timestamp(); |
94 | this.creationTime = description.creationTime(); | 90 | this.creationTime = description.creationTime(); |
... | @@ -104,8 +100,7 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -104,8 +100,7 @@ public class DefaultTopology extends AbstractModel implements Topology { |
104 | 100 | ||
105 | this.weight = new HopCountLinkWeight(graph.getVertexes().size()); | 101 | this.weight = new HopCountLinkWeight(graph.getVertexes().size()); |
106 | this.broadcastSets = Suppliers.memoize(() -> buildBroadcastSets()); | 102 | this.broadcastSets = Suppliers.memoize(() -> buildBroadcastSets()); |
107 | - this.infrastructurePoints = Suppliers | 103 | + this.infrastructurePoints = Suppliers.memoize(() -> findInfrastructurePoints()); |
108 | - .memoize(() -> findInfrastructurePoints()); | ||
109 | this.computeCost = Math.max(0, System.nanoTime() - time); | 104 | this.computeCost = Math.max(0, System.nanoTime() - time); |
110 | } | 105 | } |
111 | 106 | ||
... | @@ -156,7 +151,7 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -156,7 +151,7 @@ public class DefaultTopology extends AbstractModel implements Topology { |
156 | * | 151 | * |
157 | * @return topology graph | 152 | * @return topology graph |
158 | */ | 153 | */ |
159 | - TopologyGraph getGraph() { | 154 | + public TopologyGraph getGraph() { |
160 | return graph; | 155 | return graph; |
161 | } | 156 | } |
162 | 157 | ||
... | @@ -165,7 +160,7 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -165,7 +160,7 @@ public class DefaultTopology extends AbstractModel implements Topology { |
165 | * | 160 | * |
166 | * @return set of clusters | 161 | * @return set of clusters |
167 | */ | 162 | */ |
168 | - Set<TopologyCluster> getClusters() { | 163 | + public Set<TopologyCluster> getClusters() { |
169 | return ImmutableSet.copyOf(clusters.get().values()); | 164 | return ImmutableSet.copyOf(clusters.get().values()); |
170 | } | 165 | } |
171 | 166 | ||
... | @@ -173,10 +168,9 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -173,10 +168,9 @@ public class DefaultTopology extends AbstractModel implements Topology { |
173 | * Returns the specified topology cluster. | 168 | * Returns the specified topology cluster. |
174 | * | 169 | * |
175 | * @param clusterId cluster identifier | 170 | * @param clusterId cluster identifier |
176 | - * | ||
177 | * @return topology cluster | 171 | * @return topology cluster |
178 | */ | 172 | */ |
179 | - TopologyCluster getCluster(ClusterId clusterId) { | 173 | + public TopologyCluster getCluster(ClusterId clusterId) { |
180 | return clusters.get().get(clusterId); | 174 | return clusters.get().get(clusterId); |
181 | } | 175 | } |
182 | 176 | ||
... | @@ -184,10 +178,9 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -184,10 +178,9 @@ public class DefaultTopology extends AbstractModel implements Topology { |
184 | * Returns the topology cluster that contains the given device. | 178 | * Returns the topology cluster that contains the given device. |
185 | * | 179 | * |
186 | * @param deviceId device identifier | 180 | * @param deviceId device identifier |
187 | - * | ||
188 | * @return topology cluster | 181 | * @return topology cluster |
189 | */ | 182 | */ |
190 | - TopologyCluster getCluster(DeviceId deviceId) { | 183 | + public TopologyCluster getCluster(DeviceId deviceId) { |
191 | return clustersByDevice().get(deviceId); | 184 | return clustersByDevice().get(deviceId); |
192 | } | 185 | } |
193 | 186 | ||
... | @@ -195,10 +188,9 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -195,10 +188,9 @@ public class DefaultTopology extends AbstractModel implements Topology { |
195 | * Returns the set of cluster devices. | 188 | * Returns the set of cluster devices. |
196 | * | 189 | * |
197 | * @param cluster topology cluster | 190 | * @param cluster topology cluster |
198 | - * | ||
199 | * @return cluster devices | 191 | * @return cluster devices |
200 | */ | 192 | */ |
201 | - Set<DeviceId> getClusterDevices(TopologyCluster cluster) { | 193 | + public Set<DeviceId> getClusterDevices(TopologyCluster cluster) { |
202 | return devicesByCluster().get(cluster); | 194 | return devicesByCluster().get(cluster); |
203 | } | 195 | } |
204 | 196 | ||
... | @@ -206,10 +198,9 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -206,10 +198,9 @@ public class DefaultTopology extends AbstractModel implements Topology { |
206 | * Returns the set of cluster links. | 198 | * Returns the set of cluster links. |
207 | * | 199 | * |
208 | * @param cluster topology cluster | 200 | * @param cluster topology cluster |
209 | - * | ||
210 | * @return cluster links | 201 | * @return cluster links |
211 | */ | 202 | */ |
212 | - Set<Link> getClusterLinks(TopologyCluster cluster) { | 203 | + public Set<Link> getClusterLinks(TopologyCluster cluster) { |
213 | return linksByCluster().get(cluster); | 204 | return linksByCluster().get(cluster); |
214 | } | 205 | } |
215 | 206 | ||
... | @@ -217,10 +208,9 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -217,10 +208,9 @@ public class DefaultTopology extends AbstractModel implements Topology { |
217 | * Indicates whether the given point is an infrastructure link end-point. | 208 | * Indicates whether the given point is an infrastructure link end-point. |
218 | * | 209 | * |
219 | * @param connectPoint connection point | 210 | * @param connectPoint connection point |
220 | - * | ||
221 | * @return true if infrastructure | 211 | * @return true if infrastructure |
222 | */ | 212 | */ |
223 | - boolean isInfrastructure(ConnectPoint connectPoint) { | 213 | + public boolean isInfrastructure(ConnectPoint connectPoint) { |
224 | return infrastructurePoints.get().contains(connectPoint); | 214 | return infrastructurePoints.get().contains(connectPoint); |
225 | } | 215 | } |
226 | 216 | ||
... | @@ -228,10 +218,9 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -228,10 +218,9 @@ public class DefaultTopology extends AbstractModel implements Topology { |
228 | * Indicates whether the given point is part of a broadcast set. | 218 | * Indicates whether the given point is part of a broadcast set. |
229 | * | 219 | * |
230 | * @param connectPoint connection point | 220 | * @param connectPoint connection point |
231 | - * | ||
232 | * @return true if in broadcast set | 221 | * @return true if in broadcast set |
233 | */ | 222 | */ |
234 | - boolean isBroadcastPoint(ConnectPoint connectPoint) { | 223 | + public boolean isBroadcastPoint(ConnectPoint connectPoint) { |
235 | // Any non-infrastructure, i.e. edge points are assumed to be OK. | 224 | // Any non-infrastructure, i.e. edge points are assumed to be OK. |
236 | if (!isInfrastructure(connectPoint)) { | 225 | if (!isInfrastructure(connectPoint)) { |
237 | return true; | 226 | return true; |
... | @@ -254,10 +243,9 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -254,10 +243,9 @@ public class DefaultTopology extends AbstractModel implements Topology { |
254 | * Returns the size of the cluster broadcast set. | 243 | * Returns the size of the cluster broadcast set. |
255 | * | 244 | * |
256 | * @param clusterId cluster identifier | 245 | * @param clusterId cluster identifier |
257 | - * | ||
258 | * @return size of the cluster broadcast set | 246 | * @return size of the cluster broadcast set |
259 | */ | 247 | */ |
260 | - int broadcastSetSize(ClusterId clusterId) { | 248 | + public int broadcastSetSize(ClusterId clusterId) { |
261 | return broadcastSets.get().get(clusterId).size(); | 249 | return broadcastSets.get().get(clusterId).size(); |
262 | } | 250 | } |
263 | 251 | ||
... | @@ -266,12 +254,10 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -266,12 +254,10 @@ public class DefaultTopology extends AbstractModel implements Topology { |
266 | * destination devices. | 254 | * destination devices. |
267 | * | 255 | * |
268 | * @param src source device | 256 | * @param src source device |
269 | - * | ||
270 | * @param dst destination device | 257 | * @param dst destination device |
271 | - * | ||
272 | * @return set of shortest paths | 258 | * @return set of shortest paths |
273 | */ | 259 | */ |
274 | - Set<Path> getPaths(DeviceId src, DeviceId dst) { | 260 | + public Set<Path> getPaths(DeviceId src, DeviceId dst) { |
275 | return getPaths(src, dst, null); | 261 | return getPaths(src, dst, null); |
276 | } | 262 | } |
277 | 263 | ||
... | @@ -280,14 +266,11 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -280,14 +266,11 @@ public class DefaultTopology extends AbstractModel implements Topology { |
280 | * destination devices. | 266 | * destination devices. |
281 | * | 267 | * |
282 | * @param src source device | 268 | * @param src source device |
283 | - * | ||
284 | * @param dst destination device | 269 | * @param dst destination device |
285 | - * | ||
286 | * @param weight link weight function | 270 | * @param weight link weight function |
287 | - * | ||
288 | * @return set of shortest paths | 271 | * @return set of shortest paths |
289 | */ | 272 | */ |
290 | - Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight) { | 273 | + public Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight) { |
291 | final DefaultTopologyVertex srcV = new DefaultTopologyVertex(src); | 274 | final DefaultTopologyVertex srcV = new DefaultTopologyVertex(src); |
292 | final DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst); | 275 | final DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst); |
293 | Set<TopologyVertex> vertices = graph.getVertexes(); | 276 | Set<TopologyVertex> vertices = graph.getVertexes(); |
... | @@ -470,8 +453,7 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -470,8 +453,7 @@ public class DefaultTopology extends AbstractModel implements Topology { |
470 | final ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster; | 453 | final ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster; |
471 | final ImmutableSetMultimap<TopologyCluster, Link> linksByCluster; | 454 | final ImmutableSetMultimap<TopologyCluster, Link> linksByCluster; |
472 | 455 | ||
473 | - public ClusterIndexes( | 456 | + public ClusterIndexes(ImmutableMap<DeviceId, TopologyCluster> clustersByDevice, |
474 | - ImmutableMap<DeviceId, TopologyCluster> clustersByDevice, | ||
475 | ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster, | 457 | ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster, |
476 | ImmutableSetMultimap<TopologyCluster, Link> linksByCluster) { | 458 | ImmutableSetMultimap<TopologyCluster, Link> linksByCluster) { |
477 | this.clustersByDevice = clustersByDevice; | 459 | this.clustersByDevice = clustersByDevice; | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.store.trivial; | 16 | +package org.onosproject.common; |
17 | 17 | ||
18 | import org.onlab.graph.AdjacencyListsGraph; | 18 | import org.onlab.graph.AdjacencyListsGraph; |
19 | import org.onosproject.net.topology.TopologyEdge; | 19 | import org.onosproject.net.topology.TopologyEdge; | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.store.trivial; | 16 | +package org.onosproject.common; |
17 | 17 | ||
18 | import org.junit.Before; | 18 | import org.junit.Before; |
19 | import org.junit.Test; | 19 | import org.junit.Test; | ... | ... |
1 | -/* | ||
2 | - * Copyright 2014-2015 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.onosproject.store.trivial; | ||
17 | - | ||
18 | -import static com.google.common.base.MoreObjects.toStringHelper; | ||
19 | -import static org.onlab.graph.GraphPathSearch.ALL_PATHS; | ||
20 | -import static org.onosproject.core.CoreService.CORE_PROVIDER_ID; | ||
21 | -import static org.onosproject.net.Link.State.ACTIVE; | ||
22 | -import static org.onosproject.net.Link.State.INACTIVE; | ||
23 | -import static org.onosproject.net.Link.Type.INDIRECT; | ||
24 | - | ||
25 | -import java.util.ArrayList; | ||
26 | -import java.util.List; | ||
27 | -import java.util.Map; | ||
28 | -import java.util.Set; | ||
29 | - | ||
30 | -import org.onlab.graph.DijkstraGraphSearch; | ||
31 | -import org.onlab.graph.GraphPathSearch; | ||
32 | -import org.onlab.graph.GraphPathSearch.Result; | ||
33 | -import org.onlab.graph.TarjanGraphSearch; | ||
34 | -import org.onlab.graph.TarjanGraphSearch.SCCResult; | ||
35 | -import org.onosproject.net.AbstractModel; | ||
36 | -import org.onosproject.net.ConnectPoint; | ||
37 | -import org.onosproject.net.DefaultPath; | ||
38 | -import org.onosproject.net.DeviceId; | ||
39 | -import org.onosproject.net.Link; | ||
40 | -import org.onosproject.net.Path; | ||
41 | -import org.onosproject.net.provider.ProviderId; | ||
42 | -import org.onosproject.net.topology.ClusterId; | ||
43 | -import org.onosproject.net.topology.DefaultTopologyCluster; | ||
44 | -import org.onosproject.net.topology.DefaultTopologyVertex; | ||
45 | -import org.onosproject.net.topology.GraphDescription; | ||
46 | -import org.onosproject.net.topology.LinkWeight; | ||
47 | -import org.onosproject.net.topology.Topology; | ||
48 | -import org.onosproject.net.topology.TopologyCluster; | ||
49 | -import org.onosproject.net.topology.TopologyEdge; | ||
50 | -import org.onosproject.net.topology.TopologyGraph; | ||
51 | -import org.onosproject.net.topology.TopologyVertex; | ||
52 | - | ||
53 | -import com.google.common.base.Supplier; | ||
54 | -import com.google.common.base.Suppliers; | ||
55 | -import com.google.common.collect.ImmutableMap; | ||
56 | -import com.google.common.collect.ImmutableSet; | ||
57 | -import com.google.common.collect.ImmutableSetMultimap; | ||
58 | -import com.google.common.collect.ImmutableSetMultimap.Builder; | ||
59 | - | ||
60 | -// FIXME: Move to onos-core-common when ready | ||
61 | -/** | ||
62 | - * Default implementation of the topology descriptor. This carries the backing | ||
63 | - * topology data. | ||
64 | - */ | ||
65 | -public class DefaultTopology extends AbstractModel implements Topology { | ||
66 | - | ||
67 | - private static final DijkstraGraphSearch<TopologyVertex, TopologyEdge> DIJKSTRA = new DijkstraGraphSearch<>(); | ||
68 | - private static final TarjanGraphSearch<TopologyVertex, TopologyEdge> TARJAN = new TarjanGraphSearch<>(); | ||
69 | - | ||
70 | - private final long time; | ||
71 | - private final long creationTime; | ||
72 | - private final long computeCost; | ||
73 | - private final TopologyGraph graph; | ||
74 | - | ||
75 | - private final LinkWeight weight; | ||
76 | - private final Supplier<SCCResult<TopologyVertex, TopologyEdge>> clusterResults; | ||
77 | - private final Supplier<ImmutableMap<ClusterId, TopologyCluster>> clusters; | ||
78 | - private final Supplier<ImmutableSet<ConnectPoint>> infrastructurePoints; | ||
79 | - private final Supplier<ImmutableSetMultimap<ClusterId, ConnectPoint>> broadcastSets; | ||
80 | - | ||
81 | - private final Supplier<ClusterIndexes> clusterIndexes; | ||
82 | - | ||
83 | - /** | ||
84 | - * Creates a topology descriptor attributed to the specified provider. | ||
85 | - * | ||
86 | - * @param providerId | ||
87 | - * identity of the provider | ||
88 | - * @param description | ||
89 | - * data describing the new topology | ||
90 | - */ | ||
91 | - DefaultTopology(ProviderId providerId, GraphDescription description) { | ||
92 | - super(providerId); | ||
93 | - this.time = description.timestamp(); | ||
94 | - this.creationTime = description.creationTime(); | ||
95 | - | ||
96 | - // Build the graph | ||
97 | - this.graph = new DefaultTopologyGraph(description.vertexes(), | ||
98 | - description.edges()); | ||
99 | - | ||
100 | - this.clusterResults = Suppliers.memoize(() -> searchForClusters()); | ||
101 | - this.clusters = Suppliers.memoize(() -> buildTopologyClusters()); | ||
102 | - | ||
103 | - this.clusterIndexes = Suppliers.memoize(() -> buildIndexes()); | ||
104 | - | ||
105 | - this.weight = new HopCountLinkWeight(graph.getVertexes().size()); | ||
106 | - this.broadcastSets = Suppliers.memoize(() -> buildBroadcastSets()); | ||
107 | - this.infrastructurePoints = Suppliers | ||
108 | - .memoize(() -> findInfrastructurePoints()); | ||
109 | - this.computeCost = Math.max(0, System.nanoTime() - time); | ||
110 | - } | ||
111 | - | ||
112 | - @Override | ||
113 | - public long time() { | ||
114 | - return time; | ||
115 | - } | ||
116 | - | ||
117 | - @Override | ||
118 | - public long creationTime() { | ||
119 | - return creationTime; | ||
120 | - } | ||
121 | - | ||
122 | - @Override | ||
123 | - public long computeCost() { | ||
124 | - return computeCost; | ||
125 | - } | ||
126 | - | ||
127 | - @Override | ||
128 | - public int clusterCount() { | ||
129 | - return clusters.get().size(); | ||
130 | - } | ||
131 | - | ||
132 | - @Override | ||
133 | - public int deviceCount() { | ||
134 | - return graph.getVertexes().size(); | ||
135 | - } | ||
136 | - | ||
137 | - @Override | ||
138 | - public int linkCount() { | ||
139 | - return graph.getEdges().size(); | ||
140 | - } | ||
141 | - | ||
142 | - private ImmutableMap<DeviceId, TopologyCluster> clustersByDevice() { | ||
143 | - return clusterIndexes.get().clustersByDevice; | ||
144 | - } | ||
145 | - | ||
146 | - private ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster() { | ||
147 | - return clusterIndexes.get().devicesByCluster; | ||
148 | - } | ||
149 | - | ||
150 | - private ImmutableSetMultimap<TopologyCluster, Link> linksByCluster() { | ||
151 | - return clusterIndexes.get().linksByCluster; | ||
152 | - } | ||
153 | - | ||
154 | - /** | ||
155 | - * Returns the backing topology graph. | ||
156 | - * | ||
157 | - * @return topology graph | ||
158 | - */ | ||
159 | - TopologyGraph getGraph() { | ||
160 | - return graph; | ||
161 | - } | ||
162 | - | ||
163 | - /** | ||
164 | - * Returns the set of topology clusters. | ||
165 | - * | ||
166 | - * @return set of clusters | ||
167 | - */ | ||
168 | - Set<TopologyCluster> getClusters() { | ||
169 | - return ImmutableSet.copyOf(clusters.get().values()); | ||
170 | - } | ||
171 | - | ||
172 | - /** | ||
173 | - * Returns the specified topology cluster. | ||
174 | - * | ||
175 | - * @param clusterId cluster identifier | ||
176 | - * | ||
177 | - * @return topology cluster | ||
178 | - */ | ||
179 | - TopologyCluster getCluster(ClusterId clusterId) { | ||
180 | - return clusters.get().get(clusterId); | ||
181 | - } | ||
182 | - | ||
183 | - /** | ||
184 | - * Returns the topology cluster that contains the given device. | ||
185 | - * | ||
186 | - * @param deviceId device identifier | ||
187 | - * | ||
188 | - * @return topology cluster | ||
189 | - */ | ||
190 | - TopologyCluster getCluster(DeviceId deviceId) { | ||
191 | - return clustersByDevice().get(deviceId); | ||
192 | - } | ||
193 | - | ||
194 | - /** | ||
195 | - * Returns the set of cluster devices. | ||
196 | - * | ||
197 | - * @param cluster topology cluster | ||
198 | - * | ||
199 | - * @return cluster devices | ||
200 | - */ | ||
201 | - Set<DeviceId> getClusterDevices(TopologyCluster cluster) { | ||
202 | - return devicesByCluster().get(cluster); | ||
203 | - } | ||
204 | - | ||
205 | - /** | ||
206 | - * Returns the set of cluster links. | ||
207 | - * | ||
208 | - * @param cluster topology cluster | ||
209 | - * | ||
210 | - * @return cluster links | ||
211 | - */ | ||
212 | - Set<Link> getClusterLinks(TopologyCluster cluster) { | ||
213 | - return linksByCluster().get(cluster); | ||
214 | - } | ||
215 | - | ||
216 | - /** | ||
217 | - * Indicates whether the given point is an infrastructure link end-point. | ||
218 | - * | ||
219 | - * @param connectPoint connection point | ||
220 | - * | ||
221 | - * @return true if infrastructure | ||
222 | - */ | ||
223 | - boolean isInfrastructure(ConnectPoint connectPoint) { | ||
224 | - return infrastructurePoints.get().contains(connectPoint); | ||
225 | - } | ||
226 | - | ||
227 | - /** | ||
228 | - * Indicates whether the given point is part of a broadcast set. | ||
229 | - * | ||
230 | - * @param connectPoint connection point | ||
231 | - * | ||
232 | - * @return true if in broadcast set | ||
233 | - */ | ||
234 | - boolean isBroadcastPoint(ConnectPoint connectPoint) { | ||
235 | - // Any non-infrastructure, i.e. edge points are assumed to be OK. | ||
236 | - if (!isInfrastructure(connectPoint)) { | ||
237 | - return true; | ||
238 | - } | ||
239 | - | ||
240 | - // Find the cluster to which the device belongs. | ||
241 | - TopologyCluster cluster = clustersByDevice().get(connectPoint.deviceId()); | ||
242 | - if (cluster == null) { | ||
243 | - throw new IllegalArgumentException("No cluster found for device " | ||
244 | - + connectPoint.deviceId()); | ||
245 | - } | ||
246 | - | ||
247 | - // If the broadcast set is null or empty, or if the point explicitly | ||
248 | - // belongs to it, return true; | ||
249 | - Set<ConnectPoint> points = broadcastSets.get().get(cluster.id()); | ||
250 | - return (points == null) || points.isEmpty() || points.contains(connectPoint); | ||
251 | - } | ||
252 | - | ||
253 | - /** | ||
254 | - * Returns the size of the cluster broadcast set. | ||
255 | - * | ||
256 | - * @param clusterId cluster identifier | ||
257 | - * | ||
258 | - * @return size of the cluster broadcast set | ||
259 | - */ | ||
260 | - int broadcastSetSize(ClusterId clusterId) { | ||
261 | - return broadcastSets.get().get(clusterId).size(); | ||
262 | - } | ||
263 | - | ||
264 | - /** | ||
265 | - * Returns the set of pre-computed shortest paths between source and | ||
266 | - * destination devices. | ||
267 | - * | ||
268 | - * @param src source device | ||
269 | - * | ||
270 | - * @param dst destination device | ||
271 | - * | ||
272 | - * @return set of shortest paths | ||
273 | - */ | ||
274 | - Set<Path> getPaths(DeviceId src, DeviceId dst) { | ||
275 | - return getPaths(src, dst, null); | ||
276 | - } | ||
277 | - | ||
278 | - /** | ||
279 | - * Computes on-demand the set of shortest paths between source and | ||
280 | - * destination devices. | ||
281 | - * | ||
282 | - * @param src source device | ||
283 | - * | ||
284 | - * @param dst destination device | ||
285 | - * | ||
286 | - * @param weight link weight function | ||
287 | - * | ||
288 | - * @return set of shortest paths | ||
289 | - */ | ||
290 | - Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight) { | ||
291 | - final DefaultTopologyVertex srcV = new DefaultTopologyVertex(src); | ||
292 | - final DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst); | ||
293 | - Set<TopologyVertex> vertices = graph.getVertexes(); | ||
294 | - if (!vertices.contains(srcV) || !vertices.contains(dstV)) { | ||
295 | - // src or dst not part of the current graph | ||
296 | - return ImmutableSet.of(); | ||
297 | - } | ||
298 | - | ||
299 | - GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = | ||
300 | - DIJKSTRA.search(graph, srcV, dstV, weight, ALL_PATHS); | ||
301 | - ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); | ||
302 | - for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) { | ||
303 | - builder.add(networkPath(path)); | ||
304 | - } | ||
305 | - return builder.build(); | ||
306 | - } | ||
307 | - | ||
308 | - // Converts graph path to a network path with the same cost. | ||
309 | - private Path networkPath(org.onlab.graph.Path<TopologyVertex, TopologyEdge> path) { | ||
310 | - List<Link> links = new ArrayList<>(); | ||
311 | - for (TopologyEdge edge : path.edges()) { | ||
312 | - links.add(edge.link()); | ||
313 | - } | ||
314 | - return new DefaultPath(CORE_PROVIDER_ID, links, path.cost()); | ||
315 | - } | ||
316 | - | ||
317 | - // Searches for SCC clusters in the network topology graph using Tarjan | ||
318 | - // algorithm. | ||
319 | - private SCCResult<TopologyVertex, TopologyEdge> searchForClusters() { | ||
320 | - return TARJAN.search(graph, new NoIndirectLinksWeight()); | ||
321 | - } | ||
322 | - | ||
323 | - // Builds the topology clusters and returns the id-cluster bindings. | ||
324 | - private ImmutableMap<ClusterId, TopologyCluster> buildTopologyClusters() { | ||
325 | - ImmutableMap.Builder<ClusterId, TopologyCluster> clusterBuilder = ImmutableMap.builder(); | ||
326 | - SCCResult<TopologyVertex, TopologyEdge> results = clusterResults.get(); | ||
327 | - // Extract both vertexes and edges from the results; the lists form | ||
328 | - // pairs along the same index. | ||
329 | - List<Set<TopologyVertex>> clusterVertexes = results.clusterVertexes(); | ||
330 | - List<Set<TopologyEdge>> clusterEdges = results.clusterEdges(); | ||
331 | - | ||
332 | - // Scan over the lists and create a cluster from the results. | ||
333 | - for (int i = 0, n = results.clusterCount(); i < n; i++) { | ||
334 | - Set<TopologyVertex> vertexSet = clusterVertexes.get(i); | ||
335 | - Set<TopologyEdge> edgeSet = clusterEdges.get(i); | ||
336 | - | ||
337 | - ClusterId cid = ClusterId.clusterId(i); | ||
338 | - DefaultTopologyCluster cluster = new DefaultTopologyCluster(cid, | ||
339 | - vertexSet.size(), | ||
340 | - edgeSet.size(), | ||
341 | - findRoot(vertexSet)); | ||
342 | - clusterBuilder.put(cid, cluster); | ||
343 | - } | ||
344 | - return clusterBuilder.build(); | ||
345 | - } | ||
346 | - | ||
347 | - // Finds the vertex whose device id is the lexicographical minimum in the | ||
348 | - // specified set. | ||
349 | - private TopologyVertex findRoot(Set<TopologyVertex> vertexSet) { | ||
350 | - TopologyVertex minVertex = null; | ||
351 | - for (TopologyVertex vertex : vertexSet) { | ||
352 | - if ((minVertex == null) || (minVertex.deviceId().toString() | ||
353 | - .compareTo(minVertex.deviceId().toString()) < 0)) { | ||
354 | - minVertex = vertex; | ||
355 | - } | ||
356 | - } | ||
357 | - return minVertex; | ||
358 | - } | ||
359 | - | ||
360 | - // Processes a map of broadcast sets for each cluster. | ||
361 | - private ImmutableSetMultimap<ClusterId, ConnectPoint> buildBroadcastSets() { | ||
362 | - Builder<ClusterId, ConnectPoint> builder = ImmutableSetMultimap.builder(); | ||
363 | - for (TopologyCluster cluster : clusters.get().values()) { | ||
364 | - addClusterBroadcastSet(cluster, builder); | ||
365 | - } | ||
366 | - return builder.build(); | ||
367 | - } | ||
368 | - | ||
369 | - // Finds all broadcast points for the cluster. These are those connection | ||
370 | - // points which lie along the shortest paths between the cluster root and | ||
371 | - // all other devices within the cluster. | ||
372 | - private void addClusterBroadcastSet(TopologyCluster cluster, Builder<ClusterId, ConnectPoint> builder) { | ||
373 | - // Use the graph root search results to build the broadcast set. | ||
374 | - Result<TopologyVertex, TopologyEdge> result = | ||
375 | - DIJKSTRA.search(graph, cluster.root(), null, weight, 1); | ||
376 | - for (Map.Entry<TopologyVertex, Set<TopologyEdge>> entry : result.parents().entrySet()) { | ||
377 | - TopologyVertex vertex = entry.getKey(); | ||
378 | - | ||
379 | - // Ignore any parents that lead outside the cluster. | ||
380 | - if (clustersByDevice().get(vertex.deviceId()) != cluster) { | ||
381 | - continue; | ||
382 | - } | ||
383 | - | ||
384 | - // Ignore any back-link sets that are empty. | ||
385 | - Set<TopologyEdge> parents = entry.getValue(); | ||
386 | - if (parents.isEmpty()) { | ||
387 | - continue; | ||
388 | - } | ||
389 | - | ||
390 | - // Use the first back-link source and destinations to add to the | ||
391 | - // broadcast set. | ||
392 | - Link link = parents.iterator().next().link(); | ||
393 | - builder.put(cluster.id(), link.src()); | ||
394 | - builder.put(cluster.id(), link.dst()); | ||
395 | - } | ||
396 | - } | ||
397 | - | ||
398 | - // Collects and returns an set of all infrastructure link end-points. | ||
399 | - private ImmutableSet<ConnectPoint> findInfrastructurePoints() { | ||
400 | - ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder(); | ||
401 | - for (TopologyEdge edge : graph.getEdges()) { | ||
402 | - builder.add(edge.link().src()); | ||
403 | - builder.add(edge.link().dst()); | ||
404 | - } | ||
405 | - return builder.build(); | ||
406 | - } | ||
407 | - | ||
408 | - // Builds cluster-devices, cluster-links and device-cluster indexes. | ||
409 | - private ClusterIndexes buildIndexes() { | ||
410 | - // Prepare the index builders | ||
411 | - ImmutableMap.Builder<DeviceId, TopologyCluster> clusterBuilder = | ||
412 | - ImmutableMap.builder(); | ||
413 | - ImmutableSetMultimap.Builder<TopologyCluster, DeviceId> devicesBuilder = | ||
414 | - ImmutableSetMultimap.builder(); | ||
415 | - ImmutableSetMultimap.Builder<TopologyCluster, Link> linksBuilder = | ||
416 | - ImmutableSetMultimap.builder(); | ||
417 | - | ||
418 | - // Now scan through all the clusters | ||
419 | - for (TopologyCluster cluster : clusters.get().values()) { | ||
420 | - int i = cluster.id().index(); | ||
421 | - | ||
422 | - // Scan through all the cluster vertexes. | ||
423 | - for (TopologyVertex vertex : clusterResults.get().clusterVertexes().get(i)) { | ||
424 | - devicesBuilder.put(cluster, vertex.deviceId()); | ||
425 | - clusterBuilder.put(vertex.deviceId(), cluster); | ||
426 | - } | ||
427 | - | ||
428 | - // Scan through all the cluster edges. | ||
429 | - for (TopologyEdge edge : clusterResults.get().clusterEdges().get(i)) { | ||
430 | - linksBuilder.put(cluster, edge.link()); | ||
431 | - } | ||
432 | - } | ||
433 | - | ||
434 | - // Finalize all indexes. | ||
435 | - return new ClusterIndexes(clusterBuilder.build(), | ||
436 | - devicesBuilder.build(), linksBuilder.build()); | ||
437 | - } | ||
438 | - | ||
439 | - // Link weight for measuring link cost as hop count with indirect links | ||
440 | - // being as expensive as traversing the entire graph to assume the worst. | ||
441 | - private static class HopCountLinkWeight implements LinkWeight { | ||
442 | - private final int indirectLinkCost; | ||
443 | - | ||
444 | - HopCountLinkWeight(int indirectLinkCost) { | ||
445 | - this.indirectLinkCost = indirectLinkCost; | ||
446 | - } | ||
447 | - | ||
448 | - @Override | ||
449 | - public double weight(TopologyEdge edge) { | ||
450 | - // To force preference to use direct paths first, make indirect | ||
451 | - // links as expensive as the linear vertex traversal. | ||
452 | - return edge.link().state() == | ||
453 | - ACTIVE ? (edge.link().type() == | ||
454 | - INDIRECT ? indirectLinkCost : 1) : -1; | ||
455 | - } | ||
456 | - } | ||
457 | - | ||
458 | - // Link weight for preventing traversal over indirect links. | ||
459 | - private static class NoIndirectLinksWeight implements LinkWeight { | ||
460 | - @Override | ||
461 | - public double weight(TopologyEdge edge) { | ||
462 | - return (edge.link().state() == INACTIVE) | ||
463 | - || (edge.link().type() == INDIRECT) ? -1 : 1; | ||
464 | - } | ||
465 | - } | ||
466 | - | ||
467 | - static final class ClusterIndexes { | ||
468 | - final ImmutableMap<DeviceId, TopologyCluster> clustersByDevice; | ||
469 | - final ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster; | ||
470 | - final ImmutableSetMultimap<TopologyCluster, Link> linksByCluster; | ||
471 | - | ||
472 | - public ClusterIndexes( | ||
473 | - ImmutableMap<DeviceId, TopologyCluster> clustersByDevice, | ||
474 | - ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster, | ||
475 | - ImmutableSetMultimap<TopologyCluster, Link> linksByCluster) { | ||
476 | - this.clustersByDevice = clustersByDevice; | ||
477 | - this.devicesByCluster = devicesByCluster; | ||
478 | - this.linksByCluster = linksByCluster; | ||
479 | - } | ||
480 | - } | ||
481 | - | ||
482 | - @Override | ||
483 | - public String toString() { | ||
484 | - return toStringHelper(this) | ||
485 | - .add("time", time) | ||
486 | - .add("created", creationTime) | ||
487 | - .add("computeCost", computeCost) | ||
488 | - .add("clusters", clusterCount()) | ||
489 | - .add("devices", deviceCount()) | ||
490 | - .add("links", linkCount()).toString(); | ||
491 | - } | ||
492 | -} |
... | @@ -19,6 +19,7 @@ import org.apache.felix.scr.annotations.Activate; | ... | @@ -19,6 +19,7 @@ import org.apache.felix.scr.annotations.Activate; |
19 | import org.apache.felix.scr.annotations.Component; | 19 | import org.apache.felix.scr.annotations.Component; |
20 | import org.apache.felix.scr.annotations.Deactivate; | 20 | import org.apache.felix.scr.annotations.Deactivate; |
21 | import org.apache.felix.scr.annotations.Service; | 21 | import org.apache.felix.scr.annotations.Service; |
22 | +import org.onosproject.common.DefaultTopology; | ||
22 | import org.onosproject.event.Event; | 23 | import org.onosproject.event.Event; |
23 | import org.onosproject.net.ConnectPoint; | 24 | import org.onosproject.net.ConnectPoint; |
24 | import org.onosproject.net.DeviceId; | 25 | import org.onosproject.net.DeviceId; | ... | ... |
core/store/dist/src/main/java/org/onosproject/store/topology/impl/DefaultTopologyGraph.java
deleted
100644 → 0
1 | -/* | ||
2 | - * Copyright 2014 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.onosproject.store.topology.impl; | ||
17 | - | ||
18 | -import org.onlab.graph.AdjacencyListsGraph; | ||
19 | -import org.onosproject.net.topology.TopologyEdge; | ||
20 | -import org.onosproject.net.topology.TopologyGraph; | ||
21 | -import org.onosproject.net.topology.TopologyVertex; | ||
22 | - | ||
23 | -import java.util.Set; | ||
24 | - | ||
25 | -/** | ||
26 | - * Default implementation of an immutable topology graph based on a generic | ||
27 | - * implementation of adjacency lists graph. | ||
28 | - */ | ||
29 | -public class DefaultTopologyGraph | ||
30 | - extends AdjacencyListsGraph<TopologyVertex, TopologyEdge> | ||
31 | - implements TopologyGraph { | ||
32 | - | ||
33 | - /** | ||
34 | - * Creates a topology graph comprising of the specified vertexes and edges. | ||
35 | - * | ||
36 | - * @param vertexes set of graph vertexes | ||
37 | - * @param edges set of graph edges | ||
38 | - */ | ||
39 | - public DefaultTopologyGraph(Set<TopologyVertex> vertexes, Set<TopologyEdge> edges) { | ||
40 | - super(vertexes, edges); | ||
41 | - } | ||
42 | - | ||
43 | -} |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.topology.impl; | 16 | package org.onosproject.store.topology.impl; |
17 | 17 | ||
18 | +import static com.google.common.base.Preconditions.checkArgument; | ||
19 | +import static org.onosproject.net.topology.TopologyEvent.Type.TOPOLOGY_CHANGED; | ||
18 | import static org.slf4j.LoggerFactory.getLogger; | 20 | import static org.slf4j.LoggerFactory.getLogger; |
19 | 21 | ||
20 | import java.util.Collections; | 22 | import java.util.Collections; |
... | @@ -25,6 +27,7 @@ import org.apache.felix.scr.annotations.Activate; | ... | @@ -25,6 +27,7 @@ import org.apache.felix.scr.annotations.Activate; |
25 | import org.apache.felix.scr.annotations.Component; | 27 | import org.apache.felix.scr.annotations.Component; |
26 | import org.apache.felix.scr.annotations.Deactivate; | 28 | import org.apache.felix.scr.annotations.Deactivate; |
27 | import org.apache.felix.scr.annotations.Service; | 29 | import org.apache.felix.scr.annotations.Service; |
30 | +import org.onosproject.common.DefaultTopology; | ||
28 | import org.onosproject.event.Event; | 31 | import org.onosproject.event.Event; |
29 | import org.onosproject.net.ConnectPoint; | 32 | import org.onosproject.net.ConnectPoint; |
30 | import org.onosproject.net.Device; | 33 | import org.onosproject.net.Device; |
... | @@ -48,21 +51,21 @@ import org.slf4j.Logger; | ... | @@ -48,21 +51,21 @@ import org.slf4j.Logger; |
48 | /** | 51 | /** |
49 | * Manages inventory of topology snapshots using trivial in-memory | 52 | * Manages inventory of topology snapshots using trivial in-memory |
50 | * structures implementation. | 53 | * structures implementation. |
51 | - * | 54 | + * <p> |
52 | * Note: This component is not distributed per-se. It runs on every | 55 | * Note: This component is not distributed per-se. It runs on every |
53 | * instance and feeds off of other distributed stores. | 56 | * instance and feeds off of other distributed stores. |
54 | */ | 57 | */ |
55 | @Component(immediate = true) | 58 | @Component(immediate = true) |
56 | @Service | 59 | @Service |
57 | public class DistributedTopologyStore | 60 | public class DistributedTopologyStore |
58 | -extends AbstractStore<TopologyEvent, TopologyStoreDelegate> | 61 | + extends AbstractStore<TopologyEvent, TopologyStoreDelegate> |
59 | -implements TopologyStore { | 62 | + implements TopologyStore { |
60 | 63 | ||
61 | private final Logger log = getLogger(getClass()); | 64 | private final Logger log = getLogger(getClass()); |
62 | 65 | ||
63 | private volatile DefaultTopology current = | 66 | private volatile DefaultTopology current = |
64 | new DefaultTopology(ProviderId.NONE, | 67 | new DefaultTopology(ProviderId.NONE, |
65 | - new DefaultGraphDescription(0L, | 68 | + new DefaultGraphDescription(0L, 0L, |
66 | Collections.<Device>emptyList(), | 69 | Collections.<Device>emptyList(), |
67 | Collections.<Link>emptyList())); | 70 | Collections.<Link>emptyList())); |
68 | 71 | ||
... | @@ -75,6 +78,7 @@ implements TopologyStore { | ... | @@ -75,6 +78,7 @@ implements TopologyStore { |
75 | public void deactivate() { | 78 | public void deactivate() { |
76 | log.info("Stopped"); | 79 | log.info("Stopped"); |
77 | } | 80 | } |
81 | + | ||
78 | @Override | 82 | @Override |
79 | public Topology currentTopology() { | 83 | public Topology currentTopology() { |
80 | return current; | 84 | return current; |
... | @@ -149,18 +153,15 @@ implements TopologyStore { | ... | @@ -149,18 +153,15 @@ implements TopologyStore { |
149 | // Promote the new topology to current and return a ready-to-send event. | 153 | // Promote the new topology to current and return a ready-to-send event. |
150 | synchronized (this) { | 154 | synchronized (this) { |
151 | current = newTopology; | 155 | current = newTopology; |
152 | - return new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, | 156 | + return new TopologyEvent(TOPOLOGY_CHANGED, current, reasons); |
153 | - current, reasons); | ||
154 | } | 157 | } |
155 | } | 158 | } |
156 | 159 | ||
157 | // Validates the specified topology and returns it as a default | 160 | // Validates the specified topology and returns it as a default |
158 | private DefaultTopology defaultTopology(Topology topology) { | 161 | private DefaultTopology defaultTopology(Topology topology) { |
159 | - if (topology instanceof DefaultTopology) { | 162 | + checkArgument(topology instanceof DefaultTopology, |
163 | + "Topology class %s not supported", topology.getClass()); | ||
160 | return (DefaultTopology) topology; | 164 | return (DefaultTopology) topology; |
161 | } | 165 | } |
162 | - throw new IllegalArgumentException("Topology class " + topology.getClass() + | ||
163 | - " not supported"); | ||
164 | - } | ||
165 | 166 | ||
166 | } | 167 | } | ... | ... |
-
Please register or login to post a comment