alshabib
Committed by Gerrit Code Review

reinstating the key field in FilterObjectives

Change-Id: I25f7d105edd562785cb213f747e7d9e0650f2635
......@@ -375,6 +375,10 @@ public final class Criteria {
return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
}
public static Criterion dummy() {
return new DummyCriterion();
}
/**
* Implementation of input port criterion.
*/
......@@ -1729,4 +1733,15 @@ public final class Criteria {
return false;
}
}
/**
* Dummy Criterion used with @see{FilteringObjective}.
*/
private static class DummyCriterion implements Criterion {
@Override
public Type type() {
return Type.DUMMY;
}
}
}
......
......@@ -124,7 +124,12 @@ public interface Criterion {
/** Optical channel signal ID (lambda). */
OCH_SIGID,
/** Optical channel signal type (fixed or flexible). */
OCH_SIGTYPE
OCH_SIGTYPE,
/**
* An empty criterion.
*/
DUMMY
}
/**
......
......@@ -17,6 +17,7 @@ package org.onosproject.net.flowobjective;
import com.google.common.collect.ImmutableList;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import java.util.Collection;
......@@ -37,13 +38,15 @@ public final class DefaultFilteringObjective implements FilteringObjective {
private final int timeout;
private final ApplicationId appId;
private final int priority;
private final Criterion key;
private final List<Criterion> conditions;
private final int id;
private final Operation op;
private DefaultFilteringObjective(Type type, boolean permanent, int timeout,
ApplicationId appId, int priority,
ApplicationId appId, int priority, Criterion key,
List<Criterion> conditions, Operation op) {
this.key = key;
this.type = type;
this.permanent = permanent;
this.timeout = timeout;
......@@ -52,11 +55,16 @@ public final class DefaultFilteringObjective implements FilteringObjective {
this.conditions = conditions;
this.op = op;
this.id = Objects.hash(type, conditions, permanent,
this.id = Objects.hash(type, key, conditions, permanent,
timeout, appId, priority);
}
@Override
public Criterion key() {
return key;
}
@Override
public Type type() {
return this.type;
}
......@@ -115,6 +123,13 @@ public final class DefaultFilteringObjective implements FilteringObjective {
private int timeout = DEFAULT_TIMEOUT;
private ApplicationId appId;
private int priority = DEFAULT_PRIORITY;
private Criterion key = Criteria.dummy();
@Override
public Builder withKey(Criterion key) {
this.key = key;
return this;
}
@Override
public Builder addCondition(Criterion criterion) {
......@@ -167,7 +182,7 @@ public final class DefaultFilteringObjective implements FilteringObjective {
checkNotNull(appId, "Must supply an application id");
return new DefaultFilteringObjective(type, permanent, timeout,
appId, priority, conditions,
appId, priority, key, conditions,
Operation.ADD);
}
......@@ -179,8 +194,9 @@ public final class DefaultFilteringObjective implements FilteringObjective {
checkArgument(!conditions.isEmpty(), "Must have at least one condition.");
checkNotNull(appId, "Must supply an application id");
return new DefaultFilteringObjective(type, permanent, timeout,
appId, priority, conditions,
appId, priority, key, conditions,
Operation.REMOVE);
}
......
......@@ -41,6 +41,13 @@ public interface FilteringObjective extends Objective {
}
/**
* Obtain the key for this filter.
*
* @return a criterion
*/
public Criterion key();
/**
* Obtain this filtering type.
* @return the type
*/
......@@ -59,6 +66,14 @@ public interface FilteringObjective extends Objective {
public interface Builder extends Objective.Builder {
/**
* Specify the key for the filter.
*
* @param key a criterion
* @return a filter objective builder
*/
public Builder withKey(Criterion key);
/**
* Add a filtering condition.
*
* @param criterion new criterion
......
......@@ -74,6 +74,7 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
formatMap.put(Criterion.Type.IPV6_EXTHDR, new FormatIpV6Exthdr());
formatMap.put(Criterion.Type.OCH_SIGID, new FormatOchSigId());
formatMap.put(Criterion.Type.OCH_SIGTYPE, new FormatOchSigType());
formatMap.put(Criterion.Type.DUMMY, new FormatDummyType());
// Currently unimplemented
formatMap.put(Criterion.Type.ARP_OP, new FormatUnknown());
......@@ -316,6 +317,17 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
}
}
private class FormatDummyType implements CriterionTypeFormatter {
@Override
public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
checkNotNull(criterion, "Criterion cannot be null");
return root.put("type", criterion.type().toString());
}
}
@Override
public ObjectNode encode(Criterion criterion, CodecContext context) {
checkNotNull(criterion, "Criterion cannot be null");
......@@ -331,4 +343,6 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
return formatter.formatCriterion(result, criterion);
}
}
......