use of org.onosproject.net.intent.constraint.TierConstraint in project onos by opennetworkinglab.
the class DecodeConstraintCodecHelper method decodeTierConstraint.
/**
* Decodes a link type constraint.
*
* @return link type constraint object.
*/
private Constraint decodeTierConstraint() {
boolean inclusive = nullIsIllegal(json.get(ConstraintCodec.INCLUSIVE), ConstraintCodec.INCLUSIVE + ConstraintCodec.MISSING_MEMBER_MESSAGE).asBoolean();
TierConstraint.CostType costType = TierConstraint.CostType.valueOf(nullIsIllegal(json.get(ConstraintCodec.COST_TYPE), ConstraintCodec.COST_TYPE + ConstraintCodec.MISSING_MEMBER_MESSAGE).asText());
JsonNode tiers = nullIsIllegal(json.get(ConstraintCodec.TIERS), ConstraintCodec.TIERS + ConstraintCodec.MISSING_MEMBER_MESSAGE);
if (tiers.size() < 1) {
throw new IllegalArgumentException(ConstraintCodec.TIERS + " array in tier constraint must have at least one value");
}
ArrayList<Integer> tierEntries = new ArrayList<>(tiers.size());
IntStream.range(0, tiers.size()).forEach(index -> tierEntries.add(new Integer(tiers.get(index).asText())));
return new TierConstraint(inclusive, costType, tierEntries.toArray(new Integer[tiers.size()]));
}
use of org.onosproject.net.intent.constraint.TierConstraint in project onos by opennetworkinglab.
the class EncodeConstraintCodecHelper method encodeTierConstraint.
/**
* Encodes a tier constraint.
*
* @return JSON ObjectNode representing the constraint
*/
private ObjectNode encodeTierConstraint() {
checkNotNull(constraint, "Tier constraint cannot be null");
final TierConstraint tierConstraint = (TierConstraint) constraint;
final ObjectNode result = context.mapper().createObjectNode().put(ConstraintCodec.INCLUSIVE, tierConstraint.isInclusive()).put(ConstraintCodec.COST_TYPE, tierConstraint.costType().name());
final ArrayNode jsonTiers = result.putArray(ConstraintCodec.TIERS);
if (tierConstraint.tiers() != null) {
for (Integer tier : tierConstraint.tiers()) {
jsonTiers.add(tier);
}
}
return result;
}
use of org.onosproject.net.intent.constraint.TierConstraint in project onos by opennetworkinglab.
the class ConstraintCodecTest method tierConstraint.
/**
* Tests tier constraint.
*/
@Test
public void tierConstraint() {
Constraint constraint = getConstraint("TierConstraint.json");
assertThat(constraint, instanceOf(TierConstraint.class));
TierConstraint tierConstraint = (TierConstraint) constraint;
assertThat(tierConstraint.isInclusive(), is(true));
assertThat(tierConstraint.costType(), is(TierConstraint.CostType.ORDER));
assertThat(tierConstraint.tiers().get(0), is(3));
assertThat(tierConstraint.tiers().get(1), is(2));
assertThat(tierConstraint.tiers().get(2), is(1));
}
use of org.onosproject.net.intent.constraint.TierConstraint in project onos by opennetworkinglab.
the class EncodeConstraintCodecHelper method encode.
/**
* Encodes the constraint in JSON.
*
* @return JSON node
*/
public ObjectNode encode() {
final ObjectNode result;
if (constraint instanceof BandwidthConstraint) {
result = encodeBandwidthConstraint();
} else if (constraint instanceof LinkTypeConstraint) {
result = encodeLinkTypeConstraint();
} else if (constraint instanceof AnnotationConstraint) {
result = encodeAnnotationConstraint();
} else if (constraint instanceof LatencyConstraint) {
result = encodeLatencyConstraint();
} else if (constraint instanceof ObstacleConstraint) {
result = encodeObstacleConstraint();
} else if (constraint instanceof WaypointConstraint) {
result = encodeWaypointConstraint();
} else if (constraint instanceof MeteredConstraint) {
result = encodeMeteredConstraint();
} else if (constraint instanceof TierConstraint) {
result = encodeTierConstraint();
} else {
result = context.mapper().createObjectNode();
}
result.put(ConstraintCodec.TYPE, constraint.getClass().getSimpleName());
return result;
}
Aggregations