blob: 331bf83a0c73519d66d281ad87eccbf38d78afb5 [file] [log] [blame]
Toshio Koide485b4782014-10-20 19:34:21 -07001package org.onlab.onos.net.resource;
2
3import java.util.Collection;
Toshio Koide569ca702014-10-23 11:37:44 -07004import java.util.HashSet;
Toshio Koide485b4782014-10-20 19:34:21 -07005import java.util.Set;
6
7import org.onlab.onos.net.Link;
8import org.onlab.onos.net.intent.IntentId;
9
Toshio Koide569ca702014-10-23 11:37:44 -070010import com.google.common.collect.ImmutableSet;
11
Toshio Koide485b4782014-10-20 19:34:21 -070012/**
13 * Representation of a request for link resource.
14 */
Toshio Koide569ca702014-10-23 11:37:44 -070015public final class LinkResourceRequest implements ResourceRequest {
16 // TODO: should this class be interface?
17
18 private final IntentId intentId;
19 private final Collection<Link> links;
20 private final Set<ResourceRequest> resources;
21
22 /**
23 * Creates a new link resource request with the given ID, links, and
24 * resource requests.
25 *
26 * @param intentId intent ID related to this request
27 * @param links a set of links for the request
28 * @param resources a set of resources to be requested
29 */
30 private LinkResourceRequest(IntentId intentId,
31 Collection<Link> links,
32 Set<ResourceRequest> resources) {
33 this.intentId = intentId;
34 this.links = ImmutableSet.copyOf(links);
35 this.resources = ImmutableSet.copyOf(resources);
36 }
Toshio Koide485b4782014-10-20 19:34:21 -070037
38 /**
39 * Returns the {@link IntentId} associated with the request.
40 *
41 * @return the {@link IntentId} associated with the request
42 */
Toshio Koide569ca702014-10-23 11:37:44 -070043 IntentId intendId() {
44 return intentId;
45 }
Toshio Koide485b4782014-10-20 19:34:21 -070046
47 /**
48 * Returns the set of target links.
49 *
50 * @return the set of target links
51 */
Toshio Koide569ca702014-10-23 11:37:44 -070052 Collection<Link> links() {
53 return links;
54 }
Toshio Koide485b4782014-10-20 19:34:21 -070055
56 /**
57 * Returns the set of resource requests.
58 *
59 * @return the set of resource requests
60 */
Toshio Koide569ca702014-10-23 11:37:44 -070061 Set<ResourceRequest> resources() {
62 return resources;
63 }
64
65 /**
66 * Returns builder of link resource request.
67 *
68 * @param intentId intent ID related to this request
69 * @param links a set of links for the request
70 * @return builder of link resource request
71 */
72 public static LinkResourceRequest.Builder builder(
73 IntentId intentId, Collection<Link> links) {
74 return new Builder(intentId, links);
75 }
76
77 /**
78 * Builder of link resource request.
79 */
80 public static final class Builder {
81 private IntentId intentId;
82 private Collection<Link> links;
83 private Set<ResourceRequest> resources;
84
85 /**
86 * Creates a new link resource request.
87 *
88 * @param intentId intent ID related to this request
89 * @param links a set of links for the request
90 */
91 private Builder(IntentId intentId, Collection<Link> links) {
92 this.intentId = intentId;
93 this.links = links;
94 this.resources = new HashSet<>();
95 }
96
97 /**
98 * Adds lambda request.
99 *
100 * @return self
101 */
102 public Builder addLambdaRequest() {
103 resources.add(new LambdaResourceRequest());
104 return this;
105 }
106
107 /**
108 * Adds bandwidth request with bandwidth value.
109 *
110 * @param bandwidth bandwidth value to be requested
111 * @return self
112 */
113 public Builder addBandwidthRequest(double bandwidth) {
114 resources.add(new BandwidthResourceRequest(bandwidth));
115 return this;
116 }
117
118 /**
119 * Returns link resource request.
120 *
121 * @return link resource request
122 */
123 public LinkResourceRequest build() {
124 return new LinkResourceRequest(intentId, links, resources);
125 }
126 }
Toshio Koide485b4782014-10-20 19:34:21 -0700127}