blob: 75e081863421c093538ee7fb432bc734ce804f2e [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;
6import java.util.Map;
7import java.util.Set;
8
Toshio Koide50df38d2014-10-23 10:36:51 -07009import org.apache.felix.scr.annotations.Activate;
10import org.apache.felix.scr.annotations.Component;
11import org.apache.felix.scr.annotations.Deactivate;
12import org.apache.felix.scr.annotations.Service;
13import org.onlab.onos.net.Link;
14import org.onlab.onos.net.intent.IntentId;
Toshio Koide5c0a7262014-10-23 14:50:21 -070015import org.onlab.onos.net.resource.BandwidthResourceAllocation;
16import org.onlab.onos.net.resource.BandwidthResourceRequest;
17import org.onlab.onos.net.resource.Lambda;
18import org.onlab.onos.net.resource.LambdaResourceAllocation;
19import org.onlab.onos.net.resource.LinkResourceAllocations;
20import org.onlab.onos.net.resource.LinkResourceRequest;
21import org.onlab.onos.net.resource.LinkResourceService;
22import org.onlab.onos.net.resource.ResourceAllocation;
23import org.onlab.onos.net.resource.ResourceRequest;
Toshio Koide50df38d2014-10-23 10:36:51 -070024import org.slf4j.Logger;
25
Toshio Koideca0fcff2014-10-23 14:08:36 -070026import com.google.common.collect.Sets;
27
Toshio Koide50df38d2014-10-23 10:36:51 -070028/**
29 * Provides basic implementation of link resources allocation.
30 */
31@Component(immediate = true)
32@Service
33public class LinkResourceManager implements LinkResourceService {
34
35 private final Logger log = getLogger(getClass());
36
37 @Activate
38 public void activate() {
39 log.info("Started");
40 }
41
42 @Deactivate
43 public void deactivate() {
44 log.info("Stopped");
45 }
46
47 @Override
48 public LinkResourceAllocations requestResources(LinkResourceRequest req) {
Toshio Koideca0fcff2014-10-23 14:08:36 -070049 // TODO implement it using a resource data store.
50
51 ResourceAllocation alloc = null;
52 for (ResourceRequest r: req.resources()) {
53 switch (r.type()) {
54 case BANDWIDTH:
55 log.info("requestResources() always returns requested bandwidth");
56 BandwidthResourceRequest br = (BandwidthResourceRequest) r;
57 alloc = new BandwidthResourceAllocation(br.bandwidth());
58 break;
59 case LAMBDA:
60 log.info("requestResources() always returns lambda 7");
61 alloc = new LambdaResourceAllocation(Lambda.valueOf(7));
62 break;
63 default:
64 break;
65 }
66 }
67
68 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
69 for (Link link: req.links()) {
70 allocations.put(link, Sets.newHashSet(alloc));
71 }
72 return new DefaultLinkResourceAllocations(req, allocations);
Toshio Koide50df38d2014-10-23 10:36:51 -070073 }
74
75 @Override
76 public void releaseResources(LinkResourceAllocations allocations) {
77 // TODO Auto-generated method stub
78
79 }
80
81 @Override
Thomas Vachuskaf9976952014-10-24 11:55:05 -070082 public LinkResourceAllocations updateResources(LinkResourceRequest req,
83 LinkResourceAllocations oldAllocations) {
84 return null;
85 }
86
87 @Override
Toshio Koide50df38d2014-10-23 10:36:51 -070088 public Iterable<LinkResourceAllocations> getAllocations() {
89 // TODO Auto-generated method stub
90 return null;
91 }
92
93 @Override
Toshio Koide86160f52014-10-23 14:59:07 -070094 public LinkResourceAllocations getAllocations(IntentId intentId) {
Brian O'Connore7e4bd52014-10-23 13:36:23 -070095 // TODO Auto-generated method stub
96 return null;
97 }
98
99 @Override
Toshio Koide50df38d2014-10-23 10:36:51 -0700100 public Iterable<LinkResourceAllocations> getAllocations(Link link) {
101 // TODO Auto-generated method stub
102 return null;
103 }
104
105 @Override
106 public Iterable<IntentId> getIntents(Link link) {
107 // TODO Auto-generated method stub
108 return null;
109 }
110
111 @Override
112 public ResourceRequest getAvailableResources(Link link) {
113 // TODO Auto-generated method stub
114 return null;
115 }
116
Thomas Vachuskaf9976952014-10-24 11:55:05 -0700117 @Override
118 public ResourceRequest getAvailableResources(Link link,
119 LinkResourceAllocations allocations) {
120 return null;
121 }
122
Toshio Koide50df38d2014-10-23 10:36:51 -0700123}