Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -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 | */ |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 16 | package org.onosproject.net.optical.intent.impl.compiler; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 17 | |
Sho SHIMIZU | 12d0268 | 2016-02-24 13:55:12 -0800 | [diff] [blame] | 18 | import com.google.common.base.Strings; |
Rimon Ashkenazy | 0c59de0 | 2016-03-21 13:23:26 +0200 | [diff] [blame] | 19 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 20 | import org.apache.commons.lang3.tuple.Pair; |
| 21 | import org.apache.felix.scr.annotations.Activate; |
Sho SHIMIZU | 9a2b829 | 2015-10-28 13:00:16 -0700 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Component; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Deactivate; |
Aaron Kruglikov | 6490a3b | 2015-06-05 14:25:32 -0700 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Modified; |
| 25 | import org.apache.felix.scr.annotations.Property; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 26 | import org.apache.felix.scr.annotations.Reference; |
| 27 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Aaron Kruglikov | 6490a3b | 2015-06-05 14:25:32 -0700 | [diff] [blame] | 28 | import org.onlab.util.Tools; |
| 29 | import org.onosproject.cfg.ComponentConfigService; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreService; |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 32 | import org.onosproject.net.AnnotationKeys; |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 33 | import org.onosproject.net.CltSignalType; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 34 | import org.onosproject.net.ConnectPoint; |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 35 | import org.onosproject.net.OduSignalId; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 36 | import org.onosproject.net.OduSignalType; |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 37 | import org.onosproject.net.OduSignalUtils; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 38 | import org.onosproject.net.Port; |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 39 | import org.onosproject.net.TributarySlot; |
| 40 | import org.onosproject.net.behaviour.TributarySlotQuery; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 41 | import org.onosproject.net.device.DeviceService; |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 42 | import org.onosproject.net.driver.Driver; |
| 43 | import org.onosproject.net.driver.DriverService; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 44 | import org.onosproject.net.flow.DefaultFlowRule; |
| 45 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 46 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 47 | import org.onosproject.net.flow.FlowRule; |
| 48 | import org.onosproject.net.flow.TrafficSelector; |
| 49 | import org.onosproject.net.flow.TrafficTreatment; |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 50 | import org.onosproject.net.flow.criteria.Criteria; |
| 51 | import org.onosproject.net.flow.instructions.Instructions; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 52 | import org.onosproject.net.intent.FlowRuleIntent; |
| 53 | import org.onosproject.net.intent.Intent; |
| 54 | import org.onosproject.net.intent.IntentCompiler; |
| 55 | import org.onosproject.net.intent.IntentExtensionService; |
| 56 | import org.onosproject.net.intent.IntentId; |
| 57 | import org.onosproject.net.intent.IntentService; |
| 58 | import org.onosproject.net.intent.OpticalCircuitIntent; |
| 59 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame^] | 60 | import org.onosproject.net.intent.PathIntent; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 61 | import org.onosproject.net.optical.OchPort; |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 62 | import org.onosproject.net.optical.OduCltPort; |
Sho SHIMIZU | 739873b | 2016-02-23 17:02:12 -0800 | [diff] [blame] | 63 | import org.onosproject.net.intent.IntentSetMultimap; |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 64 | import org.onosproject.net.resource.ResourceAllocation; |
| 65 | import org.onosproject.net.resource.Resource; |
| 66 | import org.onosproject.net.resource.ResourceService; |
| 67 | import org.onosproject.net.resource.Resources; |
Aaron Kruglikov | 6490a3b | 2015-06-05 14:25:32 -0700 | [diff] [blame] | 68 | import org.osgi.service.component.ComponentContext; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 69 | import org.slf4j.Logger; |
| 70 | import org.slf4j.LoggerFactory; |
| 71 | |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 72 | import com.google.common.collect.ImmutableList; |
| 73 | import com.google.common.collect.Sets; |
| 74 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 75 | import java.util.Collections; |
Aaron Kruglikov | 6490a3b | 2015-06-05 14:25:32 -0700 | [diff] [blame] | 76 | import java.util.Dictionary; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 77 | import java.util.LinkedList; |
| 78 | import java.util.List; |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 79 | import java.util.Optional; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 80 | import java.util.Set; |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 81 | import java.util.stream.Collectors; |
Rimon Ashkenazy | 0c59de0 | 2016-03-21 13:23:26 +0200 | [diff] [blame] | 82 | import java.util.stream.Stream; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 83 | |
| 84 | import static com.google.common.base.Preconditions.checkArgument; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 85 | import static org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * An intent compiler for {@link org.onosproject.net.intent.OpticalCircuitIntent}. |
| 89 | */ |
Sho SHIMIZU | 9a2b829 | 2015-10-28 13:00:16 -0700 | [diff] [blame] | 90 | @Component(immediate = true) |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 91 | public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircuitIntent> { |
| 92 | |
| 93 | private static final Logger log = LoggerFactory.getLogger(OpticalCircuitIntentCompiler.class); |
| 94 | |
Aaron Kruglikov | 6490a3b | 2015-06-05 14:25:32 -0700 | [diff] [blame] | 95 | private static final int DEFAULT_MAX_CAPACITY = 10; |
| 96 | |
| 97 | @Property(name = "maxCapacity", intValue = DEFAULT_MAX_CAPACITY, |
| 98 | label = "Maximum utilization of an optical connection.") |
| 99 | |
| 100 | private int maxCapacity = DEFAULT_MAX_CAPACITY; |
| 101 | |
| 102 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 103 | protected ComponentConfigService cfgService; |
| 104 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 105 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 106 | protected IntentExtensionService intentManager; |
| 107 | |
| 108 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 109 | protected CoreService coreService; |
| 110 | |
| 111 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 112 | protected DeviceService deviceService; |
| 113 | |
| 114 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 115 | protected ResourceService resourceService; |
| 116 | |
| 117 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | 7d20af1 | 2015-10-01 16:03:51 -0700 | [diff] [blame] | 118 | protected IntentSetMultimap intentSetMultimap; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 119 | |
| 120 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 121 | protected IntentService intentService; |
| 122 | |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 123 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 124 | protected DriverService driverService; |
| 125 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 126 | private ApplicationId appId; |
| 127 | |
Aaron Kruglikov | 6490a3b | 2015-06-05 14:25:32 -0700 | [diff] [blame] | 128 | @Modified |
| 129 | public void modified(ComponentContext context) { |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 130 | if (context == null) { |
| 131 | return; |
| 132 | } |
| 133 | |
Aaron Kruglikov | 6490a3b | 2015-06-05 14:25:32 -0700 | [diff] [blame] | 134 | Dictionary properties = context.getProperties(); |
| 135 | |
| 136 | //TODO for reduction check if the new capacity is smaller than the size of the current mapping |
| 137 | String propertyString = Tools.get(properties, "maxCapacity"); |
| 138 | |
Sho SHIMIZU | 12d0268 | 2016-02-24 13:55:12 -0800 | [diff] [blame] | 139 | //Ignore if propertyString is empty or null |
| 140 | if (!Strings.isNullOrEmpty(propertyString)) { |
Aaron Kruglikov | 6490a3b | 2015-06-05 14:25:32 -0700 | [diff] [blame] | 141 | try { |
| 142 | int temp = Integer.parseInt(propertyString); |
| 143 | //Ensure value is non-negative but allow zero as a way to shutdown the link |
| 144 | if (temp >= 0) { |
| 145 | maxCapacity = temp; |
| 146 | } |
| 147 | } catch (NumberFormatException e) { |
| 148 | //Malformed arguments lead to no change of value (user should be notified of error) |
| 149 | log.error("The value '{}' for maxCapacity was not parsable as an integer.", propertyString, e); |
| 150 | } |
| 151 | } else { |
| 152 | //Notify of empty value but do not return (other properties will also go in this function) |
| 153 | log.error("The value for maxCapacity was set to an empty value."); |
| 154 | } |
| 155 | |
| 156 | } |
| 157 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 158 | @Activate |
Aaron Kruglikov | 6490a3b | 2015-06-05 14:25:32 -0700 | [diff] [blame] | 159 | public void activate(ComponentContext context) { |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 160 | deviceService = opticalView(deviceService); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 161 | appId = coreService.registerApplication("org.onosproject.net.intent"); |
| 162 | intentManager.registerCompiler(OpticalCircuitIntent.class, this); |
Aaron Kruglikov | 6490a3b | 2015-06-05 14:25:32 -0700 | [diff] [blame] | 163 | cfgService.registerProperties(getClass()); |
| 164 | modified(context); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | @Deactivate |
| 168 | public void deactivate() { |
| 169 | intentManager.unregisterCompiler(OpticalCircuitIntent.class); |
Aaron Kruglikov | 6490a3b | 2015-06-05 14:25:32 -0700 | [diff] [blame] | 170 | cfgService.unregisterProperties(getClass(), false); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | @Override |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 174 | public List<Intent> compile(OpticalCircuitIntent intent, List<Intent> installable) { |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 175 | // Check if ports are OduClt ports |
| 176 | ConnectPoint src = intent.getSrc(); |
| 177 | ConnectPoint dst = intent.getDst(); |
| 178 | Port srcPort = deviceService.getPort(src.deviceId(), src.port()); |
| 179 | Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); |
| 180 | checkArgument(srcPort instanceof OduCltPort); |
| 181 | checkArgument(dstPort instanceof OduCltPort); |
| 182 | |
| 183 | log.debug("Compiling optical circuit intent between {} and {}", src, dst); |
| 184 | |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 185 | // Release of intent resources here is only a temporary solution for handling the |
| 186 | // case of recompiling due to intent restoration (when intent state is FAILED). |
| 187 | // TODO: try to release intent resources in IntentManager. |
| 188 | resourceService.release(intent.id()); |
| 189 | |
Rimon Ashkenazy | 0c59de0 | 2016-03-21 13:23:26 +0200 | [diff] [blame] | 190 | // Check OduClt ports availability |
Sho SHIMIZU | 460b972 | 2016-01-28 10:48:26 -0800 | [diff] [blame] | 191 | Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource(); |
| 192 | Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource(); |
Rimon Ashkenazy | 0c59de0 | 2016-03-21 13:23:26 +0200 | [diff] [blame] | 193 | // If ports are not available, compilation fails |
| 194 | if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) { |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 195 | throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 196 | } |
Rimon Ashkenazy | 0c59de0 | 2016-03-21 13:23:26 +0200 | [diff] [blame] | 197 | List<Resource> ports = ImmutableList.of(srcPortResource, dstPortResource); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 198 | |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 199 | // Check if both devices support multiplexing (usage of TributarySlots) |
Sho SHIMIZU | caf0b34 | 2016-02-29 13:49:04 -0800 | [diff] [blame] | 200 | boolean multiplexingSupported = isMultiplexingSupported(intent.getSrc()) |
| 201 | && isMultiplexingSupported(intent.getDst()); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 202 | |
Sho SHIMIZU | 6d10aed | 2016-02-29 11:44:42 -0800 | [diff] [blame] | 203 | OpticalConnectivityIntent connIntent = findOpticalConnectivityIntent(intent.getSrc(), intent.getDst(), |
| 204 | intent.getSignalType(), multiplexingSupported); |
Sho SHIMIZU | 8a4f8a1 | 2016-03-01 17:38:10 -0800 | [diff] [blame] | 205 | |
| 206 | if (connIntent != null && !multiplexingSupported) { |
| 207 | return compile(intent, src, dst, Optional.of(connIntent), ports, false); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 208 | } |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 209 | |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 210 | // Create optical connectivity intent if needed - no optical intent or not enough slots available |
Sho SHIMIZU | 8a4f8a1 | 2016-03-01 17:38:10 -0800 | [diff] [blame] | 211 | if (connIntent == null) { |
| 212 | return compile(intent, src, dst, Optional.empty(), ports, multiplexingSupported); |
| 213 | } |
| 214 | |
| 215 | List<Resource> slots = availableSlotResources(connIntent.getSrc(), connIntent.getDst(), |
| 216 | intent.getSignalType()); |
| 217 | if (slots.isEmpty()) { |
| 218 | return compile(intent, src, dst, Optional.empty(), ports, true); |
| 219 | } |
| 220 | |
| 221 | return compile(intent, src, dst, Optional.of(connIntent), ImmutableList.<Resource>builder() |
| 222 | .addAll(ports).addAll(slots).build(), false); |
| 223 | |
| 224 | } |
| 225 | |
| 226 | private List<Intent> compile(OpticalCircuitIntent intent, ConnectPoint src, ConnectPoint dst, |
| 227 | Optional<OpticalConnectivityIntent> existingConnectivity, |
| 228 | List<Resource> resources, boolean supportsMultiplexing) { |
| 229 | OpticalConnectivityIntent connectivityIntent; |
| 230 | List<Resource> required; |
| 231 | if (existingConnectivity.isPresent()) { |
| 232 | connectivityIntent = existingConnectivity.get(); |
| 233 | required = resources; |
| 234 | } else { |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 235 | // Find OCh ports with available resources |
Sho SHIMIZU | 979c3d9 | 2016-02-29 11:08:57 -0800 | [diff] [blame] | 236 | Pair<OchPort, OchPort> ochPorts = findPorts(intent.getSrc(), intent.getDst(), intent.getSignalType()); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 237 | |
| 238 | if (ochPorts == null) { |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 239 | throw new OpticalIntentCompilationException("Unable to find suitable OCH ports for intent " + intent); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | ConnectPoint srcCP = new ConnectPoint(src.elementId(), ochPorts.getLeft().number()); |
| 243 | ConnectPoint dstCP = new ConnectPoint(dst.elementId(), ochPorts.getRight().number()); |
| 244 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 245 | // Create optical connectivity intent |
Sho SHIMIZU | 8a4f8a1 | 2016-03-01 17:38:10 -0800 | [diff] [blame] | 246 | connectivityIntent = OpticalConnectivityIntent.builder() |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 247 | .appId(appId) |
Yuta HIGUCHI | 652f27f | 2016-10-31 16:54:30 -0700 | [diff] [blame] | 248 | // TODO New top-level Intent created and submitted |
| 249 | // during compilation. |
| 250 | // We'll need to track inter-Intent dependency, |
| 251 | // but `key` field cannot be used for the purpose. |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 252 | .src(srcCP) |
| 253 | .dst(dstCP) |
Sho SHIMIZU | 8a4f8a1 | 2016-03-01 17:38:10 -0800 | [diff] [blame] | 254 | .signalType(ochPorts.getLeft().signalType()) |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 255 | .bidirectional(intent.isBidirectional()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame^] | 256 | .resourceGroup(intent.resourceGroup()) |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 257 | .build(); |
Sho SHIMIZU | 8a4f8a1 | 2016-03-01 17:38:10 -0800 | [diff] [blame] | 258 | |
| 259 | if (!supportsMultiplexing) { |
| 260 | required = resources; |
| 261 | } else { |
| 262 | List<Resource> slots = availableSlotResources(srcCP, dstCP, intent.getSignalType()); |
| 263 | if (slots.isEmpty()) { |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 264 | throw new OpticalIntentCompilationException("Unable to find Tributary Slots for intent " + intent); |
Sho SHIMIZU | 8a4f8a1 | 2016-03-01 17:38:10 -0800 | [diff] [blame] | 265 | } |
| 266 | required = ImmutableList.<Resource>builder().addAll(resources).addAll(slots).build(); |
| 267 | } |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Sho SHIMIZU | 8a4f8a1 | 2016-03-01 17:38:10 -0800 | [diff] [blame] | 270 | if (resourceService.allocate(intent.id(), required).isEmpty()) { |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 271 | throw new OpticalIntentCompilationException("Unable to allocate resources for intent " + intent |
Sho SHIMIZU | 8a4f8a1 | 2016-03-01 17:38:10 -0800 | [diff] [blame] | 272 | + ": resources=" + required); |
| 273 | } |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 274 | |
Sho SHIMIZU | 8a4f8a1 | 2016-03-01 17:38:10 -0800 | [diff] [blame] | 275 | intentService.submit(connectivityIntent); |
| 276 | |
| 277 | // Save circuit to connectivity intent mapping |
| 278 | intentSetMultimap.allocateMapping(connectivityIntent.id(), intent.id()); |
| 279 | |
| 280 | FlowRuleIntent circuitIntent = createFlowRule(intent, connectivityIntent, required.stream(). |
| 281 | flatMap(x -> Tools.stream(x.valueAs(TributarySlot.class))) |
| 282 | .collect(Collectors.toSet())); |
Sho SHIMIZU | 953b0fb | 2016-02-26 16:42:13 -0800 | [diff] [blame] | 283 | return ImmutableList.of(circuitIntent); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Sho SHIMIZU | 8a4f8a1 | 2016-03-01 17:38:10 -0800 | [diff] [blame] | 286 | private List<Resource> availableSlotResources(ConnectPoint src, ConnectPoint dst, CltSignalType signalType) { |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 287 | OduSignalType oduSignalType = OduSignalUtils.mappingCltSignalTypeToOduSignalType(signalType); |
Sho SHIMIZU | 8a4f8a1 | 2016-03-01 17:38:10 -0800 | [diff] [blame] | 288 | int requestedTsNum = oduSignalType.tributarySlots(); |
| 289 | Set<TributarySlot> commonTributarySlots = findCommonTributarySlotsOnCps(src, dst); |
| 290 | if (commonTributarySlots.isEmpty()) { |
| 291 | return Collections.emptyList(); |
| 292 | } |
| 293 | if (commonTributarySlots.size() < requestedTsNum) { |
| 294 | return Collections.emptyList(); |
| 295 | } |
| 296 | |
| 297 | Set<TributarySlot> tributarySlots = commonTributarySlots.stream() |
| 298 | .limit(requestedTsNum) |
| 299 | .collect(Collectors.toSet()); |
| 300 | |
| 301 | final List<ConnectPoint> portsList = ImmutableList.of(src, dst); |
| 302 | List<Resource> tributarySlotResources = portsList.stream() |
| 303 | .flatMap(cp -> tributarySlots |
| 304 | .stream() |
| 305 | .map(ts-> Resources.discrete(cp.deviceId(), cp.port()).resource().child(ts))) |
| 306 | .collect(Collectors.toList()); |
| 307 | |
| 308 | if (!tributarySlotResources.stream().allMatch(resourceService::isAvailable)) { |
| 309 | log.debug("Resource allocation for {} on {} and {} failed (resource request: {})", |
| 310 | signalType, src, dst, tributarySlotResources); |
| 311 | return Collections.emptyList(); |
| 312 | } |
| 313 | return tributarySlotResources; |
| 314 | } |
| 315 | |
Sho SHIMIZU | 874e0a3 | 2016-02-26 16:56:11 -0800 | [diff] [blame] | 316 | private FlowRuleIntent createFlowRule(OpticalCircuitIntent higherIntent, |
| 317 | OpticalConnectivityIntent lowerIntent, Set<TributarySlot> slots) { |
| 318 | // Create optical circuit intent |
| 319 | List<FlowRule> rules = new LinkedList<>(); |
| 320 | // at the source: ODUCLT port mapping to OCH port |
| 321 | rules.add(connectPorts(higherIntent.getSrc(), lowerIntent.getSrc(), higherIntent.priority(), slots)); |
| 322 | // at the destination: OCH port mapping to ODUCLT port |
| 323 | rules.add(connectPorts(lowerIntent.getDst(), higherIntent.getDst(), higherIntent.priority(), slots)); |
| 324 | |
| 325 | // Create flow rules for reverse path |
| 326 | if (higherIntent.isBidirectional()) { |
| 327 | // at the destination: OCH port mapping to ODUCLT port |
| 328 | rules.add(connectPorts(lowerIntent.getSrc(), higherIntent.getSrc(), higherIntent.priority(), slots)); |
| 329 | // at the source: ODUCLT port mapping to OCH port |
| 330 | rules.add(connectPorts(higherIntent.getDst(), lowerIntent.getDst(), higherIntent.priority(), slots)); |
| 331 | } |
| 332 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame^] | 333 | return new FlowRuleIntent(appId, higherIntent.key(), rules, |
| 334 | higherIntent.resources(), |
| 335 | PathIntent.ProtectionType.PRIMARY, |
| 336 | higherIntent.resourceGroup()); |
Sho SHIMIZU | 874e0a3 | 2016-02-26 16:56:11 -0800 | [diff] [blame] | 337 | } |
| 338 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 339 | /** |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 340 | * Returns existing and available optical connectivity intent that matches the given circuit intent. |
| 341 | * |
Sho SHIMIZU | 6d10aed | 2016-02-29 11:44:42 -0800 | [diff] [blame] | 342 | * @param src source connect point of optical circuit intent |
| 343 | * @param dst destination connect point of optical circuit intent |
| 344 | * @param signalType signal type of optical circuit intent |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 345 | * @param multiplexingSupported indicates whether ODU multiplexing is supported |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 346 | * @return existing optical connectivity intent, null otherwise. |
| 347 | */ |
Sho SHIMIZU | 6d10aed | 2016-02-29 11:44:42 -0800 | [diff] [blame] | 348 | private OpticalConnectivityIntent findOpticalConnectivityIntent(ConnectPoint src, |
| 349 | ConnectPoint dst, |
| 350 | CltSignalType signalType, |
| 351 | boolean multiplexingSupported) { |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 352 | |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 353 | OduSignalType oduSignalType = OduSignalUtils.mappingCltSignalTypeToOduSignalType(signalType); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 354 | |
Sho SHIMIZU | 0505f1d | 2016-02-29 13:31:47 -0800 | [diff] [blame] | 355 | return Tools.stream(intentService.getIntents()) |
| 356 | .filter(x -> x instanceof OpticalConnectivityIntent) |
| 357 | .map(x -> (OpticalConnectivityIntent) x) |
| 358 | .filter(x -> src.deviceId().equals(x.getSrc().deviceId())) |
| 359 | .filter(x -> dst.deviceId().equals(x.getDst().deviceId())) |
| 360 | .filter(x -> isAllowed(src, x.getSrc())) |
| 361 | .filter(x -> isAllowed(dst, x.getDst())) |
| 362 | .filter(x -> isAvailable(x.id())) |
| 363 | .filter(x -> !multiplexingSupported || |
| 364 | isAvailableTributarySlots(x.getSrc(), x.getDst(), oduSignalType.tributarySlots())) |
| 365 | .findFirst() |
| 366 | .orElse(null); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Sho SHIMIZU | 98de57a | 2016-02-29 17:20:44 -0800 | [diff] [blame] | 369 | private boolean isAllowed(ConnectPoint circuitCp, ConnectPoint connectivityCp) { |
| 370 | ConnectPoint staticPort = staticPort(circuitCp); |
| 371 | return staticPort == null || staticPort.equals(connectivityCp); |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * Checks if current allocations on given resource can satisfy request. |
| 376 | * If the resource is null, return true. |
| 377 | * |
| 378 | * @param resource the resource on which to map the intent |
| 379 | * @return true if the resource can accept the request, false otherwise |
| 380 | */ |
| 381 | private boolean isAvailable(IntentId resource) { |
| 382 | if (resource == null) { |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | Set<IntentId> mapping = intentSetMultimap.getMapping(resource); |
| 387 | |
| 388 | if (mapping == null) { |
| 389 | return true; |
| 390 | } |
| 391 | |
| 392 | return mapping.size() < maxCapacity; |
| 393 | } |
| 394 | |
Sho SHIMIZU | 64339fe | 2016-02-29 11:21:29 -0800 | [diff] [blame] | 395 | private boolean isAvailableTributarySlots(ConnectPoint src, ConnectPoint dst, int requestedTsNum) { |
| 396 | Set<TributarySlot> common = findCommonTributarySlotsOnCps(src, dst); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 397 | if (common.isEmpty()) { |
| 398 | log.debug("No available TributarySlots"); |
| 399 | return false; |
| 400 | } |
| 401 | if (common.size() < requestedTsNum) { |
| 402 | log.debug("Not enough available TributarySlots={} < requestedTsNum={}", common.size(), requestedTsNum); |
| 403 | return false; |
| 404 | } |
| 405 | return true; |
| 406 | } |
| 407 | |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 408 | private ConnectPoint staticPort(ConnectPoint connectPoint) { |
| 409 | Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); |
| 410 | |
| 411 | String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT); |
| 412 | |
| 413 | // FIXME: need a better way to match the port |
| 414 | if (staticPort != null) { |
| 415 | for (Port p : deviceService.getPorts(connectPoint.deviceId())) { |
| 416 | if (staticPort.equals(p.number().name())) { |
| 417 | return new ConnectPoint(p.element().id(), p.number()); |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | return null; |
| 423 | } |
| 424 | |
Sho SHIMIZU | 98de57a | 2016-02-29 17:20:44 -0800 | [diff] [blame] | 425 | private Pair<OchPort, OchPort> findPorts(ConnectPoint src, ConnectPoint dst, CltSignalType signalType) { |
| 426 | // According to the OpticalCircuitIntent's signalType find OCH ports with available TributarySlots resources |
| 427 | switch (signalType) { |
| 428 | case CLT_1GBE: |
| 429 | case CLT_10GBE: |
| 430 | // First search for OCH ports with OduSignalType of ODU2. If not found - search for those with ODU4 |
| 431 | return findPorts(src, dst, OduSignalType.ODU2) |
| 432 | .orElse(findPorts(src, dst, OduSignalType.ODU4).orElse(null)); |
| 433 | case CLT_100GBE: |
| 434 | return findPorts(src, dst, OduSignalType.ODU4).orElse(null); |
| 435 | case CLT_40GBE: |
| 436 | default: |
| 437 | return null; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | private Optional<Pair<OchPort, OchPort>> findPorts(ConnectPoint src, ConnectPoint dst, |
| 442 | OduSignalType ochPortSignalType) { |
| 443 | return findAvailableOchPort(src, ochPortSignalType) |
| 444 | .flatMap(srcOch -> |
| 445 | findAvailableOchPort(dst, ochPortSignalType).map(dstOch -> Pair.of(srcOch, dstOch))); |
| 446 | } |
| 447 | |
Sho SHIMIZU | aa00e50 | 2016-02-29 16:21:54 -0800 | [diff] [blame] | 448 | private Optional<OchPort> findAvailableOchPort(ConnectPoint oduPort, OduSignalType ochPortSignalType) { |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 449 | // First see if the port mappings are constrained |
| 450 | ConnectPoint ochCP = staticPort(oduPort); |
| 451 | |
| 452 | if (ochCP != null) { |
| 453 | OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 454 | Optional<IntentId> intentId = |
Sho SHIMIZU | dd3750c | 2016-02-01 11:37:04 -0800 | [diff] [blame] | 455 | resourceService.getResourceAllocations(Resources.discrete(ochCP.deviceId(), ochCP.port()).id()) |
Sho SHIMIZU | 6c9e33a | 2016-01-07 18:45:27 -0800 | [diff] [blame] | 456 | .stream() |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 457 | .map(ResourceAllocation::consumerId) |
| 458 | .map(ResourceHelper::getIntentId) |
| 459 | .flatMap(Tools::stream) |
Sho SHIMIZU | 6c9e33a | 2016-01-07 18:45:27 -0800 | [diff] [blame] | 460 | .findAny(); |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 461 | |
| 462 | if (isAvailable(intentId.orElse(null))) { |
Sho SHIMIZU | aa00e50 | 2016-02-29 16:21:54 -0800 | [diff] [blame] | 463 | return Optional.of(ochPort); |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 464 | } |
Sho SHIMIZU | aa00e50 | 2016-02-29 16:21:54 -0800 | [diff] [blame] | 465 | return Optional.empty(); |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | // No port constraints, so find any port that works |
| 469 | List<Port> ports = deviceService.getPorts(oduPort.deviceId()); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 470 | |
| 471 | for (Port port : ports) { |
| 472 | if (!(port instanceof OchPort)) { |
| 473 | continue; |
| 474 | } |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 475 | // This should be the first allocation on the OCH port |
| 476 | if (!resourceService.isAvailable(Resources.discrete(oduPort.deviceId(), port.number()).resource())) { |
| 477 | continue; |
| 478 | } |
| 479 | // OchPort is required to have the requested oduSignalType |
| 480 | if (((OchPort) port).signalType() != ochPortSignalType) { |
| 481 | continue; |
| 482 | } |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 483 | |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 484 | Optional<IntentId> intentId = |
Sho SHIMIZU | dd3750c | 2016-02-01 11:37:04 -0800 | [diff] [blame] | 485 | resourceService.getResourceAllocations(Resources.discrete(oduPort.deviceId(), port.number()).id()) |
Sho SHIMIZU | 6c9e33a | 2016-01-07 18:45:27 -0800 | [diff] [blame] | 486 | .stream() |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 487 | .map(ResourceAllocation::consumerId) |
| 488 | .map(ResourceHelper::getIntentId) |
| 489 | .flatMap(Tools::stream) |
Sho SHIMIZU | 6c9e33a | 2016-01-07 18:45:27 -0800 | [diff] [blame] | 490 | .findAny(); |
| 491 | |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 492 | if (isAvailable(intentId.orElse(null))) { |
Sho SHIMIZU | aa00e50 | 2016-02-29 16:21:54 -0800 | [diff] [blame] | 493 | return Optional.of((OchPort) port); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
Sho SHIMIZU | aa00e50 | 2016-02-29 16:21:54 -0800 | [diff] [blame] | 497 | return Optional.empty(); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 500 | /** |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 501 | * Builds flow rule for mapping between two ports. |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 502 | * |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 503 | * @param src source port |
| 504 | * @param dst destination port |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 505 | * @param priority |
| 506 | * @param slots Set of TributarySlots |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 507 | * @return flow rules |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 508 | */ |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 509 | private FlowRule connectPorts(ConnectPoint src, ConnectPoint dst, int priority, Set<TributarySlot> slots) { |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 510 | checkArgument(src.deviceId().equals(dst.deviceId())); |
| 511 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 512 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
| 513 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 514 | |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 515 | selectorBuilder.matchInPort(src.port()); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 516 | if (!slots.isEmpty()) { |
| 517 | Port srcPort = deviceService.getPort(src.deviceId(), src.port()); |
| 518 | Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); |
| 519 | OduSignalType oduCltPortOduSignalType; |
| 520 | OduSignalType ochPortOduSignalType; |
| 521 | |
| 522 | if (srcPort instanceof OduCltPort) { |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 523 | oduCltPortOduSignalType = |
| 524 | OduSignalUtils.mappingCltSignalTypeToOduSignalType(((OduCltPort) srcPort).signalType()); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 525 | ochPortOduSignalType = ((OchPort) dstPort).signalType(); |
| 526 | |
| 527 | selectorBuilder.add(Criteria.matchOduSignalType(oduCltPortOduSignalType)); |
| 528 | // use Instruction of OduSignalId only in case of ODU Multiplexing |
| 529 | if (oduCltPortOduSignalType != ochPortOduSignalType) { |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 530 | OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(ochPortOduSignalType, slots); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 531 | treatmentBuilder.add(Instructions.modL1OduSignalId(oduSignalId)); |
| 532 | } |
| 533 | } else { // srcPort is OchPort |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 534 | oduCltPortOduSignalType = |
| 535 | OduSignalUtils.mappingCltSignalTypeToOduSignalType(((OduCltPort) dstPort).signalType()); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 536 | ochPortOduSignalType = ((OchPort) srcPort).signalType(); |
| 537 | |
| 538 | selectorBuilder.add(Criteria.matchOduSignalType(oduCltPortOduSignalType)); |
| 539 | // use Criteria of OduSignalId only in case of ODU Multiplexing |
| 540 | if (oduCltPortOduSignalType != ochPortOduSignalType) { |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 541 | OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(ochPortOduSignalType, slots); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 542 | selectorBuilder.add(Criteria.matchOduSignalId(oduSignalId)); |
| 543 | } |
| 544 | } |
| 545 | } |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 546 | treatmentBuilder.setOutput(dst.port()); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 547 | |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 548 | FlowRule flowRule = DefaultFlowRule.builder() |
| 549 | .forDevice(src.deviceId()) |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 550 | .withSelector(selectorBuilder.build()) |
| 551 | .withTreatment(treatmentBuilder.build()) |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 552 | .withPriority(priority) |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 553 | .fromApp(appId) |
| 554 | .makePermanent() |
| 555 | .build(); |
| 556 | |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 557 | return flowRule; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 558 | } |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 559 | |
Sho SHIMIZU | caf0b34 | 2016-02-29 13:49:04 -0800 | [diff] [blame] | 560 | private boolean isMultiplexingSupported(ConnectPoint cp) { |
Sho SHIMIZU | 0a8332c | 2016-02-29 13:54:08 -0800 | [diff] [blame] | 561 | Driver driver = driverService.getDriver(cp.deviceId()); |
| 562 | return driver != null |
| 563 | && driver.hasBehaviour(TributarySlotQuery.class) |
| 564 | && staticPort(cp) == null; |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /** |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 568 | * Finds the common TributarySlots available on the two connect points. |
| 569 | * |
Sho SHIMIZU | 3763a02 | 2016-02-29 11:10:17 -0800 | [diff] [blame] | 570 | * @param src source connect point |
| 571 | * @param dst dest connect point |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 572 | * @return set of common TributarySlots on both connect points |
| 573 | */ |
Sho SHIMIZU | 3763a02 | 2016-02-29 11:10:17 -0800 | [diff] [blame] | 574 | Set<TributarySlot> findCommonTributarySlotsOnCps(ConnectPoint src, ConnectPoint dst) { |
| 575 | Set<TributarySlot> forward = findTributarySlotsOnCp(src); |
| 576 | Set<TributarySlot> backward = findTributarySlotsOnCp(dst); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 577 | return Sets.intersection(forward, backward); |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Finds the TributarySlots available on the connect point. |
| 582 | * |
| 583 | * @param cp connect point |
| 584 | * @return set of TributarySlots available on the connect point |
| 585 | */ |
| 586 | Set<TributarySlot> findTributarySlotsOnCp(ConnectPoint cp) { |
Sho SHIMIZU | c4ae4d5 | 2016-02-19 15:15:31 -0800 | [diff] [blame] | 587 | return resourceService.getAvailableResourceValues( |
| 588 | Resources.discrete(cp.deviceId(), cp.port()).id(), |
| 589 | TributarySlot.class); |
Rimon Ashkenazy | f069970 | 2016-01-17 19:28:49 +0200 | [diff] [blame] | 590 | } |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 591 | } |