Search in sources :

Example 11 with ResourceService

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

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

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

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

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

the class OpticalCircuitIntentCompiler method availableSlotResources.

private List<Resource> availableSlotResources(ConnectPoint src, ConnectPoint dst, CltSignalType signalType) {
    OduSignalType oduSignalType = OduSignalUtils.mappingCltSignalTypeToOduSignalType(signalType);
    int requestedTsNum = oduSignalType.tributarySlots();
    Set<TributarySlot> commonTributarySlots = findCommonTributarySlotsOnCps(src, dst);
    if (commonTributarySlots.isEmpty()) {
        return Collections.emptyList();
    }
    if (commonTributarySlots.size() < requestedTsNum) {
        return Collections.emptyList();
    }
    Set<TributarySlot> tributarySlots = commonTributarySlots.stream().limit(requestedTsNum).collect(Collectors.toSet());
    final List<ConnectPoint> portsList = ImmutableList.of(src, dst);
    List<Resource> tributarySlotResources = portsList.stream().flatMap(cp -> tributarySlots.stream().map(ts -> Resources.discrete(cp.deviceId(), cp.port()).resource().child(ts))).collect(Collectors.toList());
    if (!tributarySlotResources.stream().allMatch(resourceService::isAvailable)) {
        log.debug("Resource allocation for {} on {} and {} failed (resource request: {})", signalType, src, dst, tributarySlotResources);
        return Collections.emptyList();
    }
    return tributarySlotResources;
}
Also used : Arrays(java.util.Arrays) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) ResourceService(org.onosproject.net.resource.ResourceService) DriverService(org.onosproject.net.driver.DriverService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) Pair(org.apache.commons.lang3.tuple.Pair) Port(org.onosproject.net.Port) TributarySlotQuery(org.onosproject.net.behaviour.TributarySlotQuery) ApplicationId(org.onosproject.core.ApplicationId) OchPort(org.onosproject.net.optical.OchPort) Driver(org.onosproject.net.driver.Driver) OduSignalUtils(org.onosproject.net.OduSignalUtils) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Resources(org.onosproject.net.resource.Resources) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Resource(org.onosproject.net.resource.Resource) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) CltSignalType(org.onosproject.net.CltSignalType) List(java.util.List) OduCltPort(org.onosproject.net.optical.OduCltPort) Stream(java.util.stream.Stream) OduSignalId(org.onosproject.net.OduSignalId) FlowRule(org.onosproject.net.flow.FlowRule) IntentCompiler(org.onosproject.net.intent.IntentCompiler) Optional(java.util.Optional) Dictionary(java.util.Dictionary) IntentSetMultimap(org.onosproject.net.intent.IntentSetMultimap) Tools(org.onlab.util.Tools) ComponentContext(org.osgi.service.component.ComponentContext) AnnotationKeys(org.onosproject.net.AnnotationKeys) Strings(com.google.common.base.Strings) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) 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) Criteria(org.onosproject.net.flow.criteria.Criteria) LinkedList(java.util.LinkedList) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OduSignalType(org.onosproject.net.OduSignalType) IntentId(org.onosproject.net.intent.IntentId) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) TributarySlot(org.onosproject.net.TributarySlot) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) MAX_CAPACITY(org.onosproject.net.optical.intent.impl.compiler.OsgiPropertyConstants.MAX_CAPACITY) OpticalDeviceServiceView.opticalView(org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView) Modified(org.osgi.service.component.annotations.Modified) MAX_CAPACITY_DEFAULT(org.onosproject.net.optical.intent.impl.compiler.OsgiPropertyConstants.MAX_CAPACITY_DEFAULT) Reference(org.osgi.service.component.annotations.Reference) Comparator(java.util.Comparator) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Collections(java.util.Collections) OduSignalType(org.onosproject.net.OduSignalType) TributarySlot(org.onosproject.net.TributarySlot) Resource(org.onosproject.net.resource.Resource) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

ResourceService (org.onosproject.net.resource.ResourceService)16 ConnectPoint (org.onosproject.net.ConnectPoint)12 Test (org.junit.Test)11 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)11 Constraint (org.onosproject.net.intent.Constraint)11 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)11 MockResourceService (org.onosproject.net.resource.MockResourceService)11 ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)11 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)10 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)8 Key (org.onosproject.net.intent.Key)5 Bandwidth (org.onlab.util.Bandwidth)4 DeviceId (org.onosproject.net.DeviceId)4 DeviceService (org.onosproject.net.device.DeviceService)4 Collections (java.util.Collections)3 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Link (org.onosproject.net.Link)3 Intent (org.onosproject.net.intent.Intent)3