blob: 5183a3edcaab121e78cd90a7659f051fa32f6d13 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Yuta HIGUCHId95d5902016-06-27 00:18:45 -070016package org.onosproject.net.optical.intent.impl.compiler;
weibitf32383b2014-10-22 10:17:31 -070017
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -070018import com.google.common.collect.ImmutableList;
Sho SHIMIZUc25a0082015-10-27 17:06:29 -070019import com.google.common.collect.ImmutableSet;
Sho SHIMIZU07ade9b2016-01-28 19:38:50 -080020import com.google.common.collect.Maps;
Sho SHIMIZUc25a0082015-10-27 17:06:29 -070021import com.google.common.collect.Sets;
weibitf32383b2014-10-22 10:17:31 -070022import org.apache.felix.scr.annotations.Activate;
Sho SHIMIZU9a2b8292015-10-28 13:00:16 -070023import org.apache.felix.scr.annotations.Component;
weibitf32383b2014-10-22 10:17:31 -070024import org.apache.felix.scr.annotations.Deactivate;
25import org.apache.felix.scr.annotations.Reference;
26import org.apache.felix.scr.annotations.ReferenceCardinality;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070027import org.onlab.util.Frequency;
Marc De Leenheer723f5532015-06-03 20:16:17 -070028import org.onosproject.net.AnnotationKeys;
Marc De Leenheer2c305302015-12-07 21:37:44 -080029import org.onosproject.net.ChannelSpacing;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.net.ConnectPoint;
Marc De Leenheer2c305302015-12-07 21:37:44 -080031import org.onosproject.net.DefaultOchSignalComparator;
Marc De Leenheer723f5532015-06-03 20:16:17 -070032import org.onosproject.net.DeviceId;
Brian O'Connorabafb502014-12-02 22:26:20 -080033import org.onosproject.net.Link;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070034import org.onosproject.net.OchSignal;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070035import org.onosproject.net.OchSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080036import org.onosproject.net.Path;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070037import org.onosproject.net.Port;
38import org.onosproject.net.device.DeviceService;
Brian O'Connorabafb502014-12-02 22:26:20 -080039import org.onosproject.net.intent.Intent;
40import org.onosproject.net.intent.IntentCompiler;
41import org.onosproject.net.intent.IntentExtensionService;
42import org.onosproject.net.intent.OpticalConnectivityIntent;
43import org.onosproject.net.intent.OpticalPathIntent;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080044import org.onosproject.net.optical.OchPort;
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080045import org.onosproject.net.resource.ResourceAllocation;
46import org.onosproject.net.resource.Resource;
47import org.onosproject.net.resource.ResourceService;
48import org.onosproject.net.resource.Resources;
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -070049import org.onosproject.net.topology.AdapterLinkWeigher;
Brian O'Connorabafb502014-12-02 22:26:20 -080050import org.onosproject.net.topology.LinkWeight;
51import org.onosproject.net.topology.Topology;
Yuta HIGUCHId95d5902016-06-27 00:18:45 -070052import org.onosproject.net.topology.TopologyEdge;
Brian O'Connorabafb502014-12-02 22:26:20 -080053import org.onosproject.net.topology.TopologyService;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070054import org.slf4j.Logger;
55import org.slf4j.LoggerFactory;
weibitf32383b2014-10-22 10:17:31 -070056
Marc De Leenheer2c305302015-12-07 21:37:44 -080057import java.util.ArrayList;
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -070058import java.util.Collection;
Sho SHIMIZUc25a0082015-10-27 17:06:29 -070059import java.util.Collections;
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -070060import java.util.LinkedList;
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -070061import java.util.List;
Sho SHIMIZU07ade9b2016-01-28 19:38:50 -080062import java.util.Map;
63import java.util.Optional;
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -070064import java.util.Set;
Sho SHIMIZU280e7912015-09-29 13:42:03 -070065import java.util.stream.Collectors;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080066import java.util.stream.Stream;
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -070067
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070068import static com.google.common.base.Preconditions.checkArgument;
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -070069import static org.onosproject.net.OchSignal.toFlexGrid;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080070import static org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070071
weibitf32383b2014-10-22 10:17:31 -070072/**
Brian O'Connorabafb502014-12-02 22:26:20 -080073 * An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}.
weibitf32383b2014-10-22 10:17:31 -070074 */
Sho SHIMIZU9a2b8292015-10-28 13:00:16 -070075@Component(immediate = true)
weibitf32383b2014-10-22 10:17:31 -070076public class OpticalConnectivityIntentCompiler implements IntentCompiler<OpticalConnectivityIntent> {
77
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070078 protected static final Logger log = LoggerFactory.getLogger(OpticalConnectivityIntentCompiler.class);
Marc De Leenheer2c305302015-12-07 21:37:44 -080079 // By default, allocate 50 GHz lambdas (4 slots of 12.5 GHz) for each intent.
80 private static final int SLOT_COUNT = 4;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070081
weibitf32383b2014-10-22 10:17:31 -070082 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
83 protected IntentExtensionService intentManager;
84
85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
weibit7e583462014-10-23 10:14:05 -070086 protected TopologyService topologyService;
weibitf32383b2014-10-22 10:17:31 -070087
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070088 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
89 protected DeviceService deviceService;
90
91 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sho SHIMIZU5c16df82015-09-29 12:52:07 -070092 protected ResourceService resourceService;
93
weibitf32383b2014-10-22 10:17:31 -070094 @Activate
95 public void activate() {
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080096 deviceService = opticalView(deviceService);
weibitf32383b2014-10-22 10:17:31 -070097 intentManager.registerCompiler(OpticalConnectivityIntent.class, this);
98 }
99
100 @Deactivate
101 public void deactivate() {
102 intentManager.unregisterCompiler(OpticalConnectivityIntent.class);
103 }
104
105 @Override
Brian O'Connorfa81eae2014-10-30 13:20:05 -0700106 public List<Intent> compile(OpticalConnectivityIntent intent,
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800107 List<Intent> installable) {
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700108 // Check if source and destination are optical OCh ports
109 ConnectPoint src = intent.getSrc();
110 ConnectPoint dst = intent.getDst();
111 Port srcPort = deviceService.getPort(src.deviceId(), src.port());
112 Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
113 checkArgument(srcPort instanceof OchPort);
114 checkArgument(dstPort instanceof OchPort);
115
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700116 log.debug("Compiling optical connectivity intent between {} and {}", src, dst);
117
Rimon Ashkenazyf0699702016-01-17 19:28:49 +0200118 // Release of intent resources here is only a temporary solution for handling the
119 // case of recompiling due to intent restoration (when intent state is FAILED).
120 // TODO: try to release intent resources in IntentManager.
Yuta HIGUCHI65d9d0e2017-05-04 12:44:32 -0700121 resourceService.release(intent.key());
Rimon Ashkenazyf0699702016-01-17 19:28:49 +0200122
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800123 // Check OCh port availability
Sho SHIMIZU460b9722016-01-28 10:48:26 -0800124 Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
125 Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800126 // If ports are not available, compilation fails
127 if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
Yuta HIGUCHId95d5902016-06-27 00:18:45 -0700128 throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700129 }
130
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800131 List<Resource> resources = new ArrayList<>();
132 resources.add(srcPortResource);
133 resources.add(dstPortResource);
134
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700135 // Calculate available light paths
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -0700136 Stream<Path> paths = getOpticalPaths(intent);
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800137
Sho SHIMIZUd978d9a2016-01-28 08:55:49 -0800138 // Static or dynamic lambda allocation
139 String staticLambda = srcPort.annotations().value(AnnotationKeys.STATIC_LAMBDA);
140 OchPort srcOchPort = (OchPort) srcPort;
141 OchPort dstOchPort = (OchPort) dstPort;
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800142
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800143 // FIXME: need to actually reserve the lambda for static lambda's
144 // static lambda case: early return
145 if (staticLambda != null) {
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800146
147 OchSignal lambda = new OchSignal(Frequency.ofHz(Long.parseLong(staticLambda)),
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -0700148 srcOchPort.lambda().channelSpacing(),
149 srcOchPort.lambda().slotGranularity());
150 log.debug("Using staticalluy assigned lambda : {}", lambda);
151
152 List<Resource> res = new ArrayList<>();
153
154 Path satPath = paths.filter(path -> {
155 // FIXME trimming both ends (staticLambda assigned ports)
156 // Proper fix is to let device advertise static lambda as resource.
157 LinkedList<Link> links = new LinkedList<>(path.links());
158 links.pollFirst();
159 links.pollLast();
160
161 List<Resource> r = convertToResources(links, toFlexGrid(lambda));
162 if (r.stream().allMatch(resourceService::isAvailable)) {
163 // FIXME bad practice to have side-effect during stream
164 res.addAll(r);
165 return true;
166 }
167 return false;
168 }).findFirst().orElse(null);
169
170 if (satPath == null) {
171 // FIXME doing something very wrong to preserve old behavior
172 // as a fallback
173 log.warn("No feasible path between {}-{} using {}",
174 src, dst, lambda);
175
176 satPath = getOpticalPaths(intent).iterator().next();
177 if (satPath == null) {
178 throw new OpticalIntentCompilationException(
179 "Unable to find suitable lightpath for intent " + intent);
180 }
181 return ImmutableList.of(createIntent(intent, satPath, lambda));
182 }
183
184 resources.addAll(res);
185 allocateResources(intent, resources);
186
187 return ImmutableList.of(createIntent(intent, satPath, lambda));
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800188 }
189
190 // FIXME: also check destination OCh port
191 // non-tunable case: early return
192 if (!srcOchPort.isTunable() || !dstOchPort.isTunable()) {
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -0700193 Path firstPath = paths.findAny().orElse(null);
194 if (firstPath == null) {
195 throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
196 }
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800197 OchSignal lambda = srcOchPort.lambda();
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -0700198 // TODO apply the same as static lambda case above
199 // - pick feasible path
200 // - allocate resources
201 //resources.addAll(convertToResources(firstPath.links(), toFlexGrid(lambda)));
202 allocateResources(intent, resources);
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800203 return ImmutableList.of(createIntent(intent, firstPath, lambda));
204 }
Sho SHIMIZUd978d9a2016-01-28 08:55:49 -0800205
Sho SHIMIZU07ade9b2016-01-28 19:38:50 -0800206 // remaining cases
207 // Use first path that the required resources are available
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -0700208 Optional<Map.Entry<Path, List<OchSignal>>> found = paths
Sho SHIMIZU07ade9b2016-01-28 19:38:50 -0800209 .map(path -> Maps.immutableEntry(path, findFirstAvailableOch(path)))
210 .filter(entry -> !entry.getValue().isEmpty())
211 .filter(entry -> convertToResources(entry.getKey().links(),
212 entry.getValue()).stream().allMatch(resourceService::isAvailable))
213 .findFirst();
214
215 if (found.isPresent()) {
216 resources.addAll(convertToResources(found.get().getKey().links(), found.get().getValue()));
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700217
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800218 allocateResources(intent, resources);
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700219
Sho SHIMIZU07ade9b2016-01-28 19:38:50 -0800220 OchSignal ochSignal = OchSignal.toFixedGrid(found.get().getValue(), ChannelSpacing.CHL_50GHZ);
221 return ImmutableList.of(createIntent(intent, found.get().getKey(), ochSignal));
222 } else {
Yuta HIGUCHId95d5902016-06-27 00:18:45 -0700223 throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700224 }
weibitf32383b2014-10-22 10:17:31 -0700225 }
226
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800227 private Intent createIntent(OpticalConnectivityIntent parentIntent, Path path, OchSignal lambda) {
228 // Create installable optical path intent
229 // Only support fixed grid for now
230 OchSignalType signalType = OchSignalType.FIXED_GRID;
231
232 return OpticalPathIntent.builder()
233 .appId(parentIntent.appId())
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700234 .key(parentIntent.key())
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800235 .src(parentIntent.getSrc())
236 .dst(parentIntent.getDst())
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800237 .path(path)
238 .lambda(lambda)
239 .signalType(signalType)
240 .bidirectional(parentIntent.isBidirectional())
Luca Prete670ac5d2017-02-03 15:55:43 -0800241 .resourceGroup(parentIntent.resourceGroup())
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800242 .build();
243 }
244
245 private void allocateResources(Intent intent, List<Resource> resources) {
246 // reserve all of required resources
Yuta HIGUCHI65d9d0e2017-05-04 12:44:32 -0700247 List<ResourceAllocation> allocations = resourceService.allocate(intent.key(), resources);
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800248 if (allocations.isEmpty()) {
Yuta HIGUCHI65d9d0e2017-05-04 12:44:32 -0700249 log.error("Resource allocation for {} failed (resource request: {})", intent.key(), resources);
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -0700250 if (log.isDebugEnabled()) {
251 log.debug("requested resources:\n\t{}", resources.stream()
252 .map(Resource::toString)
253 .collect(Collectors.joining("\n\t")));
254 }
Yuta HIGUCHId95d5902016-06-27 00:18:45 -0700255 throw new OpticalIntentCompilationException("Unable to allocate resources: " + resources);
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800256 }
257 }
258
259 private List<OchSignal> findFirstAvailableOch(Path path) {
Marc De Leenheer2c305302015-12-07 21:37:44 -0800260 Set<OchSignal> lambdas = findCommonLambdasOverLinks(path.links());
Sho SHIMIZUc25a0082015-10-27 17:06:29 -0700261 if (lambdas.isEmpty()) {
Marc De Leenheer2c305302015-12-07 21:37:44 -0800262 return Collections.emptyList();
Sho SHIMIZUc25a0082015-10-27 17:06:29 -0700263 }
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700264
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800265 return findFirstLambda(lambdas, slotCount());
266 }
267
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -0700268 private List<Resource> convertToResources(List<Link> links, Collection<OchSignal> lambda) {
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800269 return links.stream()
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800270 .flatMap(x -> Stream.of(
Sho SHIMIZU460b9722016-01-28 10:48:26 -0800271 Resources.discrete(x.src().deviceId(), x.src().port()).resource(),
272 Resources.discrete(x.dst().deviceId(), x.dst().port()).resource()
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800273 ))
Sho SHIMIZU394918d2016-01-28 16:32:10 -0800274 .flatMap(x -> lambda.stream().map(x::child))
Sho SHIMIZU7f44cfc2015-10-28 13:54:40 -0700275 .collect(Collectors.toList());
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700276 }
277
Marc De Leenheer2c305302015-12-07 21:37:44 -0800278 /**
279 * Get the number of 12.5 GHz slots required for the path.
280 *
281 * For now this returns a constant value of 4 (i.e., fixed grid 50 GHz slot),
282 * but in the future can depend on optical reach, line rate, transponder port capabilities, etc.
283 *
284 * @return number of slots
285 */
286 private int slotCount() {
287 return SLOT_COUNT;
288 }
289
290 private Set<OchSignal> findCommonLambdasOverLinks(List<Link> links) {
Sho SHIMIZUc25a0082015-10-27 17:06:29 -0700291 return links.stream()
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800292 .flatMap(x -> Stream.of(
Sho SHIMIZUdd3750c2016-02-01 11:37:04 -0800293 Resources.discrete(x.src().deviceId(), x.src().port()).id(),
294 Resources.discrete(x.dst().deviceId(), x.dst().port()).id()
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800295 ))
Sho SHIMIZU7332fe42016-02-15 14:58:33 -0800296 .map(x -> resourceService.getAvailableResourceValues(x, OchSignal.class))
Marc De Leenheer2c305302015-12-07 21:37:44 -0800297 .map(x -> (Set<OchSignal>) ImmutableSet.copyOf(x))
Sho SHIMIZUc25a0082015-10-27 17:06:29 -0700298 .reduce(Sets::intersection)
299 .orElse(Collections.emptySet());
300 }
301
Marc De Leenheer2c305302015-12-07 21:37:44 -0800302 /**
303 * Returns list of consecutive resources in given set of lambdas.
304 *
305 * @param lambdas list of lambdas
306 * @param count number of consecutive lambdas to return
307 * @return list of consecutive lambdas
308 */
309 private List<OchSignal> findFirstLambda(Set<OchSignal> lambdas, int count) {
310 // Sort available lambdas
311 List<OchSignal> lambdaList = new ArrayList<>(lambdas);
312 lambdaList.sort(new DefaultOchSignalComparator());
313
314 // Look ahead by count and ensure spacing multiplier is as expected (i.e., no gaps)
315 for (int i = 0; i < lambdaList.size() - count; i++) {
316 if (lambdaList.get(i).spacingMultiplier() + 2 * count ==
317 lambdaList.get(i + count).spacingMultiplier()) {
318 return lambdaList.subList(i, i + count);
319 }
320 }
321
322 return Collections.emptyList();
Sho SHIMIZUc25a0082015-10-27 17:06:29 -0700323 }
324
Marc De Leenheer723f5532015-06-03 20:16:17 -0700325 private ConnectPoint staticPort(ConnectPoint connectPoint) {
326 Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port());
327
328 String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT);
329
330 // FIXME: need a better way to match the port
331 if (staticPort != null) {
332 for (Port p : deviceService.getPorts(connectPoint.deviceId())) {
333 if (staticPort.equals(p.number().name())) {
334 return new ConnectPoint(p.element().id(), p.number());
335 }
336 }
337 }
338
339 return null;
340 }
341
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700342 /**
343 * Calculates optical paths in WDM topology.
344 *
345 * @param intent optical connectivity intent
346 * @return set of paths in WDM topology
347 */
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -0700348 private Stream<Path> getOpticalPaths(OpticalConnectivityIntent intent) {
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700349 // Route in WDM topology
weibit7e583462014-10-23 10:14:05 -0700350 Topology topology = topologyService.currentTopology();
Yuta HIGUCHId95d5902016-06-27 00:18:45 -0700351 LinkWeight weight = new LinkWeight() {
Sho SHIMIZU74626412015-09-11 11:46:27 -0700352
Yuta HIGUCHId95d5902016-06-27 00:18:45 -0700353 @Override
354 public double weight(TopologyEdge edge) {
355 // Disregard inactive or non-optical links
356 if (edge.link().state() == Link.State.INACTIVE) {
357 return -1;
358 }
359 if (edge.link().type() != Link.Type.OPTICAL) {
360 return -1;
361 }
362 // Adhere to static port mappings
363 DeviceId srcDeviceId = edge.link().src().deviceId();
364 if (srcDeviceId.equals(intent.getSrc().deviceId())) {
365 ConnectPoint srcStaticPort = staticPort(intent.getSrc());
366 if (srcStaticPort != null) {
367 return srcStaticPort.equals(edge.link().src()) ? 1 : -1;
368 }
369 }
370 DeviceId dstDeviceId = edge.link().dst().deviceId();
371 if (dstDeviceId.equals(intent.getDst().deviceId())) {
372 ConnectPoint dstStaticPort = staticPort(intent.getDst());
373 if (dstStaticPort != null) {
374 return dstStaticPort.equals(edge.link().dst()) ? 1 : -1;
375 }
376 }
377
378 return 1;
379 }
weibit7e583462014-10-23 10:14:05 -0700380 };
weibitf32383b2014-10-22 10:17:31 -0700381
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700382 ConnectPoint start = intent.getSrc();
383 ConnectPoint end = intent.getDst();
Yuta HIGUCHI02f8d2e2017-04-14 17:00:12 -0700384 Stream<Path> paths = topologyService.getKShortestPaths(topology,
385 start.deviceId(),
386 end.deviceId(),
387 AdapterLinkWeigher.adapt(weight));
388 if (log.isDebugEnabled()) {
389 return paths
390 .map(path -> {
391 // no-op map stage to add debug logging
392 log.debug("Candidate path: {}",
393 path.links().stream()
394 .map(lk -> lk.src() + "-" + lk.dst())
395 .collect(Collectors.toList()));
396 return path;
397 });
398 }
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700399 return paths;
weibitf32383b2014-10-22 10:17:31 -0700400 }
weibitf32383b2014-10-22 10:17:31 -0700401}