blob: c9437de32bdac93e6afbdcd74978a1dc80d79ce9 [file] [log] [blame]
Marc De Leenheer1afa2a02015-05-13 09:18:07 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16package org.onosproject.net.resource.impl;
17
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
21import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
23import org.apache.felix.scr.annotations.Service;
24import org.onosproject.net.Port;
25import org.onosproject.net.intent.Intent;
26import org.onosproject.net.intent.IntentId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070027import org.onosproject.net.resource.device.DeviceResourceService;
28import org.onosproject.net.resource.device.DeviceResourceStore;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070029import org.slf4j.Logger;
30
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070031import java.util.Set;
32
33import static com.google.common.base.Preconditions.checkNotNull;
34import static org.slf4j.LoggerFactory.getLogger;
35
36/**
37 * Provides basic implementation of device resources allocation.
38 */
39@Component(immediate = true)
40@Service
41public class DeviceResourceManager implements DeviceResourceService {
42
43 private final Logger log = getLogger(getClass());
44
45 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
46 private DeviceResourceStore store;
47
48 @Activate
49 public void activate() {
50 log.info("Started");
51 }
52
53 @Deactivate
54 public void deactivate() {
55 log.info("Stopped");
56 }
57
58 @Override
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070059 public boolean requestPorts(Set<Port> ports, Intent intent) {
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070060 checkNotNull(intent);
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070061
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070062 return store.allocatePorts(ports, intent.id());
63 }
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070064
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070065 @Override
66 public Set<Port> getAllocations(IntentId intentId) {
67 return store.getAllocations(intentId);
68 }
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070069
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070070 @Override
71 public IntentId getAllocations(Port port) {
72 return store.getAllocations(port);
73 }
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070074
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070075 @Override
76 public void releaseMapping(IntentId keyIntentId, IntentId valIntentId) {
77 store.releaseMapping(keyIntentId, valIntentId);
78 }
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070079
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070080 @Override
81 public boolean requestMapping(IntentId keyIntentId, IntentId valIntentId) {
82 return store.allocateMapping(keyIntentId, valIntentId);
83 }
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070084
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070085 @Override
86 public Set<IntentId> getMapping(IntentId intentId) {
87 return store.getMapping(intentId);
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070088 }
89
90 @Override
91 public void releasePorts(IntentId intentId) {
92 store.releasePorts(intentId);
93 }
94
95 private Port getTypedPort(Set<Port> ports, Port.Type type) {
96 for (Port port : ports) {
97 if (port.type() == type) {
98 return port;
99 }
100 }
101
102 return null;
103 }
104}