Search in sources :

Example 31 with Constraint

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

the class IntentJsonMatcher method matchConnectivityIntent.

/**
 * Matches the JSON representation of a connectivity intent. Calls the
 * matcher for the connectivity intent subtype.
 *
 * @param jsonIntent JSON representation of the intent
 * @param description Description object used for recording errors
 * @return true if the JSON matches the intent, false otherwise
 */
private boolean matchConnectivityIntent(JsonNode jsonIntent, Description description) {
    final ConnectivityIntent connectivityIntent = (ConnectivityIntent) intent;
    // check selector
    final JsonNode jsonSelector = jsonIntent.get("selector");
    final TrafficSelector selector = connectivityIntent.selector();
    final Set<Criterion> criteria = selector.criteria();
    final JsonNode jsonCriteria = jsonSelector.get("criteria");
    if (jsonCriteria.size() != criteria.size()) {
        description.appendText("size of criteria array is " + Integer.toString(jsonCriteria.size()));
        return false;
    }
    for (Criterion criterion : criteria) {
        boolean criterionFound = false;
        for (int criterionIndex = 0; criterionIndex < jsonCriteria.size(); criterionIndex++) {
            final CriterionJsonMatcher criterionMatcher = CriterionJsonMatcher.matchesCriterion(criterion);
            if (criterionMatcher.matches(jsonCriteria.get(criterionIndex))) {
                criterionFound = true;
                break;
            }
        }
        if (!criterionFound) {
            description.appendText("criterion not found " + criterion.toString());
            return false;
        }
    }
    // check treatment
    final JsonNode jsonTreatment = jsonIntent.get("treatment");
    final TrafficTreatment treatment = connectivityIntent.treatment();
    final List<Instruction> instructions = treatment.immediate();
    final JsonNode jsonInstructions = jsonTreatment.get("instructions");
    if (jsonInstructions.size() != instructions.size()) {
        description.appendText("size of instructions array is " + Integer.toString(jsonInstructions.size()));
        return false;
    }
    for (Instruction instruction : instructions) {
        boolean instructionFound = false;
        for (int instructionIndex = 0; instructionIndex < jsonInstructions.size(); instructionIndex++) {
            final InstructionJsonMatcher instructionMatcher = InstructionJsonMatcher.matchesInstruction(instruction);
            if (instructionMatcher.matches(jsonInstructions.get(instructionIndex))) {
                instructionFound = true;
                break;
            }
        }
        if (!instructionFound) {
            description.appendText("instruction not found " + instruction.toString());
            return false;
        }
    }
    // Check constraints
    final JsonNode jsonConstraints = jsonIntent.get("constraints");
    if (connectivityIntent.constraints() != null) {
        if (connectivityIntent.constraints().size() != jsonConstraints.size()) {
            description.appendText("constraints array size was " + Integer.toString(jsonConstraints.size()));
            return false;
        }
        for (final Constraint constraint : connectivityIntent.constraints()) {
            boolean constraintFound = false;
            for (int constraintIndex = 0; constraintIndex < jsonConstraints.size(); constraintIndex++) {
                final JsonNode value = jsonConstraints.get(constraintIndex);
                if (matchConstraint(constraint, value)) {
                    constraintFound = true;
                }
            }
            if (!constraintFound) {
                final String constraintString = constraint.toString();
                description.appendText("constraint missing " + constraintString);
                return false;
            }
        }
    } else if (jsonConstraints.size() != 0) {
        description.appendText("constraint array not empty");
        return false;
    }
    if (connectivityIntent instanceof HostToHostIntent) {
        return matchHostToHostIntent(jsonIntent, description);
    } else if (connectivityIntent instanceof PointToPointIntent) {
        return matchPointToPointIntent(jsonIntent, description);
    } else {
        description.appendText("class of connectivity intent is unknown");
        return false;
    }
}
Also used : WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) 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) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) 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) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector)

Example 32 with Constraint

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

the class AddHostToHostIntentCommand method doExecute.

@Override
protected void doExecute() {
    IntentService service = get(IntentService.class);
    HostId oneId = HostId.hostId(one);
    HostId twoId = HostId.hostId(two);
    TrafficSelector selector = buildTrafficSelector();
    TrafficTreatment treatment = buildTrafficTreatment();
    List<Constraint> constraints = buildConstraints();
    HostToHostIntent intent = HostToHostIntent.builder().appId(appId()).key(key()).one(oneId).two(twoId).selector(selector).treatment(treatment).constraints(constraints).priority(priority()).resourceGroup(resourceGroup()).build();
    service.submit(intent);
    print("Host to Host intent submitted:\n%s", intent.toString());
}
Also used : IntentService(org.onosproject.net.intent.IntentService) Constraint(org.onosproject.net.intent.Constraint) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) TrafficSelector(org.onosproject.net.flow.TrafficSelector) HostId(org.onosproject.net.HostId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 33 with Constraint

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

the class AddPointToPointIntentCommand method doExecute.

@Override
protected void doExecute() {
    IntentService service = get(IntentService.class);
    ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
    ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
    TrafficSelector selector = buildTrafficSelector();
    TrafficTreatment treatment = buildTrafficTreatment();
    List<Constraint> constraints = buildConstraints();
    if (backup) {
        constraints.add(protection());
    }
    if (useProtected) {
        constraints.add(ProtectedConstraint.useProtectedLink());
    }
    Intent intent = PointToPointIntent.builder().appId(appId()).key(key()).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).constraints(constraints).priority(priority()).resourceGroup(resourceGroup()).build();
    service.submit(intent);
    print("Point to point intent submitted:\n%s", intent.toString());
}
Also used : IntentService(org.onosproject.net.intent.IntentService) Constraint(org.onosproject.net.intent.Constraint) ProtectedConstraint(org.onosproject.net.intent.constraint.ProtectedConstraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Intent(org.onosproject.net.intent.Intent) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 34 with Constraint

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

the class AddSinglePointToMultiPointIntentCommand method doExecute.

@Override
protected void doExecute() {
    IntentService service = get(IntentService.class);
    if (deviceStrings.length < 2) {
        return;
    }
    String ingressDeviceString = deviceStrings[0];
    ConnectPoint ingressPoint = ConnectPoint.deviceConnectPoint(ingressDeviceString);
    Set<FilteredConnectPoint> egressPoints = new HashSet<>();
    for (int index = 1; index < deviceStrings.length; index++) {
        String egressDeviceString = deviceStrings[index];
        ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
        egressPoints.add(new FilteredConnectPoint(egress));
    }
    TrafficSelector selector = buildTrafficSelector();
    TrafficTreatment treatment = buildTrafficTreatment();
    List<Constraint> constraints = buildConstraints();
    SinglePointToMultiPointIntent intent = SinglePointToMultiPointIntent.builder().appId(appId()).key(key()).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingressPoint)).filteredEgressPoints(egressPoints).constraints(constraints).priority(priority()).resourceGroup(resourceGroup()).build();
    service.submit(intent);
    print("Single point to multipoint intent submitted:\n%s", intent.toString());
}
Also used : IntentService(org.onosproject.net.intent.IntentService) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) Constraint(org.onosproject.net.intent.Constraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Constraint(org.onosproject.net.intent.Constraint) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet)

Example 35 with Constraint

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

the class MultiPointToSinglePointIntentCompilerTest method testPartialFailureConstraintSuccess.

/**
 * Tests if all expected links are present when a partial failure
 * constraint is used and one ingress is not present.
 */
@Test
public void testPartialFailureConstraintSuccess() {
    Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)), new FilteredConnectPoint(new ConnectPoint(DID_5, PORT_1)));
    FilteredConnectPoint egress = new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_2));
    final List<Constraint> constraints = Collections.singletonList(new PartialFailureConstraint());
    MultiPointToSinglePointIntent intent = makeIntent(ingress, egress, constraints);
    String[] hops = { S3 };
    MultiPointToSinglePointIntentCompiler compiler = makeCompiler(null, new IntentTestsMocks.FixedMP2MPMockPathService(hops), null);
    assertThat(compiler, is(notNullValue()));
    List<Intent> result = compiler.compile(intent, null);
    assertThat(result, is(notNullValue()));
    assertThat(result, hasSize(1));
    Intent resultIntent = result.get(0);
    assertThat(resultIntent, instanceOf(LinkCollectionIntent.class));
    if (resultIntent instanceof LinkCollectionIntent) {
        LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
        assertThat(linkIntent.links(), hasSize(2));
        assertThat(linkIntent.links(), linksHasPath(S1, S3));
        assertThat(linkIntent.links(), linksHasPath(S3, S4));
    }
    assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
Also used : PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Constraint(org.onosproject.net.intent.Constraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) IntentTestsMocks(org.onosproject.net.intent.IntentTestsMocks) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

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