blob: 28ace887e94048d965741b4b8bae666df1e4ecec [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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 Koide5c0a7262014-10-23 14:50:21 -070016package org.onlab.onos.net.resource.impl;
Toshio Koideca0fcff2014-10-23 14:08:36 -070017
18import java.util.Collection;
19import java.util.Collections;
20import java.util.Map;
21import java.util.Set;
22
23import org.onlab.onos.net.Link;
24import org.onlab.onos.net.intent.IntentId;
Toshio Koide5c0a7262014-10-23 14:50:21 -070025import org.onlab.onos.net.resource.LinkResourceAllocations;
26import org.onlab.onos.net.resource.LinkResourceRequest;
27import org.onlab.onos.net.resource.ResourceAllocation;
28import org.onlab.onos.net.resource.ResourceRequest;
29import org.onlab.onos.net.resource.ResourceType;
Toshio Koideca0fcff2014-10-23 14:08:36 -070030
31/**
32 * Implementation of {@link LinkResourceAllocations}.
33 */
34public 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 Koide9be539e2014-10-23 18:43:30 -070044 DefaultLinkResourceAllocations(LinkResourceRequest request,
Toshio Koideca0fcff2014-10-23 14:08:36 -070045 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}