Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.resource; |
| 2 | |
| 3 | import static org.slf4j.LoggerFactory.getLogger; |
| 4 | |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame^] | 5 | import java.util.HashMap; |
| 6 | import java.util.Map; |
| 7 | import java.util.Set; |
| 8 | |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 9 | import org.apache.felix.scr.annotations.Activate; |
| 10 | import org.apache.felix.scr.annotations.Component; |
| 11 | import org.apache.felix.scr.annotations.Deactivate; |
| 12 | import org.apache.felix.scr.annotations.Service; |
| 13 | import org.onlab.onos.net.Link; |
| 14 | import org.onlab.onos.net.intent.IntentId; |
| 15 | import org.slf4j.Logger; |
| 16 | |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame^] | 17 | import com.google.common.collect.Sets; |
| 18 | |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 19 | /** |
| 20 | * Provides basic implementation of link resources allocation. |
| 21 | */ |
| 22 | @Component(immediate = true) |
| 23 | @Service |
| 24 | public class LinkResourceManager implements LinkResourceService { |
| 25 | |
| 26 | private final Logger log = getLogger(getClass()); |
| 27 | |
| 28 | @Activate |
| 29 | public void activate() { |
| 30 | log.info("Started"); |
| 31 | } |
| 32 | |
| 33 | @Deactivate |
| 34 | public void deactivate() { |
| 35 | log.info("Stopped"); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public LinkResourceAllocations requestResources(LinkResourceRequest req) { |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame^] | 40 | // TODO implement it using a resource data store. |
| 41 | |
| 42 | ResourceAllocation alloc = null; |
| 43 | for (ResourceRequest r: req.resources()) { |
| 44 | switch (r.type()) { |
| 45 | case BANDWIDTH: |
| 46 | log.info("requestResources() always returns requested bandwidth"); |
| 47 | BandwidthResourceRequest br = (BandwidthResourceRequest) r; |
| 48 | alloc = new BandwidthResourceAllocation(br.bandwidth()); |
| 49 | break; |
| 50 | case LAMBDA: |
| 51 | log.info("requestResources() always returns lambda 7"); |
| 52 | alloc = new LambdaResourceAllocation(Lambda.valueOf(7)); |
| 53 | break; |
| 54 | default: |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>(); |
| 60 | for (Link link: req.links()) { |
| 61 | allocations.put(link, Sets.newHashSet(alloc)); |
| 62 | } |
| 63 | return new DefaultLinkResourceAllocations(req, allocations); |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public void releaseResources(LinkResourceAllocations allocations) { |
| 68 | // TODO Auto-generated method stub |
| 69 | |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public Iterable<LinkResourceAllocations> getAllocations() { |
| 74 | // TODO Auto-generated method stub |
| 75 | return null; |
| 76 | } |
| 77 | |
| 78 | @Override |
Brian O'Connor | e7e4bd5 | 2014-10-23 13:36:23 -0700 | [diff] [blame] | 79 | public LinkResourceAllocations getAllocation(IntentId intentId) { |
| 80 | // TODO Auto-generated method stub |
| 81 | return null; |
| 82 | } |
| 83 | |
| 84 | @Override |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 85 | public Iterable<LinkResourceAllocations> getAllocations(Link link) { |
| 86 | // TODO Auto-generated method stub |
| 87 | return null; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public Iterable<IntentId> getIntents(Link link) { |
| 92 | // TODO Auto-generated method stub |
| 93 | return null; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public ResourceRequest getAvailableResources(Link link) { |
| 98 | // TODO Auto-generated method stub |
| 99 | return null; |
| 100 | } |
| 101 | |
| 102 | } |