Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Sho SHIMIZU | 6c28f83 | 2015-02-20 16:12:19 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.impl.compiler; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 17 | |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
Sho SHIMIZU | c25a008 | 2015-10-27 17:06:29 -0700 | [diff] [blame^] | 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import com.google.common.collect.Iterables; |
| 21 | import com.google.common.collect.Sets; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Activate; |
Sho SHIMIZU | 9a2b829 | 2015-10-28 13:00:16 -0700 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Component; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Deactivate; |
| 25 | import org.apache.felix.scr.annotations.Reference; |
| 26 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 27 | import org.onlab.util.Frequency; |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 28 | import org.onosproject.net.AnnotationKeys; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 29 | import org.onosproject.net.ConnectPoint; |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 30 | import org.onosproject.net.DeviceId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.net.Link; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 32 | import org.onosproject.net.OchPort; |
| 33 | import org.onosproject.net.OchSignal; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 34 | import org.onosproject.net.OchSignalType; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 35 | import org.onosproject.net.OmsPort; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 36 | import org.onosproject.net.Path; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 37 | import org.onosproject.net.Port; |
| 38 | import org.onosproject.net.device.DeviceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 39 | import org.onosproject.net.intent.Intent; |
| 40 | import org.onosproject.net.intent.IntentCompiler; |
| 41 | import org.onosproject.net.intent.IntentExtensionService; |
| 42 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 43 | import org.onosproject.net.intent.OpticalPathIntent; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 44 | import org.onosproject.net.intent.impl.IntentCompilationException; |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 45 | import org.onosproject.net.newresource.ResourcePath; |
| 46 | import org.onosproject.net.newresource.ResourceService; |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 47 | import org.onosproject.net.resource.ResourceType; |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 48 | import org.onosproject.net.resource.link.DefaultLinkResourceRequest; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 49 | import org.onosproject.net.resource.link.LambdaResource; |
| 50 | import org.onosproject.net.resource.link.LambdaResourceAllocation; |
Sho SHIMIZU | c25a008 | 2015-10-27 17:06:29 -0700 | [diff] [blame^] | 51 | import org.onosproject.net.resource.link.LambdaResourceRequest; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 52 | import org.onosproject.net.resource.link.LinkResourceAllocations; |
| 53 | import org.onosproject.net.resource.link.LinkResourceRequest; |
| 54 | import org.onosproject.net.resource.link.LinkResourceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 55 | import org.onosproject.net.topology.LinkWeight; |
| 56 | import org.onosproject.net.topology.Topology; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 57 | import org.onosproject.net.topology.TopologyService; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 58 | import org.slf4j.Logger; |
| 59 | import org.slf4j.LoggerFactory; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 60 | |
Sho SHIMIZU | c25a008 | 2015-10-27 17:06:29 -0700 | [diff] [blame^] | 61 | import java.util.Collections; |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 62 | import java.util.List; |
| 63 | import java.util.Set; |
Sho SHIMIZU | 280e791 | 2015-09-29 13:42:03 -0700 | [diff] [blame] | 64 | import java.util.stream.Collectors; |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 65 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 66 | import static com.google.common.base.Preconditions.checkArgument; |
| 67 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 68 | /** |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 69 | * An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}. |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 70 | */ |
Ray Milkey | e609941 | 2015-10-05 10:53:17 -0700 | [diff] [blame] | 71 | // For now, remove component designation until dependency on the new resource manager is available. |
Sho SHIMIZU | 9a2b829 | 2015-10-28 13:00:16 -0700 | [diff] [blame] | 72 | @Component(immediate = true) |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 73 | public class OpticalConnectivityIntentCompiler implements IntentCompiler<OpticalConnectivityIntent> { |
| 74 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 75 | protected static final Logger log = LoggerFactory.getLogger(OpticalConnectivityIntentCompiler.class); |
| 76 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 78 | protected IntentExtensionService intentManager; |
| 79 | |
| 80 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 81 | protected TopologyService topologyService; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 82 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 83 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 84 | protected DeviceService deviceService; |
| 85 | |
| 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 87 | protected ResourceService resourceService; |
| 88 | |
| 89 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 90 | protected LinkResourceService linkResourceService; |
| 91 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 92 | @Activate |
| 93 | public void activate() { |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 94 | intentManager.registerCompiler(OpticalConnectivityIntent.class, this); |
| 95 | } |
| 96 | |
| 97 | @Deactivate |
| 98 | public void deactivate() { |
| 99 | intentManager.unregisterCompiler(OpticalConnectivityIntent.class); |
| 100 | } |
| 101 | |
| 102 | @Override |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 103 | public List<Intent> compile(OpticalConnectivityIntent intent, |
| 104 | List<Intent> installable, |
| 105 | Set<LinkResourceAllocations> resources) { |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 106 | // Check if source and destination are optical OCh ports |
| 107 | ConnectPoint src = intent.getSrc(); |
| 108 | ConnectPoint dst = intent.getDst(); |
| 109 | Port srcPort = deviceService.getPort(src.deviceId(), src.port()); |
| 110 | Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); |
| 111 | checkArgument(srcPort instanceof OchPort); |
| 112 | checkArgument(dstPort instanceof OchPort); |
| 113 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 114 | log.debug("Compiling optical connectivity intent between {} and {}", src, dst); |
| 115 | |
| 116 | // Reserve OCh ports |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 117 | ResourcePath srcPortPath = new ResourcePath(src.deviceId(), src.port()); |
| 118 | ResourcePath dstPortPath = new ResourcePath(dst.deviceId(), dst.port()); |
| 119 | List<org.onosproject.net.newresource.ResourceAllocation> allocation = |
| 120 | resourceService.allocate(intent.id(), srcPortPath, dstPortPath); |
| 121 | if (allocation.isEmpty()) { |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 122 | throw new IntentCompilationException("Unable to reserve ports for intent " + intent); |
| 123 | } |
| 124 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 125 | // Calculate available light paths |
| 126 | Set<Path> paths = getOpticalPaths(intent); |
| 127 | |
| 128 | // Use first path that can be successfully reserved |
| 129 | for (Path path : paths) { |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 130 | |
| 131 | // Static or dynamic lambda allocation |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 132 | String staticLambda = srcPort.annotations().value(AnnotationKeys.STATIC_LAMBDA); |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 133 | OchPort srcOchPort = (OchPort) srcPort; |
| 134 | OchPort dstOchPort = (OchPort) dstPort; |
| 135 | OchSignal ochSignal; |
| 136 | |
| 137 | // FIXME: need to actually reserve the lambda for static lambda's |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 138 | if (staticLambda != null) { |
HIGUCHI Yuta | 4a6a70a | 2015-09-04 14:42:10 -0700 | [diff] [blame] | 139 | ochSignal = new OchSignal(Frequency.ofHz(Long.parseLong(staticLambda)), |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 140 | srcOchPort.lambda().channelSpacing(), |
| 141 | srcOchPort.lambda().slotGranularity()); |
| 142 | } else if (!srcOchPort.isTunable() || !dstOchPort.isTunable()) { |
| 143 | // FIXME: also check OCh port |
| 144 | ochSignal = srcOchPort.lambda(); |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 145 | } else { |
| 146 | // Request and reserve lambda on path |
| 147 | LinkResourceAllocations linkAllocs = assignWavelength(intent, path); |
| 148 | if (linkAllocs == null) { |
| 149 | continue; |
| 150 | } |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 151 | LambdaResourceAllocation lambdaAlloc = getWavelength(path, linkAllocs); |
| 152 | OmsPort omsPort = (OmsPort) deviceService.getPort(path.src().deviceId(), path.src().port()); |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 153 | ochSignal = new OchSignal(lambdaAlloc.lambda().toInt(), omsPort.maxFrequency(), omsPort.grid()); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 156 | // Create installable optical path intent |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 157 | // Only support fixed grid for now |
| 158 | OchSignalType signalType = OchSignalType.FIXED_GRID; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 159 | |
| 160 | Intent newIntent = OpticalPathIntent.builder() |
| 161 | .appId(intent.appId()) |
| 162 | .src(intent.getSrc()) |
| 163 | .dst(intent.getDst()) |
| 164 | .path(path) |
| 165 | .lambda(ochSignal) |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 166 | .signalType(signalType) |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 167 | .bidirectional(intent.isBidirectional()) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 168 | .build(); |
| 169 | |
| 170 | return ImmutableList.of(newIntent); |
| 171 | } |
| 172 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 173 | // Release port allocations if unsuccessful |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 174 | resourceService.release(intent.id()); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 175 | |
| 176 | throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 179 | /** |
| 180 | * Find the lambda allocated to the path. |
| 181 | * |
| 182 | * @param path the path |
| 183 | * @param linkAllocs the link allocations |
Sho SHIMIZU | 5a6e2e5 | 2015-09-09 15:04:12 -0700 | [diff] [blame] | 184 | * @return lambda allocated to the given path |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 185 | */ |
| 186 | private LambdaResourceAllocation getWavelength(Path path, LinkResourceAllocations linkAllocs) { |
Sho SHIMIZU | 280e791 | 2015-09-29 13:42:03 -0700 | [diff] [blame] | 187 | return path.links().stream() |
| 188 | .flatMap(x -> linkAllocs.getResourceAllocation(x).stream()) |
| 189 | .filter(x -> x.type() == ResourceType.LAMBDA) |
| 190 | .findFirst() |
| 191 | .map(x -> (LambdaResourceAllocation) x) |
| 192 | .orElse(null); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Request and reserve first available wavelength across path. |
| 197 | * |
| 198 | * @param path path in WDM topology |
| 199 | * @return first available lambda resource allocation |
| 200 | */ |
| 201 | private LinkResourceAllocations assignWavelength(Intent intent, Path path) { |
Sho SHIMIZU | c25a008 | 2015-10-27 17:06:29 -0700 | [diff] [blame^] | 202 | Set<LambdaResource> lambdas = findCommonLambdasOverLinks(path.links()); |
| 203 | if (lambdas.isEmpty()) { |
| 204 | return null; |
| 205 | } |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 206 | |
Sho SHIMIZU | c25a008 | 2015-10-27 17:06:29 -0700 | [diff] [blame^] | 207 | LambdaResource minLambda = findFirstLambda(lambdas); |
| 208 | |
| 209 | LinkResourceRequest request = |
| 210 | DefaultLinkResourceRequest.builder(intent.id(), path.links()) |
| 211 | .addLambdaRequest(minLambda) |
| 212 | .build(); |
| 213 | |
| 214 | LinkResourceAllocations allocations = linkResourceService.requestResources(request); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 215 | |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 216 | if (!checkWavelengthContinuity(allocations, path)) { |
| 217 | linkResourceService.releaseResources(allocations); |
| 218 | return null; |
| 219 | } |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 220 | |
| 221 | return allocations; |
| 222 | } |
| 223 | |
Sho SHIMIZU | c25a008 | 2015-10-27 17:06:29 -0700 | [diff] [blame^] | 224 | private Set<LambdaResource> findCommonLambdasOverLinks(List<Link> links) { |
| 225 | return links.stream() |
| 226 | .map(x -> ImmutableSet.copyOf(linkResourceService.getAvailableResources(x))) |
| 227 | .map(x -> Sets.filter(x, req -> req instanceof LambdaResourceRequest)) |
| 228 | .map(x -> Iterables.transform(x, req -> (LambdaResourceRequest) req)) |
| 229 | .map(x -> Iterables.transform(x, LambdaResourceRequest::lambda)) |
| 230 | .map(x -> (Set<LambdaResource>) ImmutableSet.copyOf(x)) |
| 231 | .reduce(Sets::intersection) |
| 232 | .orElse(Collections.emptySet()); |
| 233 | } |
| 234 | |
| 235 | private LambdaResource findFirstLambda(Set<LambdaResource> lambdas) { |
| 236 | return lambdas.stream() |
| 237 | .findFirst() |
| 238 | .get(); |
| 239 | } |
| 240 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 241 | /** |
| 242 | * Checks wavelength continuity constraint across path, i.e., an identical lambda is used on all links. |
| 243 | * @return true if wavelength continuity is met, false otherwise |
| 244 | */ |
| 245 | private boolean checkWavelengthContinuity(LinkResourceAllocations allocations, Path path) { |
| 246 | if (allocations == null) { |
| 247 | return false; |
| 248 | } |
| 249 | |
Sho SHIMIZU | 280e791 | 2015-09-29 13:42:03 -0700 | [diff] [blame] | 250 | List<LambdaResource> lambdas = path.links().stream() |
| 251 | .flatMap(x -> allocations.getResourceAllocation(x).stream()) |
| 252 | .filter(x -> x.type() == ResourceType.LAMBDA) |
| 253 | .map(x -> ((LambdaResourceAllocation) x).lambda()) |
| 254 | .collect(Collectors.toList()); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 255 | |
Sho SHIMIZU | 280e791 | 2015-09-29 13:42:03 -0700 | [diff] [blame] | 256 | LambdaResource lambda = null; |
| 257 | for (LambdaResource nextLambda: lambdas) { |
| 258 | if (nextLambda == null) { |
| 259 | return false; |
| 260 | } |
| 261 | if (lambda == null) { |
| 262 | lambda = nextLambda; |
| 263 | continue; |
| 264 | } |
| 265 | if (!lambda.equals(nextLambda)) { |
| 266 | return false; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
| 270 | return true; |
| 271 | } |
| 272 | |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 273 | private ConnectPoint staticPort(ConnectPoint connectPoint) { |
| 274 | Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); |
| 275 | |
| 276 | String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT); |
| 277 | |
| 278 | // FIXME: need a better way to match the port |
| 279 | if (staticPort != null) { |
| 280 | for (Port p : deviceService.getPorts(connectPoint.deviceId())) { |
| 281 | if (staticPort.equals(p.number().name())) { |
| 282 | return new ConnectPoint(p.element().id(), p.number()); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | return null; |
| 288 | } |
| 289 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 290 | /** |
| 291 | * Calculates optical paths in WDM topology. |
| 292 | * |
| 293 | * @param intent optical connectivity intent |
| 294 | * @return set of paths in WDM topology |
| 295 | */ |
| 296 | private Set<Path> getOpticalPaths(OpticalConnectivityIntent intent) { |
| 297 | // Route in WDM topology |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 298 | Topology topology = topologyService.currentTopology(); |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame] | 299 | LinkWeight weight = edge -> { |
| 300 | // Disregard inactive or non-optical links |
| 301 | if (edge.link().state() == Link.State.INACTIVE) { |
| 302 | return -1; |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 303 | } |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame] | 304 | if (edge.link().type() != Link.Type.OPTICAL) { |
| 305 | return -1; |
| 306 | } |
| 307 | // Adhere to static port mappings |
| 308 | DeviceId srcDeviceId = edge.link().src().deviceId(); |
| 309 | if (srcDeviceId.equals(intent.getSrc().deviceId())) { |
| 310 | ConnectPoint srcStaticPort = staticPort(intent.getSrc()); |
| 311 | if (srcStaticPort != null) { |
| 312 | return srcStaticPort.equals(edge.link().src()) ? 1 : -1; |
| 313 | } |
| 314 | } |
| 315 | DeviceId dstDeviceId = edge.link().dst().deviceId(); |
| 316 | if (dstDeviceId.equals(intent.getDst().deviceId())) { |
| 317 | ConnectPoint dstStaticPort = staticPort(intent.getDst()); |
| 318 | if (dstStaticPort != null) { |
| 319 | return dstStaticPort.equals(edge.link().dst()) ? 1 : -1; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | return 1; |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 324 | }; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 325 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 326 | ConnectPoint start = intent.getSrc(); |
| 327 | ConnectPoint end = intent.getDst(); |
Thomas Vachuska | 425a2d7 | 2014-10-29 11:28:28 -0700 | [diff] [blame] | 328 | Set<Path> paths = topologyService.getPaths(topology, start.deviceId(), |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 329 | end.deviceId(), weight); |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 330 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 331 | return paths; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 332 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 333 | } |