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