Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -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 | |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Sets; |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 19 | import org.onlab.packet.EthType; |
| 20 | import org.onlab.packet.Ethernet; |
| 21 | import org.onlab.packet.MplsLabel; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 22 | import org.onlab.packet.VlanId; |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 23 | import org.onlab.util.Identifier; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 24 | import org.onosproject.net.ConnectPoint; |
| 25 | import org.onosproject.net.DeviceId; |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 26 | import org.onosproject.net.EncapsulationType; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 27 | import org.onosproject.net.Link; |
| 28 | import org.onosproject.net.LinkKey; |
| 29 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 30 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 31 | import org.onosproject.net.flow.TrafficSelector; |
| 32 | import org.onosproject.net.flow.TrafficTreatment; |
| 33 | import org.onosproject.net.flow.criteria.Criterion; |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 34 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 35 | import org.onosproject.net.flow.criteria.MplsCriterion; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 36 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 37 | import org.onosproject.net.flow.instructions.Instruction; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 38 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 39 | import org.onosproject.net.intent.IntentCompilationException; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 40 | import org.onosproject.net.intent.PathIntent; |
| 41 | import org.onosproject.net.intent.constraint.EncapsulationConstraint; |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 42 | import org.onosproject.net.resource.ResourceService; |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 43 | import org.onosproject.net.resource.impl.LabelAllocator; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 44 | import org.slf4j.Logger; |
| 45 | |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 46 | import java.util.Iterator; |
| 47 | import java.util.List; |
| 48 | import java.util.Map; |
| 49 | import java.util.Optional; |
| 50 | import java.util.Set; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 51 | |
| 52 | import static org.onosproject.net.LinkKey.linkKey; |
| 53 | |
| 54 | /** |
| 55 | * Shared APIs and implementations for path compilers. |
| 56 | */ |
| 57 | |
| 58 | public class PathCompiler<T> { |
| 59 | |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 60 | private static final String ERROR_VLAN = "No VLAN Ids available for "; |
| 61 | private static final String ERROR_MPLS = "No available MPLS labels for "; |
| 62 | |
| 63 | static LabelAllocator labelAllocator; |
Pier Luigi Ventre | 51313bd | 2016-06-02 10:50:30 +0200 | [diff] [blame] | 64 | |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 65 | /** |
| 66 | * Defines methods used to create objects representing flows. |
| 67 | */ |
| 68 | public interface PathCompilerCreateFlow<T> { |
| 69 | |
| 70 | void createFlow(TrafficSelector originalSelector, |
| 71 | TrafficTreatment originalTreatment, |
| 72 | ConnectPoint ingress, ConnectPoint egress, |
| 73 | int priority, |
| 74 | boolean applyTreatment, |
| 75 | List<T> flows, |
| 76 | List<DeviceId> devices); |
| 77 | |
| 78 | Logger log(); |
| 79 | |
| 80 | ResourceService resourceService(); |
| 81 | } |
| 82 | |
| 83 | private boolean isLast(List<Link> links, int i) { |
| 84 | return i == links.size() - 2; |
| 85 | } |
| 86 | |
Pier Luigi Ventre | 51313bd | 2016-06-02 10:50:30 +0200 | [diff] [blame] | 87 | /** |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 88 | * Returns the ethertype match needed. If the selector provides |
| 89 | * an ethertype, it will be used. IPv4 will be used otherwise. |
Pier Luigi Ventre | 51313bd | 2016-06-02 10:50:30 +0200 | [diff] [blame] | 90 | * |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 91 | * @param selector the traffic selector. |
| 92 | * @return the ethertype we should match against |
Pier Luigi Ventre | 51313bd | 2016-06-02 10:50:30 +0200 | [diff] [blame] | 93 | */ |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 94 | private EthType getEthType(TrafficSelector selector) { |
| 95 | Criterion c = selector.getCriterion(Criterion.Type.ETH_TYPE); |
| 96 | if (c != null && c instanceof EthTypeCriterion) { |
| 97 | EthTypeCriterion ethertype = (EthTypeCriterion) c; |
| 98 | return ethertype.ethType(); |
| 99 | } else { |
| 100 | return EthType.EtherType.IPV4.ethType(); |
Pier Luigi Ventre | 51313bd | 2016-06-02 10:50:30 +0200 | [diff] [blame] | 101 | } |
Pier Luigi Ventre | 51313bd | 2016-06-02 10:50:30 +0200 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /** |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 105 | * Creates the flow rules for the path intent using VLAN |
| 106 | * encapsulation. |
Pier Luigi Ventre | 51313bd | 2016-06-02 10:50:30 +0200 | [diff] [blame] | 107 | * |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 108 | * @param creator the flowrules creator |
| 109 | * @param flows the list of flows to fill |
| 110 | * @param devices the devices on the path |
| 111 | * @param intent the PathIntent to compile |
Pier Luigi Ventre | 51313bd | 2016-06-02 10:50:30 +0200 | [diff] [blame] | 112 | */ |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 113 | private void manageVlanEncap(PathCompilerCreateFlow<T> creator, List<T> flows, |
| 114 | List<DeviceId> devices, |
| 115 | PathIntent intent) { |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 116 | |
| 117 | Set<Link> linksSet = Sets.newConcurrentHashSet(); |
| 118 | for (int i = 1; i <= intent.path().links().size() - 2; i++) { |
| 119 | linksSet.add(intent.path().links().get(i)); |
| 120 | } |
| 121 | |
| 122 | Map<LinkKey, Identifier<?>> vlanIds = labelAllocator.assignLabelToLinks( |
| 123 | linksSet, |
| 124 | intent.id(), |
| 125 | EncapsulationType.VLAN |
| 126 | ); |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 127 | |
| 128 | Iterator<Link> links = intent.path().links().iterator(); |
| 129 | Link srcLink = links.next(); |
| 130 | |
| 131 | Link link = links.next(); |
| 132 | |
| 133 | // Ingress traffic |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 134 | VlanId vlanId = (VlanId) vlanIds.get(linkKey(link)); |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 135 | if (vlanId == null) { |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 136 | throw new IntentCompilationException(ERROR_VLAN + link); |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 137 | } |
| 138 | VlanId prevVlanId = vlanId; |
| 139 | |
| 140 | Optional<VlanIdCriterion> vlanCriterion = intent.selector().criteria() |
| 141 | .stream().filter(criterion -> criterion.type() == Criterion.Type.VLAN_VID) |
| 142 | .map(criterion -> (VlanIdCriterion) criterion) |
| 143 | .findAny(); |
| 144 | |
| 145 | //Push VLAN if selector does not include VLAN |
| 146 | TrafficTreatment.Builder treatBuilder = DefaultTrafficTreatment.builder(); |
| 147 | if (!vlanCriterion.isPresent()) { |
| 148 | treatBuilder.pushVlan(); |
| 149 | } |
| 150 | //Tag the traffic with the new encapsulation VLAN |
| 151 | treatBuilder.setVlanId(vlanId); |
| 152 | creator.createFlow(intent.selector(), treatBuilder.build(), |
| 153 | srcLink.dst(), link.src(), intent.priority(), true, |
| 154 | flows, devices); |
| 155 | |
| 156 | ConnectPoint prev = link.dst(); |
| 157 | |
| 158 | while (links.hasNext()) { |
| 159 | |
| 160 | link = links.next(); |
| 161 | |
| 162 | if (links.hasNext()) { |
| 163 | // Transit traffic |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 164 | VlanId egressVlanId = (VlanId) vlanIds.get(linkKey(link)); |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 165 | if (egressVlanId == null) { |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 166 | throw new IntentCompilationException(ERROR_VLAN + link); |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 167 | } |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 168 | |
| 169 | TrafficSelector transitSelector = DefaultTrafficSelector.builder() |
| 170 | .matchInPort(prev.port()) |
| 171 | .matchVlanId(prevVlanId).build(); |
| 172 | |
| 173 | TrafficTreatment.Builder transitTreat = DefaultTrafficTreatment.builder(); |
| 174 | |
| 175 | // Set the new vlanId only if the previous one is different |
| 176 | if (!prevVlanId.equals(egressVlanId)) { |
| 177 | transitTreat.setVlanId(egressVlanId); |
| 178 | } |
| 179 | creator.createFlow(transitSelector, |
| 180 | transitTreat.build(), prev, link.src(), |
| 181 | intent.priority(), true, flows, devices); |
Pier Luigi Ventre | 51313bd | 2016-06-02 10:50:30 +0200 | [diff] [blame] | 182 | /* For the next hop we have to remember |
| 183 | * the previous egress VLAN id and the egress |
| 184 | * node |
| 185 | */ |
| 186 | prevVlanId = egressVlanId; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 187 | prev = link.dst(); |
| 188 | } else { |
| 189 | // Egress traffic |
| 190 | TrafficSelector egressSelector = DefaultTrafficSelector.builder() |
| 191 | .matchInPort(prev.port()) |
| 192 | .matchVlanId(prevVlanId).build(); |
| 193 | TrafficTreatment.Builder egressTreat = DefaultTrafficTreatment.builder(intent.treatment()); |
| 194 | |
| 195 | Optional<L2ModificationInstruction.ModVlanIdInstruction> modVlanIdInstruction = intent.treatment() |
| 196 | .allInstructions().stream().filter( |
| 197 | instruction -> instruction instanceof L2ModificationInstruction.ModVlanIdInstruction) |
| 198 | .map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).findAny(); |
| 199 | |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 200 | Optional<L2ModificationInstruction.ModVlanHeaderInstruction> popVlanInstruction = intent.treatment() |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 201 | .allInstructions().stream().filter( |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 202 | instruction -> instruction instanceof |
| 203 | L2ModificationInstruction.ModVlanHeaderInstruction) |
| 204 | .map(x -> (L2ModificationInstruction.ModVlanHeaderInstruction) x).findAny(); |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 205 | |
| 206 | if (!modVlanIdInstruction.isPresent() && !popVlanInstruction.isPresent()) { |
| 207 | if (vlanCriterion.isPresent()) { |
| 208 | egressTreat.setVlanId(vlanCriterion.get().vlanId()); |
| 209 | } else { |
| 210 | egressTreat.popVlan(); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | creator.createFlow(egressSelector, |
| 215 | egressTreat.build(), prev, link.src(), |
| 216 | intent.priority(), true, flows, devices); |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 221 | /** |
| 222 | * Creates the flow rules for the path intent using MPLS |
| 223 | * encapsulation. |
| 224 | * |
| 225 | * @param creator the flowrules creator |
| 226 | * @param flows the list of flows to fill |
| 227 | * @param devices the devices on the path |
| 228 | * @param intent the PathIntent to compile |
| 229 | */ |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 230 | private void manageMplsEncap(PathCompilerCreateFlow<T> creator, List<T> flows, |
| 231 | List<DeviceId> devices, |
| 232 | PathIntent intent) { |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 233 | |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 234 | Set<Link> linksSet = Sets.newConcurrentHashSet(); |
| 235 | for (int i = 1; i <= intent.path().links().size() - 2; i++) { |
| 236 | linksSet.add(intent.path().links().get(i)); |
| 237 | } |
| 238 | |
| 239 | Map<LinkKey, Identifier<?>> mplsLabels = labelAllocator.assignLabelToLinks( |
| 240 | linksSet, |
| 241 | intent.id(), |
| 242 | EncapsulationType.MPLS |
| 243 | ); |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 244 | Iterator<Link> links = intent.path().links().iterator(); |
| 245 | Link srcLink = links.next(); |
| 246 | |
| 247 | Link link = links.next(); |
| 248 | // List of flow rules to be installed |
| 249 | |
| 250 | // Ingress traffic |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 251 | MplsLabel mplsLabel = (MplsLabel) mplsLabels.get(linkKey(link)); |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 252 | if (mplsLabel == null) { |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 253 | throw new IntentCompilationException(ERROR_MPLS + link); |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 254 | } |
| 255 | MplsLabel prevMplsLabel = mplsLabel; |
| 256 | |
| 257 | Optional<MplsCriterion> mplsCriterion = intent.selector().criteria() |
| 258 | .stream().filter(criterion -> criterion.type() == Criterion.Type.MPLS_LABEL) |
| 259 | .map(criterion -> (MplsCriterion) criterion) |
| 260 | .findAny(); |
| 261 | |
| 262 | //Push MPLS if selector does not include MPLS |
| 263 | TrafficTreatment.Builder treatBuilder = DefaultTrafficTreatment.builder(); |
| 264 | if (!mplsCriterion.isPresent()) { |
| 265 | treatBuilder.pushMpls(); |
| 266 | } |
| 267 | //Tag the traffic with the new encapsulation MPLS label |
| 268 | treatBuilder.setMpls(mplsLabel); |
| 269 | creator.createFlow(intent.selector(), treatBuilder.build(), |
| 270 | srcLink.dst(), link.src(), intent.priority(), true, flows, devices); |
| 271 | |
| 272 | ConnectPoint prev = link.dst(); |
| 273 | |
| 274 | while (links.hasNext()) { |
| 275 | |
| 276 | link = links.next(); |
| 277 | |
| 278 | if (links.hasNext()) { |
| 279 | // Transit traffic |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 280 | MplsLabel transitMplsLabel = (MplsLabel) mplsLabels.get(linkKey(link)); |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 281 | if (transitMplsLabel == null) { |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 282 | throw new IntentCompilationException(ERROR_MPLS + link); |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 283 | } |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 284 | TrafficSelector transitSelector = DefaultTrafficSelector.builder() |
| 285 | .matchInPort(prev.port()) |
| 286 | .matchEthType(Ethernet.MPLS_UNICAST) |
| 287 | .matchMplsLabel(prevMplsLabel).build(); |
| 288 | |
| 289 | TrafficTreatment.Builder transitTreat = DefaultTrafficTreatment.builder(); |
| 290 | |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 291 | // Set the new MPLS label only if the previous one is different |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 292 | if (!prevMplsLabel.equals(transitMplsLabel)) { |
| 293 | transitTreat.setMpls(transitMplsLabel); |
| 294 | } |
| 295 | creator.createFlow(transitSelector, |
| 296 | transitTreat.build(), prev, link.src(), intent.priority(), true, flows, devices); |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 297 | prevMplsLabel = transitMplsLabel; |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 298 | prev = link.dst(); |
| 299 | } else { |
| 300 | TrafficSelector.Builder egressSelector = DefaultTrafficSelector.builder() |
| 301 | .matchInPort(prev.port()) |
| 302 | .matchEthType(Ethernet.MPLS_UNICAST) |
| 303 | .matchMplsLabel(prevMplsLabel); |
| 304 | TrafficTreatment.Builder egressTreat = DefaultTrafficTreatment.builder(intent.treatment()); |
| 305 | |
| 306 | // Egress traffic |
| 307 | // check if the treatement is popVlan or setVlan (rewrite), |
| 308 | // than selector needs to match any VlanId |
| 309 | for (Instruction instruct : intent.treatment().allInstructions()) { |
| 310 | if (instruct instanceof L2ModificationInstruction) { |
| 311 | L2ModificationInstruction l2Mod = (L2ModificationInstruction) instruct; |
| 312 | if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) { |
| 313 | break; |
| 314 | } |
| 315 | if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_POP || |
| 316 | l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) { |
| 317 | egressSelector.matchVlanId(VlanId.ANY); |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | if (mplsCriterion.isPresent()) { |
| 323 | egressTreat.setMpls(mplsCriterion.get().label()); |
| 324 | } else { |
Pier Ventre | f8543d8 | 2016-09-28 19:49:33 -0700 | [diff] [blame] | 325 | egressTreat.popMpls(getEthType(intent.selector())); |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | creator.createFlow(egressSelector.build(), |
| 329 | egressTreat.build(), prev, link.src(), intent.priority(), true, flows, devices); |
| 330 | } |
| 331 | |
| 332 | } |
| 333 | |
| 334 | } |
| 335 | |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 336 | /** |
| 337 | * Compiles an intent down to flows. |
| 338 | * |
| 339 | * @param creator how to create the flows |
| 340 | * @param intent intent to process |
| 341 | * @param flows list of generated flows |
| 342 | * @param devices list of devices that correspond to the flows |
| 343 | */ |
| 344 | public void compile(PathCompilerCreateFlow<T> creator, |
| 345 | PathIntent intent, |
| 346 | List<T> flows, |
| 347 | List<DeviceId> devices) { |
| 348 | // Note: right now recompile is not considered |
| 349 | // TODO: implement recompile behavior |
| 350 | |
| 351 | List<Link> links = intent.path().links(); |
| 352 | |
| 353 | Optional<EncapsulationConstraint> encapConstraint = intent.constraints().stream() |
| 354 | .filter(constraint -> constraint instanceof EncapsulationConstraint) |
| 355 | .map(x -> (EncapsulationConstraint) x).findAny(); |
| 356 | //if no encapsulation or is involved only a single switch use the default behaviour |
Pier | 1677f9f | 2016-07-06 15:42:17 +0200 | [diff] [blame] | 357 | if (!encapConstraint.isPresent() || links.size() == 2) { |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 358 | for (int i = 0; i < links.size() - 1; i++) { |
| 359 | ConnectPoint ingress = links.get(i).dst(); |
| 360 | ConnectPoint egress = links.get(i + 1).src(); |
| 361 | creator.createFlow(intent.selector(), intent.treatment(), |
| 362 | ingress, egress, intent.priority(), |
| 363 | isLast(links, i), flows, devices); |
| 364 | } |
Pier | 1677f9f | 2016-07-06 15:42:17 +0200 | [diff] [blame] | 365 | return; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | encapConstraint.map(EncapsulationConstraint::encapType) |
| 369 | .map(type -> { |
| 370 | switch (type) { |
| 371 | case VLAN: |
| 372 | manageVlanEncap(creator, flows, devices, intent); |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 373 | break; |
| 374 | case MPLS: |
| 375 | manageMplsEncap(creator, flows, devices, intent); |
| 376 | break; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 377 | default: |
| 378 | // Nothing to do |
| 379 | } |
| 380 | return 0; |
| 381 | }); |
| 382 | } |
| 383 | |
| 384 | } |