Jonathan Hart
Committed by Ray Milkey

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
......@@ -41,6 +41,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
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 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
/**
* 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 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
@Override
public List<Instruction> allInstructions() {
return ListUtils.union(immediate, deferred);
return all;
}
@Override
......@@ -92,7 +103,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
}
@Override
public Boolean clearedDeferred() {
public boolean clearedDeferred() {
return hasClear;
}
......@@ -162,8 +173,6 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
*/
public static final class Builder implements TrafficTreatment.Builder {
boolean drop = false;
boolean clear = false;
Instructions.TableTypeTransition table;
......@@ -179,11 +188,14 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
}
// 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
......
......@@ -64,7 +64,7 @@ public interface TrafficTreatment {
* by the device.
* @return a boolean
*/
Boolean clearedDeferred();
boolean clearedDeferred();
/**
* Builder of traffic treatment entities.
......
......@@ -54,7 +54,6 @@ import org.onosproject.net.topology.PathService;
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 class IntentTestsMocks {
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 @@ public class IntentTestsMocks {
}
@Override
public Boolean clearedDeferred() {
return null;
public boolean clearedDeferred() {
return false;
}
}
......
......@@ -577,8 +577,8 @@ public class FlowRuleManagerTest {
}
@Override
public Boolean clearedDeferred() {
return null;
public boolean clearedDeferred() {
return false;
}
@Override
......