Search in sources :

Example 41 with Constraint

use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.

the class ConstraintCodecTest method linkTypeConstraint.

/**
 * Tests link type constraint.
 */
@Test
public void linkTypeConstraint() {
    Constraint constraint = getConstraint("LinkTypeConstraint.json");
    assertThat(constraint, instanceOf(LinkTypeConstraint.class));
    LinkTypeConstraint linkTypeConstraint = (LinkTypeConstraint) constraint;
    assertThat(linkTypeConstraint.isInclusive(), is(false));
    assertThat(linkTypeConstraint.types(), hasSize(2));
    assertThat(linkTypeConstraint.types(), hasItem(Link.Type.OPTICAL));
    assertThat(linkTypeConstraint.types(), hasItem(Link.Type.DIRECT));
}
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) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) Test(org.junit.Test)

Example 42 with Constraint

use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.

the class ConstraintCodecTest method asymmetricPathConstraint.

/**
 * Tests asymmetric path constraint.
 */
@Test
public void asymmetricPathConstraint() {
    Constraint constraint = getConstraint("AsymmetricPathConstraint.json");
    assertThat(constraint, instanceOf(AsymmetricPathConstraint.class));
}
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) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) Test(org.junit.Test)

Example 43 with Constraint

use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.

the class ConstraintCodecTest method bandwidthConstraint.

/**
 * Tests bandwidth constraint.
 */
@Test
public void bandwidthConstraint() {
    Constraint constraint = getConstraint("BandwidthConstraint.json");
    assertThat(constraint, instanceOf(BandwidthConstraint.class));
    BandwidthConstraint bandwidthConstraint = (BandwidthConstraint) constraint;
    assertThat(bandwidthConstraint.bandwidth().bps(), is(345.678D));
}
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) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) Test(org.junit.Test)

Example 44 with Constraint

use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.

the class IntentJsonMatcher method matchLinkTypeConstraint.

/**
 * Matches a link type constraint against a JSON representation of the
 * constraint.
 *
 * @param linkTypeConstraint constraint object to match
 * @param constraintJson JSON representation of the constraint
 * @return true if the constraint and JSON match, false otherwise.
 */
private boolean matchLinkTypeConstraint(LinkTypeConstraint linkTypeConstraint, JsonNode constraintJson) {
    final JsonNode inclusiveJson = constraintJson.get("inclusive");
    final JsonNode typesJson = constraintJson.get("types");
    if (typesJson.size() != linkTypeConstraint.types().size()) {
        return false;
    }
    int foundType = 0;
    for (Link.Type type : linkTypeConstraint.types()) {
        for (int jsonIndex = 0; jsonIndex < typesJson.size(); jsonIndex++) {
            if (type.name().equals(typesJson.get(jsonIndex).asText())) {
                foundType++;
                break;
            }
        }
    }
    return (inclusiveJson != null && inclusiveJson.asBoolean() == linkTypeConstraint.isInclusive()) && foundType == typesJson.size();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) ConnectPoint(org.onosproject.net.ConnectPoint) 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) Link(org.onosproject.net.Link)

Example 45 with Constraint

use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.

the class IntentJsonMatcher method matchWaypointConstraint.

/**
 * Matches a waypoint constraint against a JSON representation of the
 * constraint.
 *
 * @param waypointConstraint constraint object to match
 * @param constraintJson JSON representation of the constraint
 * @return true if the constraint and JSON match, false otherwise.
 */
private boolean matchWaypointConstraint(WaypointConstraint waypointConstraint, JsonNode constraintJson) {
    final JsonNode waypointsJson = constraintJson.get("waypoints");
    if (waypointsJson.size() != waypointConstraint.waypoints().size()) {
        return false;
    }
    for (int waypointsIndex = 0; waypointsIndex < waypointsJson.size(); waypointsIndex++) {
        boolean waypointFound = false;
        final String waypointJson = waypointsJson.get(waypointsIndex).asText();
        for (DeviceId waypoint : waypointConstraint.waypoints()) {
            if (waypoint.toString().equals(waypointJson)) {
                waypointFound = true;
            }
        }
        if (!waypointFound) {
            return false;
        }
    }
    return true;
}
Also used : DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) ConnectPoint(org.onosproject.net.ConnectPoint) 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)

Aggregations

Constraint (org.onosproject.net.intent.Constraint)48 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)31 Test (org.junit.Test)28 ConnectPoint (org.onosproject.net.ConnectPoint)27 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)22 TrafficSelector (org.onosproject.net.flow.TrafficSelector)17 LatencyConstraint (org.onosproject.net.intent.constraint.LatencyConstraint)17 AnnotationConstraint (org.onosproject.net.intent.constraint.AnnotationConstraint)16 ObstacleConstraint (org.onosproject.net.intent.constraint.ObstacleConstraint)16 WaypointConstraint (org.onosproject.net.intent.constraint.WaypointConstraint)16 LinkTypeConstraint (org.onosproject.net.intent.constraint.LinkTypeConstraint)15 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)14 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 Key (org.onosproject.net.intent.Key)13 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)12 AsymmetricPathConstraint (org.onosproject.net.intent.constraint.AsymmetricPathConstraint)12 DomainConstraint (org.onosproject.net.intent.constraint.DomainConstraint)12 ResourceService (org.onosproject.net.resource.ResourceService)12 Intent (org.onosproject.net.intent.Intent)11 MeteredConstraint (org.onosproject.net.intent.constraint.MeteredConstraint)11