blob: e61e87ee3b14d1d6e126c3be7d20134a4e6db67e [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'Connor6de2e202015-05-21 14:30:41 -070016package org.onosproject.net.resource.link;
Toshio Koide65e890f2014-10-23 12:02:25 -070017
18import java.util.Collection;
19import java.util.HashSet;
20import java.util.Set;
Ayaka Koshibee114f042015-05-01 11:43:00 -070021import java.util.Objects;
Toshio Koide65e890f2014-10-23 12:02:25 -070022
Sho SHIMIZUc25a0082015-10-27 17:06:29 -070023import com.google.common.annotations.Beta;
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -070024import org.onlab.util.Bandwidth;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.Link;
26import org.onosproject.net.intent.Constraint;
27import org.onosproject.net.intent.IntentId;
Toshio Koide65e890f2014-10-23 12:02:25 -070028
29import com.google.common.collect.ImmutableSet;
Ayaka Koshibee114f042015-05-01 11:43:00 -070030
Brian O'Connorabafb502014-12-02 22:26:20 -080031import org.onosproject.net.intent.constraint.BandwidthConstraint;
32import org.onosproject.net.intent.constraint.LambdaConstraint;
Brian O'Connor6de2e202015-05-21 14:30:41 -070033import org.onosproject.net.resource.ResourceRequest;
34import org.onosproject.net.resource.ResourceType;
Toshio Koide65e890f2014-10-23 12:02:25 -070035
36/**
37 * Implementation of {@link LinkResourceRequest}.
38 */
39public final class DefaultLinkResourceRequest implements LinkResourceRequest {
40
41 private final IntentId intentId;
42 private final Collection<Link> links;
43 private final Set<ResourceRequest> resources;
44
45 /**
46 * Creates a new link resource request with the given ID, links, and
47 * resource requests.
48 *
49 * @param intentId intent ID related to this request
50 * @param links a set of links for the request
51 * @param resources a set of resources to be requested
52 */
53 private DefaultLinkResourceRequest(IntentId intentId,
54 Collection<Link> links,
55 Set<ResourceRequest> resources) {
56 this.intentId = intentId;
57 this.links = ImmutableSet.copyOf(links);
58 this.resources = ImmutableSet.copyOf(resources);
59 }
60
Toshio Koideca0fcff2014-10-23 14:08:36 -070061
62 @Override
63 public ResourceType type() {
64 return null;
65 }
66
Toshio Koide65e890f2014-10-23 12:02:25 -070067 @Override
Ayaka Koshibee114f042015-05-01 11:43:00 -070068 public IntentId intentId() {
Toshio Koide65e890f2014-10-23 12:02:25 -070069 return intentId;
70 }
71
72 @Override
73 public Collection<Link> links() {
74 return links;
75 }
76
77 @Override
78 public Set<ResourceRequest> resources() {
79 return resources;
80 }
81
82 /**
83 * Returns builder of link resource request.
84 *
85 * @param intentId intent ID related to this request
86 * @param links a set of links for the request
87 * @return builder of link resource request
88 */
89 public static LinkResourceRequest.Builder builder(
90 IntentId intentId, Collection<Link> links) {
91 return new Builder(intentId, links);
92 }
93
94 /**
95 * Builder of link resource request.
96 */
97 public static final class Builder implements LinkResourceRequest.Builder {
98 private IntentId intentId;
99 private Collection<Link> links;
100 private Set<ResourceRequest> resources;
101
102 /**
103 * Creates a new link resource request.
104 *
105 * @param intentId intent ID related to this request
106 * @param links a set of links for the request
107 */
108 private Builder(IntentId intentId, Collection<Link> links) {
109 this.intentId = intentId;
110 this.links = links;
111 this.resources = new HashSet<>();
112 }
113
114 /**
115 * Adds lambda request.
116 *
117 * @return self
Sho SHIMIZUc25a0082015-10-27 17:06:29 -0700118 * @deprecated in Emu Release
Toshio Koide65e890f2014-10-23 12:02:25 -0700119 */
Sho SHIMIZUc25a0082015-10-27 17:06:29 -0700120 @Deprecated
Toshio Koide65e890f2014-10-23 12:02:25 -0700121 @Override
122 public Builder addLambdaRequest() {
123 resources.add(new LambdaResourceRequest());
124 return this;
125 }
126
Sho SHIMIZUc25a0082015-10-27 17:06:29 -0700127 @Beta
128 @Override
129 public LinkResourceRequest.Builder addLambdaRequest(LambdaResource lambda) {
130 resources.add(new LambdaResourceRequest(lambda));
131 return this;
132 }
133
Toshio Koide65e890f2014-10-23 12:02:25 -0700134 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100135 * Adds Mpls request.
136 *
137 * @return self
138 */
139 @Override
140 public Builder addMplsRequest() {
141 resources.add(new MplsLabelResourceRequest());
142 return this;
143 }
144
145 /**
Toshio Koide65e890f2014-10-23 12:02:25 -0700146 * Adds bandwidth request with bandwidth value.
147 *
Ray Milkeycf590df2015-02-23 17:43:24 -0800148 * @param bandwidth bandwidth value in bits per second to be requested
Toshio Koide65e890f2014-10-23 12:02:25 -0700149 * @return self
150 */
151 @Override
152 public Builder addBandwidthRequest(double bandwidth) {
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -0700153 resources.add(new BandwidthResourceRequest(new BandwidthResource(Bandwidth.bps(bandwidth))));
Toshio Koide65e890f2014-10-23 12:02:25 -0700154 return this;
155 }
156
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800157 @Override
158 public LinkResourceRequest.Builder addConstraint(Constraint constraint) {
159 if (constraint instanceof LambdaConstraint) {
160 return addLambdaRequest();
161 } else if (constraint instanceof BandwidthConstraint) {
162 BandwidthConstraint bw = (BandwidthConstraint) constraint;
163 return addBandwidthRequest(bw.bandwidth().toDouble());
164 }
165 return this;
166 }
167
Toshio Koide65e890f2014-10-23 12:02:25 -0700168 /**
169 * Returns link resource request.
170 *
171 * @return link resource request
172 */
173 @Override
174 public LinkResourceRequest build() {
175 return new DefaultLinkResourceRequest(intentId, links, resources);
176 }
177 }
178
Ayaka Koshibee114f042015-05-01 11:43:00 -0700179 @Override
180 public int hashCode() {
181 return Objects.hash(intentId, links);
182 }
183
184 @Override
185 public boolean equals(Object obj) {
186 if (this == obj) {
187 return true;
188 }
189 if (obj == null || getClass() != obj.getClass()) {
190 return false;
191 }
192 final DefaultLinkResourceRequest other = (DefaultLinkResourceRequest) obj;
193 return Objects.equals(this.intentId, other.intentId)
194 && Objects.equals(this.links, other.links);
195 }
Toshio Koide65e890f2014-10-23 12:02:25 -0700196}