blob: bdd07618d5058151786de3cc330da69d2d2143ed [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
Toshio Koide5c0a7262014-10-23 14:50:21 -070016package org.onlab.onos.net.resource.impl;
Toshio Koide50df38d2014-10-23 10:36:51 -070017
18import static org.slf4j.LoggerFactory.getLogger;
19
Toshio Koideca0fcff2014-10-23 14:08:36 -070020import java.util.HashMap;
Toshio Koide9be539e2014-10-23 18:43:30 -070021import java.util.Iterator;
Toshio Koideca0fcff2014-10-23 14:08:36 -070022import java.util.Map;
23import java.util.Set;
24
Toshio Koide50df38d2014-10-23 10:36:51 -070025import org.apache.felix.scr.annotations.Activate;
26import org.apache.felix.scr.annotations.Component;
27import org.apache.felix.scr.annotations.Deactivate;
28import org.apache.felix.scr.annotations.Service;
29import org.onlab.onos.net.Link;
30import org.onlab.onos.net.intent.IntentId;
Toshio Koide5c0a7262014-10-23 14:50:21 -070031import org.onlab.onos.net.resource.BandwidthResourceAllocation;
32import org.onlab.onos.net.resource.BandwidthResourceRequest;
33import org.onlab.onos.net.resource.Lambda;
34import org.onlab.onos.net.resource.LambdaResourceAllocation;
35import org.onlab.onos.net.resource.LinkResourceAllocations;
36import org.onlab.onos.net.resource.LinkResourceRequest;
37import org.onlab.onos.net.resource.LinkResourceService;
38import org.onlab.onos.net.resource.ResourceAllocation;
39import org.onlab.onos.net.resource.ResourceRequest;
Toshio Koide50df38d2014-10-23 10:36:51 -070040import org.slf4j.Logger;
41
Toshio Koideca0fcff2014-10-23 14:08:36 -070042import com.google.common.collect.Sets;
43
Toshio Koide50df38d2014-10-23 10:36:51 -070044/**
45 * Provides basic implementation of link resources allocation.
46 */
47@Component(immediate = true)
48@Service
49public class LinkResourceManager implements LinkResourceService {
50
51 private final Logger log = getLogger(getClass());
52
53 @Activate
54 public void activate() {
55 log.info("Started");
56 }
57
58 @Deactivate
59 public void deactivate() {
60 log.info("Stopped");
61 }
62
Toshio Koide9be539e2014-10-23 18:43:30 -070063 private Iterable<Lambda> getAvailableLambdas(Iterable<Link> links) {
64 return Sets.newHashSet(Lambda.valueOf(7));
65 }
66
Toshio Koide50df38d2014-10-23 10:36:51 -070067 @Override
68 public LinkResourceAllocations requestResources(LinkResourceRequest req) {
Toshio Koideca0fcff2014-10-23 14:08:36 -070069 // TODO implement it using a resource data store.
70
71 ResourceAllocation alloc = null;
Toshio Koide9be539e2014-10-23 18:43:30 -070072 for (ResourceRequest r : req.resources()) {
Toshio Koideca0fcff2014-10-23 14:08:36 -070073 switch (r.type()) {
74 case BANDWIDTH:
75 log.info("requestResources() always returns requested bandwidth");
76 BandwidthResourceRequest br = (BandwidthResourceRequest) r;
77 alloc = new BandwidthResourceAllocation(br.bandwidth());
78 break;
79 case LAMBDA:
80 log.info("requestResources() always returns lambda 7");
Toshio Koide9be539e2014-10-23 18:43:30 -070081 Iterator<Lambda> lambdaIterator = getAvailableLambdas(req.links()).iterator();
82 if (lambdaIterator.hasNext()) {
83 alloc = new LambdaResourceAllocation(lambdaIterator.next());
84 }
Toshio Koideca0fcff2014-10-23 14:08:36 -070085 break;
86 default:
87 break;
88 }
89 }
90
91 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
Toshio Koide9be539e2014-10-23 18:43:30 -070092 for (Link link : req.links()) {
Toshio Koideca0fcff2014-10-23 14:08:36 -070093 allocations.put(link, Sets.newHashSet(alloc));
94 }
95 return new DefaultLinkResourceAllocations(req, allocations);
Toshio Koide50df38d2014-10-23 10:36:51 -070096 }
97
98 @Override
99 public void releaseResources(LinkResourceAllocations allocations) {
100 // TODO Auto-generated method stub
101
102 }
103
104 @Override
Thomas Vachuskaf9976952014-10-24 11:55:05 -0700105 public LinkResourceAllocations updateResources(LinkResourceRequest req,
106 LinkResourceAllocations oldAllocations) {
107 return null;
108 }
109
110 @Override
Toshio Koide50df38d2014-10-23 10:36:51 -0700111 public Iterable<LinkResourceAllocations> getAllocations() {
112 // TODO Auto-generated method stub
113 return null;
114 }
115
116 @Override
Toshio Koide50df38d2014-10-23 10:36:51 -0700117 public Iterable<LinkResourceAllocations> getAllocations(Link link) {
118 // TODO Auto-generated method stub
119 return null;
120 }
121
122 @Override
Toshio Koide9be539e2014-10-23 18:43:30 -0700123 public LinkResourceAllocations getAllocations(IntentId intentId) {
Toshio Koide50df38d2014-10-23 10:36:51 -0700124 // TODO Auto-generated method stub
125 return null;
126 }
127
128 @Override
Toshio Koide9be539e2014-10-23 18:43:30 -0700129 public Iterable<ResourceRequest> getAvailableResources(Link link) {
Toshio Koide50df38d2014-10-23 10:36:51 -0700130 // TODO Auto-generated method stub
131 return null;
132 }
133
Thomas Vachuskaf9976952014-10-24 11:55:05 -0700134 @Override
135 public ResourceRequest getAvailableResources(Link link,
136 LinkResourceAllocations allocations) {
137 return null;
138 }
139
Toshio Koide50df38d2014-10-23 10:36:51 -0700140}