[ONOS-6303] Fix incorrect flow rule from link collection Intent compiler

Change-Id: If39da291c7558cf6a97e742dc0774df0874a9330
This commit is contained in:
Yi Tseng 2017-04-14 16:42:59 -07:00
parent a64f0c88b5
commit 84c5a3d8ad
10 changed files with 48 additions and 30 deletions

View File

@ -70,10 +70,10 @@ public class IntentConfigurableRegistrator {
private String labelSelection = DEFAULT_LABEL_SELECTION; private String labelSelection = DEFAULT_LABEL_SELECTION;
private static final boolean DEFAULT_FLOW_OPTIMIZATION = false; private static final boolean DEFAULT_FLOW_OPTIMIZATION = false;
@Property(name = "useFlowOptimization", @Property(name = "optimizeInstructions",
boolValue = DEFAULT_FLOW_OPTIMIZATION, boolValue = DEFAULT_FLOW_OPTIMIZATION,
label = "Indicates whether or not to optimize the flows in the link collection compiler") label = "Indicates whether or not to optimize the flows in the link collection compiler")
private boolean useFlowOptimization = DEFAULT_FLOW_OPTIMIZATION; private boolean optimizeInstructions = DEFAULT_FLOW_OPTIMIZATION;
private static final boolean DEFAULT_COPY_TTL = false; private static final boolean DEFAULT_COPY_TTL = false;
@Property(name = "useCopyTtl", @Property(name = "useCopyTtl",
@ -115,7 +115,7 @@ public class IntentConfigurableRegistrator {
if (context == null) { if (context == null) {
log.info("Settings: useFlowObjectives={}", useFlowObjectives); log.info("Settings: useFlowObjectives={}", useFlowObjectives);
log.info("Settings: labelSelection={}", labelSelection); log.info("Settings: labelSelection={}", labelSelection);
log.info("Settings: useFlowOptimization={}", useFlowOptimization); log.info("Settings: useFlowOptimization={}", optimizeInstructions);
log.info("Settings: useCopyTtl={}", useCopyTtl); log.info("Settings: useCopyTtl={}", useCopyTtl);
// FIXME: temporary code for switching old compiler to new compiler // FIXME: temporary code for switching old compiler to new compiler
@ -169,15 +169,15 @@ public class IntentConfigurableRegistrator {
boolean newFlowOptimization; boolean newFlowOptimization;
try { try {
String s = Tools.get(context.getProperties(), "useFlowOptimization"); String s = Tools.get(context.getProperties(), "useFlowOptimization");
newFlowOptimization = isNullOrEmpty(s) ? useFlowOptimization : Boolean.parseBoolean(s.trim()); newFlowOptimization = isNullOrEmpty(s) ? optimizeInstructions : Boolean.parseBoolean(s.trim());
} catch (ClassCastException e) { } catch (ClassCastException e) {
newFlowOptimization = useFlowOptimization; newFlowOptimization = optimizeInstructions;
} }
if (useFlowOptimization != newFlowOptimization) { if (optimizeInstructions != newFlowOptimization) {
useFlowOptimization = newFlowOptimization; optimizeInstructions = newFlowOptimization;
changeFlowOptimization(); changeFlowOptimization();
log.info("Settings: useFlowOptimization={}", useFlowOptimization); log.info("Settings: useFlowOptimization={}", optimizeInstructions);
} }
boolean newCopyTtl; boolean newCopyTtl;
@ -266,7 +266,7 @@ public class IntentConfigurableRegistrator {
} }
private void changeFlowOptimization() { private void changeFlowOptimization() {
LinkCollectionCompiler.optimize = useFlowOptimization; LinkCollectionCompiler.optimizeInstructions = optimizeInstructions;
} }
private void changeCopyTtl() { private void changeCopyTtl() {

View File

@ -77,7 +77,7 @@ import static org.onosproject.net.flow.criteria.Criterion.Type.*;
/** /**
* Shared APIs and implementations for Link Collection compilers. * Shared APIs and implementations for Link Collection compilers.
*/ */
public class LinkCollectionCompiler<T> { public abstract class LinkCollectionCompiler<T> {
/** /**
* Reference to the label allocator. * Reference to the label allocator.
@ -88,7 +88,7 @@ public class LinkCollectionCompiler<T> {
* Influence compiler behavior. If true the compiler * Influence compiler behavior. If true the compiler
* try to optimize the chain of the actions. * try to optimize the chain of the actions.
*/ */
static boolean optimize; static boolean optimizeInstructions;
/** /**
* Influence compiler behavior. If true the compiler * Influence compiler behavior. If true the compiler
@ -187,6 +187,13 @@ public class LinkCollectionCompiler<T> {
*/ */
private static final String UNSUPPORTED_INSTRUCTION = "Unknown instruction type"; private static final String UNSUPPORTED_INSTRUCTION = "Unknown instruction type";
/**
* Influence compiler behavior.
*
* @return true if we need the compiler optimizeTreatments the chain of the actions.
*/
abstract boolean optimizeTreatments();
/** /**
* Creates the flows representations. This default implementation does * Creates the flows representations. This default implementation does
* nothing. Subclasses should override this method to create their * nothing. Subclasses should override this method to create their
@ -331,7 +338,7 @@ public class LinkCollectionCompiler<T> {
* The encapsulation modifies the packet. If we are optimizing * The encapsulation modifies the packet. If we are optimizing
* we have to update the state. * we have to update the state.
*/ */
if (optimize) { if (optimizeTreatments()) {
preCondition = encapBuilder; preCondition = encapBuilder;
} }
} else { } else {
@ -345,7 +352,7 @@ public class LinkCollectionCompiler<T> {
* the others. * the others.
*/ */
TrafficSelector prevState = preCondition.build(); TrafficSelector prevState = preCondition.build();
if (optimize) { if (optimizeTreatments()) {
egressPoints = orderedEgressPoints(prevState, egressPoints); egressPoints = orderedEgressPoints(prevState, egressPoints);
} }
/* /*
@ -395,7 +402,7 @@ public class LinkCollectionCompiler<T> {
* Finally we set the output action. * Finally we set the output action.
*/ */
treatmentBuilder.setOutput(egressPoint.connectPoint().port()); treatmentBuilder.setOutput(egressPoint.connectPoint().port());
if (optimize) { if (optimizeTreatments()) {
/* /*
* We update the previous state. In this way instead of * We update the previous state. In this way instead of
* transiting from FIP->FEP we do FEP->FEP and so on. * transiting from FIP->FEP we do FEP->FEP and so on.
@ -558,7 +565,7 @@ public class LinkCollectionCompiler<T> {
* point then the others. * point then the others.
*/ */
TrafficSelector prevState = filteredIngressPoint.get().trafficSelector(); TrafficSelector prevState = filteredIngressPoint.get().trafficSelector();
if (optimize) { if (optimizeTreatments()) {
egressPoints = orderedEgressPoints(prevState, egressPoints); egressPoints = orderedEgressPoints(prevState, egressPoints);
} }
/* /*

View File

@ -126,6 +126,11 @@ public class LinkCollectionIntentCompiler
return Collections.singletonList(new FlowRuleIntent(appId, intent.key(), rules, intent.resources())); return Collections.singletonList(new FlowRuleIntent(appId, intent.key(), rules, intent.resources()));
} }
@Override
boolean optimizeTreatments() {
return true;
}
@Override @Override
protected List<FlowRule> createRules(LinkCollectionIntent intent, protected List<FlowRule> createRules(LinkCollectionIntent intent,
DeviceId deviceId, DeviceId deviceId,
@ -150,7 +155,7 @@ public class LinkCollectionIntentCompiler
labels labels
); );
if (optimize) { if (optimizeInstructions) {
TrafficTreatment compactedTreatment = compactActions(instructions.treatment()); TrafficTreatment compactedTreatment = compactActions(instructions.treatment());
instructions = new ForwardingInstructions(compactedTreatment, instructions.selector()); instructions = new ForwardingInstructions(compactedTreatment, instructions.selector());
} }

View File

@ -127,6 +127,11 @@ public class LinkCollectionIntentFlowObjectiveCompiler
intent.resourceGroup())); intent.resourceGroup()));
} }
@Override
boolean optimizeTreatments() {
return false;
}
@Override @Override
protected List<Objective> createRules(LinkCollectionIntent intent, protected List<Objective> createRules(LinkCollectionIntent intent,
DeviceId deviceId, DeviceId deviceId,

View File

@ -137,6 +137,11 @@ public class LinkCollectionIntentObjectiveCompiler
intent.resourceGroup())); intent.resourceGroup()));
} }
@Override
boolean optimizeTreatments() {
return false;
}
@Override @Override
protected List<Objective> createRules(LinkCollectionIntent intent, protected List<Objective> createRules(LinkCollectionIntent intent,
DeviceId deviceId, DeviceId deviceId,

View File

@ -80,7 +80,7 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio
sut.registrator = registrator; sut.registrator = registrator;
sut.resourceService = new MockResourceService(); sut.resourceService = new MockResourceService();
LinkCollectionCompiler.optimize = false; LinkCollectionCompiler.optimizeInstructions = false;
LinkCollectionCompiler.copyTtl = false; LinkCollectionCompiler.copyTtl = false;
replay(coreService, intentExtensionService); replay(coreService, intentExtensionService);
@ -326,7 +326,6 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio
.builder() .builder()
.popMpls(IPV4.ethType()) .popMpls(IPV4.ethType())
.setOutput(d1p10.port()) .setOutput(d1p10.port())
.popMpls(IPV4.ethType())
.setOutput(d1p11.port()) .setOutput(d1p11.port())
.build() .build()
)); ));
@ -580,8 +579,6 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio
.pushMpls() .pushMpls()
.setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()) .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
.setOutput(d1p10.port()) .setOutput(d1p10.port())
.popVlan()
.pushMpls()
.setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label()) .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
.setOutput(d1p11.port()) .setOutput(d1p11.port())
.build() .build()
@ -856,8 +853,6 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio
.stream() .stream()
.filter(instruction -> instruction instanceof ModEtherInstruction) .filter(instruction -> instruction instanceof ModEtherInstruction)
.findFirst().get()).mac()) .findFirst().get()).mac())
.popMpls(IPV4.ethType())
.pushVlan()
.setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()) .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
.setOutput(d1p11.port()) .setOutput(d1p11.port())
.build() .build()
@ -1102,12 +1097,12 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio
assertThat(ruleS1.treatment(), is( assertThat(ruleS1.treatment(), is(
DefaultTrafficTreatment DefaultTrafficTreatment
.builder() .builder()
.setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
.setOutput(d1p11.port())
.popVlan() .popVlan()
.pushMpls() .pushMpls()
.setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()) .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
.setOutput(d1p10.port()) .setOutput(d1p10.port())
.setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
.setOutput(d1p11.port())
.build() .build()
)); ));
@ -1162,6 +1157,7 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio
.pushVlan() .pushVlan()
.setVlanId(VlanId.vlanId(LABEL)) .setVlanId(VlanId.vlanId(LABEL))
.setOutput(d1p0.port()) .setOutput(d1p0.port())
.popVlan()
.setOutput(d1p11.port()) .setOutput(d1p11.port())
.build() .build()
)); ));
@ -1363,6 +1359,8 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio
.pushMpls() .pushMpls()
.setMpls(MplsLabel.mplsLabel(LABEL)) .setMpls(MplsLabel.mplsLabel(LABEL))
.setOutput(d1p0.port()) .setOutput(d1p0.port())
.popMpls(IPV4.ethType())
.pushVlan()
.setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()) .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
.setOutput(d1p11.port()) .setOutput(d1p11.port())
.build() .build()
@ -1780,8 +1778,6 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio
.stream() .stream()
.filter(instruction -> instruction instanceof ModEtherInstruction) .filter(instruction -> instruction instanceof ModEtherInstruction)
.findFirst().get()).mac()) .findFirst().get()).mac())
.popVlan()
.pushMpls()
.setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()) .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
.setOutput(d1p11.port()) .setOutput(d1p11.port())
.build() .build()

View File

@ -83,7 +83,7 @@ public class LinkCollectionIntentCompilerP2PTest extends AbstractLinkCollectionT
sut.registrator = registrator; sut.registrator = registrator;
sut.resourceService = new MockResourceService(); sut.resourceService = new MockResourceService();
LinkCollectionCompiler.optimize = false; LinkCollectionCompiler.optimizeInstructions = false;
LinkCollectionCompiler.copyTtl = false; LinkCollectionCompiler.copyTtl = false;
replay(coreService, intentExtensionService); replay(coreService, intentExtensionService);

View File

@ -104,7 +104,7 @@ public class LinkCollectionIntentCompilerTest extends AbstractLinkCollectionTest
sut.registrator = registrator; sut.registrator = registrator;
sut.resourceService = new MockResourceService(); sut.resourceService = new MockResourceService();
LinkCollectionCompiler.optimize = false; LinkCollectionCompiler.optimizeInstructions = false;
LinkCollectionCompiler.copyTtl = false; LinkCollectionCompiler.copyTtl = false;
replay(coreService, intentExtensionService); replay(coreService, intentExtensionService);

View File

@ -96,7 +96,7 @@ public class LinkCollectionIntentObjectiveCompilerTest extends AbstractLinkColle
compiler.registrator = registrator; compiler.registrator = registrator;
compiler.resourceService = resourceService; compiler.resourceService = resourceService;
LinkCollectionCompiler.optimize = false; LinkCollectionCompiler.optimizeInstructions = false;
LinkCollectionCompiler.copyTtl = false; LinkCollectionCompiler.copyTtl = false;
replay(coreService, intentExtensionService); replay(coreService, intentExtensionService);

View File

@ -83,7 +83,7 @@ public class LinkCollectionOptimizationTest extends AbstractLinkCollectionTest {
/* /*
* We activate the optimizations. * We activate the optimizations.
*/ */
LinkCollectionCompiler.optimize = true; LinkCollectionCompiler.optimizeInstructions = true;
LinkCollectionCompiler.copyTtl = true; LinkCollectionCompiler.copyTtl = true;
replay(coreService, intentExtensionService); replay(coreService, intentExtensionService);