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