Toshio Koide

Add DefaultLinkResourceRequest implementation.

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