Intent treatments need to be passed down to the flows
Change-Id: I4569536cb62188f711ce005af1c3501dc31f7e74
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
index d3fb7d9..5e64c64 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
@@ -44,6 +44,16 @@
return new Builder();
}
+ /**
+ * Returns a new traffic treatment builder primed to produce entities
+ * patterned after the supplied treatment.
+ *
+ * @return traffic treatment builder
+ */
+ public static TrafficTreatment.Builder builder(TrafficTreatment treatment) {
+ return new Builder(treatment);
+ }
+
//FIXME: Order of instructions may affect hashcode
@Override
public int hashCode() {
@@ -90,6 +100,13 @@
private Builder() {
}
+ // Creates a new builder based off an existing treatment
+ private Builder(TrafficTreatment treatment) {
+ for (Instruction instruction : treatment.instructions()) {
+ add(instruction);
+ }
+ }
+
@Override
public Builder add(Instruction instruction) {
if (drop) {
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java
index b3eb0f5..2983a68 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java
@@ -1,6 +1,5 @@
package org.onlab.onos.net.intent.impl;
-import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.List;
@@ -17,6 +16,7 @@
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.DefaultFlowRule;
import org.onlab.onos.net.flow.DefaultTrafficSelector;
+import org.onlab.onos.net.flow.DefaultTrafficTreatment;
import org.onlab.onos.net.flow.FlowRule;
import org.onlab.onos.net.flow.FlowRuleBatchEntry;
import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
@@ -61,18 +61,16 @@
@Override
public List<FlowRuleBatchOperation> install(LinkCollectionIntent intent) {
- TrafficSelector.Builder builder =
- DefaultTrafficSelector.builder(intent.selector());
List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
for (Link link : intent.links()) {
rules.add(createBatchEntry(FlowRuleOperation.ADD,
- builder.build(),
+ intent,
link.src().deviceId(),
link.src().port()));
}
rules.add(createBatchEntry(FlowRuleOperation.ADD,
- builder.build(),
+ intent,
intent.egressPoint().deviceId(),
intent.egressPoint().port()));
@@ -81,19 +79,17 @@
@Override
public List<FlowRuleBatchOperation> uninstall(LinkCollectionIntent intent) {
- TrafficSelector.Builder builder =
- DefaultTrafficSelector.builder(intent.selector());
List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
for (Link link : intent.links()) {
rules.add(createBatchEntry(FlowRuleOperation.REMOVE,
- builder.build(),
+ intent,
link.src().deviceId(),
link.src().port()));
}
rules.add(createBatchEntry(FlowRuleOperation.REMOVE,
- builder.build(),
+ intent,
intent.egressPoint().deviceId(),
intent.egressPoint().port()));
@@ -104,17 +100,23 @@
* Creates a FlowRuleBatchEntry based on the provided parameters.
*
* @param operation the FlowRuleOperation to use
- * @param selector the traffic selector
+ * @param intent the link collection intent
* @param deviceId the device ID for the flow rule
* @param outPort the output port of the flow rule
* @return the new flow rule batch entry
*/
private FlowRuleBatchEntry createBatchEntry(FlowRuleOperation operation,
- TrafficSelector selector,
+ LinkCollectionIntent intent,
DeviceId deviceId,
PortNumber outPort) {
- TrafficTreatment treatment = builder().setOutput(outPort).build();
+ TrafficTreatment.Builder treatmentBuilder =
+ DefaultTrafficTreatment.builder(intent.treatment());
+
+ TrafficTreatment treatment = treatmentBuilder.setOutput(outPort).build();
+
+ TrafficSelector selector = DefaultTrafficSelector.builder(intent.selector())
+ .build();
FlowRule rule = new DefaultFlowRule(deviceId,
selector, treatment, 123, appId, 0, true);