Brian O'Connor

IntentInstaller: changing from Set to Collection to improve perf

Change-Id: Ia7f0f7d893645c7528ac9f51acff133f6d82383d
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
15 */ 15 */
16 package org.onosproject.net.intent; 16 package org.onosproject.net.intent;
17 17
18 -import java.util.List;
19 -import java.util.Set;
20 -
21 import org.onosproject.net.flow.FlowRuleOperation; 18 import org.onosproject.net.flow.FlowRuleOperation;
22 19
20 +import java.util.Collection;
21 +import java.util.List;
22 +
23 /** 23 /**
24 * Abstraction of entity capable of installing intents to the environment. 24 * Abstraction of entity capable of installing intents to the environment.
25 */ 25 */
...@@ -32,7 +32,7 @@ public interface IntentInstaller<T extends Intent> { ...@@ -32,7 +32,7 @@ public interface IntentInstaller<T extends Intent> {
32 * @return flow rule operations to complete install 32 * @return flow rule operations to complete install
33 * @throws IntentException if issues are encountered while installing the intent 33 * @throws IntentException if issues are encountered while installing the intent
34 */ 34 */
35 - List<Set<FlowRuleOperation>> install(T intent); 35 + List<Collection<FlowRuleOperation>> install(T intent);
36 36
37 /** 37 /**
38 * Uninstalls the specified intent from the environment. 38 * Uninstalls the specified intent from the environment.
...@@ -41,7 +41,7 @@ public interface IntentInstaller<T extends Intent> { ...@@ -41,7 +41,7 @@ public interface IntentInstaller<T extends Intent> {
41 * @return flow rule operations to complete uninstall 41 * @return flow rule operations to complete uninstall
42 * @throws IntentException if issues are encountered while uninstalling the intent 42 * @throws IntentException if issues are encountered while uninstalling the intent
43 */ 43 */
44 - List<Set<FlowRuleOperation>> uninstall(T intent); 44 + List<Collection<FlowRuleOperation>> uninstall(T intent);
45 45
46 /** 46 /**
47 * Replaces the specified intent with a new one in the environment. 47 * Replaces the specified intent with a new one in the environment.
...@@ -51,6 +51,6 @@ public interface IntentInstaller<T extends Intent> { ...@@ -51,6 +51,6 @@ public interface IntentInstaller<T extends Intent> {
51 * @return flow rule operations to complete the replace 51 * @return flow rule operations to complete the replace
52 * @throws IntentException if issues are encountered while uninstalling the intent 52 * @throws IntentException if issues are encountered while uninstalling the intent
53 */ 53 */
54 - List<Set<FlowRuleOperation>> replace(T oldIntent, T newIntent); 54 + List<Collection<FlowRuleOperation>> replace(T oldIntent, T newIntent);
55 55
56 } 56 }
......
...@@ -15,28 +15,23 @@ ...@@ -15,28 +15,23 @@
15 */ 15 */
16 package org.onosproject.net.intent; 16 package org.onosproject.net.intent;
17 17
18 -import static org.junit.Assert.assertEquals; 18 +import org.junit.After;
19 -import static org.junit.Assert.assertFalse; 19 +import org.junit.Before;
20 -import static org.junit.Assert.assertNull; 20 +import org.junit.Test;
21 -import static org.junit.Assert.fail; 21 +import org.onosproject.core.IdGenerator;
22 -import static org.onosproject.net.intent.IntentEvent.Type.FAILED; 22 +import org.onosproject.net.flow.FlowRuleOperation;
23 -import static org.onosproject.net.intent.IntentEvent.Type.INSTALLED; 23 +import org.onosproject.net.resource.LinkResourceAllocations;
24 -import static org.onosproject.net.intent.IntentEvent.Type.INSTALL_REQ;
25 -import static org.onosproject.net.intent.IntentEvent.Type.WITHDRAWN;
26 24
27 import java.util.ArrayList; 25 import java.util.ArrayList;
28 import java.util.Arrays; 26 import java.util.Arrays;
27 +import java.util.Collection;
29 import java.util.Collections; 28 import java.util.Collections;
30 import java.util.Iterator; 29 import java.util.Iterator;
31 import java.util.List; 30 import java.util.List;
32 import java.util.Set; 31 import java.util.Set;
33 32
34 -import org.junit.After; 33 +import static org.junit.Assert.*;
35 -import org.junit.Before; 34 +import static org.onosproject.net.intent.IntentEvent.Type.*;
36 -import org.junit.Test;
37 -import org.onosproject.core.IdGenerator;
38 -import org.onosproject.net.flow.FlowRuleOperation;
39 -import org.onosproject.net.resource.LinkResourceAllocations;
40 35
41 /** 36 /**
42 * Suite of tests for the intent service contract. 37 * Suite of tests for the intent service contract.
...@@ -319,7 +314,7 @@ public class IntentServiceTest { ...@@ -319,7 +314,7 @@ public class IntentServiceTest {
319 } 314 }
320 315
321 @Override 316 @Override
322 - public List<Set<FlowRuleOperation>> install(TestInstallableIntent intent) { 317 + public List<Collection<FlowRuleOperation>> install(TestInstallableIntent intent) {
323 if (fail) { 318 if (fail) {
324 throw new IntentException("install failed by design"); 319 throw new IntentException("install failed by design");
325 } 320 }
...@@ -327,7 +322,7 @@ public class IntentServiceTest { ...@@ -327,7 +322,7 @@ public class IntentServiceTest {
327 } 322 }
328 323
329 @Override 324 @Override
330 - public List<Set<FlowRuleOperation>> uninstall(TestInstallableIntent intent) { 325 + public List<Collection<FlowRuleOperation>> uninstall(TestInstallableIntent intent) {
331 if (fail) { 326 if (fail) {
332 throw new IntentException("remove failed by design"); 327 throw new IntentException("remove failed by design");
333 } 328 }
...@@ -335,7 +330,7 @@ public class IntentServiceTest { ...@@ -335,7 +330,7 @@ public class IntentServiceTest {
335 } 330 }
336 331
337 @Override 332 @Override
338 - public List<Set<FlowRuleOperation>> replace(TestInstallableIntent intent, 333 + public List<Collection<FlowRuleOperation>> replace(TestInstallableIntent intent,
339 TestInstallableIntent newIntent) { 334 TestInstallableIntent newIntent) {
340 return null; 335 return null;
341 } 336 }
......
...@@ -15,23 +15,8 @@ ...@@ -15,23 +15,8 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import java.util.ArrayList; 18 +import com.google.common.collect.ImmutableList;
19 -import java.util.Collection; 19 +import com.google.common.collect.ImmutableMap;
20 -import java.util.Collections;
21 -import java.util.EnumSet;
22 -import java.util.Iterator;
23 -import java.util.List;
24 -import java.util.Map;
25 -import java.util.Optional;
26 -import java.util.Set;
27 -import java.util.concurrent.Callable;
28 -import java.util.concurrent.ConcurrentHashMap;
29 -import java.util.concurrent.ConcurrentMap;
30 -import java.util.concurrent.ExecutionException;
31 -import java.util.concurrent.ExecutorService;
32 -import java.util.concurrent.Future;
33 -import java.util.stream.Collectors;
34 -
35 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
36 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
37 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
...@@ -68,8 +53,21 @@ import org.onosproject.net.intent.impl.phase.WithdrawRequest; ...@@ -68,8 +53,21 @@ import org.onosproject.net.intent.impl.phase.WithdrawRequest;
68 import org.onosproject.net.intent.impl.phase.Withdrawn; 53 import org.onosproject.net.intent.impl.phase.Withdrawn;
69 import org.slf4j.Logger; 54 import org.slf4j.Logger;
70 55
71 -import com.google.common.collect.ImmutableList; 56 +import java.util.ArrayList;
72 -import com.google.common.collect.ImmutableMap; 57 +import java.util.Collection;
58 +import java.util.Collections;
59 +import java.util.EnumSet;
60 +import java.util.Iterator;
61 +import java.util.List;
62 +import java.util.Map;
63 +import java.util.Optional;
64 +import java.util.concurrent.Callable;
65 +import java.util.concurrent.ConcurrentHashMap;
66 +import java.util.concurrent.ConcurrentMap;
67 +import java.util.concurrent.ExecutionException;
68 +import java.util.concurrent.ExecutorService;
69 +import java.util.concurrent.Future;
70 +import java.util.stream.Collectors;
73 71
74 import static com.google.common.base.Preconditions.checkNotNull; 72 import static com.google.common.base.Preconditions.checkNotNull;
75 import static com.google.common.base.Preconditions.checkState; 73 import static com.google.common.base.Preconditions.checkState;
...@@ -77,11 +75,7 @@ import static java.util.concurrent.Executors.newFixedThreadPool; ...@@ -77,11 +75,7 @@ import static java.util.concurrent.Executors.newFixedThreadPool;
77 import static java.util.concurrent.Executors.newSingleThreadExecutor; 75 import static java.util.concurrent.Executors.newSingleThreadExecutor;
78 import static org.onlab.util.Tools.groupedThreads; 76 import static org.onlab.util.Tools.groupedThreads;
79 import static org.onlab.util.Tools.isNullOrEmpty; 77 import static org.onlab.util.Tools.isNullOrEmpty;
80 -import static org.onosproject.net.intent.IntentState.FAILED; 78 +import static org.onosproject.net.intent.IntentState.*;
81 -import static org.onosproject.net.intent.IntentState.INSTALLED;
82 -import static org.onosproject.net.intent.IntentState.INSTALL_REQ;
83 -import static org.onosproject.net.intent.IntentState.WITHDRAWN;
84 -import static org.onosproject.net.intent.IntentState.WITHDRAW_REQ;
85 import static org.slf4j.LoggerFactory.getLogger; 79 import static org.slf4j.LoggerFactory.getLogger;
86 80
87 /** 81 /**
...@@ -310,7 +304,7 @@ public class IntentManager ...@@ -310,7 +304,7 @@ public class IntentManager
310 oldInstallables.size() == newInstallables.size(), 304 oldInstallables.size() == newInstallables.size(),
311 "Old and New Intent must have equivalent installable intents."); 305 "Old and New Intent must have equivalent installable intents.");
312 306
313 - List<List<Set<FlowRuleOperation>>> plans = new ArrayList<>(); 307 + List<List<Collection<FlowRuleOperation>>> plans = new ArrayList<>();
314 for (int i = 0; i < newInstallables.size(); i++) { 308 for (int i = 0; i < newInstallables.size(); i++) {
315 Intent newInstallable = newInstallables.get(i); 309 Intent newInstallable = newInstallables.get(i);
316 registerSubclassInstallerIfNeeded(newInstallable); 310 registerSubclassInstallerIfNeeded(newInstallable);
...@@ -369,7 +363,7 @@ public class IntentManager ...@@ -369,7 +363,7 @@ public class IntentManager
369 // TODO: make this non-public due to short term hack for ONOS-1051 363 // TODO: make this non-public due to short term hack for ONOS-1051
370 public FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) { 364 public FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) {
371 List<Intent> installables = current.installables(); 365 List<Intent> installables = current.installables();
372 - List<List<Set<FlowRuleOperation>>> plans = new ArrayList<>(); 366 + List<List<Collection<FlowRuleOperation>>> plans = new ArrayList<>();
373 for (Intent installable : installables) { 367 for (Intent installable : installables) {
374 plans.add(getInstaller(installable).uninstall(installable)); 368 plans.add(getInstaller(installable).uninstall(installable));
375 trackerService.removeTrackedResources(pending.key(), installable.resources()); 369 trackerService.removeTrackedResources(pending.key(), installable.resources());
...@@ -395,20 +389,20 @@ public class IntentManager ...@@ -395,20 +389,20 @@ public class IntentManager
395 389
396 390
397 // TODO needs tests... or maybe it's just perfect 391 // TODO needs tests... or maybe it's just perfect
398 - private FlowRuleOperations.Builder merge(List<List<Set<FlowRuleOperation>>> plans) { 392 + private FlowRuleOperations.Builder merge(List<List<Collection<FlowRuleOperation>>> plans) {
399 FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); 393 FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
400 // Build a batch one stage at a time 394 // Build a batch one stage at a time
401 for (int stageNumber = 0;; stageNumber++) { 395 for (int stageNumber = 0;; stageNumber++) {
402 // Get the sub-stage from each plan (List<Set<FlowRuleOperation>) 396 // Get the sub-stage from each plan (List<Set<FlowRuleOperation>)
403 - for (Iterator<List<Set<FlowRuleOperation>>> itr = plans.iterator(); itr.hasNext();) { 397 + for (Iterator<List<Collection<FlowRuleOperation>>> itr = plans.iterator(); itr.hasNext();) {
404 - List<Set<FlowRuleOperation>> plan = itr.next(); 398 + List<Collection<FlowRuleOperation>> plan = itr.next();
405 if (plan.size() <= stageNumber) { 399 if (plan.size() <= stageNumber) {
406 // we have consumed all stages from this plan, so remove it 400 // we have consumed all stages from this plan, so remove it
407 itr.remove(); 401 itr.remove();
408 continue; 402 continue;
409 } 403 }
410 // write operations from this sub-stage into the builder 404 // write operations from this sub-stage into the builder
411 - Set<FlowRuleOperation> stage = plan.get(stageNumber); 405 + Collection<FlowRuleOperation> stage = plan.get(stageNumber);
412 for (FlowRuleOperation entry : stage) { 406 for (FlowRuleOperation entry : stage) {
413 builder.operation(entry); 407 builder.operation(entry);
414 } 408 }
......
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import java.util.List; 18 +import com.google.common.collect.HashMultimap;
19 -import java.util.Set; 19 +import com.google.common.collect.ImmutableSet;
20 -import java.util.stream.Collectors; 20 +import com.google.common.collect.Lists;
21 - 21 +import com.google.common.collect.SetMultimap;
22 import org.apache.felix.scr.annotations.Activate; 22 import org.apache.felix.scr.annotations.Activate;
23 import org.apache.felix.scr.annotations.Component; 23 import org.apache.felix.scr.annotations.Component;
24 import org.apache.felix.scr.annotations.Deactivate; 24 import org.apache.felix.scr.annotations.Deactivate;
...@@ -42,10 +42,10 @@ import org.onosproject.net.intent.IntentExtensionService; ...@@ -42,10 +42,10 @@ import org.onosproject.net.intent.IntentExtensionService;
42 import org.onosproject.net.intent.IntentInstaller; 42 import org.onosproject.net.intent.IntentInstaller;
43 import org.onosproject.net.intent.LinkCollectionIntent; 43 import org.onosproject.net.intent.LinkCollectionIntent;
44 44
45 -import com.google.common.collect.HashMultimap; 45 +import java.util.Collection;
46 -import com.google.common.collect.ImmutableSet; 46 +import java.util.List;
47 -import com.google.common.collect.Lists; 47 +import java.util.Set;
48 -import com.google.common.collect.SetMultimap; 48 +import java.util.stream.Collectors;
49 49
50 /** 50 /**
51 * Installer for {@link org.onosproject.net.intent.LinkCollectionIntent} path 51 * Installer for {@link org.onosproject.net.intent.LinkCollectionIntent} path
...@@ -75,18 +75,19 @@ public class LinkCollectionIntentInstaller ...@@ -75,18 +75,19 @@ public class LinkCollectionIntentInstaller
75 } 75 }
76 76
77 @Override 77 @Override
78 - public List<Set<FlowRuleOperation>> install(LinkCollectionIntent intent) { 78 + public List<Collection<FlowRuleOperation>> install(LinkCollectionIntent intent) {
79 return generateBatchOperations(intent, FlowRuleOperation.Type.ADD); 79 return generateBatchOperations(intent, FlowRuleOperation.Type.ADD);
80 } 80 }
81 81
82 @Override 82 @Override
83 - public List<Set<FlowRuleOperation>> uninstall(LinkCollectionIntent intent) { 83 + public List<Collection<FlowRuleOperation>> uninstall(LinkCollectionIntent intent) {
84 return generateBatchOperations(intent, FlowRuleOperation.Type.REMOVE); 84 return generateBatchOperations(intent, FlowRuleOperation.Type.REMOVE);
85 } 85 }
86 86
87 - private List<Set<FlowRuleOperation>> generateBatchOperations( 87 + private List<Collection<FlowRuleOperation>> generateBatchOperations(
88 LinkCollectionIntent intent, FlowRuleOperation.Type operation) { 88 LinkCollectionIntent intent, FlowRuleOperation.Type operation) {
89 89
90 + //TODO do we need a set here?
90 SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); 91 SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
91 92
92 for (Link link : intent.links()) { 93 for (Link link : intent.links()) {
...@@ -121,10 +122,10 @@ public class LinkCollectionIntentInstaller ...@@ -121,10 +122,10 @@ public class LinkCollectionIntentInstaller
121 } 122 }
122 123
123 @Override 124 @Override
124 - public List<Set<FlowRuleOperation>> replace(LinkCollectionIntent oldIntent, 125 + public List<Collection<FlowRuleOperation>> replace(LinkCollectionIntent oldIntent,
125 LinkCollectionIntent newIntent) { 126 LinkCollectionIntent newIntent) {
126 // FIXME: implement this in a more intelligent/less brute force way 127 // FIXME: implement this in a more intelligent/less brute force way
127 - List<Set<FlowRuleOperation>> batches = Lists.newArrayList(); 128 + List<Collection<FlowRuleOperation>> batches = Lists.newArrayList();
128 batches.addAll(uninstall(oldIntent)); 129 batches.addAll(uninstall(oldIntent));
129 batches.addAll(install(newIntent)); 130 batches.addAll(install(newIntent));
130 return batches; 131 return batches;
......
1 package org.onosproject.net.intent.impl; 1 package org.onosproject.net.intent.impl;
2 2
3 -import java.util.Iterator; 3 +import com.google.common.collect.ImmutableSet;
4 -import java.util.List; 4 +import com.google.common.collect.Lists;
5 -import java.util.Set; 5 +import com.google.common.collect.Sets;
6 -
7 import org.apache.felix.scr.annotations.Activate; 6 import org.apache.felix.scr.annotations.Activate;
8 import org.apache.felix.scr.annotations.Component; 7 import org.apache.felix.scr.annotations.Component;
9 import org.apache.felix.scr.annotations.Deactivate; 8 import org.apache.felix.scr.annotations.Deactivate;
...@@ -40,9 +39,10 @@ import org.onosproject.net.resource.ResourceAllocation; ...@@ -40,9 +39,10 @@ import org.onosproject.net.resource.ResourceAllocation;
40 import org.onosproject.net.resource.ResourceType; 39 import org.onosproject.net.resource.ResourceType;
41 import org.slf4j.Logger; 40 import org.slf4j.Logger;
42 41
43 -import com.google.common.collect.ImmutableSet; 42 +import java.util.Collection;
44 -import com.google.common.collect.Lists; 43 +import java.util.Iterator;
45 -import com.google.common.collect.Sets; 44 +import java.util.List;
45 +import java.util.Set;
46 46
47 import static com.google.common.base.Preconditions.checkNotNull; 47 import static com.google.common.base.Preconditions.checkNotNull;
48 import static org.slf4j.LoggerFactory.getLogger; 48 import static org.slf4j.LoggerFactory.getLogger;
...@@ -81,14 +81,14 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> ...@@ -81,14 +81,14 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
81 } 81 }
82 82
83 @Override 83 @Override
84 - public List<Set<FlowRuleOperation>> install(MplsPathIntent intent) { 84 + public List<Collection<FlowRuleOperation>> install(MplsPathIntent intent) {
85 LinkResourceAllocations allocations = assignMplsLabel(intent); 85 LinkResourceAllocations allocations = assignMplsLabel(intent);
86 return generateRules(intent, allocations, FlowRuleOperation.Type.ADD); 86 return generateRules(intent, allocations, FlowRuleOperation.Type.ADD);
87 87
88 } 88 }
89 89
90 @Override 90 @Override
91 - public List<Set<FlowRuleOperation>> uninstall(MplsPathIntent intent) { 91 + public List<Collection<FlowRuleOperation>> uninstall(MplsPathIntent intent) {
92 LinkResourceAllocations allocations = resourceService 92 LinkResourceAllocations allocations = resourceService
93 .getAllocations(intent.id()); 93 .getAllocations(intent.id());
94 resourceService.releaseResources(allocations); 94 resourceService.releaseResources(allocations);
...@@ -97,10 +97,10 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> ...@@ -97,10 +97,10 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
97 } 97 }
98 98
99 @Override 99 @Override
100 - public List<Set<FlowRuleOperation>> replace(MplsPathIntent oldIntent, 100 + public List<Collection<FlowRuleOperation>> replace(MplsPathIntent oldIntent,
101 MplsPathIntent newIntent) { 101 MplsPathIntent newIntent) {
102 - 102 + //FIXME this is brute force
103 - List<Set<FlowRuleOperation>> batches = Lists.newArrayList(); 103 + List<Collection<FlowRuleOperation>> batches = Lists.newArrayList();
104 batches.addAll(uninstall(oldIntent)); 104 batches.addAll(uninstall(oldIntent));
105 batches.addAll(install(newIntent)); 105 batches.addAll(install(newIntent));
106 return batches; 106 return batches;
...@@ -140,7 +140,7 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> ...@@ -140,7 +140,7 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
140 return null; 140 return null;
141 } 141 }
142 142
143 - private List<Set<FlowRuleOperation>> generateRules(MplsPathIntent intent, 143 + private List<Collection<FlowRuleOperation>> generateRules(MplsPathIntent intent,
144 LinkResourceAllocations allocations, 144 LinkResourceAllocations allocations,
145 FlowRuleOperation.Type operation) { 145 FlowRuleOperation.Type operation) {
146 146
...@@ -150,7 +150,7 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> ...@@ -150,7 +150,7 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
150 150
151 Link link = links.next(); 151 Link link = links.next();
152 // List of flow rules to be installed 152 // List of flow rules to be installed
153 - Set<FlowRuleOperation> rules = Sets.newHashSet(); 153 + List<FlowRuleOperation> rules = Lists.newLinkedList();
154 154
155 // Ingress traffic 155 // Ingress traffic
156 // Get the new MPLS label 156 // Get the new MPLS label
......
...@@ -49,10 +49,10 @@ import static com.google.common.base.Preconditions.checkArgument; ...@@ -49,10 +49,10 @@ import static com.google.common.base.Preconditions.checkArgument;
49 import static com.google.common.base.Preconditions.checkNotNull; 49 import static com.google.common.base.Preconditions.checkNotNull;
50 import static com.google.common.collect.Multimaps.synchronizedSetMultimap; 50 import static com.google.common.collect.Multimaps.synchronizedSetMultimap;
51 import static java.util.concurrent.Executors.newSingleThreadExecutor; 51 import static java.util.concurrent.Executors.newSingleThreadExecutor;
52 +import static org.onlab.util.Tools.namedThreads;
52 import static org.onosproject.net.LinkKey.linkKey; 53 import static org.onosproject.net.LinkKey.linkKey;
53 import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED; 54 import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED;
54 import static org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED; 55 import static org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED;
55 -import static org.onlab.util.Tools.namedThreads;
56 import static org.slf4j.LoggerFactory.getLogger; 56 import static org.slf4j.LoggerFactory.getLogger;
57 57
58 /** 58 /**
...@@ -66,6 +66,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { ...@@ -66,6 +66,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
66 private final Logger log = getLogger(getClass()); 66 private final Logger log = getLogger(getClass());
67 67
68 private final SetMultimap<LinkKey, Key> intentsByLink = 68 private final SetMultimap<LinkKey, Key> intentsByLink =
69 + //TODO this could be slow as a point of synchronization
69 synchronizedSetMultimap(HashMultimap.<LinkKey, Key>create()); 70 synchronizedSetMultimap(HashMultimap.<LinkKey, Key>create());
70 71
71 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 72 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......
...@@ -15,9 +15,8 @@ ...@@ -15,9 +15,8 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import java.util.List; 18 +import com.google.common.collect.ImmutableSet;
19 -import java.util.Set; 19 +import com.google.common.collect.Lists;
20 -
21 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
22 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
23 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
...@@ -49,9 +48,8 @@ import org.onosproject.net.resource.ResourceType; ...@@ -49,9 +48,8 @@ import org.onosproject.net.resource.ResourceType;
49 import org.onosproject.net.topology.TopologyService; 48 import org.onosproject.net.topology.TopologyService;
50 import org.slf4j.Logger; 49 import org.slf4j.Logger;
51 50
52 -import com.google.common.collect.ImmutableSet; 51 +import java.util.Collection;
53 -import com.google.common.collect.Lists; 52 +import java.util.List;
54 -import com.google.common.collect.Sets;
55 53
56 import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; 54 import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
57 import static org.slf4j.LoggerFactory.getLogger; 55 import static org.slf4j.LoggerFactory.getLogger;
...@@ -94,24 +92,24 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn ...@@ -94,24 +92,24 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
94 } 92 }
95 93
96 @Override 94 @Override
97 - public List<Set<FlowRuleOperation>> install(OpticalPathIntent intent) { 95 + public List<Collection<FlowRuleOperation>> install(OpticalPathIntent intent) {
98 LinkResourceAllocations allocations = assignWavelength(intent); 96 LinkResourceAllocations allocations = assignWavelength(intent);
99 return generateRules(intent, allocations, FlowRuleOperation.Type.ADD); 97 return generateRules(intent, allocations, FlowRuleOperation.Type.ADD);
100 } 98 }
101 99
102 @Override 100 @Override
103 - public List<Set<FlowRuleOperation>> uninstall(OpticalPathIntent intent) { 101 + public List<Collection<FlowRuleOperation>> uninstall(OpticalPathIntent intent) {
104 LinkResourceAllocations allocations = resourceService.getAllocations(intent.id()); 102 LinkResourceAllocations allocations = resourceService.getAllocations(intent.id());
105 - List<Set<FlowRuleOperation>> rules = generateRules(intent, allocations, FlowRuleOperation.Type.REMOVE); 103 + List<Collection<FlowRuleOperation>> rules = generateRules(intent, allocations, FlowRuleOperation.Type.REMOVE);
106 log.info("uninstall rules: {}", rules); 104 log.info("uninstall rules: {}", rules);
107 return rules; 105 return rules;
108 } 106 }
109 107
110 @Override 108 @Override
111 - public List<Set<FlowRuleOperation>> replace(OpticalPathIntent oldIntent, 109 + public List<Collection<FlowRuleOperation>> replace(OpticalPathIntent oldIntent,
112 OpticalPathIntent newIntent) { 110 OpticalPathIntent newIntent) {
113 // FIXME: implement this 111 // FIXME: implement this
114 - List<Set<FlowRuleOperation>> batches = Lists.newArrayList(); 112 + List<Collection<FlowRuleOperation>> batches = Lists.newArrayList();
115 batches.addAll(uninstall(oldIntent)); 113 batches.addAll(uninstall(oldIntent));
116 batches.addAll(install(newIntent)); 114 batches.addAll(install(newIntent));
117 return batches; 115 return batches;
...@@ -125,13 +123,13 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn ...@@ -125,13 +123,13 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
125 return retLambda; 123 return retLambda;
126 } 124 }
127 125
128 - private List<Set<FlowRuleOperation>> generateRules(OpticalPathIntent intent, 126 + private List<Collection<FlowRuleOperation>> generateRules(OpticalPathIntent intent,
129 LinkResourceAllocations allocations, 127 LinkResourceAllocations allocations,
130 FlowRuleOperation.Type operation) { 128 FlowRuleOperation.Type operation) {
131 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); 129 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
132 selectorBuilder.matchInPort(intent.src().port()); 130 selectorBuilder.matchInPort(intent.src().port());
133 131
134 - Set<FlowRuleOperation> rules = Sets.newHashSet(); 132 + List<FlowRuleOperation> rules = Lists.newLinkedList();
135 ConnectPoint prev = intent.src(); 133 ConnectPoint prev = intent.src();
136 134
137 //FIXME check for null allocations 135 //FIXME check for null allocations
......
...@@ -15,10 +15,8 @@ ...@@ -15,10 +15,8 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import java.util.Iterator; 18 +import com.google.common.collect.ImmutableSet;
19 -import java.util.List; 19 +import com.google.common.collect.Lists;
20 -import java.util.Set;
21 -
22 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
23 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
24 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
...@@ -45,9 +43,9 @@ import org.onosproject.net.resource.LinkResourceRequest; ...@@ -45,9 +43,9 @@ import org.onosproject.net.resource.LinkResourceRequest;
45 import org.onosproject.net.resource.LinkResourceService; 43 import org.onosproject.net.resource.LinkResourceService;
46 import org.slf4j.Logger; 44 import org.slf4j.Logger;
47 45
48 -import com.google.common.collect.ImmutableSet; 46 +import java.util.Collection;
49 -import com.google.common.collect.Lists; 47 +import java.util.Iterator;
50 -import com.google.common.collect.Sets; 48 +import java.util.List;
51 49
52 import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; 50 import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
53 import static org.slf4j.LoggerFactory.getLogger; 51 import static org.slf4j.LoggerFactory.getLogger;
...@@ -83,14 +81,14 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -83,14 +81,14 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
83 } 81 }
84 82
85 @Override 83 @Override
86 - public List<Set<FlowRuleOperation>> install(PathIntent intent) { 84 + public List<Collection<FlowRuleOperation>> install(PathIntent intent) {
87 LinkResourceAllocations allocations = allocateResources(intent); 85 LinkResourceAllocations allocations = allocateResources(intent);
88 86
89 TrafficSelector.Builder builder = 87 TrafficSelector.Builder builder =
90 DefaultTrafficSelector.builder(intent.selector()); 88 DefaultTrafficSelector.builder(intent.selector());
91 Iterator<Link> links = intent.path().links().iterator(); 89 Iterator<Link> links = intent.path().links().iterator();
92 ConnectPoint prev = links.next().dst(); 90 ConnectPoint prev = links.next().dst();
93 - Set<FlowRuleOperation> rules = Sets.newHashSet(); 91 + List<FlowRuleOperation> rules = Lists.newLinkedList();
94 // TODO Generate multiple batches 92 // TODO Generate multiple batches
95 while (links.hasNext()) { 93 while (links.hasNext()) {
96 builder.matchInPort(prev.port()); 94 builder.matchInPort(prev.port());
...@@ -113,13 +111,13 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -113,13 +111,13 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
113 } 111 }
114 112
115 @Override 113 @Override
116 - public List<Set<FlowRuleOperation>> uninstall(PathIntent intent) { 114 + public List<Collection<FlowRuleOperation>> uninstall(PathIntent intent) {
117 deallocateResources(intent); 115 deallocateResources(intent);
118 TrafficSelector.Builder builder = 116 TrafficSelector.Builder builder =
119 DefaultTrafficSelector.builder(intent.selector()); 117 DefaultTrafficSelector.builder(intent.selector());
120 Iterator<Link> links = intent.path().links().iterator(); 118 Iterator<Link> links = intent.path().links().iterator();
121 ConnectPoint prev = links.next().dst(); 119 ConnectPoint prev = links.next().dst();
122 - Set<FlowRuleOperation> rules = Sets.newHashSet(); 120 + List<FlowRuleOperation> rules = Lists.newLinkedList();
123 // TODO Generate multiple batches 121 // TODO Generate multiple batches
124 while (links.hasNext()) { 122 while (links.hasNext()) {
125 builder.matchInPort(prev.port()); 123 builder.matchInPort(prev.port());
...@@ -140,9 +138,9 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -140,9 +138,9 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
140 } 138 }
141 139
142 @Override 140 @Override
143 - public List<Set<FlowRuleOperation>> replace(PathIntent oldIntent, PathIntent newIntent) { 141 + public List<Collection<FlowRuleOperation>> replace(PathIntent oldIntent, PathIntent newIntent) {
144 // FIXME: implement this 142 // FIXME: implement this
145 - List<Set<FlowRuleOperation>> batches = Lists.newArrayList(); 143 + List<Collection<FlowRuleOperation>> batches = Lists.newArrayList();
146 batches.addAll(uninstall(oldIntent)); 144 batches.addAll(uninstall(oldIntent));
147 batches.addAll(install(newIntent)); 145 batches.addAll(install(newIntent));
148 return batches; 146 return batches;
......
...@@ -194,7 +194,7 @@ public class IntentManagerTest { ...@@ -194,7 +194,7 @@ public class IntentManagerTest {
194 194
195 private static class TestIntentInstaller implements IntentInstaller<MockInstallableIntent> { 195 private static class TestIntentInstaller implements IntentInstaller<MockInstallableIntent> {
196 @Override 196 @Override
197 - public List<Set<org.onosproject.net.flow.FlowRuleOperation>> install(MockInstallableIntent intent) { 197 + public List<Collection<org.onosproject.net.flow.FlowRuleOperation>> install(MockInstallableIntent intent) {
198 FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue()); 198 FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue());
199 Set<FlowRuleOperation> rules = ImmutableSet.of( 199 Set<FlowRuleOperation> rules = ImmutableSet.of(
200 new FlowRuleOperation(fr, FlowRuleOperation.Type.ADD)); 200 new FlowRuleOperation(fr, FlowRuleOperation.Type.ADD));
...@@ -202,7 +202,7 @@ public class IntentManagerTest { ...@@ -202,7 +202,7 @@ public class IntentManagerTest {
202 } 202 }
203 203
204 @Override 204 @Override
205 - public List<Set<FlowRuleOperation>> uninstall(MockInstallableIntent intent) { 205 + public List<Collection<FlowRuleOperation>> uninstall(MockInstallableIntent intent) {
206 FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue()); 206 FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue());
207 Set<FlowRuleOperation> rules = ImmutableSet.of( 207 Set<FlowRuleOperation> rules = ImmutableSet.of(
208 new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE)); 208 new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE));
...@@ -210,7 +210,8 @@ public class IntentManagerTest { ...@@ -210,7 +210,8 @@ public class IntentManagerTest {
210 } 210 }
211 211
212 @Override 212 @Override
213 - public List<Set<FlowRuleOperation>> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { 213 + public List<Collection<FlowRuleOperation>> replace(MockInstallableIntent oldIntent,
214 + MockInstallableIntent newIntent) {
214 FlowRule fr = new IntentTestsMocks.MockFlowRule(oldIntent.number().intValue()); 215 FlowRule fr = new IntentTestsMocks.MockFlowRule(oldIntent.number().intValue());
215 FlowRule fr2 = new IntentTestsMocks.MockFlowRule(newIntent.number().intValue()); 216 FlowRule fr2 = new IntentTestsMocks.MockFlowRule(newIntent.number().intValue());
216 Set<FlowRuleOperation> rules = ImmutableSet.of( 217 Set<FlowRuleOperation> rules = ImmutableSet.of(
...@@ -222,17 +223,18 @@ public class IntentManagerTest { ...@@ -222,17 +223,18 @@ public class IntentManagerTest {
222 223
223 private static class TestIntentErrorInstaller implements IntentInstaller<MockInstallableIntent> { 224 private static class TestIntentErrorInstaller implements IntentInstaller<MockInstallableIntent> {
224 @Override 225 @Override
225 - public List<Set<FlowRuleOperation>> install(MockInstallableIntent intent) { 226 + public List<Collection<FlowRuleOperation>> install(MockInstallableIntent intent) {
226 throw new IntentInstallationException("install() always fails"); 227 throw new IntentInstallationException("install() always fails");
227 } 228 }
228 229
229 @Override 230 @Override
230 - public List<Set<FlowRuleOperation>> uninstall(MockInstallableIntent intent) { 231 + public List<Collection<FlowRuleOperation>> uninstall(MockInstallableIntent intent) {
231 throw new IntentRemovalException("uninstall() always fails"); 232 throw new IntentRemovalException("uninstall() always fails");
232 } 233 }
233 234
234 @Override 235 @Override
235 - public List<Set<FlowRuleOperation>> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { 236 + public List<Collection<FlowRuleOperation>> replace(MockInstallableIntent oldIntent,
237 + MockInstallableIntent newIntent) {
236 throw new IntentInstallationException("replace() always fails"); 238 throw new IntentInstallationException("replace() always fails");
237 } 239 }
238 } 240 }
......
...@@ -15,10 +15,6 @@ ...@@ -15,10 +15,6 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import java.util.LinkedList;
19 -import java.util.List;
20 -import java.util.Set;
21 -
22 import org.junit.Test; 18 import org.junit.Test;
23 import org.onosproject.net.flow.FlowRuleOperation; 19 import org.onosproject.net.flow.FlowRuleOperation;
24 import org.onosproject.net.flow.TrafficSelector; 20 import org.onosproject.net.flow.TrafficSelector;
...@@ -35,11 +31,12 @@ import org.onosproject.net.resource.Bandwidth; ...@@ -35,11 +31,12 @@ import org.onosproject.net.resource.Bandwidth;
35 import org.onosproject.net.resource.Lambda; 31 import org.onosproject.net.resource.Lambda;
36 import org.onosproject.net.resource.LinkResourceService; 32 import org.onosproject.net.resource.LinkResourceService;
37 33
34 +import java.util.Collection;
35 +import java.util.LinkedList;
36 +import java.util.List;
37 +
38 import static org.hamcrest.MatcherAssert.assertThat; 38 import static org.hamcrest.MatcherAssert.assertThat;
39 -import static org.hamcrest.Matchers.containsString; 39 +import static org.hamcrest.Matchers.*;
40 -import static org.hamcrest.Matchers.hasSize;
41 -import static org.hamcrest.Matchers.instanceOf;
42 -import static org.hamcrest.Matchers.notNullValue;
43 import static org.junit.Assert.fail; 40 import static org.junit.Assert.fail;
44 import static org.onosproject.net.NetTestTools.APP_ID; 41 import static org.onosproject.net.NetTestTools.APP_ID;
45 import static org.onosproject.net.NetTestTools.connectPoint; 42 import static org.onosproject.net.NetTestTools.connectPoint;
...@@ -99,7 +96,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { ...@@ -99,7 +96,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest {
99 * @param resourceService service to use for resource allocation requests 96 * @param resourceService service to use for resource allocation requests
100 * @return fow rule entries 97 * @return fow rule entries
101 */ 98 */
102 - private List<Set<FlowRuleOperation>> installIntents(List<Intent> compiledIntents, 99 + private List<Collection<FlowRuleOperation>> installIntents(List<Intent> compiledIntents,
103 LinkResourceService resourceService) { 100 LinkResourceService resourceService) {
104 final PathIntent path = (PathIntent) compiledIntents.get(0); 101 final PathIntent path = (PathIntent) compiledIntents.get(0);
105 102
...@@ -193,7 +190,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { ...@@ -193,7 +190,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest {
193 assertThat(compiledIntents, notNullValue()); 190 assertThat(compiledIntents, notNullValue());
194 assertThat(compiledIntents, hasSize(1)); 191 assertThat(compiledIntents, hasSize(1));
195 192
196 - final List<Set<FlowRuleOperation>> flowOperations = 193 + final List<Collection<FlowRuleOperation>> flowOperations =
197 installIntents(compiledIntents, resourceService); 194 installIntents(compiledIntents, resourceService);
198 195
199 assertThat(flowOperations, notNullValue()); 196 assertThat(flowOperations, notNullValue());
...@@ -242,7 +239,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { ...@@ -242,7 +239,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest {
242 assertThat(compiledIntents, notNullValue()); 239 assertThat(compiledIntents, notNullValue());
243 assertThat(compiledIntents, hasSize(1)); 240 assertThat(compiledIntents, hasSize(1));
244 241
245 - final List<Set<FlowRuleOperation>> flowOperations = 242 + final List<Collection<FlowRuleOperation>> flowOperations =
246 installIntents(compiledIntents, resourceService); 243 installIntents(compiledIntents, resourceService);
247 244
248 assertThat(flowOperations, notNullValue()); 245 assertThat(flowOperations, notNullValue());
......