DefaultTrafficTreatment: Build all-instructions list at creation time
so that we don't have to join the two lists each time we want to see all instructions
Change-Id: I7f1ad252776abcb6768372eeaabfa661bdded36c
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
index da3cac6..bba3e91 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
@@ -41,6 +41,7 @@
private final List<Instruction> immediate;
private final List<Instruction> deferred;
+ private final List<Instruction> all;
private final Instructions.TableTypeTransition table;
private final boolean hasClear;
@@ -51,21 +52,31 @@
/**
* Creates a new traffic treatment from the specified list of instructions.
*
- * @param instructions treatment instructions
+ * @param immediate immediate instructions
*/
- private DefaultTrafficTreatment(List<Instruction> instructions) {
- this.immediate = ImmutableList.copyOf(checkNotNull(instructions));
+ private DefaultTrafficTreatment(List<Instruction> immediate) {
+ this.immediate = ImmutableList.copyOf(checkNotNull(immediate));
this.deferred = ImmutableList.of();
+ this.all = this.immediate;
this.hasClear = false;
this.table = null;
}
+ /**
+ * Creates a new traffic treatment from the specified list of instructions.
+ *
+ * @param deferred deferred instructions
+ * @param immediate immediate instructions
+ * @param table table transition instruction
+ * @param clear instruction to clear the deferred actions list
+ */
private DefaultTrafficTreatment(List<Instruction> deferred,
List<Instruction> immediate,
Instructions.TableTypeTransition table,
boolean clear) {
this.immediate = ImmutableList.copyOf(checkNotNull(immediate));
this.deferred = ImmutableList.copyOf(checkNotNull(deferred));
+ this.all = ListUtils.union(this.immediate, this.deferred);
this.table = table;
this.hasClear = clear;
@@ -83,7 +94,7 @@
@Override
public List<Instruction> allInstructions() {
- return ListUtils.union(immediate, deferred);
+ return all;
}
@Override
@@ -92,7 +103,7 @@
}
@Override
- public Boolean clearedDeferred() {
+ public boolean clearedDeferred() {
return hasClear;
}
@@ -162,8 +173,6 @@
*/
public static final class Builder implements TrafficTreatment.Builder {
- boolean drop = false;
-
boolean clear = false;
Instructions.TableTypeTransition table;
@@ -179,11 +188,14 @@
}
// Creates a new builder based off an existing treatment
- //FIXME only works for immediate instruction sets.
private Builder(TrafficTreatment treatment) {
- for (Instruction instruction : treatment.immediate()) {
- add(instruction);
- }
+ deferred();
+ treatment.deferred().forEach(i -> add(i));
+
+ immediate();
+ treatment.immediate().forEach(i -> add(i));
+
+ clear = treatment.clearedDeferred();
}
@Override
diff --git a/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java b/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
index a2254fa..8d45f35 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
@@ -64,7 +64,7 @@
* by the device.
* @return a boolean
*/
- Boolean clearedDeferred();
+ boolean clearedDeferred();
/**
* Builder of traffic treatment entities.
diff --git a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
index 8bef293..dc8cd2b 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
@@ -54,7 +54,6 @@
import org.onosproject.net.topology.TopologyVertex;
import org.onosproject.store.Timestamp;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -94,17 +93,17 @@
public static class MockTreatment implements TrafficTreatment {
@Override
public List<Instruction> deferred() {
- return null;
+ return Collections.emptyList();
}
@Override
public List<Instruction> immediate() {
- return new ArrayList<>();
+ return Collections.emptyList();
}
@Override
public List<Instruction> allInstructions() {
- return null;
+ return Collections.emptyList();
}
@Override
@@ -113,8 +112,8 @@
}
@Override
- public Boolean clearedDeferred() {
- return null;
+ public boolean clearedDeferred() {
+ return false;
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java b/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
index 6669578..7ead516 100644
--- a/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
@@ -577,8 +577,8 @@
}
@Override
- public Boolean clearedDeferred() {
- return null;
+ public boolean clearedDeferred() {
+ return false;
}
@Override