blob: 10c991cff5217b356ffb63d54627182a519324fd [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.resource;
Toshio Koide65e890f2014-10-23 12:02:25 -070017
18import java.util.Collection;
19import java.util.HashSet;
20import java.util.Set;
21
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.Link;
23import org.onosproject.net.intent.Constraint;
24import org.onosproject.net.intent.IntentId;
Toshio Koide65e890f2014-10-23 12:02:25 -070025
26import com.google.common.collect.ImmutableSet;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.net.intent.constraint.BandwidthConstraint;
28import org.onosproject.net.intent.constraint.LambdaConstraint;
Toshio Koide65e890f2014-10-23 12:02:25 -070029
30/**
31 * Implementation of {@link LinkResourceRequest}.
32 */
33public final class DefaultLinkResourceRequest implements LinkResourceRequest {
34
35 private final IntentId intentId;
36 private final Collection<Link> links;
37 private final Set<ResourceRequest> resources;
38
39 /**
40 * Creates a new link resource request with the given ID, links, and
41 * resource requests.
42 *
43 * @param intentId intent ID related to this request
44 * @param links a set of links for the request
45 * @param resources a set of resources to be requested
46 */
47 private DefaultLinkResourceRequest(IntentId intentId,
48 Collection<Link> links,
49 Set<ResourceRequest> resources) {
50 this.intentId = intentId;
51 this.links = ImmutableSet.copyOf(links);
52 this.resources = ImmutableSet.copyOf(resources);
53 }
54
Toshio Koideca0fcff2014-10-23 14:08:36 -070055
56 @Override
57 public ResourceType type() {
58 return null;
59 }
60
Toshio Koide65e890f2014-10-23 12:02:25 -070061 @Override
62 public IntentId intendId() {
63 return intentId;
64 }
65
66 @Override
67 public Collection<Link> links() {
68 return links;
69 }
70
71 @Override
72 public Set<ResourceRequest> resources() {
73 return resources;
74 }
75
76 /**
77 * Returns builder of link resource request.
78 *
79 * @param intentId intent ID related to this request
80 * @param links a set of links for the request
81 * @return builder of link resource request
82 */
83 public static LinkResourceRequest.Builder builder(
84 IntentId intentId, Collection<Link> links) {
85 return new Builder(intentId, links);
86 }
87
88 /**
89 * Builder of link resource request.
90 */
91 public static final class Builder implements LinkResourceRequest.Builder {
92 private IntentId intentId;
93 private Collection<Link> links;
94 private Set<ResourceRequest> resources;
95
96 /**
97 * Creates a new link resource request.
98 *
99 * @param intentId intent ID related to this request
100 * @param links a set of links for the request
101 */
102 private Builder(IntentId intentId, Collection<Link> links) {
103 this.intentId = intentId;
104 this.links = links;
105 this.resources = new HashSet<>();
106 }
107
108 /**
109 * Adds lambda request.
110 *
111 * @return self
112 */
113 @Override
114 public Builder addLambdaRequest() {
115 resources.add(new LambdaResourceRequest());
116 return this;
117 }
118
119 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100120 * Adds Mpls request.
121 *
122 * @return self
123 */
124 @Override
125 public Builder addMplsRequest() {
126 resources.add(new MplsLabelResourceRequest());
127 return this;
128 }
129
130 /**
Toshio Koide65e890f2014-10-23 12:02:25 -0700131 * Adds bandwidth request with bandwidth value.
132 *
Ray Milkeycf590df2015-02-23 17:43:24 -0800133 * @param bandwidth bandwidth value in bits per second to be requested
Toshio Koide65e890f2014-10-23 12:02:25 -0700134 * @return self
135 */
136 @Override
137 public Builder addBandwidthRequest(double bandwidth) {
Ray Milkeycf590df2015-02-23 17:43:24 -0800138 resources.add(new BandwidthResourceRequest(Bandwidth.bps(bandwidth)));
Toshio Koide65e890f2014-10-23 12:02:25 -0700139 return this;
140 }
141
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800142 @Override
143 public LinkResourceRequest.Builder addConstraint(Constraint constraint) {
144 if (constraint instanceof LambdaConstraint) {
145 return addLambdaRequest();
146 } else if (constraint instanceof BandwidthConstraint) {
147 BandwidthConstraint bw = (BandwidthConstraint) constraint;
148 return addBandwidthRequest(bw.bandwidth().toDouble());
149 }
150 return this;
151 }
152
153
Toshio Koide65e890f2014-10-23 12:02:25 -0700154 /**
155 * Returns link resource request.
156 *
157 * @return link resource request
158 */
159 @Override
160 public LinkResourceRequest build() {
161 return new DefaultLinkResourceRequest(intentId, links, resources);
162 }
163 }
164
165}