Search in sources :

Example 1 with BandwidthConstraint

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

the class IntentCodecTest method intentWithTreatmentSelectorAndConstraints.

/**
 * Tests the encoding of an intent with treatment, selector and constraints
 * specified.
 */
@Test
public void intentWithTreatmentSelectorAndConstraints() {
    ConnectPoint ingress = NetTestTools.connectPoint("ingress", 1);
    ConnectPoint egress = NetTestTools.connectPoint("egress", 2);
    DeviceId did1 = did("device1");
    DeviceId did2 = did("device2");
    DeviceId did3 = did("device3");
    Lambda ochSignal = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
    final TrafficSelector selector = DefaultTrafficSelector.builder().matchIPProtocol((byte) 3).matchMplsLabel(MplsLabel.mplsLabel(4)).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).matchEthDst(MacAddress.BROADCAST).matchIPDst(IpPrefix.valueOf("1.2.3.4/24")).build();
    final TrafficTreatment treatment = DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(44)).setOutput(PortNumber.CONTROLLER).setEthDst(MacAddress.BROADCAST).build();
    final List<Constraint> constraints = ImmutableList.of(new BandwidthConstraint(Bandwidth.bps(1.0)), new AnnotationConstraint("key", 33.0), new AsymmetricPathConstraint(), new LatencyConstraint(Duration.ofSeconds(2)), new ObstacleConstraint(did1, did2), new WaypointConstraint(did3));
    final PointToPointIntent intent = PointToPointIntent.builder().appId(appId).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).constraints(constraints).build();
    final JsonCodec<PointToPointIntent> intentCodec = context.codec(PointToPointIntent.class);
    assertThat(intentCodec, notNullValue());
    final ObjectNode intentJson = intentCodec.encode(intent, context);
    assertThat(intentJson, matchesIntent(intent));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) DeviceId(org.onosproject.net.DeviceId) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Lambda(org.onosproject.net.Lambda) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 2 with BandwidthConstraint

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

the class ConnectivityIntentCompiler method allocateBandwidth.

/**
 * Allocates the bandwidth specified as intent constraint on each link
 * composing the intent, if a bandwidth constraint is specified.
 *
 * @param intent the intent requesting bandwidth allocation
 * @param connectPoints the connect points composing the intent path computed
 */
protected void allocateBandwidth(ConnectivityIntent intent, List<ConnectPoint> connectPoints) {
    // Retrieve bandwidth constraint if exists
    List<Constraint> constraints = intent.constraints();
    if (constraints == null) {
        return;
    }
    Optional<Constraint> constraint = constraints.stream().filter(c -> c instanceof BandwidthConstraint).findAny();
    // If there is no bandwidth constraint continue
    if (!constraint.isPresent()) {
        return;
    }
    BandwidthConstraint bwConstraint = (BandwidthConstraint) constraint.get();
    double bw = bwConstraint.bandwidth().bps();
    // If a resource group is set on the intent, the resource consumer is
    // set equal to it. Otherwise it's set to the intent key
    ResourceConsumer newResourceConsumer = intent.resourceGroup() != null ? intent.resourceGroup() : intent.key();
    // Get the list of current resource allocations
    Collection<ResourceAllocation> resourceAllocations = resourceService.getResourceAllocations(newResourceConsumer);
    // Get the list of resources already allocated from resource allocations
    List<Resource> resourcesAllocated = resourcesFromAllocations(resourceAllocations);
    // Get the list of resource ids for resources already allocated
    List<ResourceId> idsResourcesAllocated = resourceIds(resourcesAllocated);
    // Create the list of incoming resources requested. Exclude resources
    // already allocated.
    List<Resource> incomingResources = resources(connectPoints, bw).stream().filter(r -> !resourcesAllocated.contains(r)).collect(Collectors.toList());
    if (incomingResources.isEmpty()) {
        return;
    }
    // Create the list of resources to be added, meaning their key is not
    // present in the resources already allocated
    List<Resource> resourcesToAdd = incomingResources.stream().filter(r -> !idsResourcesAllocated.contains(r.id())).collect(Collectors.toList());
    // Resources to updated are all the new valid resources except the
    // resources to be added
    List<Resource> resourcesToUpdate = Lists.newArrayList(incomingResources);
    resourcesToUpdate.removeAll(resourcesToAdd);
    // If there are no resources to update skip update procedures
    if (!resourcesToUpdate.isEmpty()) {
        // Remove old resources that need to be updated
        // TODO: use transaction updates when available in the resource service
        List<ResourceAllocation> resourceAllocationsToUpdate = resourceAllocations.stream().filter(rA -> resourceIds(resourcesToUpdate).contains(rA.resource().id())).collect(Collectors.toList());
        log.debug("Releasing bandwidth for intent {}: {} bps", newResourceConsumer, resourcesToUpdate);
        resourceService.release(resourceAllocationsToUpdate);
        // Update resourcesToAdd with the list of both the new resources and
        // the resources to update
        resourcesToAdd.addAll(resourcesToUpdate);
    }
    // remove them
    if (intent.resourceGroup() != null) {
        // Get the list of current resource allocations made by intent key
        Collection<ResourceAllocation> resourceAllocationsByKey = resourceService.getResourceAllocations(intent.key());
        resourceService.release(Lists.newArrayList(resourceAllocationsByKey));
    }
    // Allocate resources
    log.debug("Allocating bandwidth for intent {}: {} bps", newResourceConsumer, resourcesToAdd);
    List<ResourceAllocation> allocations = resourceService.allocate(newResourceConsumer, resourcesToAdd);
    if (allocations.isEmpty()) {
        log.debug("No resources allocated for intent {}", newResourceConsumer);
    }
    log.debug("Done allocating bandwidth for intent {}", newResourceConsumer);
}
Also used : HashedPathSelectionConstraint(org.onosproject.net.intent.constraint.HashedPathSelectionConstraint) TopologyEdge(org.onosproject.net.topology.TopologyEdge) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) ElementId(org.onosproject.net.ElementId) ResourceService(org.onosproject.net.resource.ResourceService) ConnectPoint(org.onosproject.net.ConnectPoint) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) PathNotFoundException(org.onosproject.net.intent.impl.PathNotFoundException) PathViabilityConstraint(org.onosproject.net.intent.constraint.PathViabilityConstraint) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Bandwidth(org.onlab.util.Bandwidth) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Resources(org.onosproject.net.resource.Resources) PathService(org.onosproject.net.topology.PathService) Collection(java.util.Collection) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) Resource(org.onosproject.net.resource.Resource) Collectors(java.util.stream.Collectors) Constraint(org.onosproject.net.intent.Constraint) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultEdgeWeigher(org.onlab.graph.DefaultEdgeWeigher) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) List(java.util.List) Weight(org.onlab.graph.Weight) ResourceId(org.onosproject.net.resource.ResourceId) TopologyVertex(org.onosproject.net.topology.TopologyVertex) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) IntentCompiler(org.onosproject.net.intent.IntentCompiler) Optional(java.util.Optional) Path(org.onosproject.net.Path) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) LinkWeigher(org.onosproject.net.topology.LinkWeigher) Reference(org.osgi.service.component.annotations.Reference) ScalarWeight(org.onlab.graph.ScalarWeight) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) DisjointPath(org.onosproject.net.DisjointPath) MarkerConstraint(org.onosproject.net.intent.constraint.MarkerConstraint) HashedPathSelectionConstraint(org.onosproject.net.intent.constraint.HashedPathSelectionConstraint) PathViabilityConstraint(org.onosproject.net.intent.constraint.PathViabilityConstraint) Constraint(org.onosproject.net.intent.Constraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) MarkerConstraint(org.onosproject.net.intent.constraint.MarkerConstraint) Resource(org.onosproject.net.resource.Resource) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ResourceId(org.onosproject.net.resource.ResourceId) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint)

Example 3 with BandwidthConstraint

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

the class HostToHostIntentCompilerTest 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_S1, PORT_1, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw1P2 = Resources.continuous(DID_S1, PORT_2, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw2P1 = Resources.continuous(DID_S2, PORT_1, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw2P2 = Resources.continuous(DID_S2, PORT_2, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw3P1 = Resources.continuous(DID_S3, PORT_1, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw3P2 = Resources.continuous(DID_S3, PORT_2, Bandwidth.class).resource(bpsToReserve);
    String[] hops = { HOST_ONE, S1, S2, S3, HOST_TWO };
    final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
    final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(bpsToReserve)));
    final HostToHostIntent intent = makeIntent(HOST_ONE, HOST_TWO, constraints);
    HostToHostIntentCompiler compiler = makeCompiler(hops, resourceService);
    compiler.compile(intent, null);
    Key intentKey = intent.key();
    ResourceAllocation rAOne = new ResourceAllocation(resourceSw1P1, intentKey);
    ResourceAllocation rATwo = new ResourceAllocation(resourceSw1P2, intentKey);
    ResourceAllocation rAThree = new ResourceAllocation(resourceSw2P1, intentKey);
    ResourceAllocation rAFour = new ResourceAllocation(resourceSw2P2, intentKey);
    ResourceAllocation rAFive = new ResourceAllocation(resourceSw3P1, intentKey);
    ResourceAllocation rASix = new ResourceAllocation(resourceSw3P2, intentKey);
    Set<ResourceAllocation> expectedresourceAllocations = ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix);
    Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(intentKey));
    assertThat(resourceAllocations, hasSize(6));
    assertEquals(expectedresourceAllocations, resourceAllocations);
}
Also used : Constraint(org.onosproject.net.intent.Constraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ResourceService(org.onosproject.net.resource.ResourceService) MockResourceService(org.onosproject.net.resource.MockResourceService) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) Bandwidth(org.onlab.util.Bandwidth) Key(org.onosproject.net.intent.Key) ContinuousResource(org.onosproject.net.resource.ContinuousResource) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 4 with BandwidthConstraint

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

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

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