Toshio Koide | 5c0a726 | 2014-10-23 14:50:21 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.net.resource.impl; |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 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; |
Toshio Koide | 5c0a726 | 2014-10-23 14:50:21 -0700 | [diff] [blame^] | 15 | import org.onlab.onos.net.resource.BandwidthResourceAllocation; |
| 16 | import org.onlab.onos.net.resource.BandwidthResourceRequest; |
| 17 | import org.onlab.onos.net.resource.Lambda; |
| 18 | import org.onlab.onos.net.resource.LambdaResourceAllocation; |
| 19 | import org.onlab.onos.net.resource.LinkResourceAllocations; |
| 20 | import org.onlab.onos.net.resource.LinkResourceRequest; |
| 21 | import org.onlab.onos.net.resource.LinkResourceService; |
| 22 | import org.onlab.onos.net.resource.ResourceAllocation; |
| 23 | import org.onlab.onos.net.resource.ResourceRequest; |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 24 | import org.slf4j.Logger; |
| 25 | |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 26 | import com.google.common.collect.Sets; |
| 27 | |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Provides basic implementation of link resources allocation. |
| 30 | */ |
| 31 | @Component(immediate = true) |
| 32 | @Service |
| 33 | public 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 Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 49 | // 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 Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void releaseResources(LinkResourceAllocations allocations) { |
| 77 | // TODO Auto-generated method stub |
| 78 | |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public Iterable<LinkResourceAllocations> getAllocations() { |
| 83 | // TODO Auto-generated method stub |
| 84 | return null; |
| 85 | } |
| 86 | |
| 87 | @Override |
Brian O'Connor | e7e4bd5 | 2014-10-23 13:36:23 -0700 | [diff] [blame] | 88 | public LinkResourceAllocations getAllocation(IntentId intentId) { |
| 89 | // TODO Auto-generated method stub |
| 90 | return null; |
| 91 | } |
| 92 | |
| 93 | @Override |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 94 | public Iterable<LinkResourceAllocations> getAllocations(Link link) { |
| 95 | // TODO Auto-generated method stub |
| 96 | return null; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public Iterable<IntentId> getIntents(Link link) { |
| 101 | // TODO Auto-generated method stub |
| 102 | return null; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public ResourceRequest getAvailableResources(Link link) { |
| 107 | // TODO Auto-generated method stub |
| 108 | return null; |
| 109 | } |
| 110 | |
| 111 | } |