Committed by
Gerrit Code Review
Refactor Intent subsystem to eliminate using FlowRuleBatchOperation
Change-Id: Iee76dac5fa9935713ffc370b34ac47d9286ff351
Showing
10 changed files
with
173 additions
and
167 deletions
... | @@ -104,6 +104,17 @@ public class FlowRuleOperations { | ... | @@ -104,6 +104,17 @@ public class FlowRuleOperations { |
104 | } | 104 | } |
105 | 105 | ||
106 | /** | 106 | /** |
107 | + * Appends an existing flow rule to the current stage. | ||
108 | + * | ||
109 | + * @param flowRuleOperation flow rule operation | ||
110 | + * @return this | ||
111 | + */ | ||
112 | + public Builder operation(FlowRuleOperation flowRuleOperation) { | ||
113 | + currentStage.add(flowRuleOperation); | ||
114 | + return this; | ||
115 | + } | ||
116 | + | ||
117 | + /** | ||
107 | * Appends a flow rule modify to the current stage. | 118 | * Appends a flow rule modify to the current stage. |
108 | * | 119 | * |
109 | * @param flowRule flow rule | 120 | * @param flowRule flow rule | ... | ... |
... | @@ -15,9 +15,10 @@ | ... | @@ -15,9 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
17 | 17 | ||
18 | -import org.onosproject.net.flow.FlowRuleBatchOperation; | ||
19 | - | ||
20 | import java.util.List; | 18 | import java.util.List; |
19 | +import java.util.Set; | ||
20 | + | ||
21 | +import org.onosproject.net.flow.FlowRuleOperation; | ||
21 | 22 | ||
22 | /** | 23 | /** |
23 | * Abstraction of entity capable of installing intents to the environment. | 24 | * Abstraction of entity capable of installing intents to the environment. |
... | @@ -31,7 +32,7 @@ public interface IntentInstaller<T extends Intent> { | ... | @@ -31,7 +32,7 @@ public interface IntentInstaller<T extends Intent> { |
31 | * @return flow rule operations to complete install | 32 | * @return flow rule operations to complete install |
32 | * @throws IntentException if issues are encountered while installing the intent | 33 | * @throws IntentException if issues are encountered while installing the intent |
33 | */ | 34 | */ |
34 | - List<FlowRuleBatchOperation> install(T intent); | 35 | + List<Set<FlowRuleOperation>> install(T intent); |
35 | 36 | ||
36 | /** | 37 | /** |
37 | * Uninstalls the specified intent from the environment. | 38 | * Uninstalls the specified intent from the environment. |
... | @@ -40,7 +41,7 @@ public interface IntentInstaller<T extends Intent> { | ... | @@ -40,7 +41,7 @@ public interface IntentInstaller<T extends Intent> { |
40 | * @return flow rule operations to complete uninstall | 41 | * @return flow rule operations to complete uninstall |
41 | * @throws IntentException if issues are encountered while uninstalling the intent | 42 | * @throws IntentException if issues are encountered while uninstalling the intent |
42 | */ | 43 | */ |
43 | - List<FlowRuleBatchOperation> uninstall(T intent); | 44 | + List<Set<FlowRuleOperation>> uninstall(T intent); |
44 | 45 | ||
45 | /** | 46 | /** |
46 | * Replaces the specified intent with a new one in the environment. | 47 | * Replaces the specified intent with a new one in the environment. |
... | @@ -50,6 +51,6 @@ public interface IntentInstaller<T extends Intent> { | ... | @@ -50,6 +51,6 @@ public interface IntentInstaller<T extends Intent> { |
50 | * @return flow rule operations to complete the replace | 51 | * @return flow rule operations to complete the replace |
51 | * @throws IntentException if issues are encountered while uninstalling the intent | 52 | * @throws IntentException if issues are encountered while uninstalling the intent |
52 | */ | 53 | */ |
53 | - List<FlowRuleBatchOperation> replace(T oldIntent, T newIntent); | 54 | + List<Set<FlowRuleOperation>> replace(T oldIntent, T newIntent); |
54 | 55 | ||
55 | } | 56 | } | ... | ... |
... | @@ -35,7 +35,7 @@ import org.junit.After; | ... | @@ -35,7 +35,7 @@ import org.junit.After; |
35 | import org.junit.Before; | 35 | import org.junit.Before; |
36 | import org.junit.Test; | 36 | import org.junit.Test; |
37 | import org.onosproject.core.IdGenerator; | 37 | import org.onosproject.core.IdGenerator; |
38 | -import org.onosproject.net.flow.FlowRuleBatchOperation; | 38 | +import org.onosproject.net.flow.FlowRuleOperation; |
39 | import org.onosproject.net.resource.LinkResourceAllocations; | 39 | import org.onosproject.net.resource.LinkResourceAllocations; |
40 | 40 | ||
41 | /** | 41 | /** |
... | @@ -319,7 +319,7 @@ public class IntentServiceTest { | ... | @@ -319,7 +319,7 @@ public class IntentServiceTest { |
319 | } | 319 | } |
320 | 320 | ||
321 | @Override | 321 | @Override |
322 | - public List<FlowRuleBatchOperation> install(TestInstallableIntent intent) { | 322 | + public List<Set<FlowRuleOperation>> install(TestInstallableIntent intent) { |
323 | if (fail) { | 323 | if (fail) { |
324 | throw new IntentException("install failed by design"); | 324 | throw new IntentException("install failed by design"); |
325 | } | 325 | } |
... | @@ -327,7 +327,7 @@ public class IntentServiceTest { | ... | @@ -327,7 +327,7 @@ public class IntentServiceTest { |
327 | } | 327 | } |
328 | 328 | ||
329 | @Override | 329 | @Override |
330 | - public List<FlowRuleBatchOperation> uninstall(TestInstallableIntent intent) { | 330 | + public List<Set<FlowRuleOperation>> uninstall(TestInstallableIntent intent) { |
331 | if (fail) { | 331 | if (fail) { |
332 | throw new IntentException("remove failed by design"); | 332 | throw new IntentException("remove failed by design"); |
333 | } | 333 | } |
... | @@ -335,7 +335,7 @@ public class IntentServiceTest { | ... | @@ -335,7 +335,7 @@ public class IntentServiceTest { |
335 | } | 335 | } |
336 | 336 | ||
337 | @Override | 337 | @Override |
338 | - public List<FlowRuleBatchOperation> replace(TestInstallableIntent intent, | 338 | + public List<Set<FlowRuleOperation>> replace(TestInstallableIntent intent, |
339 | TestInstallableIntent newIntent) { | 339 | TestInstallableIntent newIntent) { |
340 | return null; | 340 | return null; |
341 | } | 341 | } | ... | ... |
... | @@ -15,8 +15,23 @@ | ... | @@ -15,8 +15,23 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent.impl; | 16 | package org.onosproject.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.Collection; |
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 | + | ||
20 | import org.apache.felix.scr.annotations.Activate; | 35 | import org.apache.felix.scr.annotations.Activate; |
21 | import org.apache.felix.scr.annotations.Component; | 36 | import org.apache.felix.scr.annotations.Component; |
22 | import org.apache.felix.scr.annotations.Deactivate; | 37 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -27,9 +42,7 @@ import org.onosproject.core.CoreService; | ... | @@ -27,9 +42,7 @@ import org.onosproject.core.CoreService; |
27 | import org.onosproject.core.IdGenerator; | 42 | import org.onosproject.core.IdGenerator; |
28 | import org.onosproject.event.AbstractListenerRegistry; | 43 | import org.onosproject.event.AbstractListenerRegistry; |
29 | import org.onosproject.event.EventDeliveryService; | 44 | import org.onosproject.event.EventDeliveryService; |
30 | -import org.onosproject.net.flow.FlowRule; | 45 | +import org.onosproject.net.flow.FlowRuleOperation; |
31 | -import org.onosproject.net.flow.FlowRuleBatchEntry; | ||
32 | -import org.onosproject.net.flow.FlowRuleBatchOperation; | ||
33 | import org.onosproject.net.flow.FlowRuleOperations; | 46 | import org.onosproject.net.flow.FlowRuleOperations; |
34 | import org.onosproject.net.flow.FlowRuleOperationsContext; | 47 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
35 | import org.onosproject.net.flow.FlowRuleService; | 48 | import org.onosproject.net.flow.FlowRuleService; |
... | @@ -55,21 +68,8 @@ import org.onosproject.net.intent.impl.phase.WithdrawRequest; | ... | @@ -55,21 +68,8 @@ import org.onosproject.net.intent.impl.phase.WithdrawRequest; |
55 | import org.onosproject.net.intent.impl.phase.Withdrawn; | 68 | import org.onosproject.net.intent.impl.phase.Withdrawn; |
56 | import org.slf4j.Logger; | 69 | import org.slf4j.Logger; |
57 | 70 | ||
58 | -import java.util.ArrayList; | 71 | +import com.google.common.collect.ImmutableList; |
59 | -import java.util.Collection; | 72 | +import com.google.common.collect.ImmutableMap; |
60 | -import java.util.Collections; | ||
61 | -import java.util.EnumSet; | ||
62 | -import java.util.Iterator; | ||
63 | -import java.util.List; | ||
64 | -import java.util.Map; | ||
65 | -import java.util.Optional; | ||
66 | -import java.util.concurrent.Callable; | ||
67 | -import java.util.concurrent.ConcurrentHashMap; | ||
68 | -import java.util.concurrent.ConcurrentMap; | ||
69 | -import java.util.concurrent.ExecutionException; | ||
70 | -import java.util.concurrent.ExecutorService; | ||
71 | -import java.util.concurrent.Future; | ||
72 | -import java.util.stream.Collectors; | ||
73 | 73 | ||
74 | import static com.google.common.base.Preconditions.checkNotNull; | 74 | import static com.google.common.base.Preconditions.checkNotNull; |
75 | import static com.google.common.base.Preconditions.checkState; | 75 | import static com.google.common.base.Preconditions.checkState; |
... | @@ -77,7 +77,11 @@ import static java.util.concurrent.Executors.newFixedThreadPool; | ... | @@ -77,7 +77,11 @@ import static java.util.concurrent.Executors.newFixedThreadPool; |
77 | import static java.util.concurrent.Executors.newSingleThreadExecutor; | 77 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
78 | import static org.onlab.util.Tools.groupedThreads; | 78 | import static org.onlab.util.Tools.groupedThreads; |
79 | import static org.onlab.util.Tools.isNullOrEmpty; | 79 | import static org.onlab.util.Tools.isNullOrEmpty; |
80 | -import static org.onosproject.net.intent.IntentState.*; | 80 | +import static org.onosproject.net.intent.IntentState.FAILED; |
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; | ||
81 | import static org.slf4j.LoggerFactory.getLogger; | 85 | import static org.slf4j.LoggerFactory.getLogger; |
82 | 86 | ||
83 | /** | 87 | /** |
... | @@ -301,7 +305,7 @@ public class IntentManager | ... | @@ -301,7 +305,7 @@ public class IntentManager |
301 | oldInstallables.size() == newInstallables.size(), | 305 | oldInstallables.size() == newInstallables.size(), |
302 | "Old and New Intent must have equivalent installable intents."); | 306 | "Old and New Intent must have equivalent installable intents."); |
303 | 307 | ||
304 | - List<List<FlowRuleBatchOperation>> plans = new ArrayList<>(); | 308 | + List<List<Set<FlowRuleOperation>>> plans = new ArrayList<>(); |
305 | for (int i = 0; i < newInstallables.size(); i++) { | 309 | for (int i = 0; i < newInstallables.size(); i++) { |
306 | Intent newInstallable = newInstallables.get(i); | 310 | Intent newInstallable = newInstallables.get(i); |
307 | registerSubclassInstallerIfNeeded(newInstallable); | 311 | registerSubclassInstallerIfNeeded(newInstallable); |
... | @@ -359,7 +363,7 @@ public class IntentManager | ... | @@ -359,7 +363,7 @@ public class IntentManager |
359 | // 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 |
360 | public FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) { | 364 | public FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) { |
361 | List<Intent> installables = current.installables(); | 365 | List<Intent> installables = current.installables(); |
362 | - List<List<FlowRuleBatchOperation>> plans = new ArrayList<>(); | 366 | + List<List<Set<FlowRuleOperation>>> plans = new ArrayList<>(); |
363 | for (Intent installable : installables) { | 367 | for (Intent installable : installables) { |
364 | plans.add(getInstaller(installable).uninstall(installable)); | 368 | plans.add(getInstaller(installable).uninstall(installable)); |
365 | trackerService.removeTrackedResources(pending.key(), installable.resources()); | 369 | trackerService.removeTrackedResources(pending.key(), installable.resources()); |
... | @@ -385,35 +389,22 @@ public class IntentManager | ... | @@ -385,35 +389,22 @@ public class IntentManager |
385 | 389 | ||
386 | 390 | ||
387 | // TODO needs tests... or maybe it's just perfect | 391 | // TODO needs tests... or maybe it's just perfect |
388 | - private FlowRuleOperations.Builder merge(List<List<FlowRuleBatchOperation>> plans) { | 392 | + private FlowRuleOperations.Builder merge(List<List<Set<FlowRuleOperation>>> plans) { |
389 | FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); | 393 | FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); |
390 | // Build a batch one stage at a time | 394 | // Build a batch one stage at a time |
391 | for (int stageNumber = 0;; stageNumber++) { | 395 | for (int stageNumber = 0;; stageNumber++) { |
392 | - // Get the sub-stage from each plan (List<FlowRuleBatchOperation>) | 396 | + // Get the sub-stage from each plan (List<Set<FlowRuleOperation>) |
393 | - for (Iterator<List<FlowRuleBatchOperation>> itr = plans.iterator(); itr.hasNext();) { | 397 | + for (Iterator<List<Set<FlowRuleOperation>>> itr = plans.iterator(); itr.hasNext();) { |
394 | - List<FlowRuleBatchOperation> plan = itr.next(); | 398 | + List<Set<FlowRuleOperation>> plan = itr.next(); |
395 | if (plan.size() <= stageNumber) { | 399 | if (plan.size() <= stageNumber) { |
396 | // we have consumed all stages from this plan, so remove it | 400 | // we have consumed all stages from this plan, so remove it |
397 | itr.remove(); | 401 | itr.remove(); |
398 | continue; | 402 | continue; |
399 | } | 403 | } |
400 | // write operations from this sub-stage into the builder | 404 | // write operations from this sub-stage into the builder |
401 | - FlowRuleBatchOperation stage = plan.get(stageNumber); | 405 | + Set<FlowRuleOperation> stage = plan.get(stageNumber); |
402 | - for (FlowRuleBatchEntry entry : stage.getOperations()) { | 406 | + for (FlowRuleOperation entry : stage) { |
403 | - FlowRule rule = entry.target(); | 407 | + builder.operation(entry); |
404 | - switch (entry.operator()) { | ||
405 | - case ADD: | ||
406 | - builder.add(rule); | ||
407 | - break; | ||
408 | - case REMOVE: | ||
409 | - builder.remove(rule); | ||
410 | - break; | ||
411 | - case MODIFY: | ||
412 | - builder.modify(rule); | ||
413 | - break; | ||
414 | - default: | ||
415 | - break; | ||
416 | - } | ||
417 | } | 408 | } |
418 | } | 409 | } |
419 | // we are done with the stage, start the next one... | 410 | // we are done with the stage, start the next one... | ... | ... |
... | @@ -15,9 +15,10 @@ | ... | @@ -15,9 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent.impl; | 16 | package org.onosproject.net.intent.impl; |
17 | 17 | ||
18 | -import com.google.common.collect.HashMultimap; | 18 | +import java.util.List; |
19 | -import com.google.common.collect.Lists; | 19 | +import java.util.Set; |
20 | -import com.google.common.collect.SetMultimap; | 20 | +import java.util.stream.Collectors; |
21 | + | ||
21 | import org.apache.felix.scr.annotations.Activate; | 22 | import org.apache.felix.scr.annotations.Activate; |
22 | import org.apache.felix.scr.annotations.Component; | 23 | import org.apache.felix.scr.annotations.Component; |
23 | import org.apache.felix.scr.annotations.Deactivate; | 24 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -34,19 +35,17 @@ import org.onosproject.net.flow.DefaultFlowRule; | ... | @@ -34,19 +35,17 @@ import org.onosproject.net.flow.DefaultFlowRule; |
34 | import org.onosproject.net.flow.DefaultTrafficSelector; | 35 | import org.onosproject.net.flow.DefaultTrafficSelector; |
35 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 36 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
36 | import org.onosproject.net.flow.FlowRule; | 37 | import org.onosproject.net.flow.FlowRule; |
37 | -import org.onosproject.net.flow.FlowRuleBatchEntry; | 38 | +import org.onosproject.net.flow.FlowRuleOperation; |
38 | -import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation; | ||
39 | -import org.onosproject.net.flow.FlowRuleBatchOperation; | ||
40 | import org.onosproject.net.flow.TrafficSelector; | 39 | import org.onosproject.net.flow.TrafficSelector; |
41 | import org.onosproject.net.flow.TrafficTreatment; | 40 | import org.onosproject.net.flow.TrafficTreatment; |
42 | import org.onosproject.net.intent.IntentExtensionService; | 41 | import org.onosproject.net.intent.IntentExtensionService; |
43 | import org.onosproject.net.intent.IntentInstaller; | 42 | import org.onosproject.net.intent.IntentInstaller; |
44 | import org.onosproject.net.intent.LinkCollectionIntent; | 43 | import org.onosproject.net.intent.LinkCollectionIntent; |
45 | 44 | ||
46 | -import java.util.Collections; | 45 | +import com.google.common.collect.HashMultimap; |
47 | -import java.util.List; | 46 | +import com.google.common.collect.ImmutableSet; |
48 | -import java.util.Set; | 47 | +import com.google.common.collect.Lists; |
49 | -import java.util.stream.Collectors; | 48 | +import com.google.common.collect.SetMultimap; |
50 | 49 | ||
51 | /** | 50 | /** |
52 | * Installer for {@link org.onosproject.net.intent.LinkCollectionIntent} path | 51 | * Installer for {@link org.onosproject.net.intent.LinkCollectionIntent} path |
... | @@ -76,17 +75,17 @@ public class LinkCollectionIntentInstaller | ... | @@ -76,17 +75,17 @@ public class LinkCollectionIntentInstaller |
76 | } | 75 | } |
77 | 76 | ||
78 | @Override | 77 | @Override |
79 | - public List<FlowRuleBatchOperation> install(LinkCollectionIntent intent) { | 78 | + public List<Set<FlowRuleOperation>> install(LinkCollectionIntent intent) { |
80 | - return generateBatchOperations(intent, FlowRuleOperation.ADD); | 79 | + return generateBatchOperations(intent, FlowRuleOperation.Type.ADD); |
81 | } | 80 | } |
82 | 81 | ||
83 | @Override | 82 | @Override |
84 | - public List<FlowRuleBatchOperation> uninstall(LinkCollectionIntent intent) { | 83 | + public List<Set<FlowRuleOperation>> uninstall(LinkCollectionIntent intent) { |
85 | - return generateBatchOperations(intent, FlowRuleOperation.REMOVE); | 84 | + return generateBatchOperations(intent, FlowRuleOperation.Type.REMOVE); |
86 | } | 85 | } |
87 | 86 | ||
88 | - private List<FlowRuleBatchOperation> generateBatchOperations( | 87 | + private List<Set<FlowRuleOperation>> generateBatchOperations( |
89 | - LinkCollectionIntent intent, FlowRuleOperation operation) { | 88 | + LinkCollectionIntent intent, FlowRuleOperation.Type operation) { |
90 | 89 | ||
91 | SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); | 90 | SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); |
92 | 91 | ||
... | @@ -99,23 +98,33 @@ public class LinkCollectionIntentInstaller | ... | @@ -99,23 +98,33 @@ public class LinkCollectionIntentInstaller |
99 | } | 98 | } |
100 | 99 | ||
101 | //FIXME change to new api | 100 | //FIXME change to new api |
102 | - FlowRuleBatchOperation batchOperation = | 101 | + /* Fear of streams */ |
103 | - new FlowRuleBatchOperation(outputPorts | 102 | + /* |
103 | + Set<FlowRuleBatchEntry> rules = Sets.newHashSet(); | ||
104 | + for (DeviceId deviceId : outputPorts.keys()) { | ||
105 | + rules.add(createBatchEntry(operation, | ||
106 | + intent, deviceId, | ||
107 | + outputPorts.get(deviceId))); | ||
108 | + } | ||
109 | + */ | ||
110 | + | ||
111 | + Set<FlowRuleOperation> rules = | ||
112 | + outputPorts | ||
104 | .keys() | 113 | .keys() |
105 | .stream() | 114 | .stream() |
106 | .map(deviceId -> createBatchEntry(operation, | 115 | .map(deviceId -> createBatchEntry(operation, |
107 | intent, deviceId, | 116 | intent, deviceId, |
108 | outputPorts.get(deviceId))) | 117 | outputPorts.get(deviceId))) |
109 | - .collect(Collectors.toList()), null, 0); | 118 | + .collect(Collectors.toSet()); |
110 | 119 | ||
111 | - return Collections.singletonList(batchOperation); | 120 | + return Lists.newArrayList(ImmutableSet.of(rules)); |
112 | } | 121 | } |
113 | 122 | ||
114 | @Override | 123 | @Override |
115 | - public List<FlowRuleBatchOperation> replace(LinkCollectionIntent oldIntent, | 124 | + public List<Set<FlowRuleOperation>> replace(LinkCollectionIntent oldIntent, |
116 | LinkCollectionIntent newIntent) { | 125 | LinkCollectionIntent newIntent) { |
117 | // FIXME: implement this in a more intelligent/less brute force way | 126 | // FIXME: implement this in a more intelligent/less brute force way |
118 | - List<FlowRuleBatchOperation> batches = Lists.newArrayList(); | 127 | + List<Set<FlowRuleOperation>> batches = Lists.newArrayList(); |
119 | batches.addAll(uninstall(oldIntent)); | 128 | batches.addAll(uninstall(oldIntent)); |
120 | batches.addAll(install(newIntent)); | 129 | batches.addAll(install(newIntent)); |
121 | return batches; | 130 | return batches; |
... | @@ -130,7 +139,7 @@ public class LinkCollectionIntentInstaller | ... | @@ -130,7 +139,7 @@ public class LinkCollectionIntentInstaller |
130 | * @param outPorts the set of output ports for the flow rule | 139 | * @param outPorts the set of output ports for the flow rule |
131 | * @return the new flow rule batch entry | 140 | * @return the new flow rule batch entry |
132 | */ | 141 | */ |
133 | - private FlowRuleBatchEntry createBatchEntry(FlowRuleOperation operation, | 142 | + private FlowRuleOperation createBatchEntry(FlowRuleOperation.Type operation, |
134 | LinkCollectionIntent intent, | 143 | LinkCollectionIntent intent, |
135 | DeviceId deviceId, | 144 | DeviceId deviceId, |
136 | Set<PortNumber> outPorts) { | 145 | Set<PortNumber> outPorts) { |
... | @@ -151,6 +160,6 @@ public class LinkCollectionIntentInstaller | ... | @@ -151,6 +160,6 @@ public class LinkCollectionIntentInstaller |
151 | new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), | 160 | new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), |
152 | 0, true); | 161 | 0, true); |
153 | 162 | ||
154 | - return new FlowRuleBatchEntry(operation, rule); | 163 | + return new FlowRuleOperation(rule, operation); |
155 | } | 164 | } |
156 | } | 165 | } | ... | ... |
1 | package org.onosproject.net.intent.impl; | 1 | package org.onosproject.net.intent.impl; |
2 | 2 | ||
3 | -import static org.slf4j.LoggerFactory.getLogger; | ||
4 | - | ||
5 | import java.util.Iterator; | 3 | import java.util.Iterator; |
6 | import java.util.List; | 4 | import java.util.List; |
7 | import java.util.Set; | 5 | import java.util.Set; |
... | @@ -22,11 +20,9 @@ import org.onosproject.net.flow.DefaultFlowRule; | ... | @@ -22,11 +20,9 @@ import org.onosproject.net.flow.DefaultFlowRule; |
22 | import org.onosproject.net.flow.DefaultTrafficSelector; | 20 | import org.onosproject.net.flow.DefaultTrafficSelector; |
23 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 21 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
24 | import org.onosproject.net.flow.FlowRule; | 22 | import org.onosproject.net.flow.FlowRule; |
25 | -import org.onosproject.net.flow.FlowRuleBatchEntry; | 23 | +import org.onosproject.net.flow.FlowRuleOperation; |
26 | -import org.onosproject.net.flow.FlowRuleBatchOperation; | ||
27 | import org.onosproject.net.flow.TrafficSelector; | 24 | import org.onosproject.net.flow.TrafficSelector; |
28 | import org.onosproject.net.flow.TrafficTreatment; | 25 | import org.onosproject.net.flow.TrafficTreatment; |
29 | -import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation; | ||
30 | import org.onosproject.net.flow.criteria.Criteria.EthTypeCriterion; | 26 | import org.onosproject.net.flow.criteria.Criteria.EthTypeCriterion; |
31 | import org.onosproject.net.flow.criteria.Criterion; | 27 | import org.onosproject.net.flow.criteria.Criterion; |
32 | import org.onosproject.net.flow.criteria.Criterion.Type; | 28 | import org.onosproject.net.flow.criteria.Criterion.Type; |
... | @@ -44,11 +40,13 @@ import org.onosproject.net.resource.ResourceAllocation; | ... | @@ -44,11 +40,13 @@ import org.onosproject.net.resource.ResourceAllocation; |
44 | import org.onosproject.net.resource.ResourceType; | 40 | import org.onosproject.net.resource.ResourceType; |
45 | import org.slf4j.Logger; | 41 | import org.slf4j.Logger; |
46 | 42 | ||
47 | -import static com.google.common.base.Preconditions.checkNotNull; | 43 | +import com.google.common.collect.ImmutableSet; |
48 | - | ||
49 | import com.google.common.collect.Lists; | 44 | import com.google.common.collect.Lists; |
50 | import com.google.common.collect.Sets; | 45 | import com.google.common.collect.Sets; |
51 | 46 | ||
47 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
48 | +import static org.slf4j.LoggerFactory.getLogger; | ||
49 | + | ||
52 | /** | 50 | /** |
53 | * Installer for {@link MplsPathIntent packet path connectivity intents}. | 51 | * Installer for {@link MplsPathIntent packet path connectivity intents}. |
54 | */ | 52 | */ |
... | @@ -83,29 +81,26 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> | ... | @@ -83,29 +81,26 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> |
83 | } | 81 | } |
84 | 82 | ||
85 | @Override | 83 | @Override |
86 | - public List<FlowRuleBatchOperation> install(MplsPathIntent intent) { | 84 | + public List<Set<FlowRuleOperation>> install(MplsPathIntent intent) { |
87 | LinkResourceAllocations allocations = assignMplsLabel(intent); | 85 | LinkResourceAllocations allocations = assignMplsLabel(intent); |
88 | - return generateRules(intent, allocations, FlowRuleOperation.ADD); | 86 | + return generateRules(intent, allocations, FlowRuleOperation.Type.ADD); |
89 | 87 | ||
90 | } | 88 | } |
91 | 89 | ||
92 | @Override | 90 | @Override |
93 | - public List<FlowRuleBatchOperation> uninstall(MplsPathIntent intent) { | 91 | + public List<Set<FlowRuleOperation>> uninstall(MplsPathIntent intent) { |
94 | LinkResourceAllocations allocations = resourceService | 92 | LinkResourceAllocations allocations = resourceService |
95 | .getAllocations(intent.id()); | 93 | .getAllocations(intent.id()); |
96 | resourceService.releaseResources(allocations); | 94 | resourceService.releaseResources(allocations); |
97 | 95 | ||
98 | - List<FlowRuleBatchOperation> rules = generateRules(intent, | 96 | + return generateRules(intent, allocations, FlowRuleOperation.Type.REMOVE); |
99 | - allocations, | ||
100 | - FlowRuleOperation.REMOVE); | ||
101 | - return rules; | ||
102 | } | 97 | } |
103 | 98 | ||
104 | @Override | 99 | @Override |
105 | - public List<FlowRuleBatchOperation> replace(MplsPathIntent oldIntent, | 100 | + public List<Set<FlowRuleOperation>> replace(MplsPathIntent oldIntent, |
106 | MplsPathIntent newIntent) { | 101 | MplsPathIntent newIntent) { |
107 | 102 | ||
108 | - List<FlowRuleBatchOperation> batches = Lists.newArrayList(); | 103 | + List<Set<FlowRuleOperation>> batches = Lists.newArrayList(); |
109 | batches.addAll(uninstall(oldIntent)); | 104 | batches.addAll(uninstall(oldIntent)); |
110 | batches.addAll(install(newIntent)); | 105 | batches.addAll(install(newIntent)); |
111 | return batches; | 106 | return batches; |
... | @@ -145,9 +140,9 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> | ... | @@ -145,9 +140,9 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> |
145 | return null; | 140 | return null; |
146 | } | 141 | } |
147 | 142 | ||
148 | - private List<FlowRuleBatchOperation> generateRules(MplsPathIntent intent, | 143 | + private List<Set<FlowRuleOperation>> generateRules(MplsPathIntent intent, |
149 | LinkResourceAllocations allocations, | 144 | LinkResourceAllocations allocations, |
150 | - FlowRuleOperation operation) { | 145 | + FlowRuleOperation.Type operation) { |
151 | 146 | ||
152 | Iterator<Link> links = intent.path().links().iterator(); | 147 | Iterator<Link> links = intent.path().links().iterator(); |
153 | Link srcLink = links.next(); | 148 | Link srcLink = links.next(); |
... | @@ -155,7 +150,7 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> | ... | @@ -155,7 +150,7 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> |
155 | 150 | ||
156 | Link link = links.next(); | 151 | Link link = links.next(); |
157 | // List of flow rules to be installed | 152 | // List of flow rules to be installed |
158 | - List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); | 153 | + Set<FlowRuleOperation> rules = Sets.newHashSet(); |
159 | 154 | ||
160 | // Ingress traffic | 155 | // Ingress traffic |
161 | // Get the new MPLS label | 156 | // Get the new MPLS label |
... | @@ -187,13 +182,13 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> | ... | @@ -187,13 +182,13 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> |
187 | 182 | ||
188 | prev = link.dst(); | 183 | prev = link.dst(); |
189 | } | 184 | } |
190 | - return Lists.newArrayList(new FlowRuleBatchOperation(rules, null, 0)); | 185 | + return Lists.newArrayList(ImmutableSet.of(rules)); |
191 | } | 186 | } |
192 | 187 | ||
193 | - private FlowRuleBatchEntry ingressFlow(PortNumber inPort, Link link, | 188 | + private FlowRuleOperation ingressFlow(PortNumber inPort, Link link, |
194 | MplsPathIntent intent, | 189 | MplsPathIntent intent, |
195 | MplsLabel label, | 190 | MplsLabel label, |
196 | - FlowRuleOperation operation) { | 191 | + FlowRuleOperation.Type operation) { |
197 | 192 | ||
198 | TrafficSelector.Builder ingressSelector = DefaultTrafficSelector | 193 | TrafficSelector.Builder ingressSelector = DefaultTrafficSelector |
199 | .builder(intent.selector()); | 194 | .builder(intent.selector()); |
... | @@ -213,16 +208,16 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> | ... | @@ -213,16 +208,16 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> |
213 | // Add the output action | 208 | // Add the output action |
214 | treat.setOutput(link.src().port()); | 209 | treat.setOutput(link.src().port()); |
215 | 210 | ||
216 | - return flowRuleBatchEntry(intent, link.src().deviceId(), | 211 | + return flowRuleOperation(intent, link.src().deviceId(), |
217 | ingressSelector.build(), treat.build(), | 212 | ingressSelector.build(), treat.build(), |
218 | operation); | 213 | operation); |
219 | } | 214 | } |
220 | 215 | ||
221 | - private FlowRuleBatchEntry transitFlow(PortNumber inPort, Link link, | 216 | + private FlowRuleOperation transitFlow(PortNumber inPort, Link link, |
222 | MplsPathIntent intent, | 217 | MplsPathIntent intent, |
223 | MplsLabel prevLabel, | 218 | MplsLabel prevLabel, |
224 | MplsLabel outLabel, | 219 | MplsLabel outLabel, |
225 | - FlowRuleOperation operation) { | 220 | + FlowRuleOperation.Type operation) { |
226 | 221 | ||
227 | // Ignore the ingress Traffic Selector and use only the MPLS label | 222 | // Ignore the ingress Traffic Selector and use only the MPLS label |
228 | // assigned in the previous link | 223 | // assigned in the previous link |
... | @@ -238,14 +233,14 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> | ... | @@ -238,14 +233,14 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> |
238 | } | 233 | } |
239 | 234 | ||
240 | treat.setOutput(link.src().port()); | 235 | treat.setOutput(link.src().port()); |
241 | - return flowRuleBatchEntry(intent, link.src().deviceId(), | 236 | + return flowRuleOperation(intent, link.src().deviceId(), |
242 | selector.build(), treat.build(), operation); | 237 | selector.build(), treat.build(), operation); |
243 | } | 238 | } |
244 | 239 | ||
245 | - private FlowRuleBatchEntry egressFlow(PortNumber inPort, Link link, | 240 | + private FlowRuleOperation egressFlow(PortNumber inPort, Link link, |
246 | MplsPathIntent intent, | 241 | MplsPathIntent intent, |
247 | MplsLabel prevLabel, | 242 | MplsLabel prevLabel, |
248 | - FlowRuleOperation operation) { | 243 | + FlowRuleOperation.Type operation) { |
249 | // egress point: either set the egress MPLS label or pop the | 244 | // egress point: either set the egress MPLS label or pop the |
250 | // MPLS label based on the intent annotations | 245 | // MPLS label based on the intent annotations |
251 | 246 | ||
... | @@ -272,15 +267,15 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> | ... | @@ -272,15 +267,15 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> |
272 | 267 | ||
273 | } | 268 | } |
274 | treat.setOutput(link.src().port()); | 269 | treat.setOutput(link.src().port()); |
275 | - return flowRuleBatchEntry(intent, link.src().deviceId(), | 270 | + return flowRuleOperation(intent, link.src().deviceId(), |
276 | selector.build(), treat.build(), operation); | 271 | selector.build(), treat.build(), operation); |
277 | } | 272 | } |
278 | 273 | ||
279 | - protected FlowRuleBatchEntry flowRuleBatchEntry(MplsPathIntent intent, | 274 | + protected FlowRuleOperation flowRuleOperation(MplsPathIntent intent, |
280 | DeviceId deviceId, | 275 | DeviceId deviceId, |
281 | TrafficSelector selector, | 276 | TrafficSelector selector, |
282 | TrafficTreatment treat, | 277 | TrafficTreatment treat, |
283 | - FlowRuleOperation operation) { | 278 | + FlowRuleOperation.Type operation) { |
284 | FlowRule rule = new DefaultFlowRule( | 279 | FlowRule rule = new DefaultFlowRule( |
285 | deviceId, | 280 | deviceId, |
286 | selector, | 281 | selector, |
... | @@ -289,8 +284,7 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> | ... | @@ -289,8 +284,7 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> |
289 | appId, | 284 | appId, |
290 | 0, | 285 | 0, |
291 | true); | 286 | true); |
292 | - return new FlowRuleBatchEntry(operation, rule, intent.id() | 287 | + return new FlowRuleOperation(rule, operation); |
293 | - .fingerprint()); | ||
294 | 288 | ||
295 | } | 289 | } |
296 | } | 290 | } | ... | ... |
... | @@ -15,7 +15,9 @@ | ... | @@ -15,7 +15,9 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent.impl; | 16 | package org.onosproject.net.intent.impl; |
17 | 17 | ||
18 | -import com.google.common.collect.Lists; | 18 | +import java.util.List; |
19 | +import java.util.Set; | ||
20 | + | ||
19 | import org.apache.felix.scr.annotations.Activate; | 21 | import org.apache.felix.scr.annotations.Activate; |
20 | import org.apache.felix.scr.annotations.Component; | 22 | import org.apache.felix.scr.annotations.Component; |
21 | import org.apache.felix.scr.annotations.Deactivate; | 23 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -29,9 +31,7 @@ import org.onosproject.net.flow.DefaultFlowRule; | ... | @@ -29,9 +31,7 @@ import org.onosproject.net.flow.DefaultFlowRule; |
29 | import org.onosproject.net.flow.DefaultTrafficSelector; | 31 | import org.onosproject.net.flow.DefaultTrafficSelector; |
30 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 32 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
31 | import org.onosproject.net.flow.FlowRule; | 33 | import org.onosproject.net.flow.FlowRule; |
32 | -import org.onosproject.net.flow.FlowRuleBatchEntry; | 34 | +import org.onosproject.net.flow.FlowRuleOperation; |
33 | -import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation; | ||
34 | -import org.onosproject.net.flow.FlowRuleBatchOperation; | ||
35 | import org.onosproject.net.flow.FlowRuleService; | 35 | import org.onosproject.net.flow.FlowRuleService; |
36 | import org.onosproject.net.flow.TrafficSelector; | 36 | import org.onosproject.net.flow.TrafficSelector; |
37 | import org.onosproject.net.flow.TrafficTreatment; | 37 | import org.onosproject.net.flow.TrafficTreatment; |
... | @@ -49,7 +49,9 @@ import org.onosproject.net.resource.ResourceType; | ... | @@ -49,7 +49,9 @@ import org.onosproject.net.resource.ResourceType; |
49 | import org.onosproject.net.topology.TopologyService; | 49 | import org.onosproject.net.topology.TopologyService; |
50 | import org.slf4j.Logger; | 50 | import org.slf4j.Logger; |
51 | 51 | ||
52 | -import java.util.List; | 52 | +import com.google.common.collect.ImmutableSet; |
53 | +import com.google.common.collect.Lists; | ||
54 | +import com.google.common.collect.Sets; | ||
53 | 55 | ||
54 | import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; | 56 | import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; |
55 | import static org.slf4j.LoggerFactory.getLogger; | 57 | import static org.slf4j.LoggerFactory.getLogger; |
... | @@ -92,24 +94,24 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn | ... | @@ -92,24 +94,24 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn |
92 | } | 94 | } |
93 | 95 | ||
94 | @Override | 96 | @Override |
95 | - public List<FlowRuleBatchOperation> install(OpticalPathIntent intent) { | 97 | + public List<Set<FlowRuleOperation>> install(OpticalPathIntent intent) { |
96 | LinkResourceAllocations allocations = assignWavelength(intent); | 98 | LinkResourceAllocations allocations = assignWavelength(intent); |
97 | - return generateRules(intent, allocations, FlowRuleOperation.ADD); | 99 | + return generateRules(intent, allocations, FlowRuleOperation.Type.ADD); |
98 | } | 100 | } |
99 | 101 | ||
100 | @Override | 102 | @Override |
101 | - public List<FlowRuleBatchOperation> uninstall(OpticalPathIntent intent) { | 103 | + public List<Set<FlowRuleOperation>> uninstall(OpticalPathIntent intent) { |
102 | LinkResourceAllocations allocations = resourceService.getAllocations(intent.id()); | 104 | LinkResourceAllocations allocations = resourceService.getAllocations(intent.id()); |
103 | - List<FlowRuleBatchOperation> rules = generateRules(intent, allocations, FlowRuleOperation.REMOVE); | 105 | + List<Set<FlowRuleOperation>> rules = generateRules(intent, allocations, FlowRuleOperation.Type.REMOVE); |
104 | log.info("uninstall rules: {}", rules); | 106 | log.info("uninstall rules: {}", rules); |
105 | return rules; | 107 | return rules; |
106 | } | 108 | } |
107 | 109 | ||
108 | @Override | 110 | @Override |
109 | - public List<FlowRuleBatchOperation> replace(OpticalPathIntent oldIntent, | 111 | + public List<Set<FlowRuleOperation>> replace(OpticalPathIntent oldIntent, |
110 | OpticalPathIntent newIntent) { | 112 | OpticalPathIntent newIntent) { |
111 | // FIXME: implement this | 113 | // FIXME: implement this |
112 | - List<FlowRuleBatchOperation> batches = Lists.newArrayList(); | 114 | + List<Set<FlowRuleOperation>> batches = Lists.newArrayList(); |
113 | batches.addAll(uninstall(oldIntent)); | 115 | batches.addAll(uninstall(oldIntent)); |
114 | batches.addAll(install(newIntent)); | 116 | batches.addAll(install(newIntent)); |
115 | return batches; | 117 | return batches; |
... | @@ -123,13 +125,13 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn | ... | @@ -123,13 +125,13 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn |
123 | return retLambda; | 125 | return retLambda; |
124 | } | 126 | } |
125 | 127 | ||
126 | - private List<FlowRuleBatchOperation> generateRules(OpticalPathIntent intent, | 128 | + private List<Set<FlowRuleOperation>> generateRules(OpticalPathIntent intent, |
127 | LinkResourceAllocations allocations, | 129 | LinkResourceAllocations allocations, |
128 | - FlowRuleOperation operation) { | 130 | + FlowRuleOperation.Type operation) { |
129 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | 131 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
130 | selectorBuilder.matchInPort(intent.src().port()); | 132 | selectorBuilder.matchInPort(intent.src().port()); |
131 | 133 | ||
132 | - List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); | 134 | + Set<FlowRuleOperation> rules = Sets.newHashSet(); |
133 | ConnectPoint prev = intent.src(); | 135 | ConnectPoint prev = intent.src(); |
134 | 136 | ||
135 | //FIXME check for null allocations | 137 | //FIXME check for null allocations |
... | @@ -160,7 +162,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn | ... | @@ -160,7 +162,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn |
160 | 100, | 162 | 100, |
161 | true); | 163 | true); |
162 | 164 | ||
163 | - rules.add(new FlowRuleBatchEntry(operation, rule)); | 165 | + rules.add(new FlowRuleOperation(rule, operation)); |
164 | 166 | ||
165 | prev = link.dst(); | 167 | prev = link.dst(); |
166 | selectorBuilder.matchInPort(link.dst().port()); | 168 | selectorBuilder.matchInPort(link.dst().port()); |
... | @@ -179,9 +181,9 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn | ... | @@ -179,9 +181,9 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn |
179 | appId, | 181 | appId, |
180 | 100, | 182 | 100, |
181 | true); | 183 | true); |
182 | - rules.add(new FlowRuleBatchEntry(operation, rule)); | 184 | + rules.add(new FlowRuleOperation(rule, operation)); |
183 | 185 | ||
184 | //FIXME change to new api | 186 | //FIXME change to new api |
185 | - return Lists.newArrayList(new FlowRuleBatchOperation(rules, null, 0)); | 187 | + return Lists.newArrayList(ImmutableSet.of(rules)); |
186 | } | 188 | } |
187 | } | 189 | } | ... | ... |
... | @@ -17,6 +17,7 @@ package org.onosproject.net.intent.impl; | ... | @@ -17,6 +17,7 @@ package org.onosproject.net.intent.impl; |
17 | 17 | ||
18 | import java.util.Iterator; | 18 | import java.util.Iterator; |
19 | import java.util.List; | 19 | import java.util.List; |
20 | +import java.util.Set; | ||
20 | 21 | ||
21 | import org.apache.felix.scr.annotations.Activate; | 22 | import org.apache.felix.scr.annotations.Activate; |
22 | import org.apache.felix.scr.annotations.Component; | 23 | import org.apache.felix.scr.annotations.Component; |
... | @@ -31,9 +32,7 @@ import org.onosproject.net.Link; | ... | @@ -31,9 +32,7 @@ import org.onosproject.net.Link; |
31 | import org.onosproject.net.flow.DefaultFlowRule; | 32 | import org.onosproject.net.flow.DefaultFlowRule; |
32 | import org.onosproject.net.flow.DefaultTrafficSelector; | 33 | import org.onosproject.net.flow.DefaultTrafficSelector; |
33 | import org.onosproject.net.flow.FlowRule; | 34 | import org.onosproject.net.flow.FlowRule; |
34 | -import org.onosproject.net.flow.FlowRuleBatchEntry; | 35 | +import org.onosproject.net.flow.FlowRuleOperation; |
35 | -import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation; | ||
36 | -import org.onosproject.net.flow.FlowRuleBatchOperation; | ||
37 | import org.onosproject.net.flow.TrafficSelector; | 36 | import org.onosproject.net.flow.TrafficSelector; |
38 | import org.onosproject.net.flow.TrafficTreatment; | 37 | import org.onosproject.net.flow.TrafficTreatment; |
39 | import org.onosproject.net.intent.Constraint; | 38 | import org.onosproject.net.intent.Constraint; |
... | @@ -46,7 +45,9 @@ import org.onosproject.net.resource.LinkResourceRequest; | ... | @@ -46,7 +45,9 @@ import org.onosproject.net.resource.LinkResourceRequest; |
46 | import org.onosproject.net.resource.LinkResourceService; | 45 | import org.onosproject.net.resource.LinkResourceService; |
47 | import org.slf4j.Logger; | 46 | import org.slf4j.Logger; |
48 | 47 | ||
48 | +import com.google.common.collect.ImmutableSet; | ||
49 | import com.google.common.collect.Lists; | 49 | import com.google.common.collect.Lists; |
50 | +import com.google.common.collect.Sets; | ||
50 | 51 | ||
51 | import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; | 52 | import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; |
52 | import static org.slf4j.LoggerFactory.getLogger; | 53 | import static org.slf4j.LoggerFactory.getLogger; |
... | @@ -82,14 +83,14 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { | ... | @@ -82,14 +83,14 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { |
82 | } | 83 | } |
83 | 84 | ||
84 | @Override | 85 | @Override |
85 | - public List<FlowRuleBatchOperation> install(PathIntent intent) { | 86 | + public List<Set<FlowRuleOperation>> install(PathIntent intent) { |
86 | LinkResourceAllocations allocations = allocateResources(intent); | 87 | LinkResourceAllocations allocations = allocateResources(intent); |
87 | 88 | ||
88 | TrafficSelector.Builder builder = | 89 | TrafficSelector.Builder builder = |
89 | DefaultTrafficSelector.builder(intent.selector()); | 90 | DefaultTrafficSelector.builder(intent.selector()); |
90 | Iterator<Link> links = intent.path().links().iterator(); | 91 | Iterator<Link> links = intent.path().links().iterator(); |
91 | ConnectPoint prev = links.next().dst(); | 92 | ConnectPoint prev = links.next().dst(); |
92 | - List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); | 93 | + Set<FlowRuleOperation> rules = Sets.newHashSet(); |
93 | // TODO Generate multiple batches | 94 | // TODO Generate multiple batches |
94 | while (links.hasNext()) { | 95 | while (links.hasNext()) { |
95 | builder.matchInPort(prev.port()); | 96 | builder.matchInPort(prev.port()); |
... | @@ -104,23 +105,21 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { | ... | @@ -104,23 +105,21 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { |
104 | appId, | 105 | appId, |
105 | new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), | 106 | new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), |
106 | 0, true); | 107 | 0, true); |
107 | - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule, | 108 | + rules.add(new FlowRuleOperation(rule, FlowRuleOperation.Type.ADD)); |
108 | - intent.id().fingerprint())); | ||
109 | prev = link.dst(); | 109 | prev = link.dst(); |
110 | } | 110 | } |
111 | - //FIXME this should change to new api. | 111 | + |
112 | - return Lists.newArrayList(new FlowRuleBatchOperation(rules, null, 0)); | 112 | + return Lists.newArrayList(ImmutableSet.of(rules)); |
113 | } | 113 | } |
114 | 114 | ||
115 | @Override | 115 | @Override |
116 | - public List<FlowRuleBatchOperation> uninstall(PathIntent intent) { | 116 | + public List<Set<FlowRuleOperation>> uninstall(PathIntent intent) { |
117 | deallocateResources(intent); | 117 | deallocateResources(intent); |
118 | - | ||
119 | TrafficSelector.Builder builder = | 118 | TrafficSelector.Builder builder = |
120 | DefaultTrafficSelector.builder(intent.selector()); | 119 | DefaultTrafficSelector.builder(intent.selector()); |
121 | Iterator<Link> links = intent.path().links().iterator(); | 120 | Iterator<Link> links = intent.path().links().iterator(); |
122 | ConnectPoint prev = links.next().dst(); | 121 | ConnectPoint prev = links.next().dst(); |
123 | - List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); | 122 | + Set<FlowRuleOperation> rules = Sets.newHashSet(); |
124 | // TODO Generate multiple batches | 123 | // TODO Generate multiple batches |
125 | while (links.hasNext()) { | 124 | while (links.hasNext()) { |
126 | builder.matchInPort(prev.port()); | 125 | builder.matchInPort(prev.port()); |
... | @@ -133,18 +132,17 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { | ... | @@ -133,18 +132,17 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { |
133 | builder.build(), treatment, 123, appId, | 132 | builder.build(), treatment, 123, appId, |
134 | new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), | 133 | new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), |
135 | 0, true); | 134 | 0, true); |
136 | - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, rule, | 135 | + rules.add(new FlowRuleOperation(rule, FlowRuleOperation.Type.REMOVE)); |
137 | - intent.id().fingerprint())); | ||
138 | prev = link.dst(); | 136 | prev = link.dst(); |
139 | } | 137 | } |
140 | // FIXME this should change to new api | 138 | // FIXME this should change to new api |
141 | - return Lists.newArrayList(new FlowRuleBatchOperation(rules, null, 0)); | 139 | + return Lists.newArrayList(ImmutableSet.of(rules)); |
142 | } | 140 | } |
143 | 141 | ||
144 | @Override | 142 | @Override |
145 | - public List<FlowRuleBatchOperation> replace(PathIntent oldIntent, PathIntent newIntent) { | 143 | + public List<Set<FlowRuleOperation>> replace(PathIntent oldIntent, PathIntent newIntent) { |
146 | // FIXME: implement this | 144 | // FIXME: implement this |
147 | - List<FlowRuleBatchOperation> batches = Lists.newArrayList(); | 145 | + List<Set<FlowRuleOperation>> batches = Lists.newArrayList(); |
148 | batches.addAll(uninstall(oldIntent)); | 146 | batches.addAll(uninstall(oldIntent)); |
149 | batches.addAll(install(newIntent)); | 147 | batches.addAll(install(newIntent)); |
150 | return batches; | 148 | return batches; | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.net.intent.impl; | 16 | package org.onosproject.net.intent.impl; |
17 | 17 | ||
18 | import com.google.common.collect.HashMultimap; | 18 | import com.google.common.collect.HashMultimap; |
19 | +import com.google.common.collect.ImmutableSet; | ||
19 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
20 | import com.google.common.collect.Maps; | 21 | import com.google.common.collect.Maps; |
21 | import com.google.common.collect.Multimap; | 22 | import com.google.common.collect.Multimap; |
... | @@ -32,9 +33,7 @@ import org.onosproject.core.impl.TestCoreManager; | ... | @@ -32,9 +33,7 @@ import org.onosproject.core.impl.TestCoreManager; |
32 | import org.onosproject.event.impl.TestEventDispatcher; | 33 | import org.onosproject.event.impl.TestEventDispatcher; |
33 | import org.onosproject.net.NetworkResource; | 34 | import org.onosproject.net.NetworkResource; |
34 | import org.onosproject.net.flow.FlowRule; | 35 | import org.onosproject.net.flow.FlowRule; |
35 | -import org.onosproject.net.flow.FlowRuleBatchEntry; | 36 | +import org.onosproject.net.flow.FlowRuleOperation; |
36 | -import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation; | ||
37 | -import org.onosproject.net.flow.FlowRuleBatchOperation; | ||
38 | import org.onosproject.net.intent.Intent; | 37 | import org.onosproject.net.intent.Intent; |
39 | import org.onosproject.net.intent.IntentCompiler; | 38 | import org.onosproject.net.intent.IntentCompiler; |
40 | import org.onosproject.net.intent.IntentEvent; | 39 | import org.onosproject.net.intent.IntentEvent; |
... | @@ -195,45 +194,45 @@ public class IntentManagerTest { | ... | @@ -195,45 +194,45 @@ public class IntentManagerTest { |
195 | 194 | ||
196 | private static class TestIntentInstaller implements IntentInstaller<MockInstallableIntent> { | 195 | private static class TestIntentInstaller implements IntentInstaller<MockInstallableIntent> { |
197 | @Override | 196 | @Override |
198 | - public List<FlowRuleBatchOperation> install(MockInstallableIntent intent) { | 197 | + public List<Set<org.onosproject.net.flow.FlowRuleOperation>> install(MockInstallableIntent intent) { |
199 | FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue()); | 198 | FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue()); |
200 | - List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); | 199 | + Set<FlowRuleOperation> rules = ImmutableSet.of( |
201 | - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, fr)); | 200 | + new FlowRuleOperation(fr, FlowRuleOperation.Type.ADD)); |
202 | - return Lists.newArrayList(new FlowRuleBatchOperation(rules, fr.deviceId(), 0)); | 201 | + return Lists.newArrayList(ImmutableSet.of(rules)); |
203 | } | 202 | } |
204 | 203 | ||
205 | @Override | 204 | @Override |
206 | - public List<FlowRuleBatchOperation> uninstall(MockInstallableIntent intent) { | 205 | + public List<Set<FlowRuleOperation>> uninstall(MockInstallableIntent intent) { |
207 | FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue()); | 206 | FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue()); |
208 | - List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); | 207 | + Set<FlowRuleOperation> rules = ImmutableSet.of( |
209 | - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, fr)); | 208 | + new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE)); |
210 | - return Lists.newArrayList(new FlowRuleBatchOperation(rules, fr.deviceId(), 0)); | 209 | + return Lists.newArrayList(ImmutableSet.of(rules)); |
211 | } | 210 | } |
212 | 211 | ||
213 | @Override | 212 | @Override |
214 | - public List<FlowRuleBatchOperation> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { | 213 | + public List<Set<FlowRuleOperation>> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { |
215 | FlowRule fr = new IntentTestsMocks.MockFlowRule(oldIntent.number().intValue()); | 214 | FlowRule fr = new IntentTestsMocks.MockFlowRule(oldIntent.number().intValue()); |
216 | FlowRule fr2 = new IntentTestsMocks.MockFlowRule(newIntent.number().intValue()); | 215 | FlowRule fr2 = new IntentTestsMocks.MockFlowRule(newIntent.number().intValue()); |
217 | - List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); | 216 | + Set<FlowRuleOperation> rules = ImmutableSet.of( |
218 | - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, fr)); | 217 | + new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE), |
219 | - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, fr2)); | 218 | + new FlowRuleOperation(fr2, FlowRuleOperation.Type.ADD)); |
220 | - return Lists.newArrayList(new FlowRuleBatchOperation(rules, fr.deviceId(), 0)); | 219 | + return Lists.newArrayList(ImmutableSet.of(rules)); |
221 | } | 220 | } |
222 | } | 221 | } |
223 | 222 | ||
224 | private static class TestIntentErrorInstaller implements IntentInstaller<MockInstallableIntent> { | 223 | private static class TestIntentErrorInstaller implements IntentInstaller<MockInstallableIntent> { |
225 | @Override | 224 | @Override |
226 | - public List<FlowRuleBatchOperation> install(MockInstallableIntent intent) { | 225 | + public List<Set<FlowRuleOperation>> install(MockInstallableIntent intent) { |
227 | throw new IntentInstallationException("install() always fails"); | 226 | throw new IntentInstallationException("install() always fails"); |
228 | } | 227 | } |
229 | 228 | ||
230 | @Override | 229 | @Override |
231 | - public List<FlowRuleBatchOperation> uninstall(MockInstallableIntent intent) { | 230 | + public List<Set<FlowRuleOperation>> uninstall(MockInstallableIntent intent) { |
232 | throw new IntentRemovalException("uninstall() always fails"); | 231 | throw new IntentRemovalException("uninstall() always fails"); |
233 | } | 232 | } |
234 | 233 | ||
235 | @Override | 234 | @Override |
236 | - public List<FlowRuleBatchOperation> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { | 235 | + public List<Set<FlowRuleOperation>> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { |
237 | throw new IntentInstallationException("replace() always fails"); | 236 | throw new IntentInstallationException("replace() always fails"); |
238 | } | 237 | } |
239 | } | 238 | } | ... | ... |
... | @@ -17,9 +17,10 @@ package org.onosproject.net.intent.impl; | ... | @@ -17,9 +17,10 @@ package org.onosproject.net.intent.impl; |
17 | 17 | ||
18 | import java.util.LinkedList; | 18 | import java.util.LinkedList; |
19 | import java.util.List; | 19 | import java.util.List; |
20 | +import java.util.Set; | ||
20 | 21 | ||
21 | import org.junit.Test; | 22 | import org.junit.Test; |
22 | -import org.onosproject.net.flow.FlowRuleBatchOperation; | 23 | +import org.onosproject.net.flow.FlowRuleOperation; |
23 | import org.onosproject.net.flow.TrafficSelector; | 24 | import org.onosproject.net.flow.TrafficSelector; |
24 | import org.onosproject.net.flow.TrafficTreatment; | 25 | import org.onosproject.net.flow.TrafficTreatment; |
25 | import org.onosproject.net.intent.AbstractIntentTest; | 26 | import org.onosproject.net.intent.AbstractIntentTest; |
... | @@ -96,9 +97,9 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { | ... | @@ -96,9 +97,9 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { |
96 | * | 97 | * |
97 | * @param compiledIntents list of compiled intents | 98 | * @param compiledIntents list of compiled intents |
98 | * @param resourceService service to use for resource allocation requests | 99 | * @param resourceService service to use for resource allocation requests |
99 | - * @return | 100 | + * @return fow rule entries |
100 | */ | 101 | */ |
101 | - private List<FlowRuleBatchOperation> installIntents(List<Intent> compiledIntents, | 102 | + private List<Set<FlowRuleOperation>> installIntents(List<Intent> compiledIntents, |
102 | LinkResourceService resourceService) { | 103 | LinkResourceService resourceService) { |
103 | final PathIntent path = (PathIntent) compiledIntents.get(0); | 104 | final PathIntent path = (PathIntent) compiledIntents.get(0); |
104 | 105 | ||
... | @@ -192,7 +193,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { | ... | @@ -192,7 +193,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { |
192 | assertThat(compiledIntents, notNullValue()); | 193 | assertThat(compiledIntents, notNullValue()); |
193 | assertThat(compiledIntents, hasSize(1)); | 194 | assertThat(compiledIntents, hasSize(1)); |
194 | 195 | ||
195 | - final List<FlowRuleBatchOperation> flowOperations = | 196 | + final List<Set<FlowRuleOperation>> flowOperations = |
196 | installIntents(compiledIntents, resourceService); | 197 | installIntents(compiledIntents, resourceService); |
197 | 198 | ||
198 | assertThat(flowOperations, notNullValue()); | 199 | assertThat(flowOperations, notNullValue()); |
... | @@ -241,7 +242,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { | ... | @@ -241,7 +242,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { |
241 | assertThat(compiledIntents, notNullValue()); | 242 | assertThat(compiledIntents, notNullValue()); |
242 | assertThat(compiledIntents, hasSize(1)); | 243 | assertThat(compiledIntents, hasSize(1)); |
243 | 244 | ||
244 | - final List<FlowRuleBatchOperation> flowOperations = | 245 | + final List<Set<FlowRuleOperation>> flowOperations = |
245 | installIntents(compiledIntents, resourceService); | 246 | installIntents(compiledIntents, resourceService); |
246 | 247 | ||
247 | assertThat(flowOperations, notNullValue()); | 248 | assertThat(flowOperations, notNullValue()); | ... | ... |
-
Please register or login to post a comment