Updating MockFlowRuleService with new semantics
Change-Id: I0a373e6cb25728ca48736902feedc3ed8869fa44
Showing
2 changed files
with
48 additions
and
45 deletions
| ... | @@ -396,14 +396,14 @@ public class IntentManagerTest { | ... | @@ -396,14 +396,14 @@ public class IntentManagerTest { |
| 396 | @Test | 396 | @Test |
| 397 | public void errorIntentInstallFromFlows() { | 397 | public void errorIntentInstallFromFlows() { |
| 398 | final Long id = MockIntent.nextId(); | 398 | final Long id = MockIntent.nextId(); |
| 399 | - flowRuleService.setFuture(false, 1); | 399 | + flowRuleService.setFuture(false); |
| 400 | MockIntent intent = new MockIntent(id); | 400 | MockIntent intent = new MockIntent(id); |
| 401 | listener.setLatch(1, Type.FAILED); | 401 | listener.setLatch(1, Type.FAILED); |
| 402 | listener.setLatch(1, Type.INSTALL_REQ); | 402 | listener.setLatch(1, Type.INSTALL_REQ); |
| 403 | service.submit(intent); | 403 | service.submit(intent); |
| 404 | listener.await(Type.INSTALL_REQ); | 404 | listener.await(Type.INSTALL_REQ); |
| 405 | delay(10); // need to make sure we have some failed futures returned first | 405 | delay(10); // need to make sure we have some failed futures returned first |
| 406 | - flowRuleService.setFuture(true, 0); | 406 | + flowRuleService.setFuture(true); |
| 407 | listener.await(Type.FAILED); | 407 | listener.await(Type.FAILED); |
| 408 | } | 408 | } |
| 409 | 409 | ||
| ... | @@ -429,7 +429,7 @@ public class IntentManagerTest { | ... | @@ -429,7 +429,7 @@ public class IntentManagerTest { |
| 429 | @Test | 429 | @Test |
| 430 | public void errorIntentInstallNeverTrue() { | 430 | public void errorIntentInstallNeverTrue() { |
| 431 | final Long id = MockIntent.nextId(); | 431 | final Long id = MockIntent.nextId(); |
| 432 | - flowRuleService.setFuture(false, 1); | 432 | + flowRuleService.setFuture(false); |
| 433 | MockIntent intent = new MockIntent(id); | 433 | MockIntent intent = new MockIntent(id); |
| 434 | listener.setLatch(1, Type.WITHDRAWN); | 434 | listener.setLatch(1, Type.WITHDRAWN); |
| 435 | listener.setLatch(1, Type.INSTALL_REQ); | 435 | listener.setLatch(1, Type.INSTALL_REQ); |
| ... | @@ -437,7 +437,7 @@ public class IntentManagerTest { | ... | @@ -437,7 +437,7 @@ public class IntentManagerTest { |
| 437 | listener.await(Type.INSTALL_REQ); | 437 | listener.await(Type.INSTALL_REQ); |
| 438 | // The delay here forces the retry loop in the intent manager to time out | 438 | // The delay here forces the retry loop in the intent manager to time out |
| 439 | delay(100); | 439 | delay(100); |
| 440 | - flowRuleService.setFuture(false, 1); | 440 | + flowRuleService.setFuture(false); |
| 441 | service.withdraw(intent); | 441 | service.withdraw(intent); |
| 442 | listener.await(Type.WITHDRAWN); | 442 | listener.await(Type.WITHDRAWN); |
| 443 | } | 443 | } | ... | ... |
| ... | @@ -15,68 +15,67 @@ | ... | @@ -15,68 +15,67 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.intent.impl; | 16 | package org.onosproject.net.intent.impl; |
| 17 | 17 | ||
| 18 | -import java.util.Collections; | 18 | +import com.google.common.collect.Sets; |
| 19 | -import java.util.Set; | ||
| 20 | -import java.util.concurrent.Future; | ||
| 21 | - | ||
| 22 | import org.onosproject.core.ApplicationId; | 19 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.flow.CompletedBatchOperation; | 21 | import org.onosproject.net.flow.CompletedBatchOperation; |
| 22 | +import org.onosproject.net.flow.DefaultFlowEntry; | ||
| 25 | import org.onosproject.net.flow.FlowEntry; | 23 | import org.onosproject.net.flow.FlowEntry; |
| 26 | import org.onosproject.net.flow.FlowRule; | 24 | import org.onosproject.net.flow.FlowRule; |
| 27 | -import org.onosproject.net.flow.FlowRuleBatchEntry; | ||
| 28 | import org.onosproject.net.flow.FlowRuleBatchOperation; | 25 | import org.onosproject.net.flow.FlowRuleBatchOperation; |
| 29 | import org.onosproject.net.flow.FlowRuleListener; | 26 | import org.onosproject.net.flow.FlowRuleListener; |
| 30 | import org.onosproject.net.flow.FlowRuleOperations; | 27 | import org.onosproject.net.flow.FlowRuleOperations; |
| 31 | import org.onosproject.net.flow.FlowRuleService; | 28 | import org.onosproject.net.flow.FlowRuleService; |
| 32 | 29 | ||
| 33 | -import com.google.common.collect.ImmutableSet; | 30 | +import java.util.Set; |
| 34 | -import com.google.common.collect.Sets; | 31 | +import java.util.concurrent.Future; |
| 35 | -import com.google.common.util.concurrent.Futures; | 32 | +import java.util.stream.Collectors; |
| 36 | 33 | ||
| 37 | 34 | ||
| 38 | public class MockFlowRuleService implements FlowRuleService { | 35 | public class MockFlowRuleService implements FlowRuleService { |
| 39 | 36 | ||
| 40 | - private Future<CompletedBatchOperation> future; | ||
| 41 | final Set<FlowRule> flows = Sets.newHashSet(); | 37 | final Set<FlowRule> flows = Sets.newHashSet(); |
| 38 | + boolean success; | ||
| 42 | 39 | ||
| 43 | public void setFuture(boolean success) { | 40 | public void setFuture(boolean success) { |
| 44 | - setFuture(success, 0); | 41 | + this.success = success; |
| 45 | } | 42 | } |
| 46 | 43 | ||
| 47 | - public void setFuture(boolean success, long intentId) { | 44 | + @Override |
| 48 | - if (success) { | 45 | + public Future<CompletedBatchOperation> applyBatch(FlowRuleBatchOperation batch) { |
| 49 | - future = Futures.immediateFuture(new CompletedBatchOperation(true, Collections.emptySet(), null)); | 46 | + throw new UnsupportedOperationException("deprecated"); |
| 50 | - } else { | ||
| 51 | - final Set<Long> failedIds = ImmutableSet.of(intentId); | ||
| 52 | - future = Futures.immediateFuture( | ||
| 53 | - new CompletedBatchOperation(false, flows, failedIds, null)); | ||
| 54 | - } | ||
| 55 | } | 47 | } |
| 56 | 48 | ||
| 57 | @Override | 49 | @Override |
| 58 | - public Future<CompletedBatchOperation> applyBatch(FlowRuleBatchOperation batch) { | 50 | + public void apply(FlowRuleOperations ops) { |
| 59 | - for (FlowRuleBatchEntry fbe : batch.getOperations()) { | 51 | + ops.stages().forEach(stage -> stage.forEach(flow -> { |
| 60 | - FlowRule fr = fbe.target(); | 52 | + switch (flow.type()) { |
| 61 | - switch (fbe.operator()) { | ||
| 62 | case ADD: | 53 | case ADD: |
| 63 | - flows.add(fr); | 54 | + case MODIFY: //TODO is this the right behavior for modify? |
| 55 | + flows.add(flow.rule()); | ||
| 64 | break; | 56 | break; |
| 65 | case REMOVE: | 57 | case REMOVE: |
| 66 | - flows.remove(fr); | 58 | + flows.remove(flow.rule()); |
| 67 | - break; | ||
| 68 | - case MODIFY: | ||
| 69 | break; | 59 | break; |
| 70 | default: | 60 | default: |
| 71 | break; | 61 | break; |
| 72 | } | 62 | } |
| 63 | + })); | ||
| 64 | + if (success) { | ||
| 65 | + ops.callback().onSuccess(ops); | ||
| 66 | + } else { | ||
| 67 | + ops.callback().onError(ops); | ||
| 73 | } | 68 | } |
| 74 | - return future; | ||
| 75 | } | 69 | } |
| 76 | 70 | ||
| 77 | @Override | 71 | @Override |
| 78 | - public void apply(FlowRuleOperations ops) { | 72 | + public void addListener(FlowRuleListener listener) { |
| 73 | + //TODO not implemented | ||
| 74 | + } | ||
| 79 | 75 | ||
| 76 | + @Override | ||
| 77 | + public void removeListener(FlowRuleListener listener) { | ||
| 78 | + //TODO not implemented | ||
| 80 | } | 79 | } |
| 81 | 80 | ||
| 82 | @Override | 81 | @Override |
| ... | @@ -86,39 +85,43 @@ public class MockFlowRuleService implements FlowRuleService { | ... | @@ -86,39 +85,43 @@ public class MockFlowRuleService implements FlowRuleService { |
| 86 | 85 | ||
| 87 | @Override | 86 | @Override |
| 88 | public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { | 87 | public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
| 89 | - return null; | 88 | + return flows.stream() |
| 89 | + .filter(flow -> flow.deviceId().equals(deviceId)) | ||
| 90 | + .map(DefaultFlowEntry::new) | ||
| 91 | + .collect(Collectors.toList()); | ||
| 90 | } | 92 | } |
| 91 | 93 | ||
| 92 | @Override | 94 | @Override |
| 93 | public void applyFlowRules(FlowRule... flowRules) { | 95 | public void applyFlowRules(FlowRule... flowRules) { |
| 96 | + for (FlowRule flow : flowRules) { | ||
| 97 | + flows.add(flow); | ||
| 98 | + } | ||
| 94 | } | 99 | } |
| 95 | 100 | ||
| 96 | @Override | 101 | @Override |
| 97 | public void removeFlowRules(FlowRule... flowRules) { | 102 | public void removeFlowRules(FlowRule... flowRules) { |
| 103 | + for (FlowRule flow : flowRules) { | ||
| 104 | + flows.remove(flow); | ||
| 105 | + } | ||
| 98 | } | 106 | } |
| 99 | 107 | ||
| 100 | @Override | 108 | @Override |
| 101 | public void removeFlowRulesById(ApplicationId appId) { | 109 | public void removeFlowRulesById(ApplicationId appId) { |
| 110 | + //TODO not implemented | ||
| 102 | } | 111 | } |
| 103 | 112 | ||
| 104 | @Override | 113 | @Override |
| 105 | public Iterable<FlowRule> getFlowRulesById(ApplicationId id) { | 114 | public Iterable<FlowRule> getFlowRulesById(ApplicationId id) { |
| 106 | - return null; | 115 | + return flows.stream() |
| 116 | + .filter(flow -> flow.appId() == id.id()) | ||
| 117 | + .collect(Collectors.toList()); | ||
| 107 | } | 118 | } |
| 108 | 119 | ||
| 109 | @Override | 120 | @Override |
| 110 | public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) { | 121 | public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) { |
| 111 | - return null; | 122 | + return flows.stream() |
| 112 | - } | 123 | + .filter(flow -> flow.appId() == appId.id() && flow.groupId().id() == groupId) |
| 113 | - | 124 | + .collect(Collectors.toList()); |
| 114 | - @Override | ||
| 115 | - public void addListener(FlowRuleListener listener) { | ||
| 116 | - | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - @Override | ||
| 120 | - public void removeListener(FlowRuleListener listener) { | ||
| 121 | - | ||
| 122 | } | 125 | } |
| 123 | } | 126 | } |
| 124 | 127 | ... | ... |
-
Please register or login to post a comment