Search in sources :

Example 11 with Resource

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

the class ResourceDeviceListener method unregisterDeviceResource.

private void unregisterDeviceResource(Device device) {
    DiscreteResource devResource = Resources.discrete(device.id()).resource();
    List<Resource> allResources = getDescendantResources(devResource);
    adminService.unregister(Lists.transform(allResources, Resource::id));
}
Also used : Resource(org.onosproject.net.resource.Resource) DiscreteResource(org.onosproject.net.resource.DiscreteResource) DiscreteResource(org.onosproject.net.resource.DiscreteResource)

Example 12 with Resource

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

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

Example 14 with Resource

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

the class OpticalCircuitIntentCompiler method compile.

@Override
public List<Intent> compile(OpticalCircuitIntent intent, List<Intent> installable) {
    // Check if ports are OduClt ports
    ConnectPoint src = intent.getSrc();
    ConnectPoint dst = intent.getDst();
    Port srcPort = deviceService.getPort(src.deviceId(), src.port());
    Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
    checkArgument(srcPort instanceof OduCltPort);
    checkArgument(dstPort instanceof OduCltPort);
    log.debug("Compiling optical circuit intent between {} and {}", src, dst);
    // Release of intent resources here is only a temporary solution for handling the
    // case of recompiling due to intent restoration (when intent state is FAILED).
    // TODO: try to release intent resources in IntentManager.
    resourceService.release(intent.key());
    // Check OduClt ports availability
    Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
    Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
    // If ports are not available, compilation fails
    if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
        throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
    }
    List<Resource> ports = ImmutableList.of(srcPortResource, dstPortResource);
    // Check if both devices support multiplexing (usage of TributarySlots)
    boolean multiplexingSupported = isMultiplexingSupported(intent.getSrc()) && isMultiplexingSupported(intent.getDst());
    OpticalConnectivityIntent connIntent = findOpticalConnectivityIntent(intent.getSrc(), intent.getDst(), intent.getSignalType(), multiplexingSupported);
    if (connIntent != null && !multiplexingSupported) {
        return compile(intent, src, dst, Optional.of(connIntent), ports, false);
    }
    // Create optical connectivity intent if needed - no optical intent or not enough slots available
    if (connIntent == null) {
        return compile(intent, src, dst, Optional.empty(), ports, multiplexingSupported);
    }
    List<Resource> slots = availableSlotResources(connIntent.getSrc(), connIntent.getDst(), intent.getSignalType());
    if (slots.isEmpty()) {
        return compile(intent, src, dst, Optional.empty(), ports, true);
    }
    return compile(intent, src, dst, Optional.of(connIntent), ImmutableList.<Resource>builder().addAll(ports).addAll(slots).build(), false);
}
Also used : Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) OduCltPort(org.onosproject.net.optical.OduCltPort) OduCltPort(org.onosproject.net.optical.OduCltPort) Resource(org.onosproject.net.resource.Resource) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 15 with Resource

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

Resource (org.onosproject.net.resource.Resource)16 Set (java.util.Set)8 DiscreteResource (org.onosproject.net.resource.DiscreteResource)8 ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)8 List (java.util.List)7 ConnectPoint (org.onosproject.net.ConnectPoint)7 Resources (org.onosproject.net.resource.Resources)7 Optional (java.util.Optional)6 Collectors (java.util.stream.Collectors)6 Reference (org.osgi.service.component.annotations.Reference)6 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 Collection (java.util.Collection)5 Collections (java.util.Collections)5 DeviceId (org.onosproject.net.DeviceId)5 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayList (java.util.ArrayList)4