Add ability to set clearDeferred flag in treatments from REST API.
Change-Id: Ib7128f8b7bce3a51cb4a0d764cf00142095634cf
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/TrafficTreatmentCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/TrafficTreatmentCodec.java
index 1378c3e..098aef2 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/TrafficTreatmentCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/TrafficTreatmentCodec.java
@@ -15,17 +15,16 @@
*/
package org.onosproject.codec.impl;
-import java.util.stream.IntStream;
-
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.instructions.Instruction;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.util.stream.IntStream;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -35,6 +34,7 @@
public final class TrafficTreatmentCodec extends JsonCodec<TrafficTreatment> {
private static final String INSTRUCTIONS = "instructions";
private static final String DEFERRED = "deferred";
+ private static final String CLEAR_DEFERRED = "clearDeferred";
@Override
public ObjectNode encode(TrafficTreatment treatment, CodecContext context) {
@@ -56,8 +56,11 @@
if (treatment.tableTransition() != null) {
jsonInstructions.add(instructionCodec.encode(treatment.tableTransition(), context));
}
+ if (treatment.clearedDeferred()) {
+ result.put(CLEAR_DEFERRED, true);
+ }
- final ArrayNode jsonDeferred = result.putArray("deferred");
+ final ArrayNode jsonDeferred = result.putArray(DEFERRED);
for (final Instruction instruction : treatment.deferred()) {
jsonDeferred.add(instructionCodec.encode(instruction, context));
@@ -80,6 +83,11 @@
context)));
}
+ JsonNode clearDeferred = json.get(CLEAR_DEFERRED);
+ if (clearDeferred != null && clearDeferred.asBoolean(false)) {
+ builder.wipeDeferred();
+ }
+
JsonNode deferredJson = json.get(DEFERRED);
if (deferredJson != null) {
IntStream.range(0, deferredJson.size())