blob: c3f5c28d3d360e16b4f88f821ffe9f6938e6e701 [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;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080023import org.onlab.onos.net.intent.Constraint;
Toshio Koide65e890f2014-10-23 12:02:25 -070024import org.onlab.onos.net.intent.IntentId;
25
26import com.google.common.collect.ImmutableSet;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080027import org.onlab.onos.net.intent.constraint.BandwidthConstraint;
28import org.onlab.onos.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 /**
120 * Adds bandwidth request with bandwidth value.
121 *
122 * @param bandwidth bandwidth value to be requested
123 * @return self
124 */
125 @Override
126 public Builder addBandwidthRequest(double bandwidth) {
127 resources.add(new BandwidthResourceRequest(bandwidth));
128 return this;
129 }
130
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800131 @Override
132 public LinkResourceRequest.Builder addConstraint(Constraint constraint) {
133 if (constraint instanceof LambdaConstraint) {
134 return addLambdaRequest();
135 } else if (constraint instanceof BandwidthConstraint) {
136 BandwidthConstraint bw = (BandwidthConstraint) constraint;
137 return addBandwidthRequest(bw.bandwidth().toDouble());
138 }
139 return this;
140 }
141
142
Toshio Koide65e890f2014-10-23 12:02:25 -0700143 /**
144 * Returns link resource request.
145 *
146 * @return link resource request
147 */
148 @Override
149 public LinkResourceRequest build() {
150 return new DefaultLinkResourceRequest(intentId, links, resources);
151 }
152 }
153
154}