Jonathan Hart

Added getCriterion method to TrafficSelector

Change-Id: I72d89d878e1fae95d1e16d9ed473b7711895e478
......@@ -55,6 +55,16 @@ public final class DefaultTrafficSelector implements TrafficSelector {
}
@Override
public Criterion getCriterion(Criterion.Type type) {
for (Criterion c : criteria) {
if (c.type() == type) {
return c;
}
}
return null;
}
@Override
public int hashCode() {
return Objects.hash(criteria);
}
......
......@@ -39,6 +39,15 @@ public interface TrafficSelector {
Set<Criterion> criteria();
/**
* Returns the selection criterion for a particular type, if it exists in
* this traffic selector.
*
* @param type criterion type to look up
* @return the criterion of the specified type if one exists, otherwise null
*/
Criterion getCriterion(Criterion.Type type);
/**
* Builder of traffic selector entities.
*/
public interface Builder {
......
......@@ -6,12 +6,11 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADD_REQUESTED;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVE_REQUESTED;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_UPDATED;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
......@@ -39,6 +38,7 @@ import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.device.DeviceListener;
import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.flow.BatchOperation;
import org.onlab.onos.net.flow.CompletedBatchOperation;
import org.onlab.onos.net.flow.DefaultFlowEntry;
import org.onlab.onos.net.flow.DefaultFlowRule;
......@@ -58,7 +58,6 @@ import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.flow.criteria.Criterion;
import org.onlab.onos.net.flow.instructions.Instruction;
import org.onlab.onos.net.flow.BatchOperation;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.trivial.impl.SimpleFlowRuleStore;
......@@ -583,6 +582,12 @@ public class FlowRuleManagerTest {
}
@Override
public Criterion getCriterion(
org.onlab.onos.net.flow.criteria.Criterion.Type type) {
return null;
}
@Override
public int hashCode() {
return testval;
}
......@@ -594,6 +599,7 @@ public class FlowRuleManagerTest {
}
return false;
}
}
private class TestTreatment implements TrafficTreatment {
......
package org.onlab.onos.net.intent;
import static org.onlab.onos.net.NetTestTools.createPath;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
......@@ -12,12 +14,11 @@ import org.onlab.onos.net.Path;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.flow.criteria.Criterion;
import org.onlab.onos.net.flow.criteria.Criterion.Type;
import org.onlab.onos.net.flow.instructions.Instruction;
import org.onlab.onos.net.topology.LinkWeight;
import org.onlab.onos.net.topology.PathService;
import static org.onlab.onos.net.NetTestTools.createPath;
/**
* Common mocks used by the intent framework tests.
*/
......@@ -30,6 +31,11 @@ public class IntentTestsMocks {
public Set<Criterion> criteria() {
return new HashSet<>();
}
@Override
public Criterion getCriterion(Type type) {
return null;
}
}
/**
......