Updating DefaultTrafficTreatment
- Updating EMPTY treatment to contain NOACTION
- Remove NOACTION when building treatment from existing treatment
- Putting NOACTION into immediate set if no actions exist
Change-Id: I408b6b8daf2a3d38604a900c09d7c15cc3994757
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 26ab1bd..8502503 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
@@ -31,7 +31,6 @@
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.meter.MeterId;
-import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -51,7 +50,7 @@
private final boolean hasClear;
private static final DefaultTrafficTreatment EMPTY
- = new DefaultTrafficTreatment(Collections.emptyList());
+ = new DefaultTrafficTreatment(ImmutableList.of(Instructions.createNoAction()));
private final Instructions.MeterInstruction meter;
/**
@@ -224,7 +223,10 @@
treatment.deferred().forEach(i -> add(i));
immediate();
- treatment.immediate().forEach(i -> add(i));
+ treatment.immediate().stream()
+ // NOACTION will get re-added if there are no other actions
+ .filter(i -> i.type() != Instruction.Type.NOACTION)
+ .forEach(i -> add(i));
clear = treatment.clearedDeferred();
}
@@ -476,6 +478,7 @@
public TrafficTreatment build() {
if (deferred.size() == 0 && immediate.size() == 0
&& table == null && !clear) {
+ immediate();
noAction();
}
return new DefaultTrafficTreatment(deferred, immediate, table, clear, meta, meter);
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java b/core/common/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java
index 72081e6..c3cdca0 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java
@@ -416,6 +416,8 @@
description);
} else if (instruction instanceof ModMplsLabelInstruction) {
return matchModMplsLabelInstruction(jsonInstruction, description);
+ } else if (instruction instanceof NoActionInstruction) {
+ return true;
}
return false;