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
Showing
4 changed files
with
31 additions
and
20 deletions
| ... | @@ -41,6 +41,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { | ... | @@ -41,6 +41,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { |
| 41 | 41 | ||
| 42 | private final List<Instruction> immediate; | 42 | private final List<Instruction> immediate; |
| 43 | private final List<Instruction> deferred; | 43 | private final List<Instruction> deferred; |
| 44 | + private final List<Instruction> all; | ||
| 44 | private final Instructions.TableTypeTransition table; | 45 | private final Instructions.TableTypeTransition table; |
| 45 | 46 | ||
| 46 | private final boolean hasClear; | 47 | private final boolean hasClear; |
| ... | @@ -51,21 +52,31 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { | ... | @@ -51,21 +52,31 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { |
| 51 | /** | 52 | /** |
| 52 | * Creates a new traffic treatment from the specified list of instructions. | 53 | * Creates a new traffic treatment from the specified list of instructions. |
| 53 | * | 54 | * |
| 54 | - * @param instructions treatment instructions | 55 | + * @param immediate immediate instructions |
| 55 | */ | 56 | */ |
| 56 | - private DefaultTrafficTreatment(List<Instruction> instructions) { | 57 | + private DefaultTrafficTreatment(List<Instruction> immediate) { |
| 57 | - this.immediate = ImmutableList.copyOf(checkNotNull(instructions)); | 58 | + this.immediate = ImmutableList.copyOf(checkNotNull(immediate)); |
| 58 | this.deferred = ImmutableList.of(); | 59 | this.deferred = ImmutableList.of(); |
| 60 | + this.all = this.immediate; | ||
| 59 | this.hasClear = false; | 61 | this.hasClear = false; |
| 60 | this.table = null; | 62 | this.table = null; |
| 61 | } | 63 | } |
| 62 | 64 | ||
| 65 | + /** | ||
| 66 | + * Creates a new traffic treatment from the specified list of instructions. | ||
| 67 | + * | ||
| 68 | + * @param deferred deferred instructions | ||
| 69 | + * @param immediate immediate instructions | ||
| 70 | + * @param table table transition instruction | ||
| 71 | + * @param clear instruction to clear the deferred actions list | ||
| 72 | + */ | ||
| 63 | private DefaultTrafficTreatment(List<Instruction> deferred, | 73 | private DefaultTrafficTreatment(List<Instruction> deferred, |
| 64 | List<Instruction> immediate, | 74 | List<Instruction> immediate, |
| 65 | Instructions.TableTypeTransition table, | 75 | Instructions.TableTypeTransition table, |
| 66 | boolean clear) { | 76 | boolean clear) { |
| 67 | this.immediate = ImmutableList.copyOf(checkNotNull(immediate)); | 77 | this.immediate = ImmutableList.copyOf(checkNotNull(immediate)); |
| 68 | this.deferred = ImmutableList.copyOf(checkNotNull(deferred)); | 78 | this.deferred = ImmutableList.copyOf(checkNotNull(deferred)); |
| 79 | + this.all = ListUtils.union(this.immediate, this.deferred); | ||
| 69 | this.table = table; | 80 | this.table = table; |
| 70 | this.hasClear = clear; | 81 | this.hasClear = clear; |
| 71 | 82 | ||
| ... | @@ -83,7 +94,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { | ... | @@ -83,7 +94,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { |
| 83 | 94 | ||
| 84 | @Override | 95 | @Override |
| 85 | public List<Instruction> allInstructions() { | 96 | public List<Instruction> allInstructions() { |
| 86 | - return ListUtils.union(immediate, deferred); | 97 | + return all; |
| 87 | } | 98 | } |
| 88 | 99 | ||
| 89 | @Override | 100 | @Override |
| ... | @@ -92,7 +103,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { | ... | @@ -92,7 +103,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { |
| 92 | } | 103 | } |
| 93 | 104 | ||
| 94 | @Override | 105 | @Override |
| 95 | - public Boolean clearedDeferred() { | 106 | + public boolean clearedDeferred() { |
| 96 | return hasClear; | 107 | return hasClear; |
| 97 | } | 108 | } |
| 98 | 109 | ||
| ... | @@ -162,8 +173,6 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { | ... | @@ -162,8 +173,6 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { |
| 162 | */ | 173 | */ |
| 163 | public static final class Builder implements TrafficTreatment.Builder { | 174 | public static final class Builder implements TrafficTreatment.Builder { |
| 164 | 175 | ||
| 165 | - boolean drop = false; | ||
| 166 | - | ||
| 167 | boolean clear = false; | 176 | boolean clear = false; |
| 168 | 177 | ||
| 169 | Instructions.TableTypeTransition table; | 178 | Instructions.TableTypeTransition table; |
| ... | @@ -179,11 +188,14 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { | ... | @@ -179,11 +188,14 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { |
| 179 | } | 188 | } |
| 180 | 189 | ||
| 181 | // Creates a new builder based off an existing treatment | 190 | // Creates a new builder based off an existing treatment |
| 182 | - //FIXME only works for immediate instruction sets. | ||
| 183 | private Builder(TrafficTreatment treatment) { | 191 | private Builder(TrafficTreatment treatment) { |
| 184 | - for (Instruction instruction : treatment.immediate()) { | 192 | + deferred(); |
| 185 | - add(instruction); | 193 | + treatment.deferred().forEach(i -> add(i)); |
| 186 | - } | 194 | + |
| 195 | + immediate(); | ||
| 196 | + treatment.immediate().forEach(i -> add(i)); | ||
| 197 | + | ||
| 198 | + clear = treatment.clearedDeferred(); | ||
| 187 | } | 199 | } |
| 188 | 200 | ||
| 189 | @Override | 201 | @Override | ... | ... |
| ... | @@ -64,7 +64,7 @@ public interface TrafficTreatment { | ... | @@ -64,7 +64,7 @@ public interface TrafficTreatment { |
| 64 | * by the device. | 64 | * by the device. |
| 65 | * @return a boolean | 65 | * @return a boolean |
| 66 | */ | 66 | */ |
| 67 | - Boolean clearedDeferred(); | 67 | + boolean clearedDeferred(); |
| 68 | 68 | ||
| 69 | /** | 69 | /** |
| 70 | * Builder of traffic treatment entities. | 70 | * Builder of traffic treatment entities. | ... | ... |
| ... | @@ -54,7 +54,6 @@ import org.onosproject.net.topology.PathService; | ... | @@ -54,7 +54,6 @@ import org.onosproject.net.topology.PathService; |
| 54 | import org.onosproject.net.topology.TopologyVertex; | 54 | import org.onosproject.net.topology.TopologyVertex; |
| 55 | import org.onosproject.store.Timestamp; | 55 | import org.onosproject.store.Timestamp; |
| 56 | 56 | ||
| 57 | -import java.util.ArrayList; | ||
| 58 | import java.util.Arrays; | 57 | import java.util.Arrays; |
| 59 | import java.util.Collection; | 58 | import java.util.Collection; |
| 60 | import java.util.Collections; | 59 | import java.util.Collections; |
| ... | @@ -94,17 +93,17 @@ public class IntentTestsMocks { | ... | @@ -94,17 +93,17 @@ public class IntentTestsMocks { |
| 94 | public static class MockTreatment implements TrafficTreatment { | 93 | public static class MockTreatment implements TrafficTreatment { |
| 95 | @Override | 94 | @Override |
| 96 | public List<Instruction> deferred() { | 95 | public List<Instruction> deferred() { |
| 97 | - return null; | 96 | + return Collections.emptyList(); |
| 98 | } | 97 | } |
| 99 | 98 | ||
| 100 | @Override | 99 | @Override |
| 101 | public List<Instruction> immediate() { | 100 | public List<Instruction> immediate() { |
| 102 | - return new ArrayList<>(); | 101 | + return Collections.emptyList(); |
| 103 | } | 102 | } |
| 104 | 103 | ||
| 105 | @Override | 104 | @Override |
| 106 | public List<Instruction> allInstructions() { | 105 | public List<Instruction> allInstructions() { |
| 107 | - return null; | 106 | + return Collections.emptyList(); |
| 108 | } | 107 | } |
| 109 | 108 | ||
| 110 | @Override | 109 | @Override |
| ... | @@ -113,8 +112,8 @@ public class IntentTestsMocks { | ... | @@ -113,8 +112,8 @@ public class IntentTestsMocks { |
| 113 | } | 112 | } |
| 114 | 113 | ||
| 115 | @Override | 114 | @Override |
| 116 | - public Boolean clearedDeferred() { | 115 | + public boolean clearedDeferred() { |
| 117 | - return null; | 116 | + return false; |
| 118 | } | 117 | } |
| 119 | } | 118 | } |
| 120 | 119 | ... | ... |
| ... | @@ -577,8 +577,8 @@ public class FlowRuleManagerTest { | ... | @@ -577,8 +577,8 @@ public class FlowRuleManagerTest { |
| 577 | } | 577 | } |
| 578 | 578 | ||
| 579 | @Override | 579 | @Override |
| 580 | - public Boolean clearedDeferred() { | 580 | + public boolean clearedDeferred() { |
| 581 | - return null; | 581 | + return false; |
| 582 | } | 582 | } |
| 583 | 583 | ||
| 584 | @Override | 584 | @Override | ... | ... |
-
Please register or login to post a comment