Search in sources :

Example 1 with ResourceAllocation

use of org.onosproject.net.resource.ResourceAllocation in project onos by opennetworkinglab.

the class AllocationsCommand method printAllocation.

private void printAllocation(DeviceId did, PortNumber num, int level) {
    if (level == 0) {
        // print DeviceId when Port was directly specified.
        print("%s", did);
    }
    DiscreteResourceId resourceId = Resources.discrete(did, num).id();
    List<String> portConsumers = resourceService.getResourceAllocations(resourceId).stream().filter(this::isSubjectToPrint).map(ResourceAllocation::consumerId).map(AllocationsCommand::asVerboseString).collect(Collectors.toList());
    if (portConsumers.isEmpty()) {
        print("%s%s", Strings.repeat(" ", level), asVerboseString(num));
    } else {
        print("%s%s allocated by %s", Strings.repeat(" ", level), asVerboseString(num), portConsumers);
    }
    // FIXME: This workaround induces a lot of distributed store access.
    // ResourceService should have an API to get all allocations under a parent resource.
    Set<Class<?>> subResourceTypes = ImmutableSet.<Class<?>>builder().add(OchSignal.class).add(VlanId.class).add(MplsLabel.class).add(Bandwidth.class).add(TributarySlot.class).build();
    for (Class<?> t : subResourceTypes) {
        resourceService.getResourceAllocations(resourceId, t).stream().filter(a -> isSubjectToPrint(a)).forEach(a -> print("%s%s allocated by %s", Strings.repeat(" ", level + 1), a.resource().valueAs(Object.class).orElse(""), asVerboseString(a.consumerId())));
    }
}
Also used : Arrays(java.util.Arrays) DiscreteResourceId(org.onosproject.net.resource.DiscreteResourceId) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) ResourceService(org.onosproject.net.resource.ResourceService) Command(org.apache.karaf.shell.api.action.Command) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) Port(org.onosproject.net.Port) StreamSupport(java.util.stream.StreamSupport) DeviceId.deviceId(org.onosproject.net.DeviceId.deviceId) IntentId(org.onosproject.net.intent.IntentId) ImmutableSet(com.google.common.collect.ImmutableSet) TributarySlot(org.onosproject.net.TributarySlot) MplsLabel(org.onlab.packet.MplsLabel) Device(org.onosproject.net.Device) Bandwidth(org.onlab.util.Bandwidth) ResourceConsumerId(org.onosproject.net.resource.ResourceConsumerId) Resources(org.onosproject.net.resource.Resources) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) OchSignal(org.onosproject.net.OchSignal) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) TributarySlot(org.onosproject.net.TributarySlot) OchSignal(org.onosproject.net.OchSignal) MplsLabel(org.onlab.packet.MplsLabel) DiscreteResourceId(org.onosproject.net.resource.DiscreteResourceId) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation)

Example 2 with ResourceAllocation

use of org.onosproject.net.resource.ResourceAllocation 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 ResourceAllocation

use of org.onosproject.net.resource.ResourceAllocation 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 ResourceAllocation

use of org.onosproject.net.resource.ResourceAllocation 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 ResourceAllocation

use of org.onosproject.net.resource.ResourceAllocation in project onos by opennetworkinglab.

the class PointToPointIntentCompilerTest method testBandwidthConstrainedIntentAllocation.

/**
 * Tests if bandwidth resources get allocated correctly. An intent with a
 * key only is submitted.
 */
@Test
public void testBandwidthConstrainedIntentAllocation() {
    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();
    ResourceAllocation rAOne = new ResourceAllocation(RESOURCE_SW1_P1, intentKey);
    ResourceAllocation rATwo = new ResourceAllocation(RESOURCE_SW1_P2, intentKey);
    ResourceAllocation rAThree = new ResourceAllocation(RESOURCE_SW2_P1, intentKey);
    ResourceAllocation rAFour = new ResourceAllocation(RESOURCE_SW2_P2, intentKey);
    ResourceAllocation rAFive = new ResourceAllocation(RESOURCE_SW3_P1, intentKey);
    ResourceAllocation rASix = new ResourceAllocation(RESOURCE_SW3_P2, 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) 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) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Aggregations

ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)20 Test (org.junit.Test)14 Bandwidth (org.onlab.util.Bandwidth)13 ContinuousResource (org.onosproject.net.resource.ContinuousResource)13 ResourceService (org.onosproject.net.resource.ResourceService)11 ResourceConsumer (org.onosproject.net.resource.ResourceConsumer)9 ConnectPoint (org.onosproject.net.ConnectPoint)8 Constraint (org.onosproject.net.intent.Constraint)7 Key (org.onosproject.net.intent.Key)7 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)7 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)6 MockResourceService (org.onosproject.net.resource.MockResourceService)6 DeviceId (org.onosproject.net.DeviceId)5 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)5 Resource (org.onosproject.net.resource.Resource)4 Resources (org.onosproject.net.resource.Resources)4 ImmutableList (com.google.common.collect.ImmutableList)3 Collections (java.util.Collections)3 List (java.util.List)3 Set (java.util.Set)3