2 * Copyright 2015 Open Networking Laboratory
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onosproject.net.resource.impl;
18 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate;
21 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.apache.felix.scr.annotations.Service;
24 import org.onosproject.net.Port;
25 import org.onosproject.net.intent.Intent;
26 import org.onosproject.net.intent.IntentId;
27 import org.onosproject.net.resource.device.DeviceResourceService;
28 import org.onosproject.net.resource.device.DeviceResourceStore;
29 import org.slf4j.Logger;
33 import static com.google.common.base.Preconditions.checkNotNull;
34 import static org.slf4j.LoggerFactory.getLogger;
37 * Provides basic implementation of device resources allocation.
39 @Component(immediate = true)
41 public class DeviceResourceManager implements DeviceResourceService {
43 private final Logger log = getLogger(getClass());
45 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
46 private DeviceResourceStore store;
49 public void activate() {
54 public void deactivate() {
59 public boolean requestPorts(Set<Port> ports, Intent intent) {
62 return store.allocatePorts(ports, intent.id());
66 public Set<Port> getAllocations(IntentId intentId) {
67 return store.getAllocations(intentId);
71 public IntentId getAllocations(Port port) {
72 return store.getAllocations(port);
76 public void releaseMapping(IntentId intentId) {
77 store.releaseMapping(intentId);
81 public boolean requestMapping(IntentId keyIntentId, IntentId valIntentId) {
82 return store.allocateMapping(keyIntentId, valIntentId);
86 public Set<IntentId> getMapping(IntentId intentId) {
87 return store.getMapping(intentId);
91 public void releasePorts(IntentId intentId) {
92 store.releasePorts(intentId);
95 private Port getTypedPort(Set<Port> ports, Port.Type type) {
96 for (Port port : ports) {
97 if (port.type() == type) {