Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 1 | /* |
| 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 Koide | 5c0a726 | 2014-10-23 14:50:21 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.resource.impl; |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 20 | import java.util.HashMap; |
Toshio Koide | 9be539e | 2014-10-23 18:43:30 -0700 | [diff] [blame] | 21 | import java.util.Iterator; |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 22 | import java.util.Map; |
| 23 | import java.util.Set; |
| 24 | |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 25 | import org.apache.felix.scr.annotations.Activate; |
| 26 | import org.apache.felix.scr.annotations.Component; |
| 27 | import org.apache.felix.scr.annotations.Deactivate; |
| 28 | import org.apache.felix.scr.annotations.Service; |
| 29 | import org.onlab.onos.net.Link; |
| 30 | import org.onlab.onos.net.intent.IntentId; |
Toshio Koide | 5c0a726 | 2014-10-23 14:50:21 -0700 | [diff] [blame] | 31 | import org.onlab.onos.net.resource.BandwidthResourceAllocation; |
| 32 | import org.onlab.onos.net.resource.BandwidthResourceRequest; |
| 33 | import org.onlab.onos.net.resource.Lambda; |
| 34 | import org.onlab.onos.net.resource.LambdaResourceAllocation; |
| 35 | import org.onlab.onos.net.resource.LinkResourceAllocations; |
| 36 | import org.onlab.onos.net.resource.LinkResourceRequest; |
| 37 | import org.onlab.onos.net.resource.LinkResourceService; |
| 38 | import org.onlab.onos.net.resource.ResourceAllocation; |
| 39 | import org.onlab.onos.net.resource.ResourceRequest; |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 40 | import org.slf4j.Logger; |
| 41 | |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 42 | import com.google.common.collect.Sets; |
| 43 | |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Provides basic implementation of link resources allocation. |
| 46 | */ |
| 47 | @Component(immediate = true) |
| 48 | @Service |
| 49 | public 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 Koide | 9be539e | 2014-10-23 18:43:30 -0700 | [diff] [blame] | 63 | private Iterable<Lambda> getAvailableLambdas(Iterable<Link> links) { |
| 64 | return Sets.newHashSet(Lambda.valueOf(7)); |
| 65 | } |
| 66 | |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 67 | @Override |
| 68 | public LinkResourceAllocations requestResources(LinkResourceRequest req) { |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 69 | // TODO implement it using a resource data store. |
| 70 | |
| 71 | ResourceAllocation alloc = null; |
Toshio Koide | 9be539e | 2014-10-23 18:43:30 -0700 | [diff] [blame] | 72 | for (ResourceRequest r : req.resources()) { |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 73 | 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 Koide | 9be539e | 2014-10-23 18:43:30 -0700 | [diff] [blame] | 81 | Iterator<Lambda> lambdaIterator = getAvailableLambdas(req.links()).iterator(); |
| 82 | if (lambdaIterator.hasNext()) { |
| 83 | alloc = new LambdaResourceAllocation(lambdaIterator.next()); |
| 84 | } |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 85 | break; |
| 86 | default: |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>(); |
Toshio Koide | 9be539e | 2014-10-23 18:43:30 -0700 | [diff] [blame] | 92 | for (Link link : req.links()) { |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 93 | allocations.put(link, Sets.newHashSet(alloc)); |
| 94 | } |
| 95 | return new DefaultLinkResourceAllocations(req, allocations); |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void releaseResources(LinkResourceAllocations allocations) { |
| 100 | // TODO Auto-generated method stub |
| 101 | |
| 102 | } |
| 103 | |
| 104 | @Override |
Thomas Vachuska | f997695 | 2014-10-24 11:55:05 -0700 | [diff] [blame] | 105 | public LinkResourceAllocations updateResources(LinkResourceRequest req, |
| 106 | LinkResourceAllocations oldAllocations) { |
| 107 | return null; |
| 108 | } |
| 109 | |
| 110 | @Override |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 111 | public Iterable<LinkResourceAllocations> getAllocations() { |
| 112 | // TODO Auto-generated method stub |
| 113 | return null; |
| 114 | } |
| 115 | |
| 116 | @Override |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 117 | public Iterable<LinkResourceAllocations> getAllocations(Link link) { |
| 118 | // TODO Auto-generated method stub |
| 119 | return null; |
| 120 | } |
| 121 | |
| 122 | @Override |
Toshio Koide | 9be539e | 2014-10-23 18:43:30 -0700 | [diff] [blame] | 123 | public LinkResourceAllocations getAllocations(IntentId intentId) { |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 124 | // TODO Auto-generated method stub |
| 125 | return null; |
| 126 | } |
| 127 | |
| 128 | @Override |
Toshio Koide | 9be539e | 2014-10-23 18:43:30 -0700 | [diff] [blame] | 129 | public Iterable<ResourceRequest> getAvailableResources(Link link) { |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 130 | // TODO Auto-generated method stub |
| 131 | return null; |
| 132 | } |
| 133 | |
Thomas Vachuska | f997695 | 2014-10-24 11:55:05 -0700 | [diff] [blame] | 134 | @Override |
| 135 | public ResourceRequest getAvailableResources(Link link, |
| 136 | LinkResourceAllocations allocations) { |
| 137 | return null; |
| 138 | } |
| 139 | |
Toshio Koide | 50df38d | 2014-10-23 10:36:51 -0700 | [diff] [blame] | 140 | } |