Search in sources :

Example 21 with Criterion

use of org.onosproject.net.flow.criteria.Criterion in project onos by opennetworkinglab.

the class CriterionCodecTest method matchOchSignalTypeTest.

/**
 * Tests Och signal type criterion.
 */
@Test
public void matchOchSignalTypeTest() {
    Criterion criterion = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
    ObjectNode result = criterionCodec.encode(criterion, context);
    assertThat(result, matchesCriterion(criterion));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) CriterionJsonMatcher.matchesCriterion(org.onosproject.codec.impl.CriterionJsonMatcher.matchesCriterion) Test(org.junit.Test)

Example 22 with Criterion

use of org.onosproject.net.flow.criteria.Criterion in project onos by opennetworkinglab.

the class CriterionCodecTest method matchIPv6DstTest.

/**
 * Tests IPv6 destination criterion.
 */
@Test
public void matchIPv6DstTest() {
    Criterion criterion = Criteria.matchIPv6Dst(ipPrefix6);
    ObjectNode result = criterionCodec.encode(criterion, context);
    assertThat(result, matchesCriterion(criterion));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) CriterionJsonMatcher.matchesCriterion(org.onosproject.codec.impl.CriterionJsonMatcher.matchesCriterion) Test(org.junit.Test)

Example 23 with Criterion

use of org.onosproject.net.flow.criteria.Criterion in project onos by opennetworkinglab.

the class CriterionCodecTest method matchIcmpv6CodeTest.

/**
 * Tests ICMP v6 code criterion.
 */
@Test
public void matchIcmpv6CodeTest() {
    Criterion criterion = Criteria.matchIcmpv6Code((byte) 250);
    ObjectNode result = criterionCodec.encode(criterion, context);
    assertThat(result, matchesCriterion(criterion));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) CriterionJsonMatcher.matchesCriterion(org.onosproject.codec.impl.CriterionJsonMatcher.matchesCriterion) Test(org.junit.Test)

Example 24 with Criterion

use of org.onosproject.net.flow.criteria.Criterion in project onos by opennetworkinglab.

the class CriterionCodecTest method matchIPv6ExthdrFlagsTest.

/**
 * Tests IPv6 Extension Header pseudo-field flags criterion.
 */
@Test
public void matchIPv6ExthdrFlagsTest() {
    int exthdrFlags = Criterion.IPv6ExthdrFlags.NONEXT.getValue() | Criterion.IPv6ExthdrFlags.ESP.getValue() | Criterion.IPv6ExthdrFlags.AUTH.getValue() | Criterion.IPv6ExthdrFlags.DEST.getValue() | Criterion.IPv6ExthdrFlags.FRAG.getValue() | Criterion.IPv6ExthdrFlags.ROUTER.getValue() | Criterion.IPv6ExthdrFlags.HOP.getValue() | Criterion.IPv6ExthdrFlags.UNREP.getValue() | Criterion.IPv6ExthdrFlags.UNSEQ.getValue();
    Criterion criterion = Criteria.matchIPv6ExthdrFlags(exthdrFlags);
    ObjectNode result = criterionCodec.encode(criterion, context);
    assertThat(result, matchesCriterion(criterion));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) CriterionJsonMatcher.matchesCriterion(org.onosproject.codec.impl.CriterionJsonMatcher.matchesCriterion) Test(org.junit.Test)

Example 25 with Criterion

use of org.onosproject.net.flow.criteria.Criterion in project onos by opennetworkinglab.

the class FilteringObjectiveCodec method decode.

@Override
public FilteringObjective decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    CoreService coreService = context.getService(CoreService.class);
    final JsonCodec<Criterion> criterionCodec = context.codec(Criterion.class);
    final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class);
    ObjectiveCodecHelper och = new ObjectiveCodecHelper();
    DefaultFilteringObjective.Builder baseBuilder = DefaultFilteringObjective.builder();
    final DefaultFilteringObjective.Builder builder = (DefaultFilteringObjective.Builder) och.decode(json, baseBuilder, context);
    // application id
    JsonNode appIdJson = json.get(APP_ID);
    String appId = appIdJson != null ? appIdJson.asText() : REST_APP_ID;
    builder.fromApp(coreService.registerApplication(appId));
    // decode type
    String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
    switch(typeStr) {
        case "PERMIT":
            builder.permit();
            break;
        case "DENY":
            builder.deny();
            break;
        default:
            throw new IllegalArgumentException("The requested type " + typeStr + " is not defined for FilteringObjective.");
    }
    // decode key
    JsonNode keyJson = json.get(KEY);
    if (keyJson != null) {
        Criterion key = criterionCodec.decode((ObjectNode) keyJson, context);
        builder.withKey(key);
    }
    // decode conditions
    JsonNode conditionsJson = json.get(CONDITIONS);
    checkNotNull(conditionsJson);
    if (conditionsJson != null) {
        IntStream.range(0, conditionsJson.size()).forEach(i -> {
            ObjectNode conditionJson = get(conditionsJson, i);
            builder.addCondition(criterionCodec.decode(conditionJson, context));
        });
    }
    // decode meta
    JsonNode metaJson = json.get(META);
    if (metaJson != null) {
        TrafficTreatment trafficTreatment = trafficTreatmentCodec.decode((ObjectNode) metaJson, context);
        builder.withMeta(trafficTreatment);
    }
    // decode operation
    String opStr = nullIsIllegal(json.get(OPERATION), OPERATION + MISSING_MEMBER_MESSAGE).asText();
    FilteringObjective filteringObjective;
    switch(opStr) {
        case "ADD":
            filteringObjective = builder.add();
            break;
        case "REMOVE":
            filteringObjective = builder.remove();
            break;
        default:
            throw new IllegalArgumentException("The requested operation " + opStr + " is not defined for FilteringObjective.");
    }
    return filteringObjective;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CoreService(org.onosproject.core.CoreService) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Aggregations

Criterion (org.onosproject.net.flow.criteria.Criterion)122 Test (org.junit.Test)54 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)54 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)51 CriterionJsonMatcher.matchesCriterion (org.onosproject.codec.impl.CriterionJsonMatcher.matchesCriterion)46 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)43 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)42 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)39 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)39 Instruction (org.onosproject.net.flow.instructions.Instruction)37 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)35 TrafficSelector (org.onosproject.net.flow.TrafficSelector)33 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)29 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)29 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)25 FlowRule (org.onosproject.net.flow.FlowRule)25 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)24 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)22 Instructions (org.onosproject.net.flow.instructions.Instructions)19 List (java.util.List)17