Search in sources :

Example 11 with BandwidthConstraint

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

the class PointToPointIntentCompilerTest method testBandwidthConstrainedIntentSuccess.

/**
 * Tests that requests with sufficient available bandwidth succeed.
 */
@Test
public void testBandwidthConstrainedIntentSuccess() {
    final double bpsTotal = 1000.0;
    final double bpsToReserve = 100.0;
    final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
    final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(bpsToReserve)));
    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);
    final List<Intent> compiledIntents = compiler.compile(intent, null);
    assertThat(compiledIntents, Matchers.notNullValue());
    assertThat(compiledIntents, hasSize(1));
    assertThat("key is inherited", compiledIntents.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
}
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) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) 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)

Example 12 with BandwidthConstraint

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

the class PointToPointIntentCompilerTest method testSuggestedPathBandwidthConstrainedIntentFailure.

/**
 * Tests that requests with insufficient available bandwidth fail.
 */
@Test
public void testSuggestedPathBandwidthConstrainedIntentFailure() {
    final double bpsTotal = 10.0;
    final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
    final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE)));
    String[] suggestedPathHops = { S1, S4, S5, S3 };
    List<Link> suggestedPath = NetTestTools.createPath(suggestedPathHops).links();
    try {
        final PointToPointIntent intent = makeIntentSuggestedPath(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), suggestedPath, constraints);
        String[][] paths = { { S1, S2, S3 }, suggestedPathHops };
        final PointToPointIntentCompiler compiler = makeCompilerSuggestedPath(paths, 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) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) PathNotFoundException(org.onosproject.net.intent.impl.PathNotFoundException) Link(org.onosproject.net.Link) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 13 with BandwidthConstraint

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

the class PointToPointIntentCompilerTest method testKeyRGBandwidthConstrainedIntentAllocation.

/**
 * Tests if bandwidth resources get allocated correctly using groups.
 * An intent asks to allocate bandwidth using the intent key as a reference.
 * Then, the intent is submitted with the same key and a group set.
 * Previous allocations should be released and new resources should be
 * allocated using the group.
 */
@Test
public void testKeyRGBandwidthConstrainedIntentAllocation() {
    final double bpsTotal = 1000.0;
    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);
    PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
    compiler.compile(intent, null);
    Key intentKey = intent.key();
    ResourceGroup resourceGroup = ResourceGroup.of(100);
    final PointToPointIntent newIntent = makeIntent(intentKey, new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints, resourceGroup);
    compiler.compile(newIntent, 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) Key(org.onosproject.net.intent.Key) ResourceGroup(org.onosproject.net.ResourceGroup) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 14 with BandwidthConstraint

use of org.onosproject.net.intent.constraint.BandwidthConstraint 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)

Example 15 with BandwidthConstraint

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

the class EncodeConstraintCodecHelper method encodeBandwidthConstraint.

/**
 * Encodes a bandwidth constraint.
 *
 * @return JSON ObjectNode representing the constraint
 */
private ObjectNode encodeBandwidthConstraint() {
    checkNotNull(constraint, "Bandwidth constraint cannot be null");
    final BandwidthConstraint bandwidthConstraint = (BandwidthConstraint) constraint;
    return context.mapper().createObjectNode().put("bandwidth", bandwidthConstraint.bandwidth().bps());
}
Also used : BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint)

Aggregations

BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)17 Constraint (org.onosproject.net.intent.Constraint)15 Test (org.junit.Test)13 ConnectPoint (org.onosproject.net.ConnectPoint)12 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)12 ResourceService (org.onosproject.net.resource.ResourceService)12 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)11 MockResourceService (org.onosproject.net.resource.MockResourceService)11 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)9 ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)8 Key (org.onosproject.net.intent.Key)6 Bandwidth (org.onlab.util.Bandwidth)5 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)3 TrafficSelector (org.onosproject.net.flow.TrafficSelector)3 LatencyConstraint (org.onosproject.net.intent.constraint.LatencyConstraint)3 PartialFailureConstraint (org.onosproject.net.intent.constraint.PartialFailureConstraint)3 PathNotFoundException (org.onosproject.net.intent.impl.PathNotFoundException)3 ContinuousResource (org.onosproject.net.resource.ContinuousResource)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DeviceId (org.onosproject.net.DeviceId)2