Search in sources :

Example 11 with Constraint

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

the class ConnectivityIntentCodec method intentAttributes.

/**
 * Extracts connectivity intent specific attributes from a JSON object
 * and adds them to a builder.
 *
 * @param json root JSON object
 * @param context code context
 * @param builder builder to use for storing the attributes. Constraints,
 *                selector and treatment are modified by this call.
 */
public static void intentAttributes(ObjectNode json, CodecContext context, ConnectivityIntent.Builder builder) {
    JsonNode constraintsJson = json.get(CONSTRAINTS);
    if (constraintsJson != null) {
        JsonCodec<Constraint> constraintsCodec = context.codec(Constraint.class);
        ArrayList<Constraint> constraints = new ArrayList<>(constraintsJson.size());
        IntStream.range(0, constraintsJson.size()).forEach(i -> constraints.add(constraintsCodec.decode(get(constraintsJson, i), context)));
        builder.constraints(constraints);
    }
    ObjectNode selectorJson = get(json, SELECTOR);
    if (selectorJson != null) {
        JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
        TrafficSelector selector = selectorCodec.decode(selectorJson, context);
        builder.selector(selector);
    }
    ObjectNode treatmentJson = get(json, TREATMENT);
    if (treatmentJson != null) {
        JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
        TrafficTreatment treatment = treatmentCodec.decode(treatmentJson, context);
        builder.treatment(treatment);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Constraint(org.onosproject.net.intent.Constraint) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 12 with Constraint

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

the class ConnectivityIntentCodec method encode.

@Override
public ObjectNode encode(ConnectivityIntent intent, CodecContext context) {
    checkNotNull(intent, "Connectivity intent cannot be null");
    final JsonCodec<Intent> intentCodec = context.codec(Intent.class);
    final ObjectNode result = intentCodec.encode(intent, context);
    if (intent.selector() != null) {
        final JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
        result.set(SELECTOR, selectorCodec.encode(intent.selector(), context));
    }
    if (intent.treatment() != null) {
        final JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
        result.set(TREATMENT, treatmentCodec.encode(intent.treatment(), context));
    }
    result.put(IntentCodec.PRIORITY, intent.priority());
    if (intent.constraints() != null) {
        final ArrayNode jsonConstraints = result.putArray(CONSTRAINTS);
        if (intent.constraints() != null) {
            final JsonCodec<Constraint> constraintCodec = context.codec(Constraint.class);
            for (final Constraint constraint : intent.constraints()) {
                final ObjectNode constraintNode = constraintCodec.encode(constraint, context);
                jsonConstraints.add(constraintNode);
            }
        }
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Constraint(org.onosproject.net.intent.Constraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 13 with Constraint

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

the class MultiPointToSinglePointIntentCompilerTest method testBandwidthConstrainedIntentAllocation.

/**
 * Tests if bandwidth resources get allocated correctly.
 */
@Test
public void testBandwidthConstrainedIntentAllocation() {
    final double bpsTotal = 1000.0;
    final double bpsToReserve = 100.0;
    ContinuousResource resourceSw1P1 = Resources.continuous(DID_1, PORT_1, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw1P2 = Resources.continuous(DID_1, PORT_2, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw2P1 = Resources.continuous(DID_2, PORT_1, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw2P2 = Resources.continuous(DID_2, PORT_2, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw3P1 = Resources.continuous(DID_3, PORT_1, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw3P2 = Resources.continuous(DID_3, PORT_2, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw3P3 = Resources.continuous(DID_3, PORT_3, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw4P1 = Resources.continuous(DID_4, PORT_1, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw4P2 = Resources.continuous(DID_4, PORT_2, Bandwidth.class).resource(bpsToReserve);
    String[] hops = { DID_3.toString() };
    final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
    final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(bpsToReserve)));
    Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)), new FilteredConnectPoint(new ConnectPoint(DID_2, PORT_1)));
    TrafficSelector ipPrefixSelector = DefaultTrafficSelector.builder().matchIPDst(IpPrefix.valueOf("192.168.100.0/24")).build();
    FilteredConnectPoint egress = new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_2));
    MultiPointToSinglePointIntent intent = makeIntent(ingress, egress, ipPrefixSelector, constraints);
    MultiPointToSinglePointIntentCompiler compiler = makeCompiler(null, new IntentTestsMocks.FixedMP2MPMockPathService(hops), resourceService);
    compiler.compile(intent, null);
    Key intentKey = intent.key();
    ResourceAllocation rA1 = new ResourceAllocation(resourceSw1P1, intentKey);
    ResourceAllocation rA2 = new ResourceAllocation(resourceSw1P2, intentKey);
    ResourceAllocation rA3 = new ResourceAllocation(resourceSw2P1, intentKey);
    ResourceAllocation rA4 = new ResourceAllocation(resourceSw2P2, intentKey);
    ResourceAllocation rA5 = new ResourceAllocation(resourceSw3P1, intentKey);
    ResourceAllocation rA6 = new ResourceAllocation(resourceSw3P2, intentKey);
    ResourceAllocation rA7 = new ResourceAllocation(resourceSw3P3, intentKey);
    ResourceAllocation rA8 = new ResourceAllocation(resourceSw4P1, intentKey);
    ResourceAllocation rA9 = new ResourceAllocation(resourceSw4P2, intentKey);
    Set<ResourceAllocation> expectedResourceAllocations = ImmutableSet.of(rA1, rA2, rA3, rA4, rA5, rA6, rA7, rA8, rA9);
    Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(intentKey));
    assertThat(resourceAllocations, hasSize(9));
    assertEquals(expectedResourceAllocations, resourceAllocations);
}
Also used : PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Constraint(org.onosproject.net.intent.Constraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) ResourceService(org.onosproject.net.resource.ResourceService) MockResourceService(org.onosproject.net.resource.MockResourceService) IntentTestsMocks(org.onosproject.net.intent.IntentTestsMocks) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) Bandwidth(org.onlab.util.Bandwidth) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Key(org.onosproject.net.intent.Key) ContinuousResource(org.onosproject.net.resource.ContinuousResource) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 14 with Constraint

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

the class PointToPointIntentCompilerTest method testRGBandwidthConstrainedIntentAllocation.

/**
 * Tests if bandwidth resources get allocated correctly using the resource
 * group. An intent with a resource group is submitted.
 */
@Test
public void testRGBandwidthConstrainedIntentAllocation() {
    final double bpsTotal = 1000.0;
    ResourceGroup resourceGroup = ResourceGroup.of(100);
    String[] hops = { S1, S2, S3 };
    final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
    final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE)));
    final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints, resourceGroup);
    PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
    compiler.compile(intent, null);
    ResourceAllocation rAOne = new ResourceAllocation(RESOURCE_SW1_P1, resourceGroup);
    ResourceAllocation rATwo = new ResourceAllocation(RESOURCE_SW1_P2, resourceGroup);
    ResourceAllocation rAThree = new ResourceAllocation(RESOURCE_SW2_P1, resourceGroup);
    ResourceAllocation rAFour = new ResourceAllocation(RESOURCE_SW2_P2, resourceGroup);
    ResourceAllocation rAFive = new ResourceAllocation(RESOURCE_SW3_P1, resourceGroup);
    ResourceAllocation rASix = new ResourceAllocation(RESOURCE_SW3_P2, resourceGroup);
    Set<ResourceAllocation> expectedresourceAllocations = ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix);
    Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(resourceGroup));
    assertThat(resourceAllocations, hasSize(6));
    assertEquals(expectedresourceAllocations, resourceAllocations);
}
Also used : Constraint(org.onosproject.net.intent.Constraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) ResourceService(org.onosproject.net.resource.ResourceService) MockResourceService(org.onosproject.net.resource.MockResourceService) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ResourceGroup(org.onosproject.net.ResourceGroup) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 15 with Constraint

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

the class PointToPointIntentCompilerTest method testBandwidthConstrainedIntentFailure.

/**
 * Tests that requests with insufficient available bandwidth fail.
 */
@Test
public void testBandwidthConstrainedIntentFailure() {
    final double bpsTotal = 10.0;
    final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
    final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE)));
    try {
        final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints);
        String[] hops = { S1, S2, S3 };
        final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
        compiler.compile(intent, null);
        fail("Point to Point compilation with insufficient bandwidth does " + "not throw exception.");
    } catch (PathNotFoundException noPath) {
        assertThat(noPath.getMessage(), containsString("No path"));
    }
}
Also used : Constraint(org.onosproject.net.intent.Constraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) ResourceService(org.onosproject.net.resource.ResourceService) MockResourceService(org.onosproject.net.resource.MockResourceService) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) PathNotFoundException(org.onosproject.net.intent.impl.PathNotFoundException) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) 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