Committed by
Gerrit Code Review
Make MPLS label request specifiable for a particular MPLS label
Change-Id: I4626229040c61e927a468ab5c486a907af0108ae
Showing
4 changed files
with
148 additions
and
40 deletions
... | @@ -16,49 +16,47 @@ | ... | @@ -16,49 +16,47 @@ |
16 | package org.onosproject.net.resource.link; | 16 | package org.onosproject.net.resource.link; |
17 | 17 | ||
18 | import java.util.Collection; | 18 | import java.util.Collection; |
19 | +import java.util.HashMap; | ||
19 | import java.util.HashSet; | 20 | import java.util.HashSet; |
21 | +import java.util.Map; | ||
20 | import java.util.Set; | 22 | import java.util.Set; |
21 | import java.util.Objects; | 23 | import java.util.Objects; |
24 | +import java.util.stream.Collectors; | ||
22 | 25 | ||
23 | import com.google.common.annotations.Beta; | 26 | import com.google.common.annotations.Beta; |
27 | +import com.google.common.collect.ImmutableMap; | ||
24 | import org.onlab.util.Bandwidth; | 28 | import org.onlab.util.Bandwidth; |
25 | import org.onosproject.net.Link; | 29 | import org.onosproject.net.Link; |
26 | import org.onosproject.net.intent.Constraint; | 30 | import org.onosproject.net.intent.Constraint; |
27 | import org.onosproject.net.intent.IntentId; | 31 | import org.onosproject.net.intent.IntentId; |
28 | 32 | ||
29 | -import com.google.common.collect.ImmutableSet; | ||
30 | - | ||
31 | import org.onosproject.net.intent.constraint.BandwidthConstraint; | 33 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
32 | import org.onosproject.net.intent.constraint.LambdaConstraint; | 34 | import org.onosproject.net.intent.constraint.LambdaConstraint; |
33 | import org.onosproject.net.resource.ResourceRequest; | 35 | import org.onosproject.net.resource.ResourceRequest; |
34 | import org.onosproject.net.resource.ResourceType; | 36 | import org.onosproject.net.resource.ResourceType; |
35 | 37 | ||
38 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
39 | + | ||
36 | /** | 40 | /** |
37 | * Implementation of {@link LinkResourceRequest}. | 41 | * Implementation of {@link LinkResourceRequest}. |
38 | */ | 42 | */ |
39 | public final class DefaultLinkResourceRequest implements LinkResourceRequest { | 43 | public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
40 | 44 | ||
41 | private final IntentId intentId; | 45 | private final IntentId intentId; |
42 | - private final Collection<Link> links; | 46 | + protected final Map<Link, Set<ResourceRequest>> requests; |
43 | - private final Set<ResourceRequest> resources; | ||
44 | 47 | ||
45 | /** | 48 | /** |
46 | - * Creates a new link resource request with the given ID, links, and | 49 | + * Creates a new link resource request with the specified Intent ID, |
47 | - * resource requests. | 50 | + * and resource requests over links. |
48 | * | 51 | * |
49 | - * @param intentId intent ID related to this request | 52 | + * @param intentId intent ID associated with this request |
50 | - * @param links a set of links for the request | 53 | + * @param requests resource requests over links |
51 | - * @param resources a set of resources to be requested | ||
52 | */ | 54 | */ |
53 | - private DefaultLinkResourceRequest(IntentId intentId, | 55 | + private DefaultLinkResourceRequest(IntentId intentId, Map<Link, Set<ResourceRequest>> requests) { |
54 | - Collection<Link> links, | 56 | + this.intentId = checkNotNull(intentId); |
55 | - Set<ResourceRequest> resources) { | 57 | + this.requests = checkNotNull(ImmutableMap.copyOf(requests)); |
56 | - this.intentId = intentId; | ||
57 | - this.links = ImmutableSet.copyOf(links); | ||
58 | - this.resources = ImmutableSet.copyOf(resources); | ||
59 | } | 58 | } |
60 | 59 | ||
61 | - | ||
62 | @Override | 60 | @Override |
63 | public ResourceType type() { | 61 | public ResourceType type() { |
64 | return null; | 62 | return null; |
... | @@ -71,12 +69,19 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -71,12 +69,19 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
71 | 69 | ||
72 | @Override | 70 | @Override |
73 | public Collection<Link> links() { | 71 | public Collection<Link> links() { |
74 | - return links; | 72 | + return requests.keySet(); |
75 | } | 73 | } |
76 | 74 | ||
77 | @Override | 75 | @Override |
78 | public Set<ResourceRequest> resources() { | 76 | public Set<ResourceRequest> resources() { |
79 | - return resources; | 77 | + return requests.values().stream() |
78 | + .flatMap(Collection::stream) | ||
79 | + .collect(Collectors.toSet()); | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public Set<ResourceRequest> resources(Link link) { | ||
84 | + return requests.get(link); | ||
80 | } | 85 | } |
81 | 86 | ||
82 | /** | 87 | /** |
... | @@ -96,8 +101,7 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -96,8 +101,7 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
96 | */ | 101 | */ |
97 | public static final class Builder implements LinkResourceRequest.Builder { | 102 | public static final class Builder implements LinkResourceRequest.Builder { |
98 | private IntentId intentId; | 103 | private IntentId intentId; |
99 | - private Collection<Link> links; | 104 | + private Map<Link, Set<ResourceRequest>> requests; |
100 | - private Set<ResourceRequest> resources; | ||
101 | 105 | ||
102 | /** | 106 | /** |
103 | * Creates a new link resource request. | 107 | * Creates a new link resource request. |
... | @@ -107,8 +111,10 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -107,8 +111,10 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
107 | */ | 111 | */ |
108 | private Builder(IntentId intentId, Collection<Link> links) { | 112 | private Builder(IntentId intentId, Collection<Link> links) { |
109 | this.intentId = intentId; | 113 | this.intentId = intentId; |
110 | - this.links = links; | 114 | + this.requests = new HashMap<>(); |
111 | - this.resources = new HashSet<>(); | 115 | + for (Link link : links) { |
116 | + requests.put(link, new HashSet<>()); | ||
117 | + } | ||
112 | } | 118 | } |
113 | 119 | ||
114 | /** | 120 | /** |
... | @@ -120,14 +126,18 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -120,14 +126,18 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
120 | @Deprecated | 126 | @Deprecated |
121 | @Override | 127 | @Override |
122 | public Builder addLambdaRequest() { | 128 | public Builder addLambdaRequest() { |
123 | - resources.add(new LambdaResourceRequest()); | 129 | + for (Link link : requests.keySet()) { |
130 | + requests.get(link).add(new LambdaResourceRequest()); | ||
131 | + } | ||
124 | return this; | 132 | return this; |
125 | } | 133 | } |
126 | 134 | ||
127 | @Beta | 135 | @Beta |
128 | @Override | 136 | @Override |
129 | public LinkResourceRequest.Builder addLambdaRequest(LambdaResource lambda) { | 137 | public LinkResourceRequest.Builder addLambdaRequest(LambdaResource lambda) { |
130 | - resources.add(new LambdaResourceRequest(lambda)); | 138 | + for (Link link : requests.keySet()) { |
139 | + requests.get(link).add(new LambdaResourceRequest(lambda)); | ||
140 | + } | ||
131 | return this; | 141 | return this; |
132 | } | 142 | } |
133 | 143 | ||
... | @@ -135,10 +145,36 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -135,10 +145,36 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
135 | * Adds Mpls request. | 145 | * Adds Mpls request. |
136 | * | 146 | * |
137 | * @return self | 147 | * @return self |
148 | + * @deprecated in Emu Release | ||
138 | */ | 149 | */ |
150 | + @Deprecated | ||
139 | @Override | 151 | @Override |
140 | public Builder addMplsRequest() { | 152 | public Builder addMplsRequest() { |
141 | - resources.add(new MplsLabelResourceRequest()); | 153 | + for (Link link : requests.keySet()) { |
154 | + requests.get(link).add(new MplsLabelResourceRequest()); | ||
155 | + } | ||
156 | + return this; | ||
157 | + } | ||
158 | + | ||
159 | + @Beta | ||
160 | + @Override | ||
161 | + public Builder addMplsRequest(MplsLabel label) { | ||
162 | + for (Link link : requests.keySet()) { | ||
163 | + requests.get(link).add(new MplsLabelResourceRequest(label)); | ||
164 | + } | ||
165 | + return this; | ||
166 | + } | ||
167 | + | ||
168 | + @Beta | ||
169 | + @Override | ||
170 | + public LinkResourceRequest.Builder addMplsRequest(Map<Link, MplsLabel> labels) { | ||
171 | + for (Link link : labels.keySet()) { | ||
172 | + if (!requests.containsKey(link)) { | ||
173 | + requests.put(link, new HashSet<>()); | ||
174 | + } | ||
175 | + requests.get(link).add(new MplsLabelResourceRequest(labels.get(link))); | ||
176 | + } | ||
177 | + | ||
142 | return this; | 178 | return this; |
143 | } | 179 | } |
144 | 180 | ||
... | @@ -150,7 +186,9 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -150,7 +186,9 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
150 | */ | 186 | */ |
151 | @Override | 187 | @Override |
152 | public Builder addBandwidthRequest(double bandwidth) { | 188 | public Builder addBandwidthRequest(double bandwidth) { |
153 | - resources.add(new BandwidthResourceRequest(new BandwidthResource(Bandwidth.bps(bandwidth)))); | 189 | + for (Link link : requests.keySet()) { |
190 | + requests.get(link).add(new BandwidthResourceRequest(new BandwidthResource(Bandwidth.bps(bandwidth)))); | ||
191 | + } | ||
154 | return this; | 192 | return this; |
155 | } | 193 | } |
156 | 194 | ||
... | @@ -172,13 +210,13 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -172,13 +210,13 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
172 | */ | 210 | */ |
173 | @Override | 211 | @Override |
174 | public LinkResourceRequest build() { | 212 | public LinkResourceRequest build() { |
175 | - return new DefaultLinkResourceRequest(intentId, links, resources); | 213 | + return new DefaultLinkResourceRequest(intentId, requests); |
176 | } | 214 | } |
177 | } | 215 | } |
178 | 216 | ||
179 | @Override | 217 | @Override |
180 | public int hashCode() { | 218 | public int hashCode() { |
181 | - return Objects.hash(intentId, links); | 219 | + return Objects.hash(intentId, links()); |
182 | } | 220 | } |
183 | 221 | ||
184 | @Override | 222 | @Override |
... | @@ -191,6 +229,6 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -191,6 +229,6 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
191 | } | 229 | } |
192 | final DefaultLinkResourceRequest other = (DefaultLinkResourceRequest) obj; | 230 | final DefaultLinkResourceRequest other = (DefaultLinkResourceRequest) obj; |
193 | return Objects.equals(this.intentId, other.intentId) | 231 | return Objects.equals(this.intentId, other.intentId) |
194 | - && Objects.equals(this.links, other.links); | 232 | + && Objects.equals(this.links(), other.links()); |
195 | } | 233 | } |
196 | } | 234 | } | ... | ... |
... | @@ -15,15 +15,16 @@ | ... | @@ -15,15 +15,16 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.resource.link; | 16 | package org.onosproject.net.resource.link; |
17 | 17 | ||
18 | +import java.util.Collection; | ||
19 | +import java.util.Map; | ||
20 | +import java.util.Set; | ||
21 | + | ||
18 | import com.google.common.annotations.Beta; | 22 | import com.google.common.annotations.Beta; |
19 | import org.onosproject.net.Link; | 23 | import org.onosproject.net.Link; |
20 | import org.onosproject.net.intent.Constraint; | 24 | import org.onosproject.net.intent.Constraint; |
21 | import org.onosproject.net.intent.IntentId; | 25 | import org.onosproject.net.intent.IntentId; |
22 | import org.onosproject.net.resource.ResourceRequest; | 26 | import org.onosproject.net.resource.ResourceRequest; |
23 | 27 | ||
24 | -import java.util.Collection; | ||
25 | -import java.util.Set; | ||
26 | - | ||
27 | /** | 28 | /** |
28 | * Representation of a request for link resource. | 29 | * Representation of a request for link resource. |
29 | */ | 30 | */ |
... | @@ -51,6 +52,15 @@ public interface LinkResourceRequest extends ResourceRequest { | ... | @@ -51,6 +52,15 @@ public interface LinkResourceRequest extends ResourceRequest { |
51 | Set<ResourceRequest> resources(); | 52 | Set<ResourceRequest> resources(); |
52 | 53 | ||
53 | /** | 54 | /** |
55 | + * Returns the set of resource request against the specified link. | ||
56 | + * | ||
57 | + * @param link link whose associated resource request is to be returned | ||
58 | + * @return set of resource request against the specified link | ||
59 | + */ | ||
60 | + @Beta | ||
61 | + Set<ResourceRequest> resources(Link link); | ||
62 | + | ||
63 | + /** | ||
54 | * Builder of link resource request. | 64 | * Builder of link resource request. |
55 | */ | 65 | */ |
56 | interface Builder { | 66 | interface Builder { |
... | @@ -76,10 +86,30 @@ public interface LinkResourceRequest extends ResourceRequest { | ... | @@ -76,10 +86,30 @@ public interface LinkResourceRequest extends ResourceRequest { |
76 | * Adds MPLS request. | 86 | * Adds MPLS request. |
77 | * | 87 | * |
78 | * @return self | 88 | * @return self |
89 | + * @deprecated in Emu Release | ||
79 | */ | 90 | */ |
91 | + @Deprecated | ||
80 | Builder addMplsRequest(); | 92 | Builder addMplsRequest(); |
81 | 93 | ||
82 | /** | 94 | /** |
95 | + * Adds MPLS request. | ||
96 | + * | ||
97 | + * @param label MPLS label to be requested | ||
98 | + * @return self | ||
99 | + */ | ||
100 | + @Beta | ||
101 | + Builder addMplsRequest(MplsLabel label); | ||
102 | + | ||
103 | + /** | ||
104 | + * Adds MPLS request against the specified links. | ||
105 | + * | ||
106 | + * @param labels MPLS labels to be requested against links | ||
107 | + * @return self | ||
108 | + */ | ||
109 | + @Beta | ||
110 | + Builder addMplsRequest(Map<Link, MplsLabel> labels); | ||
111 | + | ||
112 | + /** | ||
83 | * Adds bandwidth request with bandwidth value. | 113 | * Adds bandwidth request with bandwidth value. |
84 | * | 114 | * |
85 | * @param bandwidth bandwidth value to be requested | 115 | * @param bandwidth bandwidth value to be requested | ... | ... |
... | @@ -15,15 +15,50 @@ | ... | @@ -15,15 +15,50 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.resource.link; | 16 | package org.onosproject.net.resource.link; |
17 | 17 | ||
18 | +import com.google.common.annotations.Beta; | ||
18 | import com.google.common.base.MoreObjects; | 19 | import com.google.common.base.MoreObjects; |
19 | import org.onosproject.net.resource.ResourceRequest; | 20 | import org.onosproject.net.resource.ResourceRequest; |
20 | import org.onosproject.net.resource.ResourceType; | 21 | import org.onosproject.net.resource.ResourceType; |
21 | 22 | ||
23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
24 | + | ||
22 | /** | 25 | /** |
23 | * Representation of a request for lambda resource. | 26 | * Representation of a request for lambda resource. |
24 | */ | 27 | */ |
25 | public class MplsLabelResourceRequest implements ResourceRequest { | 28 | public class MplsLabelResourceRequest implements ResourceRequest { |
26 | 29 | ||
30 | + private final MplsLabel mplsLabel; | ||
31 | + | ||
32 | + /** | ||
33 | + * Constructs a request specifying the given MPLS label. | ||
34 | + * | ||
35 | + * @param mplsLabel MPLS label to be requested | ||
36 | + */ | ||
37 | + @Beta | ||
38 | + public MplsLabelResourceRequest(MplsLabel mplsLabel) { | ||
39 | + this.mplsLabel = checkNotNull(mplsLabel); | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * Constructs a request asking an arbitrary available MPLS label. | ||
44 | + * | ||
45 | + * @deprecated in Emu Release | ||
46 | + */ | ||
47 | + @Deprecated | ||
48 | + public MplsLabelResourceRequest() { | ||
49 | + this.mplsLabel = null; | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Returns the MPLS label this request expects. | ||
54 | + * | ||
55 | + * @return the MPLS label this request expects | ||
56 | + */ | ||
57 | + @Beta | ||
58 | + public MplsLabel mplsLabel() { | ||
59 | + return mplsLabel; | ||
60 | + } | ||
61 | + | ||
27 | @Override | 62 | @Override |
28 | public ResourceType type() { | 63 | public ResourceType type() { |
29 | return ResourceType.MPLS_LABEL; | 64 | return ResourceType.MPLS_LABEL; |
... | @@ -32,6 +67,7 @@ public class MplsLabelResourceRequest implements ResourceRequest { | ... | @@ -32,6 +67,7 @@ public class MplsLabelResourceRequest implements ResourceRequest { |
32 | @Override | 67 | @Override |
33 | public String toString() { | 68 | public String toString() { |
34 | return MoreObjects.toStringHelper(this) | 69 | return MoreObjects.toStringHelper(this) |
70 | + .add("mplsLabel", mplsLabel) | ||
35 | .toString(); | 71 | .toString(); |
36 | } | 72 | } |
37 | } | 73 | } | ... | ... |
... | @@ -48,8 +48,8 @@ import org.slf4j.Logger; | ... | @@ -48,8 +48,8 @@ import org.slf4j.Logger; |
48 | import java.util.Collections; | 48 | import java.util.Collections; |
49 | import java.util.HashMap; | 49 | import java.util.HashMap; |
50 | import java.util.HashSet; | 50 | import java.util.HashSet; |
51 | -import java.util.Iterator; | ||
52 | import java.util.Map; | 51 | import java.util.Map; |
52 | +import java.util.Optional; | ||
53 | import java.util.Set; | 53 | import java.util.Set; |
54 | 54 | ||
55 | import static org.onosproject.security.AppGuard.checkPermission; | 55 | import static org.onosproject.security.AppGuard.checkPermission; |
... | @@ -130,12 +130,15 @@ public class LinkResourceManager | ... | @@ -130,12 +130,15 @@ public class LinkResourceManager |
130 | if (allocsPerLink.get(link) == null) { | 130 | if (allocsPerLink.get(link) == null) { |
131 | allocsPerLink.put(link, new HashSet<>()); | 131 | allocsPerLink.put(link, new HashSet<>()); |
132 | } | 132 | } |
133 | - Iterator<MplsLabel> mplsIter = getAvailableMplsLabels(link) | 133 | + |
134 | - .iterator(); | 134 | + Optional<MplsLabel> label = req.resources(link).stream() |
135 | - if (mplsIter.hasNext()) { | 135 | + .filter(x -> x.type() == ResourceType.MPLS_LABEL) |
136 | - allocsPerLink.get(link) | 136 | + .map(x -> (MplsLabelResourceRequest) x) |
137 | - .add(new MplsLabelResourceAllocation(mplsIter | 137 | + .map(MplsLabelResourceRequest::mplsLabel) |
138 | - .next())); | 138 | + .findFirst(); |
139 | + | ||
140 | + if (label.isPresent()) { | ||
141 | + allocsPerLink.get(link).add(new MplsLabelResourceAllocation(label.get())); | ||
139 | } else { | 142 | } else { |
140 | log.info("Failed to allocate MPLS resource."); | 143 | log.info("Failed to allocate MPLS resource."); |
141 | break; | 144 | break; |
... | @@ -214,7 +217,8 @@ public class LinkResourceManager | ... | @@ -214,7 +217,8 @@ public class LinkResourceManager |
214 | ((LambdaResourceAllocation) alloc).lambda())); | 217 | ((LambdaResourceAllocation) alloc).lambda())); |
215 | break; | 218 | break; |
216 | case MPLS_LABEL: | 219 | case MPLS_LABEL: |
217 | - result.add(new MplsLabelResourceRequest()); | 220 | + result.add(new MplsLabelResourceRequest( |
221 | + ((MplsLabelResourceAllocation) alloc).mplsLabel())); | ||
218 | break; | 222 | break; |
219 | default: | 223 | default: |
220 | break; | 224 | break; | ... | ... |
-
Please register or login to post a comment