blob: d2d9e7eb1fc8a0d28de4203492e7db7a71e26cf9 [file] [log] [blame]
Toshio Koide5c0a7262014-10-23 14:50:21 -07001package org.onlab.onos.net.resource.impl;
Toshio Koide50df38d2014-10-23 10:36:51 -07002
3import static org.slf4j.LoggerFactory.getLogger;
4
Toshio Koideca0fcff2014-10-23 14:08:36 -07005import java.util.HashMap;
Toshio Koide9be539e2014-10-23 18:43:30 -07006import java.util.Iterator;
Toshio Koideca0fcff2014-10-23 14:08:36 -07007import java.util.Map;
8import java.util.Set;
9
Toshio Koide50df38d2014-10-23 10:36:51 -070010import org.apache.felix.scr.annotations.Activate;
11import org.apache.felix.scr.annotations.Component;
12import org.apache.felix.scr.annotations.Deactivate;
13import org.apache.felix.scr.annotations.Service;
14import org.onlab.onos.net.Link;
15import org.onlab.onos.net.intent.IntentId;
Toshio Koide5c0a7262014-10-23 14:50:21 -070016import org.onlab.onos.net.resource.BandwidthResourceAllocation;
17import org.onlab.onos.net.resource.BandwidthResourceRequest;
18import org.onlab.onos.net.resource.Lambda;
19import org.onlab.onos.net.resource.LambdaResourceAllocation;
20import org.onlab.onos.net.resource.LinkResourceAllocations;
21import org.onlab.onos.net.resource.LinkResourceRequest;
22import org.onlab.onos.net.resource.LinkResourceService;
23import org.onlab.onos.net.resource.ResourceAllocation;
24import org.onlab.onos.net.resource.ResourceRequest;
Toshio Koide50df38d2014-10-23 10:36:51 -070025import org.slf4j.Logger;
26
Toshio Koideca0fcff2014-10-23 14:08:36 -070027import com.google.common.collect.Sets;
28
Toshio Koide50df38d2014-10-23 10:36:51 -070029/**
30 * Provides basic implementation of link resources allocation.
31 */
32@Component(immediate = true)
33@Service
34public class LinkResourceManager implements LinkResourceService {
35
36 private final Logger log = getLogger(getClass());
37
38 @Activate
39 public void activate() {
40 log.info("Started");
41 }
42
43 @Deactivate
44 public void deactivate() {
45 log.info("Stopped");
46 }
47
Toshio Koide9be539e2014-10-23 18:43:30 -070048 private Iterable<Lambda> getAvailableLambdas(Iterable<Link> links) {
49 return Sets.newHashSet(Lambda.valueOf(7));
50 }
51
Toshio Koide50df38d2014-10-23 10:36:51 -070052 @Override
53 public LinkResourceAllocations requestResources(LinkResourceRequest req) {
Toshio Koideca0fcff2014-10-23 14:08:36 -070054 // TODO implement it using a resource data store.
55
56 ResourceAllocation alloc = null;
Toshio Koide9be539e2014-10-23 18:43:30 -070057 for (ResourceRequest r : req.resources()) {
Toshio Koideca0fcff2014-10-23 14:08:36 -070058 switch (r.type()) {
59 case BANDWIDTH:
60 log.info("requestResources() always returns requested bandwidth");
61 BandwidthResourceRequest br = (BandwidthResourceRequest) r;
62 alloc = new BandwidthResourceAllocation(br.bandwidth());
63 break;
64 case LAMBDA:
65 log.info("requestResources() always returns lambda 7");
Toshio Koide9be539e2014-10-23 18:43:30 -070066 Iterator<Lambda> lambdaIterator = getAvailableLambdas(req.links()).iterator();
67 if (lambdaIterator.hasNext()) {
68 alloc = new LambdaResourceAllocation(lambdaIterator.next());
69 }
Toshio Koideca0fcff2014-10-23 14:08:36 -070070 break;
71 default:
72 break;
73 }
74 }
75
76 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
Toshio Koide9be539e2014-10-23 18:43:30 -070077 for (Link link : req.links()) {
Toshio Koideca0fcff2014-10-23 14:08:36 -070078 allocations.put(link, Sets.newHashSet(alloc));
79 }
80 return new DefaultLinkResourceAllocations(req, allocations);
Toshio Koide50df38d2014-10-23 10:36:51 -070081 }
82
83 @Override
84 public void releaseResources(LinkResourceAllocations allocations) {
85 // TODO Auto-generated method stub
86
87 }
88
89 @Override
Thomas Vachuskaf9976952014-10-24 11:55:05 -070090 public LinkResourceAllocations updateResources(LinkResourceRequest req,
91 LinkResourceAllocations oldAllocations) {
92 return null;
93 }
94
95 @Override
Toshio Koide50df38d2014-10-23 10:36:51 -070096 public Iterable<LinkResourceAllocations> getAllocations() {
97 // TODO Auto-generated method stub
98 return null;
99 }
100
101 @Override
Toshio Koide50df38d2014-10-23 10:36:51 -0700102 public Iterable<LinkResourceAllocations> getAllocations(Link link) {
103 // TODO Auto-generated method stub
104 return null;
105 }
106
107 @Override
Toshio Koide9be539e2014-10-23 18:43:30 -0700108 public LinkResourceAllocations getAllocations(IntentId intentId) {
Toshio Koide50df38d2014-10-23 10:36:51 -0700109 // TODO Auto-generated method stub
110 return null;
111 }
112
113 @Override
Toshio Koide9be539e2014-10-23 18:43:30 -0700114 public Iterable<ResourceRequest> getAvailableResources(Link link) {
Toshio Koide50df38d2014-10-23 10:36:51 -0700115 // TODO Auto-generated method stub
116 return null;
117 }
118
Thomas Vachuskaf9976952014-10-24 11:55:05 -0700119 @Override
120 public ResourceRequest getAvailableResources(Link link,
121 LinkResourceAllocations allocations) {
122 return null;
123 }
124
Toshio Koide50df38d2014-10-23 10:36:51 -0700125}