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