alshabib
Committed by Gerrit Code Review

reinstating the key field in FilterObjectives

Change-Id: I25f7d105edd562785cb213f747e7d9e0650f2635
...@@ -375,6 +375,10 @@ public final class Criteria { ...@@ -375,6 +375,10 @@ public final class Criteria {
375 return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE); 375 return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
376 } 376 }
377 377
378 + public static Criterion dummy() {
379 + return new DummyCriterion();
380 + }
381 +
378 /** 382 /**
379 * Implementation of input port criterion. 383 * Implementation of input port criterion.
380 */ 384 */
...@@ -1729,4 +1733,15 @@ public final class Criteria { ...@@ -1729,4 +1733,15 @@ public final class Criteria {
1729 return false; 1733 return false;
1730 } 1734 }
1731 } 1735 }
1736 +
1737 + /**
1738 + * Dummy Criterion used with @see{FilteringObjective}.
1739 + */
1740 + private static class DummyCriterion implements Criterion {
1741 +
1742 + @Override
1743 + public Type type() {
1744 + return Type.DUMMY;
1745 + }
1746 + }
1732 } 1747 }
......
...@@ -124,7 +124,12 @@ public interface Criterion { ...@@ -124,7 +124,12 @@ public interface Criterion {
124 /** Optical channel signal ID (lambda). */ 124 /** Optical channel signal ID (lambda). */
125 OCH_SIGID, 125 OCH_SIGID,
126 /** Optical channel signal type (fixed or flexible). */ 126 /** Optical channel signal type (fixed or flexible). */
127 - OCH_SIGTYPE 127 + OCH_SIGTYPE,
128 +
129 + /**
130 + * An empty criterion.
131 + */
132 + DUMMY
128 } 133 }
129 134
130 /** 135 /**
......
...@@ -17,6 +17,7 @@ package org.onosproject.net.flowobjective; ...@@ -17,6 +17,7 @@ package org.onosproject.net.flowobjective;
17 17
18 import com.google.common.collect.ImmutableList; 18 import com.google.common.collect.ImmutableList;
19 import org.onosproject.core.ApplicationId; 19 import org.onosproject.core.ApplicationId;
20 +import org.onosproject.net.flow.criteria.Criteria;
20 import org.onosproject.net.flow.criteria.Criterion; 21 import org.onosproject.net.flow.criteria.Criterion;
21 22
22 import java.util.Collection; 23 import java.util.Collection;
...@@ -37,13 +38,15 @@ public final class DefaultFilteringObjective implements FilteringObjective { ...@@ -37,13 +38,15 @@ public final class DefaultFilteringObjective implements FilteringObjective {
37 private final int timeout; 38 private final int timeout;
38 private final ApplicationId appId; 39 private final ApplicationId appId;
39 private final int priority; 40 private final int priority;
41 + private final Criterion key;
40 private final List<Criterion> conditions; 42 private final List<Criterion> conditions;
41 private final int id; 43 private final int id;
42 private final Operation op; 44 private final Operation op;
43 45
44 private DefaultFilteringObjective(Type type, boolean permanent, int timeout, 46 private DefaultFilteringObjective(Type type, boolean permanent, int timeout,
45 - ApplicationId appId, int priority, 47 + ApplicationId appId, int priority, Criterion key,
46 List<Criterion> conditions, Operation op) { 48 List<Criterion> conditions, Operation op) {
49 + this.key = key;
47 this.type = type; 50 this.type = type;
48 this.permanent = permanent; 51 this.permanent = permanent;
49 this.timeout = timeout; 52 this.timeout = timeout;
...@@ -52,11 +55,16 @@ public final class DefaultFilteringObjective implements FilteringObjective { ...@@ -52,11 +55,16 @@ public final class DefaultFilteringObjective implements FilteringObjective {
52 this.conditions = conditions; 55 this.conditions = conditions;
53 this.op = op; 56 this.op = op;
54 57
55 - this.id = Objects.hash(type, conditions, permanent, 58 + this.id = Objects.hash(type, key, conditions, permanent,
56 timeout, appId, priority); 59 timeout, appId, priority);
57 } 60 }
58 61
59 @Override 62 @Override
63 + public Criterion key() {
64 + return key;
65 + }
66 +
67 + @Override
60 public Type type() { 68 public Type type() {
61 return this.type; 69 return this.type;
62 } 70 }
...@@ -115,6 +123,13 @@ public final class DefaultFilteringObjective implements FilteringObjective { ...@@ -115,6 +123,13 @@ public final class DefaultFilteringObjective implements FilteringObjective {
115 private int timeout = DEFAULT_TIMEOUT; 123 private int timeout = DEFAULT_TIMEOUT;
116 private ApplicationId appId; 124 private ApplicationId appId;
117 private int priority = DEFAULT_PRIORITY; 125 private int priority = DEFAULT_PRIORITY;
126 + private Criterion key = Criteria.dummy();
127 +
128 + @Override
129 + public Builder withKey(Criterion key) {
130 + this.key = key;
131 + return this;
132 + }
118 133
119 @Override 134 @Override
120 public Builder addCondition(Criterion criterion) { 135 public Builder addCondition(Criterion criterion) {
...@@ -167,7 +182,7 @@ public final class DefaultFilteringObjective implements FilteringObjective { ...@@ -167,7 +182,7 @@ public final class DefaultFilteringObjective implements FilteringObjective {
167 checkNotNull(appId, "Must supply an application id"); 182 checkNotNull(appId, "Must supply an application id");
168 183
169 return new DefaultFilteringObjective(type, permanent, timeout, 184 return new DefaultFilteringObjective(type, permanent, timeout,
170 - appId, priority, conditions, 185 + appId, priority, key, conditions,
171 Operation.ADD); 186 Operation.ADD);
172 187
173 } 188 }
...@@ -179,8 +194,9 @@ public final class DefaultFilteringObjective implements FilteringObjective { ...@@ -179,8 +194,9 @@ public final class DefaultFilteringObjective implements FilteringObjective {
179 checkArgument(!conditions.isEmpty(), "Must have at least one condition."); 194 checkArgument(!conditions.isEmpty(), "Must have at least one condition.");
180 checkNotNull(appId, "Must supply an application id"); 195 checkNotNull(appId, "Must supply an application id");
181 196
197 +
182 return new DefaultFilteringObjective(type, permanent, timeout, 198 return new DefaultFilteringObjective(type, permanent, timeout,
183 - appId, priority, conditions, 199 + appId, priority, key, conditions,
184 Operation.REMOVE); 200 Operation.REMOVE);
185 201
186 } 202 }
......
...@@ -41,6 +41,13 @@ public interface FilteringObjective extends Objective { ...@@ -41,6 +41,13 @@ public interface FilteringObjective extends Objective {
41 } 41 }
42 42
43 /** 43 /**
44 + * Obtain the key for this filter.
45 + *
46 + * @return a criterion
47 + */
48 + public Criterion key();
49 +
50 + /**
44 * Obtain this filtering type. 51 * Obtain this filtering type.
45 * @return the type 52 * @return the type
46 */ 53 */
...@@ -59,6 +66,14 @@ public interface FilteringObjective extends Objective { ...@@ -59,6 +66,14 @@ public interface FilteringObjective extends Objective {
59 public interface Builder extends Objective.Builder { 66 public interface Builder extends Objective.Builder {
60 67
61 /** 68 /**
69 + * Specify the key for the filter.
70 + *
71 + * @param key a criterion
72 + * @return a filter objective builder
73 + */
74 + public Builder withKey(Criterion key);
75 +
76 + /**
62 * Add a filtering condition. 77 * Add a filtering condition.
63 * 78 *
64 * @param criterion new criterion 79 * @param criterion new criterion
......
...@@ -74,6 +74,7 @@ public final class CriterionCodec extends JsonCodec<Criterion> { ...@@ -74,6 +74,7 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
74 formatMap.put(Criterion.Type.IPV6_EXTHDR, new FormatIpV6Exthdr()); 74 formatMap.put(Criterion.Type.IPV6_EXTHDR, new FormatIpV6Exthdr());
75 formatMap.put(Criterion.Type.OCH_SIGID, new FormatOchSigId()); 75 formatMap.put(Criterion.Type.OCH_SIGID, new FormatOchSigId());
76 formatMap.put(Criterion.Type.OCH_SIGTYPE, new FormatOchSigType()); 76 formatMap.put(Criterion.Type.OCH_SIGTYPE, new FormatOchSigType());
77 + formatMap.put(Criterion.Type.DUMMY, new FormatDummyType());
77 78
78 // Currently unimplemented 79 // Currently unimplemented
79 formatMap.put(Criterion.Type.ARP_OP, new FormatUnknown()); 80 formatMap.put(Criterion.Type.ARP_OP, new FormatUnknown());
...@@ -316,6 +317,17 @@ public final class CriterionCodec extends JsonCodec<Criterion> { ...@@ -316,6 +317,17 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
316 } 317 }
317 } 318 }
318 319
320 + private class FormatDummyType implements CriterionTypeFormatter {
321 +
322 + @Override
323 + public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
324 + checkNotNull(criterion, "Criterion cannot be null");
325 +
326 + return root.put("type", criterion.type().toString());
327 +
328 + }
329 + }
330 +
319 @Override 331 @Override
320 public ObjectNode encode(Criterion criterion, CodecContext context) { 332 public ObjectNode encode(Criterion criterion, CodecContext context) {
321 checkNotNull(criterion, "Criterion cannot be null"); 333 checkNotNull(criterion, "Criterion cannot be null");
...@@ -331,4 +343,6 @@ public final class CriterionCodec extends JsonCodec<Criterion> { ...@@ -331,4 +343,6 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
331 343
332 return formatter.formatCriterion(result, criterion); 344 return formatter.formatCriterion(result, criterion);
333 } 345 }
346 +
347 +
334 } 348 }
......