blob: c55829d914bf5247ff40798ad55d7ab10c3037c1 [file] [log] [blame]
Brian Stanke8e9f8d12016-06-08 14:48:33 -04001/*
2 * Copyright 2016-present 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
17package org.onosproject.incubator.net.virtual.impl;
18
19import org.onosproject.common.DefaultTopology;
yoonseonc6a69272017-01-12 18:22:20 -080020import org.onosproject.incubator.net.virtual.NetworkId;
Brian Stanke8e9f8d12016-06-08 14:48:33 -040021import org.onosproject.incubator.net.virtual.VirtualNetworkService;
yoonseonc6a69272017-01-12 18:22:20 -080022import org.onosproject.incubator.net.virtual.event.AbstractVirtualListenerManager;
Brian Stanke8e9f8d12016-06-08 14:48:33 -040023import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.Device;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.DisjointPath;
27import org.onosproject.net.Link;
28import org.onosproject.net.Path;
29import org.onosproject.net.topology.ClusterId;
30import org.onosproject.net.topology.DefaultGraphDescription;
Andrey Komarov2398d962016-09-26 15:11:23 +030031import org.onosproject.net.topology.LinkWeigher;
Brian Stanke8e9f8d12016-06-08 14:48:33 -040032import org.onosproject.net.topology.LinkWeight;
33import org.onosproject.net.topology.Topology;
34import org.onosproject.net.topology.TopologyCluster;
35import org.onosproject.net.topology.TopologyEvent;
36import org.onosproject.net.topology.TopologyGraph;
37import org.onosproject.net.topology.TopologyListener;
38import org.onosproject.net.topology.TopologyService;
39
40import java.util.Map;
41import java.util.Set;
42import java.util.stream.Collectors;
43
44import static com.google.common.base.Preconditions.checkArgument;
45import static com.google.common.base.Preconditions.checkNotNull;
46import static org.onosproject.incubator.net.virtual.DefaultVirtualLink.PID;
Andrey Komarov2398d962016-09-26 15:11:23 +030047import static org.onosproject.net.topology.AdapterLinkWeigher.adapt;
Brian Stanke8e9f8d12016-06-08 14:48:33 -040048
49/**
50 * Topology service implementation built on the virtual network service.
51 */
yoonseon214963b2016-11-21 15:41:07 -080052public class VirtualNetworkTopologyManager
yoonseonc6a69272017-01-12 18:22:20 -080053 extends AbstractVirtualListenerManager<TopologyEvent, TopologyListener>
54 implements TopologyService {
Brian Stanke8e9f8d12016-06-08 14:48:33 -040055
Brian Stanke8e9f8d12016-06-08 14:48:33 -040056 private static final String TOPOLOGY_NULL = "Topology cannot be null";
57 private static final String DEVICE_ID_NULL = "Device ID cannot be null";
58 private static final String CLUSTER_ID_NULL = "Cluster ID cannot be null";
59 private static final String CLUSTER_NULL = "Topology cluster cannot be null";
60 private static final String CONNECTION_POINT_NULL = "Connection point cannot be null";
61 private static final String LINK_WEIGHT_NULL = "Link weight cannot be null";
62
Brian Stanke8e9f8d12016-06-08 14:48:33 -040063 /**
64 * Creates a new VirtualNetworkTopologyService object.
65 *
66 * @param virtualNetworkManager virtual network manager service
yoonseonc6a69272017-01-12 18:22:20 -080067 * @param networkId a virtual network identifier
Brian Stanke8e9f8d12016-06-08 14:48:33 -040068 */
yoonseon214963b2016-11-21 15:41:07 -080069 public VirtualNetworkTopologyManager(VirtualNetworkService virtualNetworkManager,
yoonseonc6a69272017-01-12 18:22:20 -080070 NetworkId networkId) {
71 super(virtualNetworkManager, networkId);
Brian Stanke8e9f8d12016-06-08 14:48:33 -040072 }
73
74 @Override
75 public Topology currentTopology() {
yoonseonc6a69272017-01-12 18:22:20 -080076 Iterable<Device> devices = manager.getVirtualDevices(networkId())
Brian Stanke8e9f8d12016-06-08 14:48:33 -040077 .stream()
78 .collect(Collectors.toSet());
yoonseonc6a69272017-01-12 18:22:20 -080079 Iterable<Link> links = manager.getVirtualLinks(networkId())
Brian Stanke8e9f8d12016-06-08 14:48:33 -040080 .stream()
81 .collect(Collectors.toSet());
82
yoonseon214963b2016-11-21 15:41:07 -080083 DefaultGraphDescription graph =
84 new DefaultGraphDescription(System.nanoTime(),
85 System.currentTimeMillis(),
86 devices, links);
Brian Stanke8e9f8d12016-06-08 14:48:33 -040087 return new DefaultTopology(PID, graph);
88 }
89
90 @Override
91 public boolean isLatest(Topology topology) {
92 Topology currentTopology = currentTopology();
yoonseon214963b2016-11-21 15:41:07 -080093 return defaultTopology(topology).getGraph()
94 .equals(defaultTopology(currentTopology).getGraph());
Brian Stanke8e9f8d12016-06-08 14:48:33 -040095 }
96
97 @Override
98 public TopologyGraph getGraph(Topology topology) {
99 return defaultTopology(topology).getGraph();
100 }
101
102 // Validates the specified topology and returns it as a default
103 private DefaultTopology defaultTopology(Topology topology) {
104 checkNotNull(topology, TOPOLOGY_NULL);
105 checkArgument(topology instanceof DefaultTopology,
106 "Topology class %s not supported", topology.getClass());
107 return (DefaultTopology) topology;
108 }
109
110 @Override
111 public Set<TopologyCluster> getClusters(Topology topology) {
112 return defaultTopology(topology).getClusters();
113 }
114
115 @Override
116 public TopologyCluster getCluster(Topology topology, ClusterId clusterId) {
117 checkNotNull(clusterId, CLUSTER_ID_NULL);
118 return defaultTopology(topology).getCluster(clusterId);
119 }
120
121 @Override
122 public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) {
123 checkNotNull(cluster, CLUSTER_NULL);
124 return defaultTopology(topology).getClusterDevices(cluster);
125 }
126
127 @Override
128 public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) {
129 checkNotNull(cluster, CLUSTER_NULL);
130 return defaultTopology(topology).getClusterLinks(cluster);
131 }
132
133 @Override
134 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
135 checkNotNull(src, DEVICE_ID_NULL);
136 checkNotNull(dst, DEVICE_ID_NULL);
137 return defaultTopology(topology).getPaths(src, dst);
138 }
139
140 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +0300141 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst,
142 LinkWeight weight) {
143 return getPaths(topology, src, dst, adapt(weight));
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400144 }
145
146 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +0300147 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst,
148 LinkWeigher weigher) {
149 checkNotNull(src, DEVICE_ID_NULL);
150 checkNotNull(dst, DEVICE_ID_NULL);
151 checkNotNull(weigher, LINK_WEIGHT_NULL);
152 return defaultTopology(topology).getPaths(src, dst, weigher);
153 }
154
155 @Override
156 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
157 DeviceId dst) {
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400158 checkNotNull(src, DEVICE_ID_NULL);
159 checkNotNull(dst, DEVICE_ID_NULL);
160 return defaultTopology(topology).getDisjointPaths(src, dst);
161 }
162
163 @Override
yoonseon214963b2016-11-21 15:41:07 -0800164 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
165 DeviceId dst, LinkWeight weight) {
Andrey Komarov2398d962016-09-26 15:11:23 +0300166 return getDisjointPaths(topology, src, dst, adapt(weight));
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400167 }
168
169 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +0300170 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
171 DeviceId dst,
172 LinkWeigher weigher) {
173 checkNotNull(src, DEVICE_ID_NULL);
174 checkNotNull(dst, DEVICE_ID_NULL);
175 checkNotNull(weigher, LINK_WEIGHT_NULL);
176 return defaultTopology(topology).getDisjointPaths(src, dst, weigher);
177 }
178
179 @Override
180 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
181 DeviceId dst,
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400182 Map<Link, Object> riskProfile) {
183 checkNotNull(src, DEVICE_ID_NULL);
184 checkNotNull(dst, DEVICE_ID_NULL);
185 return defaultTopology(topology).getDisjointPaths(src, dst, riskProfile);
186 }
187
188 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +0300189 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
190 DeviceId dst, LinkWeight weight,
191 Map<Link, Object> riskProfile) {
192 return getDisjointPaths(topology, src, dst, adapt(weight), riskProfile);
193 }
194
195 @Override
196 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
197 DeviceId dst,
198 LinkWeigher weigher,
199 Map<Link, Object> riskProfile) {
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400200 checkNotNull(src, DEVICE_ID_NULL);
201 checkNotNull(dst, DEVICE_ID_NULL);
Andrey Komarov2398d962016-09-26 15:11:23 +0300202 checkNotNull(weigher, LINK_WEIGHT_NULL);
203 return defaultTopology(topology).getDisjointPaths(src, dst, weigher,
204 riskProfile);
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400205 }
206
207 @Override
208 public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
209 checkNotNull(connectPoint, CONNECTION_POINT_NULL);
210 return defaultTopology(topology).isInfrastructure(connectPoint);
211 }
212
213 @Override
214 public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) {
215 checkNotNull(connectPoint, CONNECTION_POINT_NULL);
216 return defaultTopology(topology).isBroadcastPoint(connectPoint);
217 }
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400218}