Search in sources :

Example 16 with ResourceAllocation

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

the class ContinuousResourceAllocationTest method testHasEnoughResourceWhenSmallResourceIsRequested.

@Test
public void testHasEnoughResourceWhenSmallResourceIsRequested() {
    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());
    assertThat(sut.hasEnoughResource(request), 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 17 with ResourceAllocation

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

the class ContinuousResourceAllocationTest method testAllocateSameValue.

@Test
public void testAllocateSameValue() {
    ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
    ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(300).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(300).bps());
    ContinuousResourceAllocation newValue = sut.allocate(new ResourceAllocation(request, consumer));
    assertThat(newValue.allocations().size(), is(2));
    assertThat(newValue.allocations().stream().allMatch(x -> x.equals(new ResourceAllocation(allocated, consumer))), is(true));
}
Also used : Bandwidth(org.onlab.util.Bandwidth) Resources(org.onosproject.net.resource.Resources) PortNumber(org.onosproject.net.PortNumber) Test(org.junit.Test) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) Assert.assertThat(org.junit.Assert.assertThat) Matchers.hasItem(org.hamcrest.Matchers.hasItem) ImmutableList(com.google.common.collect.ImmutableList) Matchers.is(org.hamcrest.Matchers.is) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) DeviceId(org.onosproject.net.DeviceId) ContinuousResource(org.onosproject.net.resource.ContinuousResource) IntentId(org.onosproject.net.intent.IntentId) 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 18 with ResourceAllocation

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

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

the class TestAllocateResource method doExecute.

@Override
protected void doExecute() {
    resourceService = get(ResourceService.class);
    DeviceId did = DeviceId.deviceId(deviceIdStr);
    PortNumber portNum = PortNumber.fromString(portNumberStr);
    ResourceConsumer consumer = IntentId.valueOf(nIntendId);
    Resource resource = Resources.discrete(did, portNum, createLambda(Integer.parseInt(lambda))).resource();
    Optional<ResourceAllocation> allocate = resourceService.allocate(consumer, resource);
    if (allocate.isPresent()) {
        print("Allocated: %s", allocate.get());
    } else {
        print("Failed to allocate %s for %s", resource, consumer);
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) ResourceService(org.onosproject.net.resource.ResourceService) Resource(org.onosproject.net.resource.Resource) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) PortNumber(org.onosproject.net.PortNumber) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation)

Example 20 with ResourceAllocation

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

the class OpticalPathProvisioner method updateBandwidthUsage.

/**
 * Updates usage information of bandwidth based on connectivity which is established.
 * @param connectivity Optical connectivity
 */
private void updateBandwidthUsage(OpticalConnectivity connectivity) {
    if (NO_BW_REQUIREMENT.equals(connectivity.bandwidth())) {
        // no bandwidth requirement, nothing to allocate.
        return;
    }
    OpticalConnectivityId connectivityId = connectivity.id();
    List<Link> links = connectivity.links();
    List<Resource> resources = links.stream().flatMap(l -> Stream.of(l.src(), l.dst())).filter(cp -> !isTransportLayer(deviceService.getDevice(cp.deviceId()).type())).map(cp -> Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource(connectivity.bandwidth().bps())).collect(Collectors.toList());
    log.debug("allocating bandwidth for {} : {}", connectivityId, resources);
    List<ResourceAllocation> allocations = resourceService.allocate(connectivityId, resources);
    if (allocations.isEmpty()) {
        log.warn("Failed to allocate bandwidth {} to {}", connectivity.bandwidth().bps(), resources);
    // TODO any recovery?
    }
    log.debug("Done allocating bandwidth for {}", connectivityId);
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) AtomicCounter(org.onosproject.store.service.AtomicCounter) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) TopologyService(org.onosproject.net.topology.TopologyService) Link(org.onosproject.net.Link) ResourceService(org.onosproject.net.resource.ResourceService) ConnectPoint(org.onosproject.net.ConnectPoint) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) StorageService(org.onosproject.store.service.StorageService) Pair(org.apache.commons.lang3.tuple.Pair) MAX_PATHS_DEFAULT(org.onosproject.newoptical.OsgiPropertyConstants.MAX_PATHS_DEFAULT) Port(org.onosproject.net.Port) Duration(java.time.Duration) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) OchPort(org.onosproject.net.optical.OchPort) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) LinkKey(org.onosproject.net.LinkKey) Serializer(org.onosproject.store.service.Serializer) AbstractListenerManager(org.onosproject.event.AbstractListenerManager) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Bandwidth(org.onlab.util.Bandwidth) Resources(org.onosproject.net.resource.Resources) Collection(java.util.Collection) Set(java.util.Set) Resource(org.onosproject.net.resource.Resource) OpticalPathEvent(org.onosproject.newoptical.api.OpticalPathEvent) Collectors(java.util.stream.Collectors) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) Objects(java.util.Objects) Versioned(org.onosproject.store.service.Versioned) Key(org.onosproject.net.intent.Key) LinkListener(org.onosproject.net.link.LinkListener) List(java.util.List) OduCltPort(org.onosproject.net.optical.OduCltPort) Stream(java.util.stream.Stream) IntentListener(org.onosproject.net.intent.IntentListener) TopologyVertex(org.onosproject.net.topology.TopologyVertex) Entry(java.util.Map.Entry) ListenerTracker(org.onosproject.event.ListenerTracker) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) Path(org.onosproject.net.Path) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) TopologyEdge(org.onosproject.net.topology.TopologyEdge) Tools(org.onlab.util.Tools) IntentEvent(org.onosproject.net.intent.IntentEvent) BasicLinkConfig(org.onosproject.net.config.basics.BasicLinkConfig) LinkEvent(org.onosproject.net.link.LinkEvent) ComponentContext(org.osgi.service.component.ComponentContext) HashMap(java.util.HashMap) OpticalPathService(org.onosproject.newoptical.api.OpticalPathService) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) IntentService(org.onosproject.net.intent.IntentService) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) LinkedList(java.util.LinkedList) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MAX_PATHS(org.onosproject.newoptical.OsgiPropertyConstants.MAX_PATHS) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Beta(com.google.common.annotations.Beta) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultEdgeWeigher(org.onlab.graph.DefaultEdgeWeigher) OpticalPathListener(org.onosproject.newoptical.api.OpticalPathListener) DistributedSet(org.onosproject.store.service.DistributedSet) Weight(org.onlab.graph.Weight) OpticalDeviceServiceView.opticalView(org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView) MapEvent(org.onosproject.store.service.MapEvent) Modified(org.osgi.service.component.annotations.Modified) BandwidthCapacity(org.onosproject.net.config.basics.BandwidthCapacity) LinkWeigher(org.onosproject.net.topology.LinkWeigher) Reference(org.osgi.service.component.annotations.Reference) ScalarWeight(org.onlab.graph.ScalarWeight) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ContinuousResource(org.onosproject.net.resource.ContinuousResource) Collections(java.util.Collections) OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth) Resource(org.onosproject.net.resource.Resource) ContinuousResource(org.onosproject.net.resource.ContinuousResource) Link(org.onosproject.net.Link) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation)

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