Search in sources :

Example 6 with ResourceService

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

the class PointToPointIntentCompilerTest method testSuggestedPathBandwidthConstrainedIntentSuccess.

/**
 * Tests that requests with suggested path
 * and with sufficient available bandwidth succeed.
 */
@Test
public void testSuggestedPathBandwidthConstrainedIntentSuccess() {
    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)));
    String[] suggestedPathHops = { S1, S4, S5, S3 };
    List<Link> suggestedPath = NetTestTools.createPath(suggestedPathHops).links();
    final PointToPointIntent intent = makeIntentSuggestedPath(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), suggestedPath, constraints);
    String[][] hops = { { S1, S2, S3 }, suggestedPathHops };
    final PointToPointIntentCompiler compiler = makeCompilerSuggestedPath(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) Link(org.onosproject.net.Link) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 7 with ResourceService

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

the class SinglePointToMultiPointIntentCompilerTest 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)));
    FilteredConnectPoint ingress = new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_1));
    Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_2)), new FilteredConnectPoint(new ConnectPoint(DID_2, PORT_2)));
    TrafficSelector ipPrefixSelector = DefaultTrafficSelector.builder().matchIPDst(IpPrefix.valueOf("192.168.100.0/24")).build();
    SinglePointToMultiPointIntent intent = makeIntent(ingress, egress, ipPrefixSelector, constraints);
    SinglePointToMultiPointIntentCompiler 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) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) Bandwidth(org.onlab.util.Bandwidth) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) 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 8 with ResourceService

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

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

the class AllocationsCommand method doExecute.

@Override
protected void doExecute() {
    deviceService = get(DeviceService.class);
    resourceService = get(ResourceService.class);
    if (typeStrings != null) {
        typesToPrint = new HashSet<>(Arrays.asList(typeStrings));
    } else {
        typesToPrint = Collections.emptySet();
    }
    if (intentStrings != null) {
        intentsToPrint = new HashSet<>(Arrays.asList(intentStrings));
    } else {
        intentsToPrint = Collections.emptySet();
    }
    if (deviceIdStr != null && portNumberStr != null) {
        DeviceId deviceId = deviceId(deviceIdStr);
        PortNumber portNumber = PortNumber.fromString(portNumberStr);
        printAllocation(deviceId, portNumber, 0);
    } else if (deviceIdStr != null) {
        DeviceId deviceId = deviceId(deviceIdStr);
        printAllocation(deviceId, 0);
    } else {
        printAllocation();
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) ResourceService(org.onosproject.net.resource.ResourceService) PortNumber(org.onosproject.net.PortNumber)

Example 10 with ResourceService

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

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