Showing
3 changed files
with
123 additions
and
7 deletions
| ... | @@ -3,11 +3,34 @@ package org.onlab.onos.net.resource; | ... | @@ -3,11 +3,34 @@ package org.onlab.onos.net.resource; |
| 3 | /** | 3 | /** |
| 4 | * Representation of a request for bandwidth resource. | 4 | * Representation of a request for bandwidth resource. |
| 5 | */ | 5 | */ |
| 6 | -public interface BandwidthResourceRequest { | 6 | +public final class BandwidthResourceRequest implements ResourceRequest { |
| 7 | + private final Bandwidth bandwidth; | ||
| 8 | + | ||
| 9 | + /** | ||
| 10 | + * Creates a new {@link BandwidthResourceRequest} with {@link Bandwidth} | ||
| 11 | + * object. | ||
| 12 | + * | ||
| 13 | + * @param bandwidth {@link Bandwidth} object to be requested | ||
| 14 | + */ | ||
| 15 | + public BandwidthResourceRequest(Bandwidth bandwidth) { | ||
| 16 | + this.bandwidth = bandwidth; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * Creates a new {@link BandwidthResourceRequest} with bandwidth value. | ||
| 21 | + * | ||
| 22 | + * @param bandwidth bandwidth value to be requested | ||
| 23 | + */ | ||
| 24 | + public BandwidthResourceRequest(double bandwidth) { | ||
| 25 | + this.bandwidth = Bandwidth.valueOf(bandwidth); | ||
| 26 | + } | ||
| 27 | + | ||
| 7 | /** | 28 | /** |
| 8 | * Returns the bandwidth resource. | 29 | * Returns the bandwidth resource. |
| 9 | * | 30 | * |
| 10 | * @return the bandwidth resource | 31 | * @return the bandwidth resource |
| 11 | */ | 32 | */ |
| 12 | - Bandwidth bandwidth(); | 33 | + Bandwidth bandwidth() { |
| 34 | + return bandwidth; | ||
| 35 | + } | ||
| 13 | } | 36 | } | ... | ... |
| ... | @@ -3,6 +3,6 @@ package org.onlab.onos.net.resource; | ... | @@ -3,6 +3,6 @@ package org.onlab.onos.net.resource; |
| 3 | /** | 3 | /** |
| 4 | * Representation of a request for lambda resource. | 4 | * Representation of a request for lambda resource. |
| 5 | */ | 5 | */ |
| 6 | -public interface LambdaResourceRequest { | 6 | +public class LambdaResourceRequest implements ResourceRequest { |
| 7 | 7 | ||
| 8 | } | 8 | } | ... | ... |
| 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; | ||
| 4 | import java.util.Set; | 5 | import java.util.Set; |
| 5 | 6 | ||
| 6 | import org.onlab.onos.net.Link; | 7 | import org.onlab.onos.net.Link; |
| 7 | import org.onlab.onos.net.intent.IntentId; | 8 | import org.onlab.onos.net.intent.IntentId; |
| 8 | 9 | ||
| 10 | +import com.google.common.collect.ImmutableSet; | ||
| 11 | + | ||
| 9 | /** | 12 | /** |
| 10 | * Representation of a request for link resource. | 13 | * Representation of a request for link resource. |
| 11 | */ | 14 | */ |
| 12 | -public interface LinkResourceRequest extends ResourceRequest { | 15 | +public 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 | + } | ||
| 13 | 37 | ||
| 14 | /** | 38 | /** |
| 15 | * Returns the {@link IntentId} associated with the request. | 39 | * Returns the {@link IntentId} associated with the request. |
| 16 | * | 40 | * |
| 17 | * @return the {@link IntentId} associated with the request | 41 | * @return the {@link IntentId} associated with the request |
| 18 | */ | 42 | */ |
| 19 | - IntentId intendId(); | 43 | + IntentId intendId() { |
| 44 | + return intentId; | ||
| 45 | + } | ||
| 20 | 46 | ||
| 21 | /** | 47 | /** |
| 22 | * Returns the set of target links. | 48 | * Returns the set of target links. |
| 23 | * | 49 | * |
| 24 | * @return the set of target links | 50 | * @return the set of target links |
| 25 | */ | 51 | */ |
| 26 | - Collection<Link> links(); | 52 | + Collection<Link> links() { |
| 53 | + return links; | ||
| 54 | + } | ||
| 27 | 55 | ||
| 28 | /** | 56 | /** |
| 29 | * Returns the set of resource requests. | 57 | * Returns the set of resource requests. |
| 30 | * | 58 | * |
| 31 | * @return the set of resource requests | 59 | * @return the set of resource requests |
| 32 | */ | 60 | */ |
| 33 | - Set<ResourceRequest> resources(); | 61 | + 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 | + } | ||
| 34 | } | 127 | } | ... | ... |
-
Please register or login to post a comment