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 | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.Collection; |
| 19 | import java.util.Collections; |
| 20 | import java.util.Map; |
| 21 | import java.util.Set; |
| 22 | |
| 23 | import org.onlab.onos.net.Link; |
| 24 | import org.onlab.onos.net.intent.IntentId; |
Toshio Koide | 5c0a726 | 2014-10-23 14:50:21 -0700 | [diff] [blame] | 25 | import org.onlab.onos.net.resource.LinkResourceAllocations; |
| 26 | import org.onlab.onos.net.resource.LinkResourceRequest; |
| 27 | import org.onlab.onos.net.resource.ResourceAllocation; |
| 28 | import org.onlab.onos.net.resource.ResourceRequest; |
| 29 | import org.onlab.onos.net.resource.ResourceType; |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Implementation of {@link LinkResourceAllocations}. |
| 33 | */ |
| 34 | public class DefaultLinkResourceAllocations implements LinkResourceAllocations { |
| 35 | private final LinkResourceRequest request; |
| 36 | private final Map<Link, Set<ResourceAllocation>> allocations; |
| 37 | |
| 38 | /** |
| 39 | * Creates a new link resource allocations. |
| 40 | * |
| 41 | * @param request requested resources |
| 42 | * @param allocations allocated resources |
| 43 | */ |
Toshio Koide | 9be539e | 2014-10-23 18:43:30 -0700 | [diff] [blame] | 44 | DefaultLinkResourceAllocations(LinkResourceRequest request, |
Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame] | 45 | Map<Link, Set<ResourceAllocation>> allocations) { |
| 46 | this.request = request; |
| 47 | this.allocations = allocations; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public IntentId intendId() { |
| 52 | return request.intendId(); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public Collection<Link> links() { |
| 57 | return request.links(); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public Set<ResourceRequest> resources() { |
| 62 | return request.resources(); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public ResourceType type() { |
| 67 | return null; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public Set<ResourceAllocation> getResourceAllocation(Link link) { |
| 72 | Set<ResourceAllocation> result = allocations.get(link); |
| 73 | if (result == null) { |
| 74 | result = Collections.emptySet(); |
| 75 | } |
| 76 | return result; |
| 77 | } |
| 78 | |
| 79 | } |