Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [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; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 17 | |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Lists; |
alessio | d4a2b84 | 2019-04-30 18:43:17 +0200 | [diff] [blame] | 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.Device; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.Link; |
| 24 | import org.onosproject.net.PortNumber; |
| 25 | import org.onosproject.net.Port; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 26 | import org.osgi.service.component.annotations.Activate; |
| 27 | import org.osgi.service.component.annotations.Component; |
| 28 | import org.osgi.service.component.annotations.Deactivate; |
| 29 | import org.osgi.service.component.annotations.Reference; |
| 30 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 31 | import org.onosproject.core.ApplicationId; |
| 32 | import org.onosproject.core.CoreService; |
Yuta HIGUCHI | 09697d0 | 2017-03-03 16:53:39 -0800 | [diff] [blame] | 33 | import org.onosproject.net.Device.Type; |
Yuta HIGUCHI | 09697d0 | 2017-03-03 16:53:39 -0800 | [diff] [blame] | 34 | import org.onosproject.net.device.DeviceService; |
| 35 | import org.onosproject.net.device.DeviceServiceAdapter; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 36 | import org.onosproject.net.flow.DefaultFlowRule; |
| 37 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 38 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 39 | import org.onosproject.net.flow.FlowRule; |
| 40 | import org.onosproject.net.flow.TrafficSelector; |
| 41 | import org.onosproject.net.flow.TrafficTreatment; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 42 | import org.onosproject.net.flow.criteria.Criteria; |
| 43 | import org.onosproject.net.flow.instructions.Instructions; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 44 | import org.onosproject.net.intent.FlowRuleIntent; |
| 45 | import org.onosproject.net.intent.Intent; |
| 46 | import org.onosproject.net.intent.IntentCompiler; |
| 47 | import org.onosproject.net.intent.IntentExtensionService; |
| 48 | import org.onosproject.net.intent.OpticalPathIntent; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 49 | import org.onosproject.net.intent.PathIntent; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 50 | import org.slf4j.Logger; |
| 51 | import org.slf4j.LoggerFactory; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 52 | |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 53 | import java.util.Collections; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 54 | import java.util.LinkedList; |
| 55 | import java.util.List; |
Yuta HIGUCHI | 09697d0 | 2017-03-03 16:53:39 -0800 | [diff] [blame] | 56 | import java.util.Optional; |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 57 | import java.util.Set; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 58 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 59 | @Component(immediate = true) |
| 60 | public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathIntent> { |
| 61 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 62 | private static final Logger log = LoggerFactory.getLogger(OpticalPathIntentCompiler.class); |
| 63 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 64 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 65 | protected IntentExtensionService intentManager; |
| 66 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 67 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 68 | protected CoreService coreService; |
| 69 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 70 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Yuta HIGUCHI | 09697d0 | 2017-03-03 16:53:39 -0800 | [diff] [blame] | 71 | protected DeviceService deviceService = new DeviceServiceAdapter(); |
| 72 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 73 | private ApplicationId appId; |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 74 | // Devices which are wavelength transparent and thus do not require wavelength-based match/actions |
| 75 | private static final Set<Type> TRANSPARENT_DEVICES = |
| 76 | ImmutableSet.of(Type.OPTICAL_AMPLIFIER, Type.FIBER_SWITCH); |
| 77 | // Devices which don't accept flow rules |
| 78 | private static final Set<Type> NO_FLOWRULE_DEVICES = |
| 79 | ImmutableSet.of(Type.OPTICAL_AMPLIFIER); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 80 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 81 | @Activate |
| 82 | public void activate() { |
| 83 | appId = coreService.registerApplication("org.onosproject.net.intent"); |
| 84 | intentManager.registerCompiler(OpticalPathIntent.class, this); |
| 85 | } |
| 86 | |
| 87 | @Deactivate |
| 88 | public void deactivate() { |
| 89 | intentManager.unregisterCompiler(OpticalPathIntent.class); |
| 90 | } |
| 91 | |
| 92 | @Override |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 93 | public List<Intent> compile(OpticalPathIntent intent, List<Intent> installable) { |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 94 | log.debug("Compiling optical path intent between {} and {}", intent.src(), intent.dst()); |
| 95 | |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 96 | // Create rules for forward and reverse path |
| 97 | List<FlowRule> rules = createRules(intent); |
| 98 | if (intent.isBidirectional()) { |
| 99 | rules.addAll(createReverseRules(intent)); |
| 100 | } |
| 101 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 102 | return Collections.singletonList( |
| 103 | new FlowRuleIntent(appId, |
fahadnaeemkhan | 0e1b4d9 | 2018-02-08 16:40:08 -0800 | [diff] [blame] | 104 | intent.key(), |
| 105 | rules, |
| 106 | intent.resources(), |
| 107 | PathIntent.ProtectionType.PRIMARY, |
| 108 | intent.resourceGroup() |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 109 | ) |
| 110 | ); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 113 | /** |
| 114 | * Create rules for the forward path of the intent. |
| 115 | * |
| 116 | * @param intent the intent |
| 117 | * @return list of flow rules |
| 118 | */ |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 119 | private List<FlowRule> createRules(OpticalPathIntent intent) { |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 120 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
| 121 | selectorBuilder.matchInPort(intent.src().port()); |
| 122 | |
| 123 | List<FlowRule> rules = new LinkedList<>(); |
fahadnaeemkhan | 0e1b4d9 | 2018-02-08 16:40:08 -0800 | [diff] [blame] | 124 | |
| 125 | /* |
| 126 | * especial case for 0 hop when srcDeviceId = dstDeviceId |
| 127 | * and path contain only one fake default path. |
| 128 | */ |
| 129 | if (intent.src().deviceId().equals(intent.dst().deviceId()) && |
| 130 | intent.path().links().size() == 1) { |
| 131 | log.debug("handling 0 hop case for intent {}", intent); |
| 132 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 133 | if (!isTransparent(intent.src().deviceId())) { |
| 134 | treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda())); |
| 135 | } |
| 136 | treatmentBuilder.setOutput(intent.dst().port()); |
| 137 | |
| 138 | FlowRule rule = DefaultFlowRule.builder() |
| 139 | .forDevice(intent.src().deviceId()) |
| 140 | .withSelector(selectorBuilder.build()) |
| 141 | .withTreatment(treatmentBuilder.build()) |
| 142 | .withPriority(intent.priority()) |
| 143 | .fromApp(appId) |
| 144 | .makePermanent() |
| 145 | .build(); |
| 146 | rules.add(rule); |
| 147 | return rules; |
| 148 | } |
| 149 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 150 | ConnectPoint current = intent.src(); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 151 | |
| 152 | for (Link link : intent.path().links()) { |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 153 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
Marc De Leenheer | 43b91ad | 2017-03-17 14:45:28 -0700 | [diff] [blame] | 154 | if (!isTransparent(current.deviceId())) { |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 155 | treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda())); |
| 156 | } |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 157 | treatmentBuilder.setOutput(link.src().port()); |
| 158 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 159 | FlowRule rule = DefaultFlowRule.builder() |
| 160 | .forDevice(current.deviceId()) |
| 161 | .withSelector(selectorBuilder.build()) |
| 162 | .withTreatment(treatmentBuilder.build()) |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 163 | .withPriority(intent.priority()) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 164 | .fromApp(appId) |
| 165 | .makePermanent() |
| 166 | .build(); |
Marc De Leenheer | 43b91ad | 2017-03-17 14:45:28 -0700 | [diff] [blame] | 167 | selectorBuilder = DefaultTrafficSelector.builder(); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 168 | |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 169 | if (!isNoFlowRule(current.deviceId())) { |
Yuta HIGUCHI | 09697d0 | 2017-03-03 16:53:39 -0800 | [diff] [blame] | 170 | rules.add(rule); |
| 171 | } |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 172 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 173 | current = link.dst(); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 174 | selectorBuilder.matchInPort(link.dst().port()); |
Marc De Leenheer | 43b91ad | 2017-03-17 14:45:28 -0700 | [diff] [blame] | 175 | if (!isTransparent(current.deviceId())) { |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 176 | selectorBuilder.add(Criteria.matchLambda(intent.lambda())); |
| 177 | selectorBuilder.add(Criteria.matchOchSignalType(intent.signalType())); |
| 178 | } |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 181 | // Build the egress ROADM rule |
| 182 | TrafficTreatment.Builder treatmentLast = DefaultTrafficTreatment.builder(); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 183 | treatmentLast.setOutput(intent.dst().port()); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 184 | |
| 185 | FlowRule rule = new DefaultFlowRule.Builder() |
| 186 | .forDevice(intent.dst().deviceId()) |
| 187 | .withSelector(selectorBuilder.build()) |
| 188 | .withTreatment(treatmentLast.build()) |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 189 | .withPriority(intent.priority()) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 190 | .fromApp(appId) |
| 191 | .makePermanent() |
| 192 | .build(); |
Yuta HIGUCHI | 09697d0 | 2017-03-03 16:53:39 -0800 | [diff] [blame] | 193 | |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 194 | if (!isNoFlowRule(intent.dst().deviceId())) { |
Yuta HIGUCHI | 09697d0 | 2017-03-03 16:53:39 -0800 | [diff] [blame] | 195 | rules.add(rule); |
| 196 | } |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 197 | |
| 198 | return rules; |
| 199 | } |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 200 | |
| 201 | /** |
| 202 | * Create rules for the reverse path of the intent. |
| 203 | * |
| 204 | * @param intent the intent |
| 205 | * @return list of flow rules |
| 206 | */ |
| 207 | private List<FlowRule> createReverseRules(OpticalPathIntent intent) { |
| 208 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
alessio | d4a2b84 | 2019-04-30 18:43:17 +0200 | [diff] [blame] | 209 | selectorBuilder.matchInPort(reversePort(intent.dst().deviceId(), intent.dst().port())); |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 210 | |
| 211 | List<FlowRule> rules = new LinkedList<>(); |
fahadnaeemkhan | 0e1b4d9 | 2018-02-08 16:40:08 -0800 | [diff] [blame] | 212 | |
| 213 | /* |
| 214 | * especial case for 0 hop when srcDeviceId = dstDeviceId |
| 215 | * and path contain only one fake default path. |
| 216 | */ |
| 217 | if (intent.src().deviceId().equals(intent.dst().deviceId()) && |
| 218 | intent.path().links().size() == 1) { |
| 219 | log.debug("handling 0 hop reverse path case for intent {}", intent); |
| 220 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 221 | if (!isTransparent(intent.src().deviceId())) { |
| 222 | treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda())); |
| 223 | } |
alessio | d4a2b84 | 2019-04-30 18:43:17 +0200 | [diff] [blame] | 224 | treatmentBuilder.setOutput(reversePort(intent.src().deviceId(), intent.src().port())); |
fahadnaeemkhan | 0e1b4d9 | 2018-02-08 16:40:08 -0800 | [diff] [blame] | 225 | |
| 226 | FlowRule rule = DefaultFlowRule.builder() |
| 227 | .forDevice(intent.src().deviceId()) |
| 228 | .withSelector(selectorBuilder.build()) |
| 229 | .withTreatment(treatmentBuilder.build()) |
| 230 | .withPriority(intent.priority()) |
| 231 | .fromApp(appId) |
| 232 | .makePermanent() |
| 233 | .build(); |
| 234 | rules.add(rule); |
| 235 | return rules; |
| 236 | } |
| 237 | |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 238 | ConnectPoint current = intent.dst(); |
| 239 | |
| 240 | for (Link link : Lists.reverse(intent.path().links())) { |
| 241 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
Marc De Leenheer | 43b91ad | 2017-03-17 14:45:28 -0700 | [diff] [blame] | 242 | if (!isTransparent(current.deviceId())) { |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 243 | treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda())); |
| 244 | } |
alessio | d4a2b84 | 2019-04-30 18:43:17 +0200 | [diff] [blame] | 245 | treatmentBuilder.setOutput(reversePort(link.dst().deviceId(), link.dst().port())); |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 246 | |
| 247 | FlowRule rule = DefaultFlowRule.builder() |
| 248 | .forDevice(current.deviceId()) |
| 249 | .withSelector(selectorBuilder.build()) |
| 250 | .withTreatment(treatmentBuilder.build()) |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 251 | .withPriority(intent.priority()) |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 252 | .fromApp(appId) |
| 253 | .makePermanent() |
| 254 | .build(); |
Marc De Leenheer | 43b91ad | 2017-03-17 14:45:28 -0700 | [diff] [blame] | 255 | selectorBuilder = DefaultTrafficSelector.builder(); |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 256 | |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 257 | if (!isNoFlowRule(current.deviceId())) { |
Yuta HIGUCHI | 09697d0 | 2017-03-03 16:53:39 -0800 | [diff] [blame] | 258 | rules.add(rule); |
| 259 | } |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 260 | |
| 261 | current = link.src(); |
alessio | d4a2b84 | 2019-04-30 18:43:17 +0200 | [diff] [blame] | 262 | selectorBuilder.matchInPort(reversePort(link.src().deviceId(), link.src().port())); |
Marc De Leenheer | 43b91ad | 2017-03-17 14:45:28 -0700 | [diff] [blame] | 263 | if (!isTransparent(current.deviceId())) { |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 264 | selectorBuilder.add(Criteria.matchLambda(intent.lambda())); |
| 265 | selectorBuilder.add(Criteria.matchOchSignalType(intent.signalType())); |
| 266 | } |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | // Build the egress ROADM rule |
| 270 | TrafficTreatment.Builder treatmentLast = DefaultTrafficTreatment.builder(); |
alessio | d4a2b84 | 2019-04-30 18:43:17 +0200 | [diff] [blame] | 271 | treatmentLast.setOutput(reversePort(intent.src().deviceId(), intent.src().port())); |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 272 | |
| 273 | FlowRule rule = new DefaultFlowRule.Builder() |
| 274 | .forDevice(intent.src().deviceId()) |
| 275 | .withSelector(selectorBuilder.build()) |
| 276 | .withTreatment(treatmentLast.build()) |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 277 | .withPriority(intent.priority()) |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 278 | .fromApp(appId) |
| 279 | .makePermanent() |
| 280 | .build(); |
Yuta HIGUCHI | 09697d0 | 2017-03-03 16:53:39 -0800 | [diff] [blame] | 281 | |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 282 | if (!isNoFlowRule(intent.src().deviceId())) { |
Yuta HIGUCHI | 09697d0 | 2017-03-03 16:53:39 -0800 | [diff] [blame] | 283 | rules.add(rule); |
| 284 | } |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 285 | |
| 286 | return rules; |
| 287 | } |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 288 | |
| 289 | /** |
alessio | d4a2b84 | 2019-04-30 18:43:17 +0200 | [diff] [blame] | 290 | * Returns the PortNum of reverse port if annotation is present, otherwise return PortNum of the port itself. |
| 291 | * In the OpenROADM YANG models it is used the term "partner-port. |
| 292 | * |
| 293 | * @param portNumber the port |
| 294 | * @return the PortNum of reverse port if annotation is present, otherwise PortNum of the port itself. |
| 295 | */ |
| 296 | private PortNumber reversePort(DeviceId deviceId, PortNumber portNumber) { |
| 297 | Port port = deviceService.getPort(deviceId, portNumber); |
| 298 | |
| 299 | String reversePort = port.annotations().value(OpticalPathIntent.REVERSE_PORT_ANNOTATION_KEY); |
| 300 | if (reversePort != null) { |
| 301 | PortNumber reversePortNumber = PortNumber.portNumber(reversePort); |
| 302 | return reversePortNumber; |
| 303 | } else { |
| 304 | return portNumber; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 309 | * Returns true if device does not accept flow rules, false otherwise. |
| 310 | * |
| 311 | * @param deviceId the device |
| 312 | * @return true if device does not accept flow rule, false otherwise |
| 313 | */ |
| 314 | private boolean isNoFlowRule(DeviceId deviceId) { |
| 315 | return NO_FLOWRULE_DEVICES.contains( |
| 316 | Optional.ofNullable(deviceService.getDevice(deviceId)) |
| 317 | .map(Device::type) |
| 318 | .orElse(Type.OTHER)); |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Returns true if device is wavelength transparent, false otherwise. |
| 323 | * |
| 324 | * @param deviceId the device |
| 325 | * @return true if wavelength transparent, false otherwise |
| 326 | */ |
| 327 | private boolean isTransparent(DeviceId deviceId) { |
| 328 | return TRANSPARENT_DEVICES.contains( |
| 329 | Optional.ofNullable(deviceService.getDevice(deviceId)) |
fahadnaeemkhan | 0e1b4d9 | 2018-02-08 16:40:08 -0800 | [diff] [blame] | 330 | .map(Device::type) |
| 331 | .orElse(Type.OTHER)); |
Marc De Leenheer | b6f95e2 | 2017-03-15 12:18:59 -0700 | [diff] [blame] | 332 | } |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 333 | } |