blob: 73b48df676509b70edd111fd19efc3c4cd4835e6 [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 Koide65e890f2014-10-23 12:02:25 -070016package org.onlab.onos.net.resource;
17
18import java.util.Collection;
19import java.util.HashSet;
20import java.util.Set;
21
22import org.onlab.onos.net.Link;
23import org.onlab.onos.net.intent.IntentId;
24
25import com.google.common.collect.ImmutableSet;
26
27/**
28 * Implementation of {@link LinkResourceRequest}.
29 */
30public final class DefaultLinkResourceRequest implements LinkResourceRequest {
31
32 private final IntentId intentId;
33 private final Collection<Link> links;
34 private final Set<ResourceRequest> resources;
35
36 /**
37 * Creates a new link resource request with the given ID, links, and
38 * resource requests.
39 *
40 * @param intentId intent ID related to this request
41 * @param links a set of links for the request
42 * @param resources a set of resources to be requested
43 */
44 private DefaultLinkResourceRequest(IntentId intentId,
45 Collection<Link> links,
46 Set<ResourceRequest> resources) {
47 this.intentId = intentId;
48 this.links = ImmutableSet.copyOf(links);
49 this.resources = ImmutableSet.copyOf(resources);
50 }
51
Toshio Koideca0fcff2014-10-23 14:08:36 -070052
53 @Override
54 public ResourceType type() {
55 return null;
56 }
57
Toshio Koide65e890f2014-10-23 12:02:25 -070058 @Override
59 public IntentId intendId() {
60 return intentId;
61 }
62
63 @Override
64 public Collection<Link> links() {
65 return links;
66 }
67
68 @Override
69 public Set<ResourceRequest> resources() {
70 return resources;
71 }
72
73 /**
74 * Returns builder of link resource request.
75 *
76 * @param intentId intent ID related to this request
77 * @param links a set of links for the request
78 * @return builder of link resource request
79 */
80 public static LinkResourceRequest.Builder builder(
81 IntentId intentId, Collection<Link> links) {
82 return new Builder(intentId, links);
83 }
84
85 /**
86 * Builder of link resource request.
87 */
88 public static final class Builder implements LinkResourceRequest.Builder {
89 private IntentId intentId;
90 private Collection<Link> links;
91 private Set<ResourceRequest> resources;
92
93 /**
94 * Creates a new link resource request.
95 *
96 * @param intentId intent ID related to this request
97 * @param links a set of links for the request
98 */
99 private Builder(IntentId intentId, Collection<Link> links) {
100 this.intentId = intentId;
101 this.links = links;
102 this.resources = new HashSet<>();
103 }
104
105 /**
106 * Adds lambda request.
107 *
108 * @return self
109 */
110 @Override
111 public Builder addLambdaRequest() {
112 resources.add(new LambdaResourceRequest());
113 return this;
114 }
115
116 /**
117 * Adds bandwidth request with bandwidth value.
118 *
119 * @param bandwidth bandwidth value to be requested
120 * @return self
121 */
122 @Override
123 public Builder addBandwidthRequest(double bandwidth) {
124 resources.add(new BandwidthResourceRequest(bandwidth));
125 return this;
126 }
127
128 /**
129 * Returns link resource request.
130 *
131 * @return link resource request
132 */
133 @Override
134 public LinkResourceRequest build() {
135 return new DefaultLinkResourceRequest(intentId, links, resources);
136 }
137 }
138
139}