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; |
| 31 | import org.onosproject.net.topology.LinkWeight; |
| 32 | import org.onosproject.net.topology.Topology; |
| 33 | import org.onosproject.net.topology.TopologyCluster; |
| 34 | import org.onosproject.net.topology.TopologyEvent; |
| 35 | import org.onosproject.net.topology.TopologyGraph; |
| 36 | import org.onosproject.net.topology.TopologyListener; |
| 37 | import org.onosproject.net.topology.TopologyService; |
| 38 | |
| 39 | import java.util.Map; |
| 40 | import java.util.Set; |
| 41 | import java.util.stream.Collectors; |
| 42 | |
| 43 | import static com.google.common.base.Preconditions.checkArgument; |
| 44 | import static com.google.common.base.Preconditions.checkNotNull; |
| 45 | import static org.onosproject.incubator.net.virtual.DefaultVirtualLink.PID; |
| 46 | |
| 47 | /** |
| 48 | * Topology service implementation built on the virtual network service. |
| 49 | */ |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 50 | public class VirtualNetworkTopologyManager |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame^] | 51 | extends AbstractVirtualListenerManager<TopologyEvent, TopologyListener> |
| 52 | implements TopologyService { |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 53 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 54 | private static final String TOPOLOGY_NULL = "Topology cannot be null"; |
| 55 | private static final String DEVICE_ID_NULL = "Device ID cannot be null"; |
| 56 | private static final String CLUSTER_ID_NULL = "Cluster ID cannot be null"; |
| 57 | private static final String CLUSTER_NULL = "Topology cluster cannot be null"; |
| 58 | private static final String CONNECTION_POINT_NULL = "Connection point cannot be null"; |
| 59 | private static final String LINK_WEIGHT_NULL = "Link weight cannot be null"; |
| 60 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 61 | /** |
| 62 | * Creates a new VirtualNetworkTopologyService object. |
| 63 | * |
| 64 | * @param virtualNetworkManager virtual network manager service |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame^] | 65 | * @param networkId a virtual network identifier |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 66 | */ |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 67 | public VirtualNetworkTopologyManager(VirtualNetworkService virtualNetworkManager, |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame^] | 68 | NetworkId networkId) { |
| 69 | super(virtualNetworkManager, networkId); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public Topology currentTopology() { |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame^] | 74 | Iterable<Device> devices = manager.getVirtualDevices(networkId()) |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 75 | .stream() |
| 76 | .collect(Collectors.toSet()); |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame^] | 77 | Iterable<Link> links = manager.getVirtualLinks(networkId()) |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 78 | .stream() |
| 79 | .collect(Collectors.toSet()); |
| 80 | |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 81 | DefaultGraphDescription graph = |
| 82 | new DefaultGraphDescription(System.nanoTime(), |
| 83 | System.currentTimeMillis(), |
| 84 | devices, links); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 85 | return new DefaultTopology(PID, graph); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public boolean isLatest(Topology topology) { |
| 90 | Topology currentTopology = currentTopology(); |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 91 | return defaultTopology(topology).getGraph() |
| 92 | .equals(defaultTopology(currentTopology).getGraph()); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public TopologyGraph getGraph(Topology topology) { |
| 97 | return defaultTopology(topology).getGraph(); |
| 98 | } |
| 99 | |
| 100 | // Validates the specified topology and returns it as a default |
| 101 | private DefaultTopology defaultTopology(Topology topology) { |
| 102 | checkNotNull(topology, TOPOLOGY_NULL); |
| 103 | checkArgument(topology instanceof DefaultTopology, |
| 104 | "Topology class %s not supported", topology.getClass()); |
| 105 | return (DefaultTopology) topology; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public Set<TopologyCluster> getClusters(Topology topology) { |
| 110 | return defaultTopology(topology).getClusters(); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public TopologyCluster getCluster(Topology topology, ClusterId clusterId) { |
| 115 | checkNotNull(clusterId, CLUSTER_ID_NULL); |
| 116 | return defaultTopology(topology).getCluster(clusterId); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) { |
| 121 | checkNotNull(cluster, CLUSTER_NULL); |
| 122 | return defaultTopology(topology).getClusterDevices(cluster); |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) { |
| 127 | checkNotNull(cluster, CLUSTER_NULL); |
| 128 | return defaultTopology(topology).getClusterLinks(cluster); |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) { |
| 133 | checkNotNull(src, DEVICE_ID_NULL); |
| 134 | checkNotNull(dst, DEVICE_ID_NULL); |
| 135 | return defaultTopology(topology).getPaths(src, dst); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) { |
| 140 | checkNotNull(src, DEVICE_ID_NULL); |
| 141 | checkNotNull(dst, DEVICE_ID_NULL); |
| 142 | checkNotNull(weight, LINK_WEIGHT_NULL); |
| 143 | return defaultTopology(topology).getPaths(src, dst, weight); |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst) { |
| 148 | checkNotNull(src, DEVICE_ID_NULL); |
| 149 | checkNotNull(dst, DEVICE_ID_NULL); |
| 150 | return defaultTopology(topology).getDisjointPaths(src, dst); |
| 151 | } |
| 152 | |
| 153 | @Override |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 154 | public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, |
| 155 | DeviceId dst, LinkWeight weight) { |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 156 | checkNotNull(src, DEVICE_ID_NULL); |
| 157 | checkNotNull(dst, DEVICE_ID_NULL); |
| 158 | checkNotNull(weight, LINK_WEIGHT_NULL); |
| 159 | return defaultTopology(topology).getDisjointPaths(src, dst, weight); |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst, |
| 164 | Map<Link, Object> riskProfile) { |
| 165 | checkNotNull(src, DEVICE_ID_NULL); |
| 166 | checkNotNull(dst, DEVICE_ID_NULL); |
| 167 | return defaultTopology(topology).getDisjointPaths(src, dst, riskProfile); |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst, |
| 172 | LinkWeight weight, Map<Link, Object> riskProfile) { |
| 173 | checkNotNull(src, DEVICE_ID_NULL); |
| 174 | checkNotNull(dst, DEVICE_ID_NULL); |
| 175 | checkNotNull(weight, LINK_WEIGHT_NULL); |
| 176 | return defaultTopology(topology).getDisjointPaths(src, dst, weight, riskProfile); |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) { |
| 181 | checkNotNull(connectPoint, CONNECTION_POINT_NULL); |
| 182 | return defaultTopology(topology).isInfrastructure(connectPoint); |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) { |
| 187 | checkNotNull(connectPoint, CONNECTION_POINT_NULL); |
| 188 | return defaultTopology(topology).isBroadcastPoint(connectPoint); |
| 189 | } |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 190 | } |