blob: 60210ef62ead437ce4c336727a897321b015ea14 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Thomas Vachuskac97aa612015-06-23 16:00:18 -070016package org.onosproject.store.trivial;
tom0efbb1d2014-09-09 11:54:28 -070017
Thomas Vachuska930a8ee2015-08-04 18:49:36 -070018import org.onosproject.common.DefaultTopology;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.event.Event;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.net.DeviceId;
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -070022import org.onosproject.net.DisjointPath;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.Link;
24import org.onosproject.net.Path;
25import org.onosproject.net.provider.ProviderId;
26import org.onosproject.net.topology.ClusterId;
27import org.onosproject.net.topology.GraphDescription;
Andrey Komarov2398d962016-09-26 15:11:23 +030028import org.onosproject.net.topology.LinkWeigher;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.topology.Topology;
30import org.onosproject.net.topology.TopologyCluster;
31import org.onosproject.net.topology.TopologyEvent;
32import org.onosproject.net.topology.TopologyGraph;
33import org.onosproject.net.topology.TopologyStore;
34import org.onosproject.net.topology.TopologyStoreDelegate;
35import org.onosproject.store.AbstractStore;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070036import org.osgi.service.component.annotations.Activate;
37import org.osgi.service.component.annotations.Component;
38import org.osgi.service.component.annotations.Deactivate;
tom10262dd2014-09-19 10:51:19 -070039import org.slf4j.Logger;
tomdc361b62014-09-09 20:36:52 -070040
41import java.util.List;
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -070042import java.util.Map;
tomdc361b62014-09-09 20:36:52 -070043import java.util.Set;
44
tom10262dd2014-09-19 10:51:19 -070045import static org.slf4j.LoggerFactory.getLogger;
46
tom0efbb1d2014-09-09 11:54:28 -070047/**
48 * Manages inventory of topology snapshots using trivial in-memory
tomcbff9392014-09-10 00:45:23 -070049 * structures implementation.
tom0efbb1d2014-09-09 11:54:28 -070050 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070051@Component(immediate = true, service = TopologyStore.class)
tomc78acee2014-09-24 15:16:55 -070052public class SimpleTopologyStore
53 extends AbstractStore<TopologyEvent, TopologyStoreDelegate>
54 implements TopologyStore {
tom10262dd2014-09-19 10:51:19 -070055
56 private final Logger log = getLogger(getClass());
tomdc361b62014-09-09 20:36:52 -070057
58 private volatile DefaultTopology current;
59
tom10262dd2014-09-19 10:51:19 -070060 @Activate
61 public void activate() {
62 log.info("Started");
63 }
64
65 @Deactivate
66 public void deactivate() {
67 log.info("Stopped");
68 }
69 @Override
70 public Topology currentTopology() {
tomdc361b62014-09-09 20:36:52 -070071 return current;
72 }
73
tom10262dd2014-09-19 10:51:19 -070074 @Override
75 public boolean isLatest(Topology topology) {
tomcbff9392014-09-10 00:45:23 -070076 // Topology is current only if it is the same as our current topology
tomdc361b62014-09-09 20:36:52 -070077 return topology == current;
78 }
79
tom10262dd2014-09-19 10:51:19 -070080 @Override
81 public TopologyGraph getGraph(Topology topology) {
82 return defaultTopology(topology).getGraph();
tom13cb4852014-09-11 12:44:17 -070083 }
84
tom10262dd2014-09-19 10:51:19 -070085 @Override
86 public Set<TopologyCluster> getClusters(Topology topology) {
87 return defaultTopology(topology).getClusters();
tomdc361b62014-09-09 20:36:52 -070088 }
89
tom10262dd2014-09-19 10:51:19 -070090 @Override
91 public TopologyCluster getCluster(Topology topology, ClusterId clusterId) {
92 return defaultTopology(topology).getCluster(clusterId);
tom13cb4852014-09-11 12:44:17 -070093 }
94
tom10262dd2014-09-19 10:51:19 -070095 @Override
96 public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) {
97 return defaultTopology(topology).getClusterDevices(cluster);
tom13cb4852014-09-11 12:44:17 -070098 }
99
tom10262dd2014-09-19 10:51:19 -0700100 @Override
101 public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) {
102 return defaultTopology(topology).getClusterLinks(cluster);
tomdc361b62014-09-09 20:36:52 -0700103 }
104
tom10262dd2014-09-19 10:51:19 -0700105 @Override
106 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
107 return defaultTopology(topology).getPaths(src, dst);
tomdc361b62014-09-09 20:36:52 -0700108 }
109
tom10262dd2014-09-19 10:51:19 -0700110 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +0300111 public Set<Path> getPaths(Topology topology, DeviceId src,
112 DeviceId dst, LinkWeigher weigher) {
113 return defaultTopology(topology).getPaths(src, dst, weigher);
tomdc361b62014-09-09 20:36:52 -0700114 }
115
tom10262dd2014-09-19 10:51:19 -0700116 @Override
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -0700117 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst) {
118 return defaultTopology(topology).getDisjointPaths(src, dst);
119 }
120
121 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +0300122 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
123 DeviceId dst, LinkWeigher weigher) {
124 return defaultTopology(topology).getDisjointPaths(src, dst, weigher);
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -0700125 }
126
127 @Override
Thomas Vachuska48e64e42015-09-22 15:32:55 -0700128 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -0700129 Map<Link, Object> riskProfile) {
Thomas Vachuska48e64e42015-09-22 15:32:55 -0700130 return defaultTopology(topology).getDisjointPaths(src, dst, riskProfile);
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -0700131 }
132
133 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +0300134 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
135 DeviceId dst,
136 LinkWeigher weigher,
137 Map<Link, Object> riskProfile) {
138 return defaultTopology(topology).getDisjointPaths(src, dst, weigher, riskProfile);
Nikhil Cheerla2ec191f2015-07-09 12:34:54 -0700139 }
140
141 @Override
tom10262dd2014-09-19 10:51:19 -0700142 public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
143 return defaultTopology(topology).isInfrastructure(connectPoint);
tomdc361b62014-09-09 20:36:52 -0700144 }
145
tom10262dd2014-09-19 10:51:19 -0700146 @Override
147 public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) {
148 return defaultTopology(topology).isBroadcastPoint(connectPoint);
tomdc361b62014-09-09 20:36:52 -0700149 }
150
tom10262dd2014-09-19 10:51:19 -0700151 @Override
152 public TopologyEvent updateTopology(ProviderId providerId,
153 GraphDescription graphDescription,
154 List<Event> reasons) {
tome52ce702014-09-11 00:12:54 -0700155 // First off, make sure that what we're given is indeed newer than
156 // what we already have.
tom97937552014-09-11 10:48:42 -0700157 if (current != null && graphDescription.timestamp() < current.time()) {
tome52ce702014-09-11 00:12:54 -0700158 return null;
159 }
160
161 // Have the default topology construct self from the description data.
162 DefaultTopology newTopology =
tom97937552014-09-11 10:48:42 -0700163 new DefaultTopology(providerId, graphDescription);
tome52ce702014-09-11 00:12:54 -0700164
165 // Promote the new topology to current and return a ready-to-send event.
tom97937552014-09-11 10:48:42 -0700166 synchronized (this) {
167 current = newTopology;
tom95329eb2014-10-06 08:40:06 -0700168 return new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED,
169 current, reasons);
tom97937552014-09-11 10:48:42 -0700170 }
tomdc361b62014-09-09 20:36:52 -0700171 }
172
tom10262dd2014-09-19 10:51:19 -0700173 // Validates the specified topology and returns it as a default
174 private DefaultTopology defaultTopology(Topology topology) {
175 if (topology instanceof DefaultTopology) {
176 return (DefaultTopology) topology;
177 }
178 throw new IllegalArgumentException("Topology class " + topology.getClass() +
179 " not supported");
180 }
181
tom0efbb1d2014-09-09 11:54:28 -0700182}