blob: f21493ffa11d22ad74056e2b496fc5aeffde9dae [file] [log] [blame]
Brian Stanke8e9f8d12016-06-08 14:48:33 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Brian Stanke8e9f8d12016-06-08 14:48:33 -04003 *
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.Topology;
33import org.onosproject.net.topology.TopologyCluster;
34import org.onosproject.net.topology.TopologyEvent;
35import org.onosproject.net.topology.TopologyGraph;
36import org.onosproject.net.topology.TopologyListener;
37import org.onosproject.net.topology.TopologyService;
38
39import java.util.Map;
40import java.util.Set;
41import java.util.stream.Collectors;
42
43import static com.google.common.base.Preconditions.checkArgument;
44import static com.google.common.base.Preconditions.checkNotNull;
45import static org.onosproject.incubator.net.virtual.DefaultVirtualLink.PID;
46
47/**
48 * Topology service implementation built on the virtual network service.
49 */
yoonseon214963b2016-11-21 15:41:07 -080050public class VirtualNetworkTopologyManager
yoonseonc6a69272017-01-12 18:22:20 -080051 extends AbstractVirtualListenerManager<TopologyEvent, TopologyListener>
52 implements TopologyService {
Brian Stanke8e9f8d12016-06-08 14:48:33 -040053
Brian Stanke8e9f8d12016-06-08 14:48:33 -040054 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 Stanke8e9f8d12016-06-08 14:48:33 -040061 /**
62 * Creates a new VirtualNetworkTopologyService object.
63 *
64 * @param virtualNetworkManager virtual network manager service
yoonseonc6a69272017-01-12 18:22:20 -080065 * @param networkId a virtual network identifier
Brian Stanke8e9f8d12016-06-08 14:48:33 -040066 */
yoonseon214963b2016-11-21 15:41:07 -080067 public VirtualNetworkTopologyManager(VirtualNetworkService virtualNetworkManager,
yoonseonc6a69272017-01-12 18:22:20 -080068 NetworkId networkId) {
Yoonseon Hanb14461b2017-03-07 14:08:01 +090069 super(virtualNetworkManager, networkId, TopologyEvent.class);
Brian Stanke8e9f8d12016-06-08 14:48:33 -040070 }
71
72 @Override
73 public Topology currentTopology() {
yoonseonc6a69272017-01-12 18:22:20 -080074 Iterable<Device> devices = manager.getVirtualDevices(networkId())
Brian Stanke8e9f8d12016-06-08 14:48:33 -040075 .stream()
76 .collect(Collectors.toSet());
yoonseonc6a69272017-01-12 18:22:20 -080077 Iterable<Link> links = manager.getVirtualLinks(networkId())
Brian Stanke8e9f8d12016-06-08 14:48:33 -040078 .stream()
79 .collect(Collectors.toSet());
80
yoonseon214963b2016-11-21 15:41:07 -080081 DefaultGraphDescription graph =
82 new DefaultGraphDescription(System.nanoTime(),
83 System.currentTimeMillis(),
84 devices, links);
Brian Stanke8e9f8d12016-06-08 14:48:33 -040085 return new DefaultTopology(PID, graph);
86 }
87
88 @Override
89 public boolean isLatest(Topology topology) {
90 Topology currentTopology = currentTopology();
yoonseon214963b2016-11-21 15:41:07 -080091 return defaultTopology(topology).getGraph()
92 .equals(defaultTopology(currentTopology).getGraph());
Brian Stanke8e9f8d12016-06-08 14:48:33 -040093 }
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
Andrey Komarov2398d962016-09-26 15:11:23 +0300139 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst,
Andrey Komarov2398d962016-09-26 15:11:23 +0300140 LinkWeigher weigher) {
141 checkNotNull(src, DEVICE_ID_NULL);
142 checkNotNull(dst, DEVICE_ID_NULL);
143 checkNotNull(weigher, LINK_WEIGHT_NULL);
144 return defaultTopology(topology).getPaths(src, dst, weigher);
145 }
146
147 @Override
148 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
149 DeviceId dst) {
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400150 checkNotNull(src, DEVICE_ID_NULL);
151 checkNotNull(dst, DEVICE_ID_NULL);
152 return defaultTopology(topology).getDisjointPaths(src, dst);
153 }
154
155 @Override
yoonseon214963b2016-11-21 15:41:07 -0800156 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
Andrey Komarov2398d962016-09-26 15:11:23 +0300157 DeviceId dst,
158 LinkWeigher weigher) {
159 checkNotNull(src, DEVICE_ID_NULL);
160 checkNotNull(dst, DEVICE_ID_NULL);
161 checkNotNull(weigher, LINK_WEIGHT_NULL);
162 return defaultTopology(topology).getDisjointPaths(src, dst, weigher);
163 }
164
165 @Override
166 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
167 DeviceId dst,
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400168 Map<Link, Object> riskProfile) {
169 checkNotNull(src, DEVICE_ID_NULL);
170 checkNotNull(dst, DEVICE_ID_NULL);
171 return defaultTopology(topology).getDisjointPaths(src, dst, riskProfile);
172 }
173
174 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +0300175 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
Andrey Komarov2398d962016-09-26 15:11:23 +0300176 DeviceId dst,
177 LinkWeigher weigher,
178 Map<Link, Object> riskProfile) {
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400179 checkNotNull(src, DEVICE_ID_NULL);
180 checkNotNull(dst, DEVICE_ID_NULL);
Andrey Komarov2398d962016-09-26 15:11:23 +0300181 checkNotNull(weigher, LINK_WEIGHT_NULL);
182 return defaultTopology(topology).getDisjointPaths(src, dst, weigher,
183 riskProfile);
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400184 }
185
186 @Override
187 public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
188 checkNotNull(connectPoint, CONNECTION_POINT_NULL);
189 return defaultTopology(topology).isInfrastructure(connectPoint);
190 }
191
192 @Override
193 public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) {
194 checkNotNull(connectPoint, CONNECTION_POINT_NULL);
195 return defaultTopology(topology).isBroadcastPoint(connectPoint);
196 }
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400197}