blob: 0c6f4bf344adecc37115fe4f32fde3e73520d3fd [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;
Ayaka Koshibee114f042015-05-01 11:43:00 -070021import java.util.Objects;
Toshio Koide65e890f2014-10-23 12:02:25 -070022
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.Link;
24import org.onosproject.net.intent.Constraint;
25import org.onosproject.net.intent.IntentId;
Toshio Koide65e890f2014-10-23 12:02:25 -070026
27import com.google.common.collect.ImmutableSet;
Ayaka Koshibee114f042015-05-01 11:43:00 -070028
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.intent.constraint.BandwidthConstraint;
30import org.onosproject.net.intent.constraint.LambdaConstraint;
Toshio Koide65e890f2014-10-23 12:02:25 -070031
32/**
33 * Implementation of {@link LinkResourceRequest}.
34 */
35public final class DefaultLinkResourceRequest implements LinkResourceRequest {
36
37 private final IntentId intentId;
38 private final Collection<Link> links;
39 private final Set<ResourceRequest> resources;
40
41 /**
42 * Creates a new link resource request with the given ID, links, and
43 * resource requests.
44 *
45 * @param intentId intent ID related to this request
46 * @param links a set of links for the request
47 * @param resources a set of resources to be requested
48 */
49 private DefaultLinkResourceRequest(IntentId intentId,
50 Collection<Link> links,
51 Set<ResourceRequest> resources) {
52 this.intentId = intentId;
53 this.links = ImmutableSet.copyOf(links);
54 this.resources = ImmutableSet.copyOf(resources);
55 }
56
Toshio Koideca0fcff2014-10-23 14:08:36 -070057
58 @Override
59 public ResourceType type() {
60 return null;
61 }
62
Toshio Koide65e890f2014-10-23 12:02:25 -070063 @Override
Ayaka Koshibee114f042015-05-01 11:43:00 -070064 public IntentId intentId() {
Toshio Koide65e890f2014-10-23 12:02:25 -070065 return intentId;
66 }
67
68 @Override
69 public Collection<Link> links() {
70 return links;
71 }
72
73 @Override
74 public Set<ResourceRequest> resources() {
75 return resources;
76 }
77
78 /**
79 * Returns builder of link resource request.
80 *
81 * @param intentId intent ID related to this request
82 * @param links a set of links for the request
83 * @return builder of link resource request
84 */
85 public static LinkResourceRequest.Builder builder(
86 IntentId intentId, Collection<Link> links) {
87 return new Builder(intentId, links);
88 }
89
90 /**
91 * Builder of link resource request.
92 */
93 public static final class Builder implements LinkResourceRequest.Builder {
94 private IntentId intentId;
95 private Collection<Link> links;
96 private Set<ResourceRequest> resources;
97
98 /**
99 * Creates a new link resource request.
100 *
101 * @param intentId intent ID related to this request
102 * @param links a set of links for the request
103 */
104 private Builder(IntentId intentId, Collection<Link> links) {
105 this.intentId = intentId;
106 this.links = links;
107 this.resources = new HashSet<>();
108 }
109
110 /**
111 * Adds lambda request.
112 *
113 * @return self
114 */
115 @Override
116 public Builder addLambdaRequest() {
117 resources.add(new LambdaResourceRequest());
118 return this;
119 }
120
121 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100122 * Adds Mpls request.
123 *
124 * @return self
125 */
126 @Override
127 public Builder addMplsRequest() {
128 resources.add(new MplsLabelResourceRequest());
129 return this;
130 }
131
132 /**
Toshio Koide65e890f2014-10-23 12:02:25 -0700133 * Adds bandwidth request with bandwidth value.
134 *
Ray Milkeycf590df2015-02-23 17:43:24 -0800135 * @param bandwidth bandwidth value in bits per second to be requested
Toshio Koide65e890f2014-10-23 12:02:25 -0700136 * @return self
137 */
138 @Override
139 public Builder addBandwidthRequest(double bandwidth) {
Ray Milkeycf590df2015-02-23 17:43:24 -0800140 resources.add(new BandwidthResourceRequest(Bandwidth.bps(bandwidth)));
Toshio Koide65e890f2014-10-23 12:02:25 -0700141 return this;
142 }
143
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800144 @Override
145 public LinkResourceRequest.Builder addConstraint(Constraint constraint) {
146 if (constraint instanceof LambdaConstraint) {
147 return addLambdaRequest();
148 } else if (constraint instanceof BandwidthConstraint) {
149 BandwidthConstraint bw = (BandwidthConstraint) constraint;
150 return addBandwidthRequest(bw.bandwidth().toDouble());
151 }
152 return this;
153 }
154
Toshio Koide65e890f2014-10-23 12:02:25 -0700155 /**
156 * Returns link resource request.
157 *
158 * @return link resource request
159 */
160 @Override
161 public LinkResourceRequest build() {
162 return new DefaultLinkResourceRequest(intentId, links, resources);
163 }
164 }
165
Ayaka Koshibee114f042015-05-01 11:43:00 -0700166 @Override
167 public int hashCode() {
168 return Objects.hash(intentId, links);
169 }
170
171 @Override
172 public boolean equals(Object obj) {
173 if (this == obj) {
174 return true;
175 }
176 if (obj == null || getClass() != obj.getClass()) {
177 return false;
178 }
179 final DefaultLinkResourceRequest other = (DefaultLinkResourceRequest) obj;
180 return Objects.equals(this.intentId, other.intentId)
181 && Objects.equals(this.links, other.links);
182 }
Toshio Koide65e890f2014-10-23 12:02:25 -0700183}