Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -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 | */ |
| 16 | package org.onosproject.net.intent.impl.compiler; |
| 17 | |
Thomas Vachuska | bdbdd24 | 2016-03-01 01:55:55 -0800 | [diff] [blame] | 18 | import com.google.common.collect.HashMultimap; |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableList; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableMap; |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 21 | import com.google.common.collect.Lists; |
Thomas Vachuska | bdbdd24 | 2016-03-01 01:55:55 -0800 | [diff] [blame] | 22 | import com.google.common.collect.SetMultimap; |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 23 | import com.google.common.collect.Sets; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 24 | import org.osgi.service.component.annotations.Activate; |
| 25 | import org.osgi.service.component.annotations.Component; |
| 26 | import org.osgi.service.component.annotations.Deactivate; |
| 27 | import org.osgi.service.component.annotations.Reference; |
| 28 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 29 | import org.onlab.util.Identifier; |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreService; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 32 | import org.onosproject.net.ConnectPoint; |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 33 | import org.onosproject.net.DeviceId; |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 34 | import org.onosproject.net.EncapsulationType; |
| 35 | import org.onosproject.net.FilteredConnectPoint; |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 36 | import org.onosproject.net.PortNumber; |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 37 | import org.onosproject.net.domain.DomainService; |
| 38 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 39 | import org.onosproject.net.flow.TrafficSelector; |
| 40 | import org.onosproject.net.flow.TrafficTreatment; |
| 41 | import org.onosproject.net.flow.criteria.Criterion; |
| 42 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 43 | import org.onosproject.net.flow.instructions.Instruction; |
| 44 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 45 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
Michele Santuari | d2c8b15 | 2016-03-30 17:57:56 -0700 | [diff] [blame] | 46 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 47 | import org.onosproject.net.flowobjective.FilteringObjective; |
Michele Santuari | d2c8b15 | 2016-03-30 17:57:56 -0700 | [diff] [blame] | 48 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 49 | import org.onosproject.net.flowobjective.ForwardingObjective; |
Michele Santuari | d2c8b15 | 2016-03-30 17:57:56 -0700 | [diff] [blame] | 50 | import org.onosproject.net.flowobjective.NextObjective; |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 51 | import org.onosproject.net.flowobjective.Objective; |
| 52 | import org.onosproject.net.intent.FlowObjectiveIntent; |
| 53 | import org.onosproject.net.intent.Intent; |
| 54 | import org.onosproject.net.intent.IntentCompiler; |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 55 | import org.onosproject.net.intent.LinkCollectionIntent; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 56 | import org.onosproject.net.intent.constraint.EncapsulationConstraint; |
| 57 | import org.onosproject.net.resource.ResourceService; |
| 58 | import org.onosproject.net.resource.impl.LabelAllocator; |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 59 | import org.slf4j.Logger; |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 60 | |
Thomas Vachuska | bdbdd24 | 2016-03-01 01:55:55 -0800 | [diff] [blame] | 61 | import java.util.ArrayList; |
Thomas Vachuska | bdbdd24 | 2016-03-01 01:55:55 -0800 | [diff] [blame] | 62 | import java.util.List; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 63 | import java.util.Map; |
| 64 | import java.util.Optional; |
Thomas Vachuska | bdbdd24 | 2016-03-01 01:55:55 -0800 | [diff] [blame] | 65 | import java.util.Set; |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 66 | import java.util.concurrent.atomic.AtomicBoolean; |
| 67 | |
| 68 | import static org.onosproject.net.domain.DomainId.LOCAL; |
| 69 | import static org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT; |
| 70 | import static org.slf4j.LoggerFactory.getLogger; |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Compiler to produce flow objectives from link collections. |
| 74 | */ |
| 75 | @Component(immediate = true) |
Pier Ventre | d48320e | 2016-08-17 16:25:47 -0700 | [diff] [blame] | 76 | public class LinkCollectionIntentFlowObjectiveCompiler |
| 77 | extends LinkCollectionCompiler<Objective> |
| 78 | implements IntentCompiler<LinkCollectionIntent> { |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 79 | private final Logger log = getLogger(getClass()); |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 80 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 81 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | bdbdd24 | 2016-03-01 01:55:55 -0800 | [diff] [blame] | 82 | protected IntentConfigurableRegistrator registrator; |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 83 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 84 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 85 | protected CoreService coreService; |
| 86 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 87 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Michele Santuari | d2c8b15 | 2016-03-30 17:57:56 -0700 | [diff] [blame] | 88 | protected FlowObjectiveService flowObjectiveService; |
| 89 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 90 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 91 | protected ResourceService resourceService; |
| 92 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 93 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 94 | protected DomainService domainService; |
| 95 | |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 96 | private ApplicationId appId; |
| 97 | |
| 98 | @Activate |
| 99 | public void activate() { |
| 100 | appId = coreService.registerApplication("org.onosproject.net.intent"); |
Thomas Vachuska | bdbdd24 | 2016-03-01 01:55:55 -0800 | [diff] [blame] | 101 | registrator.registerCompiler(LinkCollectionIntent.class, this, true); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 102 | if (labelAllocator == null) { |
| 103 | labelAllocator = new LabelAllocator(resourceService); |
| 104 | } |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @Deactivate |
| 108 | public void deactivate() { |
Thomas Vachuska | bdbdd24 | 2016-03-01 01:55:55 -0800 | [diff] [blame] | 109 | registrator.unregisterCompiler(LinkCollectionIntent.class, true); |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 113 | public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) { |
Pier Ventre | d48320e | 2016-08-17 16:25:47 -0700 | [diff] [blame] | 114 | |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 115 | SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create(); |
| 116 | SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 117 | Map<ConnectPoint, Identifier<?>> labels = ImmutableMap.of(); |
| 118 | |
| 119 | Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent); |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 120 | |
Pier Ventre | d48320e | 2016-08-17 16:25:47 -0700 | [diff] [blame] | 121 | computePorts(intent, inputPorts, outputPorts); |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 122 | |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 123 | if (encapConstraint.isPresent()) { |
| 124 | labels = labelAllocator.assignLabelToPorts(intent.links(), |
Yi Tseng | 0db1f3b | 2017-05-25 10:08:06 -0700 | [diff] [blame] | 125 | intent.key(), |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 126 | encapConstraint.get().encapType()); |
| 127 | } |
| 128 | |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 129 | ImmutableList.Builder<Intent> intentList = ImmutableList.builder(); |
| 130 | if (this.isDomainProcessingEnabled(intent)) { |
| 131 | intentList.addAll(this.getDomainIntents(intent, domainService)); |
| 132 | } |
| 133 | |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 134 | List<Objective> objectives = new ArrayList<>(); |
| 135 | List<DeviceId> devices = new ArrayList<>(); |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 136 | for (DeviceId deviceId : outputPorts.keySet()) { |
| 137 | // add only objectives that are not inside of a domain |
| 138 | if (LOCAL.equals(domainService.getDomain(deviceId))) { |
| 139 | List<Objective> deviceObjectives = |
| 140 | createRules(intent, |
| 141 | deviceId, |
| 142 | inputPorts.get(deviceId), |
| 143 | outputPorts.get(deviceId), |
| 144 | labels); |
| 145 | deviceObjectives.forEach(objective -> { |
| 146 | objectives.add(objective); |
| 147 | devices.add(deviceId); |
| 148 | }); |
| 149 | } |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 150 | } |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 151 | // if any objectives have been created |
| 152 | if (!objectives.isEmpty()) { |
| 153 | intentList.add(new FlowObjectiveIntent(appId, intent.key(), devices, |
| 154 | objectives, |
| 155 | intent.resources(), |
| 156 | intent.resourceGroup())); |
| 157 | } |
| 158 | return intentList.build(); |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 159 | } |
| 160 | |
Pier Ventre | d48320e | 2016-08-17 16:25:47 -0700 | [diff] [blame] | 161 | @Override |
Yi Tseng | 84c5a3d | 2017-04-14 16:42:59 -0700 | [diff] [blame] | 162 | boolean optimizeTreatments() { |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | @Override |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 167 | protected List<Objective> createRules(LinkCollectionIntent intent, |
| 168 | DeviceId deviceId, |
| 169 | Set<PortNumber> inPorts, |
| 170 | Set<PortNumber> outPorts, |
| 171 | Map<ConnectPoint, Identifier<?>> labels) { |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 172 | |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 173 | List<Objective> objectives = new ArrayList<>(inPorts.size() * 2); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * Looking for the encapsulation constraint |
| 177 | */ |
| 178 | Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent); |
Pier Ventre | d48320e | 2016-08-17 16:25:47 -0700 | [diff] [blame] | 179 | |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 180 | inPorts.forEach(inPort -> { |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 181 | |
| 182 | ForwardingInstructions instructions = this.createForwardingInstruction( |
| 183 | encapConstraint, |
| 184 | intent, |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 185 | inPort, |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 186 | outPorts, |
| 187 | deviceId, |
| 188 | labels |
| 189 | ); |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 190 | |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 191 | Set<TrafficTreatment> treatmentsWithDifferentPort = |
| 192 | Sets.newHashSet(); |
Michele Santuari | d2c8b15 | 2016-03-30 17:57:56 -0700 | [diff] [blame] | 193 | |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 194 | TrafficTreatment.Builder treatmentBuilder = |
| 195 | DefaultTrafficTreatment.builder(); |
| 196 | |
| 197 | for (Instruction inst : instructions.treatment().allInstructions()) { |
| 198 | if (inst.type() == OUTPUT) { |
| 199 | treatmentBuilder.add(inst); |
| 200 | treatmentsWithDifferentPort.add(treatmentBuilder.build()); |
| 201 | treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 202 | } else { |
| 203 | treatmentBuilder.add(inst); |
| 204 | } |
Pier Ventre | d48320e | 2016-08-17 16:25:47 -0700 | [diff] [blame] | 205 | } |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 206 | |
| 207 | EthCriterion ethDst = (EthCriterion) intent.selector().getCriterion(Criterion.Type.ETH_DST); |
| 208 | boolean broadcastObjective = ethDst != null && |
| 209 | (ethDst.mac().isBroadcast() || ethDst.mac().isMulticast()); |
| 210 | |
| 211 | FilteringObjective filteringObjective = buildFilteringObjective(intent, |
| 212 | instructions.selector(), |
| 213 | deviceId, inPort); |
| 214 | if (filteringObjective != null) { |
| 215 | objectives.add(filteringObjective); |
| 216 | } |
| 217 | if (treatmentsWithDifferentPort.size() < 2 && !broadcastObjective) { |
| 218 | objectives.addAll(createSimpleNextObjective(instructions, intent)); |
| 219 | } else { |
| 220 | objectives.addAll(createBroadcastObjective(instructions, |
| 221 | treatmentsWithDifferentPort, |
| 222 | intent)); |
| 223 | } |
| 224 | }); |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 225 | |
| 226 | return objectives; |
| 227 | } |
Pier Ventre | d48320e | 2016-08-17 16:25:47 -0700 | [diff] [blame] | 228 | |
Ray Milkey | 92d206b | 2018-02-12 15:01:24 -0800 | [diff] [blame] | 229 | private List<Objective> createBroadcastObjective(ForwardingInstructions instructions, |
| 230 | Set<TrafficTreatment> treatmentsWithDifferentPort, |
| 231 | LinkCollectionIntent intent) { |
| 232 | List<Objective> objectives = Lists.newArrayList(); |
| 233 | ForwardingObjective forwardingObjective; |
| 234 | NextObjective nextObjective; |
| 235 | |
| 236 | Integer nextId = flowObjectiveService.allocateNextId(); |
| 237 | |
| 238 | forwardingObjective = buildForwardingObjective(instructions.selector(), |
| 239 | nextId, intent.priority()); |
| 240 | |
| 241 | DefaultNextObjective.Builder nxBuilder = DefaultNextObjective.builder(); |
| 242 | nxBuilder.withId(nextId) |
| 243 | .withMeta(instructions.selector()) |
| 244 | .withType(NextObjective.Type.BROADCAST) |
| 245 | .fromApp(appId) |
| 246 | .withPriority(intent.priority()) |
| 247 | .makePermanent(); |
| 248 | |
| 249 | treatmentsWithDifferentPort.forEach(nxBuilder::addTreatment); |
| 250 | nextObjective = nxBuilder.add(); |
| 251 | |
| 252 | objectives.add(forwardingObjective); |
| 253 | objectives.add(nextObjective); |
| 254 | |
| 255 | return objectives; |
| 256 | } |
| 257 | |
| 258 | private List<Objective> createSimpleNextObjective(ForwardingInstructions instructions, |
| 259 | LinkCollectionIntent intent) { |
| 260 | List<Objective> objectives = Lists.newArrayList(); |
| 261 | ForwardingObjective forwardingObjective; |
| 262 | NextObjective nextObjective; |
| 263 | |
| 264 | Integer nextId = flowObjectiveService.allocateNextId(); |
| 265 | |
| 266 | forwardingObjective = buildForwardingObjective(instructions.selector(), |
| 267 | nextId, intent.priority()); |
| 268 | |
| 269 | DefaultNextObjective.Builder nxBuilder = DefaultNextObjective.builder(); |
| 270 | nextObjective = nxBuilder.withId(nextId) |
| 271 | .withMeta(instructions.selector()) |
| 272 | .addTreatment(instructions.treatment()) |
| 273 | .withType(NextObjective.Type.SIMPLE) |
| 274 | .fromApp(appId) |
| 275 | .makePermanent() |
| 276 | .withPriority(intent.priority()) |
| 277 | .add(); |
| 278 | |
| 279 | objectives.add(forwardingObjective); |
| 280 | objectives.add(nextObjective); |
| 281 | |
| 282 | return objectives; |
| 283 | } |
| 284 | |
| 285 | private ForwardingObjective buildForwardingObjective(TrafficSelector selector, |
| 286 | Integer nextId, int priority) { |
| 287 | return DefaultForwardingObjective.builder() |
| 288 | .withMeta(selector) |
| 289 | .withSelector(selector) |
| 290 | .nextStep(nextId) |
| 291 | .fromApp(appId) |
| 292 | .withPriority(priority) |
| 293 | .withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 294 | .makePermanent() |
| 295 | .add(); |
| 296 | } |
| 297 | |
| 298 | private FilteringObjective buildFilteringObjective(LinkCollectionIntent intent, |
| 299 | TrafficSelector selector, |
| 300 | DeviceId deviceId, |
| 301 | PortNumber inPort) { |
| 302 | FilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 303 | builder.fromApp(appId) |
| 304 | .permit() |
| 305 | .makePermanent() |
| 306 | .withPriority(intent.priority()); |
| 307 | Criterion inPortCriterion = selector.getCriterion(Criterion.Type.IN_PORT); |
| 308 | if (inPortCriterion != null) { |
| 309 | builder.withKey(inPortCriterion); |
| 310 | } |
| 311 | |
| 312 | FilteredConnectPoint ingressPoint = intent.filteredIngressPoints().stream() |
| 313 | .filter(fcp -> fcp.connectPoint().equals(new ConnectPoint(deviceId, inPort))) |
| 314 | .filter(fcp -> selector.criteria().containsAll(fcp.trafficSelector().criteria())) |
| 315 | .findFirst() |
| 316 | .orElse(null); |
| 317 | |
| 318 | AtomicBoolean emptyCondition = new AtomicBoolean(true); |
| 319 | if (ingressPoint != null) { |
| 320 | // ingress point, use criterion of it |
| 321 | ingressPoint.trafficSelector().criteria().forEach(criterion -> { |
| 322 | builder.addCondition(criterion); |
| 323 | emptyCondition.set(false); |
| 324 | }); |
| 325 | if (emptyCondition.get()) { |
| 326 | return null; |
| 327 | } |
| 328 | return builder.add(); |
| 329 | } |
| 330 | Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent); |
| 331 | if (encapConstraint.isPresent() && |
| 332 | !encapConstraint.get().encapType().equals(EncapsulationType.NONE)) { |
| 333 | // encapsulation enabled, use encapsulation label and tag. |
| 334 | EncapsulationConstraint encap = encapConstraint.get(); |
| 335 | switch (encap.encapType()) { |
| 336 | case VLAN: |
| 337 | builder.addCondition(selector.getCriterion(Criterion.Type.VLAN_VID)); |
| 338 | emptyCondition.set(false); |
| 339 | break; |
| 340 | case MPLS: |
| 341 | builder.addCondition(selector.getCriterion(Criterion.Type.MPLS_LABEL)); |
| 342 | emptyCondition.set(false); |
| 343 | break; |
| 344 | default: |
| 345 | log.warn("No filtering rule found because of unknown encapsulation type."); |
| 346 | break; |
| 347 | } |
| 348 | } else { |
| 349 | // encapsulation not enabled, check if the treatment applied to the ingress or not |
| 350 | if (intent.applyTreatmentOnEgress()) { |
| 351 | // filtering criterion will be changed on egress point, use |
| 352 | // criterion of ingress point |
| 353 | ingressPoint = intent.filteredIngressPoints().stream() |
| 354 | .findFirst() |
| 355 | .orElse(null); |
| 356 | if (ingressPoint == null) { |
| 357 | log.warn("No filtering rule found because no ingress point in the Intent"); |
| 358 | } else { |
| 359 | ingressPoint.trafficSelector().criteria().stream() |
| 360 | .filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)) |
| 361 | .forEach(criterion -> { |
| 362 | builder.addCondition(criterion); |
| 363 | emptyCondition.set(false); |
| 364 | }); |
| 365 | } |
| 366 | } else { |
| 367 | // filtering criterion will be changed on ingress point, use |
| 368 | // criterion of egress point |
| 369 | FilteredConnectPoint egressPoint = intent.filteredEgressPoints().stream() |
| 370 | .findFirst() |
| 371 | .orElse(null); |
| 372 | if (egressPoint == null) { |
| 373 | log.warn("No filtering rule found because no egress point in the Intent"); |
| 374 | } else { |
| 375 | egressPoint.trafficSelector().criteria().stream() |
| 376 | .filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)) |
| 377 | .forEach(criterion -> { |
| 378 | builder.addCondition(criterion); |
| 379 | emptyCondition.set(false); |
| 380 | }); |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | if (emptyCondition.get()) { |
| 385 | return null; |
| 386 | } |
| 387 | return builder.add(); |
| 388 | } |
Ray Milkey | db74ec7 | 2016-03-01 10:35:24 -0800 | [diff] [blame] | 389 | } |