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));
}
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));
}
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));
}
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));
}
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;
}
Aggregations