diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/IntentConfigurableRegistrator.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/IntentConfigurableRegistrator.java index e14115c9b7..5750486ffa 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/IntentConfigurableRegistrator.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/IntentConfigurableRegistrator.java @@ -70,10 +70,10 @@ public class IntentConfigurableRegistrator { private String labelSelection = DEFAULT_LABEL_SELECTION; private static final boolean DEFAULT_FLOW_OPTIMIZATION = false; - @Property(name = "useFlowOptimization", + @Property(name = "optimizeInstructions", boolValue = DEFAULT_FLOW_OPTIMIZATION, 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; @Property(name = "useCopyTtl", @@ -115,7 +115,7 @@ public class IntentConfigurableRegistrator { if (context == null) { log.info("Settings: useFlowObjectives={}", useFlowObjectives); log.info("Settings: labelSelection={}", labelSelection); - log.info("Settings: useFlowOptimization={}", useFlowOptimization); + log.info("Settings: useFlowOptimization={}", optimizeInstructions); log.info("Settings: useCopyTtl={}", useCopyTtl); // FIXME: temporary code for switching old compiler to new compiler @@ -169,15 +169,15 @@ public class IntentConfigurableRegistrator { boolean newFlowOptimization; try { 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) { - newFlowOptimization = useFlowOptimization; + newFlowOptimization = optimizeInstructions; } - if (useFlowOptimization != newFlowOptimization) { - useFlowOptimization = newFlowOptimization; + if (optimizeInstructions != newFlowOptimization) { + optimizeInstructions = newFlowOptimization; changeFlowOptimization(); - log.info("Settings: useFlowOptimization={}", useFlowOptimization); + log.info("Settings: useFlowOptimization={}", optimizeInstructions); } boolean newCopyTtl; @@ -266,7 +266,7 @@ public class IntentConfigurableRegistrator { } private void changeFlowOptimization() { - LinkCollectionCompiler.optimize = useFlowOptimization; + LinkCollectionCompiler.optimizeInstructions = optimizeInstructions; } private void changeCopyTtl() { diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionCompiler.java index df87844498..7d5c4db10b 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionCompiler.java @@ -77,7 +77,7 @@ import static org.onosproject.net.flow.criteria.Criterion.Type.*; /** * Shared APIs and implementations for Link Collection compilers. */ -public class LinkCollectionCompiler { +public abstract class LinkCollectionCompiler { /** * Reference to the label allocator. @@ -88,7 +88,7 @@ public class LinkCollectionCompiler { * Influence compiler behavior. If true the compiler * try to optimize the chain of the actions. */ - static boolean optimize; + static boolean optimizeInstructions; /** * Influence compiler behavior. If true the compiler @@ -187,6 +187,13 @@ public class LinkCollectionCompiler { */ 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 * nothing. Subclasses should override this method to create their @@ -331,7 +338,7 @@ public class LinkCollectionCompiler { * The encapsulation modifies the packet. If we are optimizing * we have to update the state. */ - if (optimize) { + if (optimizeTreatments()) { preCondition = encapBuilder; } } else { @@ -345,7 +352,7 @@ public class LinkCollectionCompiler { * the others. */ TrafficSelector prevState = preCondition.build(); - if (optimize) { + if (optimizeTreatments()) { egressPoints = orderedEgressPoints(prevState, egressPoints); } /* @@ -395,7 +402,7 @@ public class LinkCollectionCompiler { * Finally we set the output action. */ treatmentBuilder.setOutput(egressPoint.connectPoint().port()); - if (optimize) { + if (optimizeTreatments()) { /* * We update the previous state. In this way instead of * transiting from FIP->FEP we do FEP->FEP and so on. @@ -558,7 +565,7 @@ public class LinkCollectionCompiler { * point then the others. */ TrafficSelector prevState = filteredIngressPoint.get().trafficSelector(); - if (optimize) { + if (optimizeTreatments()) { egressPoints = orderedEgressPoints(prevState, egressPoints); } /* diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java index 969372dcd4..b82885693e 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java @@ -126,6 +126,11 @@ public class LinkCollectionIntentCompiler return Collections.singletonList(new FlowRuleIntent(appId, intent.key(), rules, intent.resources())); } + @Override + boolean optimizeTreatments() { + return true; + } + @Override protected List createRules(LinkCollectionIntent intent, DeviceId deviceId, @@ -150,7 +155,7 @@ public class LinkCollectionIntentCompiler labels ); - if (optimize) { + if (optimizeInstructions) { TrafficTreatment compactedTreatment = compactActions(instructions.treatment()); instructions = new ForwardingInstructions(compactedTreatment, instructions.selector()); } diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java index 9396ab507d..8ea04333e6 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java @@ -127,6 +127,11 @@ public class LinkCollectionIntentFlowObjectiveCompiler intent.resourceGroup())); } + @Override + boolean optimizeTreatments() { + return false; + } + @Override protected List createRules(LinkCollectionIntent intent, DeviceId deviceId, diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompiler.java index 2af0be511a..d2bdbbc777 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompiler.java @@ -137,6 +137,11 @@ public class LinkCollectionIntentObjectiveCompiler intent.resourceGroup())); } + @Override + boolean optimizeTreatments() { + return false; + } + @Override protected List createRules(LinkCollectionIntent intent, DeviceId deviceId, diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java index 9d83e2c0a9..028f8bfc1b 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java @@ -80,7 +80,7 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio sut.registrator = registrator; sut.resourceService = new MockResourceService(); - LinkCollectionCompiler.optimize = false; + LinkCollectionCompiler.optimizeInstructions = false; LinkCollectionCompiler.copyTtl = false; replay(coreService, intentExtensionService); @@ -326,7 +326,6 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio .builder() .popMpls(IPV4.ethType()) .setOutput(d1p10.port()) - .popMpls(IPV4.ethType()) .setOutput(d1p11.port()) .build() )); @@ -580,8 +579,6 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio .pushMpls() .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()) .setOutput(d1p10.port()) - .popVlan() - .pushMpls() .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label()) .setOutput(d1p11.port()) .build() @@ -856,8 +853,6 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio .stream() .filter(instruction -> instruction instanceof ModEtherInstruction) .findFirst().get()).mac()) - .popMpls(IPV4.ethType()) - .pushVlan() .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()) .setOutput(d1p11.port()) .build() @@ -1102,12 +1097,12 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio assertThat(ruleS1.treatment(), is( DefaultTrafficTreatment .builder() + .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()) + .setOutput(d1p11.port()) .popVlan() .pushMpls() .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()) .setOutput(d1p10.port()) - .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()) - .setOutput(d1p11.port()) .build() )); @@ -1162,6 +1157,7 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio .pushVlan() .setVlanId(VlanId.vlanId(LABEL)) .setOutput(d1p0.port()) + .popVlan() .setOutput(d1p11.port()) .build() )); @@ -1363,6 +1359,8 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio .pushMpls() .setMpls(MplsLabel.mplsLabel(LABEL)) .setOutput(d1p0.port()) + .popMpls(IPV4.ethType()) + .pushVlan() .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()) .setOutput(d1p11.port()) .build() @@ -1780,8 +1778,6 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio .stream() .filter(instruction -> instruction instanceof ModEtherInstruction) .findFirst().get()).mac()) - .popVlan() - .pushMpls() .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()) .setOutput(d1p11.port()) .build() diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java index 7df4af3e6d..44754a64f6 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java @@ -83,7 +83,7 @@ public class LinkCollectionIntentCompilerP2PTest extends AbstractLinkCollectionT sut.registrator = registrator; sut.resourceService = new MockResourceService(); - LinkCollectionCompiler.optimize = false; + LinkCollectionCompiler.optimizeInstructions = false; LinkCollectionCompiler.copyTtl = false; replay(coreService, intentExtensionService); diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java index a905eaca93..f70c69ba1f 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java @@ -104,7 +104,7 @@ public class LinkCollectionIntentCompilerTest extends AbstractLinkCollectionTest sut.registrator = registrator; sut.resourceService = new MockResourceService(); - LinkCollectionCompiler.optimize = false; + LinkCollectionCompiler.optimizeInstructions = false; LinkCollectionCompiler.copyTtl = false; replay(coreService, intentExtensionService); diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java index 22ecf48cbf..613c3cb521 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java @@ -96,7 +96,7 @@ public class LinkCollectionIntentObjectiveCompilerTest extends AbstractLinkColle compiler.registrator = registrator; compiler.resourceService = resourceService; - LinkCollectionCompiler.optimize = false; + LinkCollectionCompiler.optimizeInstructions = false; LinkCollectionCompiler.copyTtl = false; replay(coreService, intentExtensionService); diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java index 01b86ba9a1..8038619976 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java @@ -83,7 +83,7 @@ public class LinkCollectionOptimizationTest extends AbstractLinkCollectionTest { /* * We activate the optimizations. */ - LinkCollectionCompiler.optimize = true; + LinkCollectionCompiler.optimizeInstructions = true; LinkCollectionCompiler.copyTtl = true; replay(coreService, intentExtensionService);