Showing
5 changed files
with
232 additions
and
0 deletions
1 | +package org.onlab.onos.net.resource; | ||
2 | + | ||
3 | +import java.util.Objects; | ||
4 | + | ||
5 | +/** | ||
6 | + * Representation of bandwidth resource. | ||
7 | + */ | ||
8 | +public final class Bandwidth extends LinkResource { | ||
9 | + | ||
10 | + private final double bandwidth; | ||
11 | + | ||
12 | + /** | ||
13 | + * Creates a new instance with given bandwidth. | ||
14 | + * | ||
15 | + * @param bandwidth bandwidth value to be assigned | ||
16 | + */ | ||
17 | + private Bandwidth(double bandwidth) { | ||
18 | + this.bandwidth = bandwidth; | ||
19 | + } | ||
20 | + | ||
21 | + /** | ||
22 | + * Creates a new instance with given bandwidth. | ||
23 | + * | ||
24 | + * @param bandwidth bandwidth value to be assigned | ||
25 | + * @return {@link Bandwidth} instance with given bandwidth | ||
26 | + */ | ||
27 | + public static Bandwidth valueOf(double bandwidth) { | ||
28 | + return new Bandwidth(bandwidth); | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * Returns bandwidth as a double value. | ||
33 | + * | ||
34 | + * @return bandwidth as a double value | ||
35 | + */ | ||
36 | + public double toDouble() { | ||
37 | + return bandwidth; | ||
38 | + } | ||
39 | + | ||
40 | + @Override | ||
41 | + public boolean equals(Object obj) { | ||
42 | + if (obj instanceof Bandwidth) { | ||
43 | + Bandwidth that = (Bandwidth) obj; | ||
44 | + return Objects.equals(this.bandwidth, that.bandwidth); | ||
45 | + } | ||
46 | + return false; | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + public int hashCode() { | ||
51 | + return Objects.hashCode(this.bandwidth); | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public String toString() { | ||
56 | + return String.valueOf(this.bandwidth); | ||
57 | + } | ||
58 | +} |
1 | +package org.onlab.onos.net.resource; | ||
2 | + | ||
3 | +import java.util.Objects; | ||
4 | + | ||
5 | +/** | ||
6 | + * Representation of lambda resource. | ||
7 | + */ | ||
8 | +public final class Lambda extends LinkResource { | ||
9 | + | ||
10 | + private final int lambda; | ||
11 | + | ||
12 | + /** | ||
13 | + * Creates a new instance with given lambda. | ||
14 | + * | ||
15 | + * @param lambda lambda value to be assigned | ||
16 | + */ | ||
17 | + private Lambda(int lambda) { | ||
18 | + this.lambda = lambda; | ||
19 | + } | ||
20 | + | ||
21 | + /** | ||
22 | + * Creates a new instance with given lambda. | ||
23 | + * | ||
24 | + * @param lambda lambda value to be assigned | ||
25 | + * @return {@link Lambda} instance with given lambda | ||
26 | + */ | ||
27 | + public static Lambda valueOf(int lambda) { | ||
28 | + return new Lambda(lambda); | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * Returns lambda as an int value. | ||
33 | + * @return lambda as an int value | ||
34 | + */ | ||
35 | + public int toInt() { | ||
36 | + return lambda; | ||
37 | + } | ||
38 | + | ||
39 | + @Override | ||
40 | + public boolean equals(Object obj) { | ||
41 | + if (obj instanceof Lambda) { | ||
42 | + Lambda that = (Lambda) obj; | ||
43 | + return Objects.equals(this.lambda, that.lambda); | ||
44 | + } | ||
45 | + return false; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public int hashCode() { | ||
50 | + return Objects.hashCode(this.lambda); | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public String toString() { | ||
55 | + return String.valueOf(this.lambda); | ||
56 | + } | ||
57 | + | ||
58 | +} |
1 | +package org.onlab.onos.net.resource; | ||
2 | + | ||
3 | +import java.util.Map; | ||
4 | + | ||
5 | +import org.onlab.onos.net.Link; | ||
6 | +import org.onlab.onos.net.intent.IntentId; | ||
7 | +import org.onlab.onos.net.intent.PathIntent; | ||
8 | + | ||
9 | +/** | ||
10 | + * Service for providing link resource allocation. | ||
11 | + */ | ||
12 | +public interface LinkResourceService { | ||
13 | + | ||
14 | + /** | ||
15 | + * Allocates resources along the path. | ||
16 | + * <p> | ||
17 | + * Tries to allocate given resources on the links along the path specified | ||
18 | + * by the given intent. | ||
19 | + * | ||
20 | + * @param res resources to be allocated | ||
21 | + * @param intent an intent to be used for specifying the path | ||
22 | + */ | ||
23 | + void allocateResource(LinkResources res, PathIntent intent); | ||
24 | + | ||
25 | + /** | ||
26 | + * Releases resources along the path. | ||
27 | + * | ||
28 | + * @param intentId an ID for the intent for specifying the path | ||
29 | + */ | ||
30 | + void releaseResource(IntentId intentId); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns all allocated resources to each link. | ||
34 | + * | ||
35 | + * @return allocated resources to each link with {@link IntentId} | ||
36 | + */ | ||
37 | + Map<Link, Map<IntentId, LinkResources>> allocatedResources(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns all allocated resources to given link. | ||
41 | + * | ||
42 | + * @param link a target link | ||
43 | + * @return allocated resources to the target link with {@link IntentId} | ||
44 | + */ | ||
45 | + Map<IntentId, LinkResources> allocatedResources(Link link); | ||
46 | + | ||
47 | + /** | ||
48 | + * Returns available resources for each link. | ||
49 | + * | ||
50 | + * @return available resources for each link | ||
51 | + */ | ||
52 | + Map<Link, LinkResources> availableResources(); | ||
53 | + | ||
54 | + /** | ||
55 | + * Returns available resources for given link. | ||
56 | + * @param link a target link | ||
57 | + * @return available resources for the target link | ||
58 | + */ | ||
59 | + LinkResource availableResources(Link link); | ||
60 | +} |
1 | +package org.onlab.onos.net.resource; | ||
2 | + | ||
3 | +import java.util.Set; | ||
4 | + | ||
5 | +/** | ||
6 | + * Abstraction of a resources of a link. | ||
7 | + */ | ||
8 | +public interface LinkResources { | ||
9 | + | ||
10 | + /** | ||
11 | + * Returns resources as a set of {@link LinkResource}s. | ||
12 | + * | ||
13 | + * @return a set of {@link LinkResource}s | ||
14 | + */ | ||
15 | + Set<LinkResource> resources(); | ||
16 | + | ||
17 | + /** | ||
18 | + * Builder of {@link LinkResources}. | ||
19 | + */ | ||
20 | + public interface Builder { | ||
21 | + | ||
22 | + /** | ||
23 | + * Adds bandwidth resource. | ||
24 | + * <p> | ||
25 | + * This operation adds given bandwidth to previous bandwidth and | ||
26 | + * generates single bandwidth resource. | ||
27 | + * | ||
28 | + * @param bandwidth bandwidth value to be added | ||
29 | + * @return self | ||
30 | + */ | ||
31 | + public Builder addBandwidth(double bandwidth); | ||
32 | + | ||
33 | + /** | ||
34 | + * Adds lambda resource. | ||
35 | + * | ||
36 | + * @param lambda lambda value to be added | ||
37 | + * @return self | ||
38 | + */ | ||
39 | + public Builder addLambda(int lambda); | ||
40 | + | ||
41 | + /** | ||
42 | + * Builds an immutable link resources. | ||
43 | + * | ||
44 | + * @return link resources | ||
45 | + */ | ||
46 | + public LinkResources build(); | ||
47 | + } | ||
48 | +} |
-
Please register or login to post a comment