Search in sources :

Example 6 with Constraint

use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.

the class ConstraintCodecTest method annotationConstraint.

/**
 * Tests annotation constraint.
 */
@Test
public void annotationConstraint() {
    Constraint constraint = getConstraint("AnnotationConstraint.json");
    assertThat(constraint, instanceOf(AnnotationConstraint.class));
    AnnotationConstraint annotationConstraint = (AnnotationConstraint) constraint;
    assertThat(annotationConstraint.key(), is("key"));
    assertThat(annotationConstraint.threshold(), is(123.0D));
}
Also used : WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) DomainConstraint(org.onosproject.net.intent.constraint.DomainConstraint) MeteredConstraint(org.onosproject.net.intent.constraint.MeteredConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) TierConstraint(org.onosproject.net.intent.constraint.TierConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) Test(org.junit.Test)

Example 7 with Constraint

use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.

the class ConstraintCodecTest method obstacleConstraint.

/**
 * Tests obstacle constraint.
 */
@Test
public void obstacleConstraint() {
    Constraint constraint = getConstraint("ObstacleConstraint.json");
    assertThat(constraint, instanceOf(ObstacleConstraint.class));
    ObstacleConstraint obstacleConstraint = (ObstacleConstraint) constraint;
    assertThat(obstacleConstraint.obstacles(), hasItem(did("dev1")));
    assertThat(obstacleConstraint.obstacles(), hasItem(did("dev2")));
    assertThat(obstacleConstraint.obstacles(), hasItem(did("dev3")));
}
Also used : ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) DomainConstraint(org.onosproject.net.intent.constraint.DomainConstraint) MeteredConstraint(org.onosproject.net.intent.constraint.MeteredConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) TierConstraint(org.onosproject.net.intent.constraint.TierConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) Test(org.junit.Test)

Example 8 with Constraint

use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.

the class ConstraintCodecTest method waypointConstraint.

/**
 * Tests waypoint constaint.
 */
@Test
public void waypointConstraint() {
    Constraint constraint = getConstraint("WaypointConstraint.json");
    assertThat(constraint, instanceOf(WaypointConstraint.class));
    WaypointConstraint waypointConstraint = (WaypointConstraint) constraint;
    assertThat(waypointConstraint.waypoints(), hasItem(did("devA")));
    assertThat(waypointConstraint.waypoints(), hasItem(did("devB")));
    assertThat(waypointConstraint.waypoints(), hasItem(did("devC")));
}
Also used : WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) DomainConstraint(org.onosproject.net.intent.constraint.DomainConstraint) MeteredConstraint(org.onosproject.net.intent.constraint.MeteredConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) TierConstraint(org.onosproject.net.intent.constraint.TierConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) Test(org.junit.Test)

Example 9 with Constraint

use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.

the class ConstraintCodecTest method getConstraint.

/**
 * Reads in a constraint from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the constraint
 * @return decoded constraint
 */
private Constraint getConstraint(String resourceName) {
    InputStream jsonStream = ConstraintCodecTest.class.getResourceAsStream(resourceName);
    try {
        JsonNode json = context.mapper().readTree(jsonStream);
        assertThat(json, notNullValue());
        Constraint constraint = constraintCodec.decode((ObjectNode) json, context);
        assertThat(constraint, notNullValue());
        return checkNotNull(constraint);
    } catch (IOException ioe) {
        Assert.fail(ioe.getMessage());
        throw new IllegalStateException("cannot happen");
    }
}
Also used : WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) DomainConstraint(org.onosproject.net.intent.constraint.DomainConstraint) MeteredConstraint(org.onosproject.net.intent.constraint.MeteredConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) TierConstraint(org.onosproject.net.intent.constraint.TierConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Example 10 with Constraint

use of org.onosproject.net.intent.Constraint 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)

Aggregations

Constraint (org.onosproject.net.intent.Constraint)48 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)31 Test (org.junit.Test)28 ConnectPoint (org.onosproject.net.ConnectPoint)27 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)22 TrafficSelector (org.onosproject.net.flow.TrafficSelector)17 LatencyConstraint (org.onosproject.net.intent.constraint.LatencyConstraint)17 AnnotationConstraint (org.onosproject.net.intent.constraint.AnnotationConstraint)16 ObstacleConstraint (org.onosproject.net.intent.constraint.ObstacleConstraint)16 WaypointConstraint (org.onosproject.net.intent.constraint.WaypointConstraint)16 LinkTypeConstraint (org.onosproject.net.intent.constraint.LinkTypeConstraint)15 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)14 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 Key (org.onosproject.net.intent.Key)13 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)12 AsymmetricPathConstraint (org.onosproject.net.intent.constraint.AsymmetricPathConstraint)12 DomainConstraint (org.onosproject.net.intent.constraint.DomainConstraint)12 ResourceService (org.onosproject.net.resource.ResourceService)12 Intent (org.onosproject.net.intent.Intent)11 MeteredConstraint (org.onosproject.net.intent.constraint.MeteredConstraint)11