Michele Santuari
Committed by Gerrit Code Review

fix on VLAN intent encapsulation ONOS-3467

Change-Id: Ia0a72d13a551fd4183531d35c04ca19d87b85280
...@@ -172,12 +172,20 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> { ...@@ -172,12 +172,20 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
172 } 172 }
173 VlanId prevVlanId = vlanId; 173 VlanId prevVlanId = vlanId;
174 174
175 - //Tag the traffic with the new VLAN 175 + Optional<VlanIdCriterion> vlanCriterion = intent.selector().criteria()
176 - TrafficTreatment treat = DefaultTrafficTreatment.builder() 176 + .stream().filter(criterion -> criterion.type() == Criterion.Type.VLAN_VID)
177 - .setVlanId(vlanId) 177 + .map(criterion -> (VlanIdCriterion) criterion)
178 - .build(); 178 + .findAny();
179 179
180 - rules.add(createFlowRule(intent.selector(), treat, srcLink.dst(), link.src(), intent.priority(), true)); 180 + //Push VLAN if selector does not include VLAN
181 + TrafficTreatment.Builder treatBuilder = DefaultTrafficTreatment.builder();
182 + if (!vlanCriterion.isPresent()) {
183 + treatBuilder.pushVlan();
184 + }
185 + //Tag the traffic with the new encapsulation VLAN
186 + treatBuilder.setVlanId(vlanId);
187 + rules.add(createFlowRule(intent.selector(), treatBuilder.build(),
188 + srcLink.dst(), link.src(), intent.priority(), true));
181 189
182 ConnectPoint prev = link.dst(); 190 ConnectPoint prev = link.dst();
183 191
...@@ -211,15 +219,9 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> { ...@@ -211,15 +219,9 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
211 TrafficSelector egressSelector = DefaultTrafficSelector.builder() 219 TrafficSelector egressSelector = DefaultTrafficSelector.builder()
212 .matchInPort(prev.port()) 220 .matchInPort(prev.port())
213 .matchVlanId(prevVlanId).build(); 221 .matchVlanId(prevVlanId).build();
214 -
215 - //TODO: think to other cases for egress packet restoration
216 - Optional<VlanIdCriterion> vlanCriteria = intent.selector().criteria()
217 - .stream().filter(criteria -> criteria.type() == Criterion.Type.VLAN_VID)
218 - .map(criteria -> (VlanIdCriterion) criteria)
219 - .findAny();
220 TrafficTreatment.Builder egressTreat = DefaultTrafficTreatment.builder(intent.treatment()); 222 TrafficTreatment.Builder egressTreat = DefaultTrafficTreatment.builder(intent.treatment());
221 - if (vlanCriteria.isPresent()) { 223 + if (vlanCriterion.isPresent()) {
222 - egressTreat.setVlanId(vlanCriteria.get().vlanId()); 224 + egressTreat.setVlanId(vlanCriterion.get().vlanId());
223 } else { 225 } else {
224 egressTreat.popVlan(); 226 egressTreat.popVlan();
225 } 227 }
......