Search in sources :

Example 36 with Constraint

use of org.onosproject.net.intent.Constraint 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 37 with Constraint

use of org.onosproject.net.intent.Constraint 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 38 with Constraint

use of org.onosproject.net.intent.Constraint 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 39 with Constraint

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

the class SinglePointToMultiPointIntentCompilerTest 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() {
    FilteredConnectPoint ingress = new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1));
    Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_2)), new FilteredConnectPoint(new ConnectPoint(DID_5, PORT_2)));
    final List<Constraint> constraints = Collections.singletonList(new PartialFailureConstraint());
    SinglePointToMultiPointIntent intent = makeIntent(ingress, egress, constraints);
    String[] hops = { S3 };
    SinglePointToMultiPointIntentCompiler 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) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) 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) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 40 with Constraint

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

the class VirtualNetworkIntentManagerTest method testCreateAndRemoveIntent.

/**
 * Tests the submit(), withdraw(), and purge() methods.
 */
@Test
public void testCreateAndRemoveIntent() {
    VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
    Key intentKey = Key.of("test", APP_ID);
    List<Constraint> constraints = new ArrayList<>();
    constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN));
    VirtualNetworkIntent virtualIntent = VirtualNetworkIntent.builder().networkId(virtualNetwork.id()).key(intentKey).appId(APP_ID).ingressPoint(cp1).egressPoint(cp5).constraints(constraints).build();
    // Test the submit() method.
    vnetIntentService.submit(virtualIntent);
    // Wait for the both intents to go into an INSTALLED state.
    try {
        if (!created.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for intent to get installed.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception during intent installation." + e.getMessage());
    }
    // Test the getIntentState() method
    assertEquals("The intent state did not match as expected.", IntentState.INSTALLED, vnetIntentService.getIntentState(virtualIntent.key()));
    // Test the withdraw() method.
    vnetIntentService.withdraw(virtualIntent);
    // Wait for the both intents to go into a WITHDRAWN state.
    try {
        if (!withdrawn.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for intent to get withdrawn.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception during intent withdrawal." + e.getMessage());
    }
    // Test the getIntentState() method
    assertEquals("The intent state did not match as expected.", IntentState.WITHDRAWN, vnetIntentService.getIntentState(virtualIntent.key()));
    // Test the purge() method.
    vnetIntentService.purge(virtualIntent);
    // Wait for the both intents to be removed/purged.
    try {
        if (!purged.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for intent to get purged.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception during intent purging." + e.getMessage());
    }
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Constraint(org.onosproject.net.intent.Constraint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) VirtualNetworkIntent(org.onosproject.incubator.net.virtual.VirtualNetworkIntent) Key(org.onosproject.net.intent.Key) Test(org.junit.Test)

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