Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.incubator.net.virtual.impl; |
| 18 | |
| 19 | import org.onosproject.common.DefaultTopology; |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 20 | import org.onosproject.incubator.net.virtual.NetworkId; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 21 | import org.onosproject.incubator.net.virtual.VirtualNetworkService; |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 22 | import org.onosproject.incubator.net.virtual.event.AbstractVirtualListenerManager; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 23 | import org.onosproject.net.ConnectPoint; |
| 24 | import org.onosproject.net.Device; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.DisjointPath; |
| 27 | import org.onosproject.net.Link; |
| 28 | import org.onosproject.net.Path; |
| 29 | import org.onosproject.net.topology.ClusterId; |
| 30 | import org.onosproject.net.topology.DefaultGraphDescription; |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 31 | import org.onosproject.net.topology.LinkWeigher; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 32 | import org.onosproject.net.topology.LinkWeight; |
| 33 | import org.onosproject.net.topology.Topology; |
| 34 | import org.onosproject.net.topology.TopologyCluster; |
| 35 | import org.onosproject.net.topology.TopologyEvent; |
| 36 | import org.onosproject.net.topology.TopologyGraph; |
| 37 | import org.onosproject.net.topology.TopologyListener; |
| 38 | import org.onosproject.net.topology.TopologyService; |
| 39 | |
| 40 | import java.util.Map; |
| 41 | import java.util.Set; |
| 42 | import java.util.stream.Collectors; |
| 43 | |
| 44 | import static com.google.common.base.Preconditions.checkArgument; |
| 45 | import static com.google.common.base.Preconditions.checkNotNull; |
| 46 | import static org.onosproject.incubator.net.virtual.DefaultVirtualLink.PID; |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 47 | import static org.onosproject.net.topology.AdapterLinkWeigher.adapt; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Topology service implementation built on the virtual network service. |
| 51 | */ |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 52 | public class VirtualNetworkTopologyManager |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 53 | extends AbstractVirtualListenerManager<TopologyEvent, TopologyListener> |
| 54 | implements TopologyService { |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 55 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 56 | 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 Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 63 | /** |
| 64 | * Creates a new VirtualNetworkTopologyService object. |
| 65 | * |
| 66 | * @param virtualNetworkManager virtual network manager service |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 67 | * @param networkId a virtual network identifier |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 68 | */ |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 69 | public VirtualNetworkTopologyManager(VirtualNetworkService virtualNetworkManager, |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 70 | NetworkId networkId) { |
Yoonseon Han | b14461b | 2017-03-07 14:08:01 +0900 | [diff] [blame] | 71 | super(virtualNetworkManager, networkId, TopologyEvent.class); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public Topology currentTopology() { |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 76 | Iterable<Device> devices = manager.getVirtualDevices(networkId()) |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 77 | .stream() |
| 78 | .collect(Collectors.toSet()); |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 79 | Iterable<Link> links = manager.getVirtualLinks(networkId()) |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 80 | .stream() |
| 81 | .collect(Collectors.toSet()); |
| 82 | |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 83 | DefaultGraphDescription graph = |
| 84 | new DefaultGraphDescription(System.nanoTime(), |
| 85 | System.currentTimeMillis(), |
| 86 | devices, links); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 87 | return new DefaultTopology(PID, graph); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public boolean isLatest(Topology topology) { |
| 92 | Topology currentTopology = currentTopology(); |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 93 | return defaultTopology(topology).getGraph() |
| 94 | .equals(defaultTopology(currentTopology).getGraph()); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 95 | } |
| 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 Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 141 | public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, |
| 142 | LinkWeight weight) { |
| 143 | return getPaths(topology, src, dst, adapt(weight)); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | @Override |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 147 | 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 Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 158 | checkNotNull(src, DEVICE_ID_NULL); |
| 159 | checkNotNull(dst, DEVICE_ID_NULL); |
| 160 | return defaultTopology(topology).getDisjointPaths(src, dst); |
| 161 | } |
| 162 | |
| 163 | @Override |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 164 | public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, |
| 165 | DeviceId dst, LinkWeight weight) { |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 166 | return getDisjointPaths(topology, src, dst, adapt(weight)); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @Override |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 170 | 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 Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 182 | 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 Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 189 | 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 Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 200 | checkNotNull(src, DEVICE_ID_NULL); |
| 201 | checkNotNull(dst, DEVICE_ID_NULL); |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 202 | checkNotNull(weigher, LINK_WEIGHT_NULL); |
| 203 | return defaultTopology(topology).getDisjointPaths(src, dst, weigher, |
| 204 | riskProfile); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 205 | } |
| 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 Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 218 | } |