Search in sources :

Example 6 with ContinuousResource

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

the class ConsistentResourceStore method release.

@Override
public boolean release(List<ResourceAllocation> allocations) {
    checkNotNull(allocations);
    while (true) {
        TransactionContext tx = service.transactionContextBuilder().build();
        tx.begin();
        TransactionalDiscreteResourceSubStore discreteTxStore = discreteStore.transactional(tx);
        TransactionalContinuousResourceSubStore continuousTxStore = continuousStore.transactional(tx);
        for (ResourceAllocation allocation : allocations) {
            Resource resource = allocation.resource();
            ResourceConsumerId consumerId = allocation.consumerId();
            if (resource instanceof DiscreteResource) {
                if (!discreteTxStore.release(consumerId, (DiscreteResource) resource)) {
                    return abortTransaction(tx);
                }
            } else if (resource instanceof ContinuousResource) {
                if (!continuousTxStore.release(consumerId, (ContinuousResource) resource)) {
                    return abortTransaction(tx);
                }
            }
        }
        try {
            if (commitTransaction(tx) == CommitStatus.SUCCESS) {
                return true;
            }
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            log.warn("Failed to release {}: {}", allocations, e);
            return false;
        }
    }
}
Also used : TransactionContext(org.onosproject.store.service.TransactionContext) Resource(org.onosproject.net.resource.Resource) ContinuousResource(org.onosproject.net.resource.ContinuousResource) DiscreteResource(org.onosproject.net.resource.DiscreteResource) ResourceConsumerId(org.onosproject.net.resource.ResourceConsumerId) DiscreteResource(org.onosproject.net.resource.DiscreteResource) ExecutionException(java.util.concurrent.ExecutionException) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ContinuousResource(org.onosproject.net.resource.ContinuousResource) TimeoutException(java.util.concurrent.TimeoutException)

Example 7 with ContinuousResource

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

the class TransactionalContinuousResourceSubStore method allocate.

@Override
public boolean allocate(ResourceConsumerId consumerId, ContinuousResource request) {
    // if the resource is not registered, then abort
    Optional<ContinuousResource> lookedUp = lookup(request.id());
    if (!lookedUp.isPresent()) {
        return false;
    }
    // Down cast: this must be safe as ContinuousResource is associated with ContinuousResourceId
    ContinuousResource original = lookedUp.get();
    ContinuousResourceAllocation allocations = consumers.get(request.id());
    if (!Optional.ofNullable(allocations).orElse(ContinuousResourceAllocation.empty(original)).hasEnoughResource(request)) {
        return false;
    }
    return appendValue(original, new ResourceAllocation(request, consumerId));
}
Also used : ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ContinuousResource(org.onosproject.net.resource.ContinuousResource)

Example 8 with ContinuousResource

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

the class ContinuousResourceAllocationTest method testReleaseWhenDifferentConsumerIsSpecified.

@Test
public void testReleaseWhenDifferentConsumerIsSpecified() {
    ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
    ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
    ResourceConsumer consumer = IntentId.valueOf(1);
    ResourceConsumer otherConsumer = IntentId.valueOf(2);
    ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
    ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
    ImmutableList<ResourceAllocation> allocations = sut.release(request, otherConsumer.consumerId()).allocations();
    assertThat(allocations.size(), is(1));
    assertThat(allocations.get(0).resource().equals(allocated), is(true));
}
Also used : Bandwidth(org.onlab.util.Bandwidth) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ContinuousResource(org.onosproject.net.resource.ContinuousResource) Test(org.junit.Test)

Example 9 with ContinuousResource

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

the class ContinuousResourceAllocationTest method testAllocateDifferentValue.

@Test
public void testAllocateDifferentValue() {
    ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
    ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
    ResourceConsumer consumer = IntentId.valueOf(1);
    ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
    ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(200).bps());
    ContinuousResourceAllocation newValue = sut.allocate(new ResourceAllocation(request, consumer));
    assertThat(newValue.allocations().size(), is(2));
    assertThat(newValue.allocations(), hasItem(new ResourceAllocation(allocated, consumer)));
    assertThat(newValue.allocations(), hasItem(new ResourceAllocation(request, consumer)));
}
Also used : Bandwidth(org.onlab.util.Bandwidth) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ContinuousResource(org.onosproject.net.resource.ContinuousResource) Test(org.junit.Test)

Example 10 with ContinuousResource

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

the class ContinuousResourceAllocationTest method testHasEnoughResourceWhenLargeResourceIsRequested.

@Test
public void testHasEnoughResourceWhenLargeResourceIsRequested() {
    ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
    ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
    ResourceConsumer consumer = IntentId.valueOf(1);
    ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
    ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(600).bps());
    assertThat(sut.hasEnoughResource(request), is(false));
}
Also used : Bandwidth(org.onlab.util.Bandwidth) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ContinuousResource(org.onosproject.net.resource.ContinuousResource) Test(org.junit.Test)

Aggregations

ContinuousResource (org.onosproject.net.resource.ContinuousResource)16 Bandwidth (org.onlab.util.Bandwidth)12 ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)12 Test (org.junit.Test)11 ResourceConsumer (org.onosproject.net.resource.ResourceConsumer)7 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)3 Constraint (org.onosproject.net.intent.Constraint)3 Key (org.onosproject.net.intent.Key)3 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)3 DiscreteResource (org.onosproject.net.resource.DiscreteResource)3 MockResourceService (org.onosproject.net.resource.MockResourceService)3 Resource (org.onosproject.net.resource.Resource)3 ResourceService (org.onosproject.net.resource.ResourceService)3 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)2 PortNumber (org.onosproject.net.PortNumber)2 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2