From 0ff59c27e4578b370524c893328e70a532b86c05 Mon Sep 17 00:00:00 2001 From: Michele Santuari Date: Fri, 15 Jan 2016 10:00:32 +0100 Subject: [PATCH] fix on VLAN intent encapsulation ONOS-3467 Change-Id: Ia0a72d13a551fd4183531d35c04ca19d87b85280 --- .../impl/compiler/PathIntentCompiler.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java index 7473ce5343..93e2d8c23c 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java @@ -172,12 +172,20 @@ public class PathIntentCompiler implements IntentCompiler { } VlanId prevVlanId = vlanId; - //Tag the traffic with the new VLAN - TrafficTreatment treat = DefaultTrafficTreatment.builder() - .setVlanId(vlanId) - .build(); + Optional vlanCriterion = intent.selector().criteria() + .stream().filter(criterion -> criterion.type() == Criterion.Type.VLAN_VID) + .map(criterion -> (VlanIdCriterion) criterion) + .findAny(); - rules.add(createFlowRule(intent.selector(), treat, srcLink.dst(), link.src(), intent.priority(), true)); + //Push VLAN if selector does not include VLAN + TrafficTreatment.Builder treatBuilder = DefaultTrafficTreatment.builder(); + if (!vlanCriterion.isPresent()) { + treatBuilder.pushVlan(); + } + //Tag the traffic with the new encapsulation VLAN + treatBuilder.setVlanId(vlanId); + rules.add(createFlowRule(intent.selector(), treatBuilder.build(), + srcLink.dst(), link.src(), intent.priority(), true)); ConnectPoint prev = link.dst(); @@ -211,15 +219,9 @@ public class PathIntentCompiler implements IntentCompiler { TrafficSelector egressSelector = DefaultTrafficSelector.builder() .matchInPort(prev.port()) .matchVlanId(prevVlanId).build(); - - //TODO: think to other cases for egress packet restoration - Optional vlanCriteria = intent.selector().criteria() - .stream().filter(criteria -> criteria.type() == Criterion.Type.VLAN_VID) - .map(criteria -> (VlanIdCriterion) criteria) - .findAny(); TrafficTreatment.Builder egressTreat = DefaultTrafficTreatment.builder(intent.treatment()); - if (vlanCriteria.isPresent()) { - egressTreat.setVlanId(vlanCriteria.get().vlanId()); + if (vlanCriterion.isPresent()) { + egressTreat.setVlanId(vlanCriterion.get().vlanId()); } else { egressTreat.popVlan(); }