blob: 13e02e565ba5da21fe00242d108630cafac00b49 [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
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070018import com.google.common.base.MoreObjects;
Toshio Koideca0fcff2014-10-23 14:08:36 -070019import org.onlab.onos.net.Link;
20import org.onlab.onos.net.intent.IntentId;
Toshio Koide5c0a7262014-10-23 14:50:21 -070021import org.onlab.onos.net.resource.LinkResourceAllocations;
22import org.onlab.onos.net.resource.LinkResourceRequest;
23import org.onlab.onos.net.resource.ResourceAllocation;
24import org.onlab.onos.net.resource.ResourceRequest;
25import org.onlab.onos.net.resource.ResourceType;
Toshio Koideca0fcff2014-10-23 14:08:36 -070026
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070027import java.util.Collection;
28import java.util.Collections;
29import java.util.Map;
30import java.util.Set;
31
Toshio Koideca0fcff2014-10-23 14:08:36 -070032/**
33 * Implementation of {@link LinkResourceAllocations}.
34 */
35public class DefaultLinkResourceAllocations implements LinkResourceAllocations {
36 private final LinkResourceRequest request;
37 private final Map<Link, Set<ResourceAllocation>> allocations;
38
39 /**
40 * Creates a new link resource allocations.
41 *
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070042 * @param request requested resources
Toshio Koideca0fcff2014-10-23 14:08:36 -070043 * @param allocations allocated resources
44 */
Toshio Koide9be539e2014-10-23 18:43:30 -070045 DefaultLinkResourceAllocations(LinkResourceRequest request,
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070046 Map<Link, Set<ResourceAllocation>> allocations) {
Toshio Koideca0fcff2014-10-23 14:08:36 -070047 this.request = request;
48 this.allocations = allocations;
49 }
50
51 @Override
52 public IntentId intendId() {
53 return request.intendId();
54 }
55
56 @Override
57 public Collection<Link> links() {
58 return request.links();
59 }
60
61 @Override
62 public Set<ResourceRequest> resources() {
63 return request.resources();
64 }
65
66 @Override
67 public ResourceType type() {
68 return null;
69 }
70
71 @Override
72 public Set<ResourceAllocation> getResourceAllocation(Link link) {
73 Set<ResourceAllocation> result = allocations.get(link);
74 if (result == null) {
75 result = Collections.emptySet();
76 }
77 return result;
78 }
79
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070080 @Override
81 public String toString() {
82 return MoreObjects.toStringHelper(this)
83 .add("allocations", allocations)
84 .toString();
85 }
Toshio Koideca0fcff2014-10-23 14:08:36 -070086}