blob: e361a3bae049060c49f30f160eb06a23ddb3fc4d [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;
31import org.onosproject.net.topology.LinkWeight;
32import 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) {
69 super(virtualNetworkManager, networkId);
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
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
yoonseon214963b2016-11-21 15:41:07 -0800154 public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
155 DeviceId dst, LinkWeight weight) {
Brian Stanke8e9f8d12016-06-08 14:48:33 -0400156 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 Stanke8e9f8d12016-06-08 14:48:33 -0400190}