Committed by
Gerrit Code Review
ONOS-239 Retrigger compilation when new resources are available
When an intent is withdrawn and frees up resources, trigger recompilation of any failed intents to allow the ones waiting for resources to be installed. Change-Id: Ic15678378ce41516a7eab890b4b4898aeb901f78
Showing
12 changed files
with
288 additions
and
51 deletions
1 | +/* | ||
2 | + * Copyright 2014 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onlab.onos.net.resource; | ||
17 | + | ||
18 | +import java.util.Collection; | ||
19 | + | ||
20 | +import org.onlab.onos.event.AbstractEvent; | ||
21 | + | ||
22 | +import com.google.common.collect.ImmutableList; | ||
23 | + | ||
24 | +/** | ||
25 | + * Describes an event related to a Link Resource. | ||
26 | + */ | ||
27 | +public final class LinkResourceEvent | ||
28 | + extends AbstractEvent<LinkResourceEvent.Type, Collection<LinkResourceAllocations>> { | ||
29 | + | ||
30 | + /** | ||
31 | + * Type of resource this event is for. | ||
32 | + */ | ||
33 | + public enum Type { | ||
34 | + /** Additional resources are now available. */ | ||
35 | + ADDITIONAL_RESOURCES_AVAILABLE | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * Constructs a link resource event. | ||
40 | + * | ||
41 | + * @param type type of resource event to create | ||
42 | + * @param linkResourceAllocations allocations that are now available | ||
43 | + */ | ||
44 | + public LinkResourceEvent(Type type, | ||
45 | + Collection<LinkResourceAllocations> linkResourceAllocations) { | ||
46 | + super(type, ImmutableList.copyOf(linkResourceAllocations)); | ||
47 | + } | ||
48 | +} |
1 | +/* | ||
2 | + * Copyright 2014 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onlab.onos.net.resource; | ||
17 | + | ||
18 | +import org.onlab.onos.event.EventListener; | ||
19 | + | ||
20 | +/** | ||
21 | + * Entity for receiving link resource events. | ||
22 | + */ | ||
23 | +public interface LinkResourceListener extends EventListener<LinkResourceEvent> { | ||
24 | +} |
... | @@ -89,4 +89,18 @@ public interface LinkResourceService { | ... | @@ -89,4 +89,18 @@ public interface LinkResourceService { |
89 | Iterable<ResourceRequest> getAvailableResources(Link link, | 89 | Iterable<ResourceRequest> getAvailableResources(Link link, |
90 | LinkResourceAllocations allocations); | 90 | LinkResourceAllocations allocations); |
91 | 91 | ||
92 | + /** | ||
93 | + * Adds a listener for resource related events. | ||
94 | + * | ||
95 | + * @param listener listener to add | ||
96 | + */ | ||
97 | + void addListener(LinkResourceListener listener); | ||
98 | + | ||
99 | + /** | ||
100 | + * Removes a listener for resource related events. | ||
101 | + * | ||
102 | + * @param listener listener to remove. | ||
103 | + */ | ||
104 | + void removeListener(LinkResourceListener listener); | ||
105 | + | ||
92 | } | 106 | } | ... | ... |
... | @@ -44,7 +44,7 @@ public interface LinkResourceStore { | ... | @@ -44,7 +44,7 @@ public interface LinkResourceStore { |
44 | * | 44 | * |
45 | * @param allocations resources to be released | 45 | * @param allocations resources to be released |
46 | */ | 46 | */ |
47 | - void releaseResources(LinkResourceAllocations allocations); | 47 | + LinkResourceEvent releaseResources(LinkResourceAllocations allocations); |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * Returns resources allocated for an Intent. | 50 | * Returns resources allocated for an Intent. | ... | ... |
1 | +/* | ||
2 | + * Copyright 2014 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onlab.onos.net.resource; | ||
17 | + | ||
18 | +import org.onlab.onos.store.StoreDelegate; | ||
19 | + | ||
20 | +/** | ||
21 | + * Link resource store delegate abstraction. | ||
22 | + */ | ||
23 | +public interface LinkResourceStoreDelegate extends StoreDelegate<LinkResourceEvent> { | ||
24 | +} |
... | @@ -43,6 +43,7 @@ import org.onlab.onos.net.flow.instructions.Instruction; | ... | @@ -43,6 +43,7 @@ import org.onlab.onos.net.flow.instructions.Instruction; |
43 | import org.onlab.onos.net.resource.BandwidthResourceRequest; | 43 | import org.onlab.onos.net.resource.BandwidthResourceRequest; |
44 | import org.onlab.onos.net.resource.LambdaResourceRequest; | 44 | import org.onlab.onos.net.resource.LambdaResourceRequest; |
45 | import org.onlab.onos.net.resource.LinkResourceAllocations; | 45 | import org.onlab.onos.net.resource.LinkResourceAllocations; |
46 | +import org.onlab.onos.net.resource.LinkResourceListener; | ||
46 | import org.onlab.onos.net.resource.LinkResourceRequest; | 47 | import org.onlab.onos.net.resource.LinkResourceRequest; |
47 | import org.onlab.onos.net.resource.LinkResourceService; | 48 | import org.onlab.onos.net.resource.LinkResourceService; |
48 | import org.onlab.onos.net.resource.ResourceAllocation; | 49 | import org.onlab.onos.net.resource.ResourceAllocation; |
... | @@ -273,6 +274,16 @@ public class IntentTestsMocks { | ... | @@ -273,6 +274,16 @@ public class IntentTestsMocks { |
273 | public Iterable<ResourceRequest> getAvailableResources(Link link, LinkResourceAllocations allocations) { | 274 | public Iterable<ResourceRequest> getAvailableResources(Link link, LinkResourceAllocations allocations) { |
274 | return null; | 275 | return null; |
275 | } | 276 | } |
277 | + | ||
278 | + @Override | ||
279 | + public void addListener(LinkResourceListener listener) { | ||
280 | + | ||
281 | + } | ||
282 | + | ||
283 | + @Override | ||
284 | + public void removeListener(LinkResourceListener listener) { | ||
285 | + | ||
286 | + } | ||
276 | } | 287 | } |
277 | 288 | ||
278 | private static final IntentTestsMocks.MockSelector SELECTOR = | 289 | private static final IntentTestsMocks.MockSelector SELECTOR = | ... | ... |
... | @@ -15,10 +15,18 @@ | ... | @@ -15,10 +15,18 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.intent.impl; | 16 | package org.onlab.onos.net.intent.impl; |
17 | 17 | ||
18 | -import com.google.common.collect.ImmutableList; | 18 | +import java.util.ArrayList; |
19 | -import com.google.common.collect.ImmutableMap; | 19 | +import java.util.Collections; |
20 | -import com.google.common.collect.Lists; | 20 | +import java.util.List; |
21 | -import com.google.common.collect.Maps; | 21 | +import java.util.Map; |
22 | +import java.util.concurrent.ConcurrentHashMap; | ||
23 | +import java.util.concurrent.ConcurrentMap; | ||
24 | +import java.util.concurrent.ExecutionException; | ||
25 | +import java.util.concurrent.ExecutorService; | ||
26 | +import java.util.concurrent.Future; | ||
27 | +import java.util.concurrent.TimeUnit; | ||
28 | +import java.util.concurrent.TimeoutException; | ||
29 | + | ||
22 | import org.apache.felix.scr.annotations.Activate; | 30 | import org.apache.felix.scr.annotations.Activate; |
23 | import org.apache.felix.scr.annotations.Component; | 31 | import org.apache.felix.scr.annotations.Component; |
24 | import org.apache.felix.scr.annotations.Deactivate; | 32 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -50,22 +58,20 @@ import org.onlab.onos.net.intent.IntentStore; | ... | @@ -50,22 +58,20 @@ import org.onlab.onos.net.intent.IntentStore; |
50 | import org.onlab.onos.net.intent.IntentStoreDelegate; | 58 | import org.onlab.onos.net.intent.IntentStoreDelegate; |
51 | import org.slf4j.Logger; | 59 | import org.slf4j.Logger; |
52 | 60 | ||
53 | -import java.util.ArrayList; | 61 | +import com.google.common.collect.ImmutableList; |
54 | -import java.util.Collections; | 62 | +import com.google.common.collect.ImmutableMap; |
55 | -import java.util.List; | 63 | +import com.google.common.collect.Lists; |
56 | -import java.util.Map; | 64 | +import com.google.common.collect.Maps; |
57 | -import java.util.concurrent.ConcurrentHashMap; | ||
58 | -import java.util.concurrent.ConcurrentMap; | ||
59 | -import java.util.concurrent.ExecutionException; | ||
60 | -import java.util.concurrent.ExecutorService; | ||
61 | -import java.util.concurrent.Future; | ||
62 | -import java.util.concurrent.TimeUnit; | ||
63 | -import java.util.concurrent.TimeoutException; | ||
64 | 65 | ||
65 | import static com.google.common.base.Preconditions.checkArgument; | 66 | import static com.google.common.base.Preconditions.checkArgument; |
66 | import static com.google.common.base.Preconditions.checkNotNull; | 67 | import static com.google.common.base.Preconditions.checkNotNull; |
67 | import static java.util.concurrent.Executors.newSingleThreadExecutor; | 68 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
68 | -import static org.onlab.onos.net.intent.IntentState.*; | 69 | +import static org.onlab.onos.net.intent.IntentState.COMPILING; |
70 | +import static org.onlab.onos.net.intent.IntentState.FAILED; | ||
71 | +import static org.onlab.onos.net.intent.IntentState.INSTALLED; | ||
72 | +import static org.onlab.onos.net.intent.IntentState.INSTALLING; | ||
73 | +import static org.onlab.onos.net.intent.IntentState.WITHDRAWING; | ||
74 | +import static org.onlab.onos.net.intent.IntentState.WITHDRAWN; | ||
69 | import static org.onlab.util.Tools.namedThreads; | 75 | import static org.onlab.util.Tools.namedThreads; |
70 | import static org.slf4j.LoggerFactory.getLogger; | 76 | import static org.slf4j.LoggerFactory.getLogger; |
71 | 77 | ||
... | @@ -159,8 +165,8 @@ public class IntentManager | ... | @@ -159,8 +165,8 @@ public class IntentManager |
159 | checkNotNull(oldIntentId, INTENT_ID_NULL); | 165 | checkNotNull(oldIntentId, INTENT_ID_NULL); |
160 | checkNotNull(newIntent, INTENT_NULL); | 166 | checkNotNull(newIntent, INTENT_NULL); |
161 | execute(IntentOperations.builder() | 167 | execute(IntentOperations.builder() |
162 | - .addReplaceOperation(oldIntentId, newIntent) | 168 | + .addReplaceOperation(oldIntentId, newIntent) |
163 | - .build()); | 169 | + .build()); |
164 | } | 170 | } |
165 | 171 | ||
166 | @Override | 172 | @Override |
... | @@ -681,7 +687,7 @@ public class IntentManager | ... | @@ -681,7 +687,7 @@ public class IntentManager |
681 | // TODO: clean this up, or set to debug | 687 | // TODO: clean this up, or set to debug |
682 | IntentState oldState = stateMap.get(intent); | 688 | IntentState oldState = stateMap.get(intent); |
683 | log.debug("intent id: {}, old state: {}, new state: {}", | 689 | log.debug("intent id: {}, old state: {}, new state: {}", |
684 | - intent.id(), oldState, newState); | 690 | + intent.id(), oldState, newState); |
685 | 691 | ||
686 | stateMap.put(intent, newState); | 692 | stateMap.put(intent, newState); |
687 | IntentEvent event = store.setState(intent, newState); | 693 | IntentEvent event = store.setState(intent, newState); |
... | @@ -845,4 +851,5 @@ public class IntentManager | ... | @@ -845,4 +851,5 @@ public class IntentManager |
845 | log.warn("NOT IMPLEMENTED -- Cancel operations: {}", operations); | 851 | log.warn("NOT IMPLEMENTED -- Cancel operations: {}", operations); |
846 | } | 852 | } |
847 | } | 853 | } |
854 | + | ||
848 | } | 855 | } | ... | ... |
... | @@ -15,8 +15,11 @@ | ... | @@ -15,8 +15,11 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.intent.impl; | 16 | package org.onlab.onos.net.intent.impl; |
17 | 17 | ||
18 | -import com.google.common.collect.HashMultimap; | 18 | +import java.util.Collection; |
19 | -import com.google.common.collect.SetMultimap; | 19 | +import java.util.HashSet; |
20 | +import java.util.Set; | ||
21 | +import java.util.concurrent.ExecutorService; | ||
22 | + | ||
20 | import org.apache.felix.scr.annotations.Activate; | 23 | import org.apache.felix.scr.annotations.Activate; |
21 | import org.apache.felix.scr.annotations.Component; | 24 | import org.apache.felix.scr.annotations.Component; |
22 | import org.apache.felix.scr.annotations.Deactivate; | 25 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -29,15 +32,16 @@ import org.onlab.onos.net.LinkKey; | ... | @@ -29,15 +32,16 @@ import org.onlab.onos.net.LinkKey; |
29 | import org.onlab.onos.net.NetworkResource; | 32 | import org.onlab.onos.net.NetworkResource; |
30 | import org.onlab.onos.net.intent.IntentId; | 33 | import org.onlab.onos.net.intent.IntentId; |
31 | import org.onlab.onos.net.link.LinkEvent; | 34 | import org.onlab.onos.net.link.LinkEvent; |
35 | +import org.onlab.onos.net.resource.LinkResourceEvent; | ||
36 | +import org.onlab.onos.net.resource.LinkResourceListener; | ||
37 | +import org.onlab.onos.net.resource.LinkResourceService; | ||
32 | import org.onlab.onos.net.topology.TopologyEvent; | 38 | import org.onlab.onos.net.topology.TopologyEvent; |
33 | import org.onlab.onos.net.topology.TopologyListener; | 39 | import org.onlab.onos.net.topology.TopologyListener; |
34 | import org.onlab.onos.net.topology.TopologyService; | 40 | import org.onlab.onos.net.topology.TopologyService; |
35 | import org.slf4j.Logger; | 41 | import org.slf4j.Logger; |
36 | 42 | ||
37 | -import java.util.Collection; | 43 | +import com.google.common.collect.HashMultimap; |
38 | -import java.util.HashSet; | 44 | +import com.google.common.collect.SetMultimap; |
39 | -import java.util.Set; | ||
40 | -import java.util.concurrent.ExecutorService; | ||
41 | 45 | ||
42 | import static com.google.common.base.Preconditions.checkArgument; | 46 | import static com.google.common.base.Preconditions.checkArgument; |
43 | import static com.google.common.base.Preconditions.checkNotNull; | 47 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -53,7 +57,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -53,7 +57,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
53 | * Entity responsible for tracking installed flows and for monitoring topology | 57 | * Entity responsible for tracking installed flows and for monitoring topology |
54 | * events to determine what flows are affected by topology changes. | 58 | * events to determine what flows are affected by topology changes. |
55 | */ | 59 | */ |
56 | -@Component | 60 | +@Component(immediate = true) |
57 | @Service | 61 | @Service |
58 | public class ObjectiveTracker implements ObjectiveTrackerService { | 62 | public class ObjectiveTracker implements ObjectiveTrackerService { |
59 | 63 | ||
... | @@ -65,21 +69,28 @@ public class ObjectiveTracker implements ObjectiveTrackerService { | ... | @@ -65,21 +69,28 @@ public class ObjectiveTracker implements ObjectiveTrackerService { |
65 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 69 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
66 | protected TopologyService topologyService; | 70 | protected TopologyService topologyService; |
67 | 71 | ||
72 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
73 | + protected LinkResourceService resourceManager; | ||
74 | + | ||
68 | private ExecutorService executorService = | 75 | private ExecutorService executorService = |
69 | newSingleThreadExecutor(namedThreads("onos-flowtracker")); | 76 | newSingleThreadExecutor(namedThreads("onos-flowtracker")); |
70 | 77 | ||
71 | private TopologyListener listener = new InternalTopologyListener(); | 78 | private TopologyListener listener = new InternalTopologyListener(); |
79 | + private LinkResourceListener linkResourceListener = | ||
80 | + new InternalLinkResourceListener(); | ||
72 | private TopologyChangeDelegate delegate; | 81 | private TopologyChangeDelegate delegate; |
73 | 82 | ||
74 | @Activate | 83 | @Activate |
75 | public void activate() { | 84 | public void activate() { |
76 | topologyService.addListener(listener); | 85 | topologyService.addListener(listener); |
86 | + resourceManager.addListener(linkResourceListener); | ||
77 | log.info("Started"); | 87 | log.info("Started"); |
78 | } | 88 | } |
79 | 89 | ||
80 | @Deactivate | 90 | @Deactivate |
81 | public void deactivate() { | 91 | public void deactivate() { |
82 | topologyService.removeListener(listener); | 92 | topologyService.removeListener(listener); |
93 | + resourceManager.removeListener(linkResourceListener); | ||
83 | log.info("Stopped"); | 94 | log.info("Stopped"); |
84 | } | 95 | } |
85 | 96 | ||
... | @@ -173,4 +184,37 @@ public class ObjectiveTracker implements ObjectiveTrackerService { | ... | @@ -173,4 +184,37 @@ public class ObjectiveTracker implements ObjectiveTrackerService { |
173 | } | 184 | } |
174 | } | 185 | } |
175 | 186 | ||
187 | + /** | ||
188 | + * Internal re-actor to resource available events. | ||
189 | + */ | ||
190 | + private class InternalLinkResourceListener implements LinkResourceListener { | ||
191 | + @Override | ||
192 | + public void event(LinkResourceEvent event) { | ||
193 | + executorService.execute(new ResourceAvailableHandler(event)); | ||
194 | + } | ||
195 | + } | ||
196 | + | ||
197 | + /* | ||
198 | + * Re-dispatcher of resource available events. | ||
199 | + */ | ||
200 | + private class ResourceAvailableHandler implements Runnable { | ||
201 | + | ||
202 | + private final LinkResourceEvent event; | ||
203 | + | ||
204 | + ResourceAvailableHandler(LinkResourceEvent event) { | ||
205 | + this.event = event; | ||
206 | + } | ||
207 | + | ||
208 | + @Override | ||
209 | + public void run() { | ||
210 | + // If there is no delegate, why bother? Just bail. | ||
211 | + if (delegate == null) { | ||
212 | + return; | ||
213 | + } | ||
214 | + | ||
215 | + delegate.triggerCompile(new HashSet<>(), true); | ||
216 | + } | ||
217 | + } | ||
218 | + | ||
219 | + | ||
176 | } | 220 | } | ... | ... |
... | @@ -32,6 +32,8 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -32,6 +32,8 @@ import org.apache.felix.scr.annotations.Deactivate; |
32 | import org.apache.felix.scr.annotations.Reference; | 32 | import org.apache.felix.scr.annotations.Reference; |
33 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 33 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
34 | import org.apache.felix.scr.annotations.Service; | 34 | import org.apache.felix.scr.annotations.Service; |
35 | +import org.onlab.onos.event.AbstractListenerRegistry; | ||
36 | +import org.onlab.onos.event.EventDeliveryService; | ||
35 | import org.onlab.onos.net.Link; | 37 | import org.onlab.onos.net.Link; |
36 | import org.onlab.onos.net.intent.IntentId; | 38 | import org.onlab.onos.net.intent.IntentId; |
37 | import org.onlab.onos.net.resource.BandwidthResourceAllocation; | 39 | import org.onlab.onos.net.resource.BandwidthResourceAllocation; |
... | @@ -41,9 +43,12 @@ import org.onlab.onos.net.resource.Lambda; | ... | @@ -41,9 +43,12 @@ import org.onlab.onos.net.resource.Lambda; |
41 | import org.onlab.onos.net.resource.LambdaResourceAllocation; | 43 | import org.onlab.onos.net.resource.LambdaResourceAllocation; |
42 | import org.onlab.onos.net.resource.LambdaResourceRequest; | 44 | import org.onlab.onos.net.resource.LambdaResourceRequest; |
43 | import org.onlab.onos.net.resource.LinkResourceAllocations; | 45 | import org.onlab.onos.net.resource.LinkResourceAllocations; |
46 | +import org.onlab.onos.net.resource.LinkResourceEvent; | ||
47 | +import org.onlab.onos.net.resource.LinkResourceListener; | ||
44 | import org.onlab.onos.net.resource.LinkResourceRequest; | 48 | import org.onlab.onos.net.resource.LinkResourceRequest; |
45 | import org.onlab.onos.net.resource.LinkResourceService; | 49 | import org.onlab.onos.net.resource.LinkResourceService; |
46 | import org.onlab.onos.net.resource.LinkResourceStore; | 50 | import org.onlab.onos.net.resource.LinkResourceStore; |
51 | +import org.onlab.onos.net.resource.LinkResourceStoreDelegate; | ||
47 | import org.onlab.onos.net.resource.ResourceAllocation; | 52 | import org.onlab.onos.net.resource.ResourceAllocation; |
48 | import org.onlab.onos.net.resource.ResourceRequest; | 53 | import org.onlab.onos.net.resource.ResourceRequest; |
49 | import org.onlab.onos.net.resource.ResourceType; | 54 | import org.onlab.onos.net.resource.ResourceType; |
... | @@ -58,11 +63,18 @@ public class LinkResourceManager implements LinkResourceService { | ... | @@ -58,11 +63,18 @@ public class LinkResourceManager implements LinkResourceService { |
58 | 63 | ||
59 | private final Logger log = getLogger(getClass()); | 64 | private final Logger log = getLogger(getClass()); |
60 | 65 | ||
66 | + protected final AbstractListenerRegistry<LinkResourceEvent, LinkResourceListener> | ||
67 | + listenerRegistry = new AbstractListenerRegistry<>(); | ||
68 | + | ||
61 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 69 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
62 | private LinkResourceStore store; | 70 | private LinkResourceStore store; |
63 | 71 | ||
72 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
73 | + protected EventDeliveryService eventDispatcher; | ||
74 | + | ||
64 | @Activate | 75 | @Activate |
65 | public void activate() { | 76 | public void activate() { |
77 | + eventDispatcher.addSink(LinkResourceEvent.class, listenerRegistry); | ||
66 | log.info("Started"); | 78 | log.info("Started"); |
67 | } | 79 | } |
68 | 80 | ||
... | @@ -150,7 +162,10 @@ public class LinkResourceManager implements LinkResourceService { | ... | @@ -150,7 +162,10 @@ public class LinkResourceManager implements LinkResourceService { |
150 | 162 | ||
151 | @Override | 163 | @Override |
152 | public void releaseResources(LinkResourceAllocations allocations) { | 164 | public void releaseResources(LinkResourceAllocations allocations) { |
153 | - store.releaseResources(allocations); | 165 | + final LinkResourceEvent event = store.releaseResources(allocations); |
166 | + if (event != null) { | ||
167 | + post(event); | ||
168 | + } | ||
154 | } | 169 | } |
155 | 170 | ||
156 | @Override | 171 | @Override |
... | @@ -205,4 +220,32 @@ public class LinkResourceManager implements LinkResourceService { | ... | @@ -205,4 +220,32 @@ public class LinkResourceManager implements LinkResourceService { |
205 | return result; | 220 | return result; |
206 | } | 221 | } |
207 | 222 | ||
223 | + @Override | ||
224 | + public void addListener(LinkResourceListener listener) { | ||
225 | + listenerRegistry.addListener(listener); | ||
226 | + } | ||
227 | + | ||
228 | + @Override | ||
229 | + public void removeListener(LinkResourceListener listener) { | ||
230 | + listenerRegistry.removeListener(listener); | ||
231 | + } | ||
232 | + | ||
233 | + /** | ||
234 | + * Posts the specified event to the local event dispatcher. | ||
235 | + */ | ||
236 | + private void post(LinkResourceEvent event) { | ||
237 | + if (event != null) { | ||
238 | + eventDispatcher.post(event); | ||
239 | + } | ||
240 | + } | ||
241 | + | ||
242 | + /** | ||
243 | + * Store delegate to re-post events emitted from the store. | ||
244 | + */ | ||
245 | + private class InternalStoreDelegate implements LinkResourceStoreDelegate { | ||
246 | + @Override | ||
247 | + public void notify(LinkResourceEvent event) { | ||
248 | + post(event); | ||
249 | + } | ||
250 | + } | ||
208 | } | 251 | } | ... | ... |
... | @@ -15,6 +15,14 @@ | ... | @@ -15,6 +15,14 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.store.resource.impl; | 16 | package org.onlab.onos.store.resource.impl; |
17 | 17 | ||
18 | +import java.util.ArrayList; | ||
19 | +import java.util.Collection; | ||
20 | +import java.util.HashMap; | ||
21 | +import java.util.HashSet; | ||
22 | +import java.util.List; | ||
23 | +import java.util.Map; | ||
24 | +import java.util.Set; | ||
25 | + | ||
18 | import org.apache.felix.scr.annotations.Activate; | 26 | import org.apache.felix.scr.annotations.Activate; |
19 | import org.apache.felix.scr.annotations.Component; | 27 | import org.apache.felix.scr.annotations.Component; |
20 | import org.apache.felix.scr.annotations.Deactivate; | 28 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -30,6 +38,7 @@ import org.onlab.onos.net.resource.BandwidthResourceAllocation; | ... | @@ -30,6 +38,7 @@ import org.onlab.onos.net.resource.BandwidthResourceAllocation; |
30 | import org.onlab.onos.net.resource.Lambda; | 38 | import org.onlab.onos.net.resource.Lambda; |
31 | import org.onlab.onos.net.resource.LambdaResourceAllocation; | 39 | import org.onlab.onos.net.resource.LambdaResourceAllocation; |
32 | import org.onlab.onos.net.resource.LinkResourceAllocations; | 40 | import org.onlab.onos.net.resource.LinkResourceAllocations; |
41 | +import org.onlab.onos.net.resource.LinkResourceEvent; | ||
33 | import org.onlab.onos.net.resource.LinkResourceStore; | 42 | import org.onlab.onos.net.resource.LinkResourceStore; |
34 | import org.onlab.onos.net.resource.ResourceAllocation; | 43 | import org.onlab.onos.net.resource.ResourceAllocation; |
35 | import org.onlab.onos.net.resource.ResourceType; | 44 | import org.onlab.onos.net.resource.ResourceType; |
... | @@ -48,17 +57,10 @@ import org.slf4j.Logger; | ... | @@ -48,17 +57,10 @@ import org.slf4j.Logger; |
48 | 57 | ||
49 | import com.google.common.base.Function; | 58 | import com.google.common.base.Function; |
50 | import com.google.common.collect.FluentIterable; | 59 | import com.google.common.collect.FluentIterable; |
60 | +import com.google.common.collect.ImmutableList; | ||
51 | import com.google.common.collect.ImmutableSet; | 61 | import com.google.common.collect.ImmutableSet; |
52 | import com.google.common.collect.Sets; | 62 | import com.google.common.collect.Sets; |
53 | 63 | ||
54 | -import java.util.ArrayList; | ||
55 | -import java.util.Collection; | ||
56 | -import java.util.HashMap; | ||
57 | -import java.util.HashSet; | ||
58 | -import java.util.List; | ||
59 | -import java.util.Map; | ||
60 | -import java.util.Set; | ||
61 | - | ||
62 | import static com.google.common.base.Preconditions.checkArgument; | 64 | import static com.google.common.base.Preconditions.checkArgument; |
63 | import static com.google.common.base.Preconditions.checkNotNull; | 65 | import static com.google.common.base.Preconditions.checkNotNull; |
64 | import static com.google.common.base.Preconditions.checkState; | 66 | import static com.google.common.base.Preconditions.checkState; |
... | @@ -98,7 +100,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -98,7 +100,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
98 | 100 | ||
99 | // Link annotation key name to use as bandwidth | 101 | // Link annotation key name to use as bandwidth |
100 | private String bandwidthAnnotation = "bandwidth"; | 102 | private String bandwidthAnnotation = "bandwidth"; |
101 | - // Link annotation key name to use as max lamda | 103 | + // Link annotation key name to use as max lambda |
102 | private String wavesAnnotation = "optical.waves"; | 104 | private String wavesAnnotation = "optical.waves"; |
103 | 105 | ||
104 | private StoreSerializer serializer; | 106 | private StoreSerializer serializer; |
... | @@ -423,7 +425,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -423,7 +425,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
423 | } | 425 | } |
424 | 426 | ||
425 | @Override | 427 | @Override |
426 | - public void releaseResources(LinkResourceAllocations allocations) { | 428 | + public LinkResourceEvent releaseResources(LinkResourceAllocations allocations) { |
427 | checkNotNull(allocations); | 429 | checkNotNull(allocations); |
428 | 430 | ||
429 | final IntentId intendId = allocations.intendId(); | 431 | final IntentId intendId = allocations.intendId(); |
... | @@ -458,6 +460,14 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -458,6 +460,14 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
458 | BatchWriteResult batchWrite = databaseService.batchWrite(tx.build()); | 460 | BatchWriteResult batchWrite = databaseService.batchWrite(tx.build()); |
459 | success = batchWrite.isSuccessful(); | 461 | success = batchWrite.isSuccessful(); |
460 | } while (!success); | 462 | } while (!success); |
463 | + | ||
464 | + // Issue events to force recompilation of intents. | ||
465 | + | ||
466 | + final List<LinkResourceAllocations> releasedResources = | ||
467 | + ImmutableList.of(allocations); | ||
468 | + return new LinkResourceEvent( | ||
469 | + LinkResourceEvent.Type.ADDITIONAL_RESOURCES_AVAILABLE, | ||
470 | + releasedResources); | ||
461 | } | 471 | } |
462 | 472 | ||
463 | @Override | 473 | @Override |
... | @@ -565,5 +575,4 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -565,5 +575,4 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
565 | }) | 575 | }) |
566 | .filter(notNull()); | 576 | .filter(notNull()); |
567 | } | 577 | } |
568 | - | ||
569 | } | 578 | } | ... | ... |
... | @@ -15,13 +15,10 @@ | ... | @@ -15,13 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.store.trivial.impl; | 16 | package org.onlab.onos.store.trivial.impl; |
17 | 17 | ||
18 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | -import static com.google.common.base.Preconditions.checkState; | ||
20 | -import static org.slf4j.LoggerFactory.getLogger; | ||
21 | - | ||
22 | import java.util.Collections; | 18 | import java.util.Collections; |
23 | import java.util.HashMap; | 19 | import java.util.HashMap; |
24 | import java.util.HashSet; | 20 | import java.util.HashSet; |
21 | +import java.util.List; | ||
25 | import java.util.Map; | 22 | import java.util.Map; |
26 | import java.util.Set; | 23 | import java.util.Set; |
27 | 24 | ||
... | @@ -38,11 +35,18 @@ import org.onlab.onos.net.resource.BandwidthResourceAllocation; | ... | @@ -38,11 +35,18 @@ import org.onlab.onos.net.resource.BandwidthResourceAllocation; |
38 | import org.onlab.onos.net.resource.Lambda; | 35 | import org.onlab.onos.net.resource.Lambda; |
39 | import org.onlab.onos.net.resource.LambdaResourceAllocation; | 36 | import org.onlab.onos.net.resource.LambdaResourceAllocation; |
40 | import org.onlab.onos.net.resource.LinkResourceAllocations; | 37 | import org.onlab.onos.net.resource.LinkResourceAllocations; |
38 | +import org.onlab.onos.net.resource.LinkResourceEvent; | ||
41 | import org.onlab.onos.net.resource.LinkResourceStore; | 39 | import org.onlab.onos.net.resource.LinkResourceStore; |
42 | import org.onlab.onos.net.resource.ResourceAllocation; | 40 | import org.onlab.onos.net.resource.ResourceAllocation; |
43 | import org.onlab.onos.net.resource.ResourceType; | 41 | import org.onlab.onos.net.resource.ResourceType; |
44 | import org.slf4j.Logger; | 42 | import org.slf4j.Logger; |
45 | 43 | ||
44 | +import com.google.common.collect.ImmutableList; | ||
45 | + | ||
46 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
47 | +import static com.google.common.base.Preconditions.checkState; | ||
48 | +import static org.slf4j.LoggerFactory.getLogger; | ||
49 | + | ||
46 | /** | 50 | /** |
47 | * Manages link resources using trivial in-memory structures implementation. | 51 | * Manages link resources using trivial in-memory structures implementation. |
48 | */ | 52 | */ |
... | @@ -51,6 +55,7 @@ import org.slf4j.Logger; | ... | @@ -51,6 +55,7 @@ import org.slf4j.Logger; |
51 | public class SimpleLinkResourceStore implements LinkResourceStore { | 55 | public class SimpleLinkResourceStore implements LinkResourceStore { |
52 | private static final int DEFAULT_BANDWIDTH = 1_000; | 56 | private static final int DEFAULT_BANDWIDTH = 1_000; |
53 | private final Logger log = getLogger(getClass()); | 57 | private final Logger log = getLogger(getClass()); |
58 | + | ||
54 | private Map<IntentId, LinkResourceAllocations> linkResourceAllocationsMap; | 59 | private Map<IntentId, LinkResourceAllocations> linkResourceAllocationsMap; |
55 | private Map<Link, Set<LinkResourceAllocations>> allocatedResources; | 60 | private Map<Link, Set<LinkResourceAllocations>> allocatedResources; |
56 | private Map<Link, Set<ResourceAllocation>> freeResources; | 61 | private Map<Link, Set<ResourceAllocation>> freeResources; |
... | @@ -213,7 +218,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -213,7 +218,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
213 | } | 218 | } |
214 | 219 | ||
215 | @Override | 220 | @Override |
216 | - public synchronized void releaseResources(LinkResourceAllocations allocations) { | 221 | + public synchronized LinkResourceEvent releaseResources(LinkResourceAllocations allocations) { |
217 | checkNotNull(allocations); | 222 | checkNotNull(allocations); |
218 | linkResourceAllocationsMap.remove(allocations.intendId()); | 223 | linkResourceAllocationsMap.remove(allocations.intendId()); |
219 | for (Link link : allocations.links()) { | 224 | for (Link link : allocations.links()) { |
... | @@ -226,6 +231,13 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -226,6 +231,13 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
226 | } | 231 | } |
227 | allocatedResources.put(link, linkAllocs); | 232 | allocatedResources.put(link, linkAllocs); |
228 | } | 233 | } |
234 | + | ||
235 | + final List<LinkResourceAllocations> releasedResources = | ||
236 | + ImmutableList.of(allocations); | ||
237 | + | ||
238 | + return new LinkResourceEvent( | ||
239 | + LinkResourceEvent.Type.ADDITIONAL_RESOURCES_AVAILABLE, | ||
240 | + releasedResources); | ||
229 | } | 241 | } |
230 | 242 | ||
231 | @Override | 243 | @Override |
... | @@ -249,4 +261,5 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -249,4 +261,5 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
249 | return Collections.unmodifiableCollection(linkResourceAllocationsMap.values()); | 261 | return Collections.unmodifiableCollection(linkResourceAllocationsMap.values()); |
250 | } | 262 | } |
251 | 263 | ||
264 | + | ||
252 | } | 265 | } | ... | ... |
... | @@ -15,13 +15,6 @@ | ... | @@ -15,13 +15,6 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.store.trivial.impl; | 16 | package org.onlab.onos.store.trivial.impl; |
17 | 17 | ||
18 | -import static org.junit.Assert.assertEquals; | ||
19 | -import static org.junit.Assert.assertFalse; | ||
20 | -import static org.junit.Assert.assertNotNull; | ||
21 | -import static org.onlab.onos.net.DeviceId.deviceId; | ||
22 | -import static org.onlab.onos.net.Link.Type.DIRECT; | ||
23 | -import static org.onlab.onos.net.PortNumber.portNumber; | ||
24 | - | ||
25 | import java.util.HashSet; | 18 | import java.util.HashSet; |
26 | import java.util.Set; | 19 | import java.util.Set; |
27 | 20 | ||
... | @@ -43,6 +36,13 @@ import org.onlab.onos.net.resource.LinkResourceStore; | ... | @@ -43,6 +36,13 @@ import org.onlab.onos.net.resource.LinkResourceStore; |
43 | import org.onlab.onos.net.resource.ResourceAllocation; | 36 | import org.onlab.onos.net.resource.ResourceAllocation; |
44 | import org.onlab.onos.net.resource.ResourceType; | 37 | import org.onlab.onos.net.resource.ResourceType; |
45 | 38 | ||
39 | +import static org.junit.Assert.assertEquals; | ||
40 | +import static org.junit.Assert.assertFalse; | ||
41 | +import static org.junit.Assert.assertNotNull; | ||
42 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
43 | +import static org.onlab.onos.net.Link.Type.DIRECT; | ||
44 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
45 | + | ||
46 | /** | 46 | /** |
47 | * Test of the simple LinkResourceStore implementation. | 47 | * Test of the simple LinkResourceStore implementation. |
48 | */ | 48 | */ | ... | ... |
-
Please register or login to post a comment