Search in sources :

Example 1 with TierConstraint

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()]));
}
Also used : TierConstraint(org.onosproject.net.intent.constraint.TierConstraint) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with TierConstraint

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TierConstraint(org.onosproject.net.intent.constraint.TierConstraint) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 3 with TierConstraint

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));
}
Also used : WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) DomainConstraint(org.onosproject.net.intent.constraint.DomainConstraint) MeteredConstraint(org.onosproject.net.intent.constraint.MeteredConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) TierConstraint(org.onosproject.net.intent.constraint.TierConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) TierConstraint(org.onosproject.net.intent.constraint.TierConstraint) Test(org.junit.Test)

Example 4 with TierConstraint

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) TierConstraint(org.onosproject.net.intent.constraint.TierConstraint) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) MeteredConstraint(org.onosproject.net.intent.constraint.MeteredConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint)

Aggregations

TierConstraint (org.onosproject.net.intent.constraint.TierConstraint)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 AnnotationConstraint (org.onosproject.net.intent.constraint.AnnotationConstraint)2 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)2 LatencyConstraint (org.onosproject.net.intent.constraint.LatencyConstraint)2 LinkTypeConstraint (org.onosproject.net.intent.constraint.LinkTypeConstraint)2 MeteredConstraint (org.onosproject.net.intent.constraint.MeteredConstraint)2 ObstacleConstraint (org.onosproject.net.intent.constraint.ObstacleConstraint)2 WaypointConstraint (org.onosproject.net.intent.constraint.WaypointConstraint)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Constraint (org.onosproject.net.intent.Constraint)1 AsymmetricPathConstraint (org.onosproject.net.intent.constraint.AsymmetricPathConstraint)1 DomainConstraint (org.onosproject.net.intent.constraint.DomainConstraint)1