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