Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 1 | package org.onosproject.net.intent.impl; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 2 | |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 3 | import java.util.Collections; |
| 4 | import java.util.Set; |
| 5 | import java.util.concurrent.Future; |
| 6 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 7 | import org.onosproject.core.ApplicationId; |
| 8 | import org.onosproject.net.DeviceId; |
| 9 | import org.onosproject.net.flow.CompletedBatchOperation; |
| 10 | import org.onosproject.net.flow.FlowEntry; |
| 11 | import org.onosproject.net.flow.FlowRule; |
| 12 | import org.onosproject.net.flow.FlowRuleBatchEntry; |
| 13 | import org.onosproject.net.flow.FlowRuleBatchOperation; |
| 14 | import org.onosproject.net.flow.FlowRuleListener; |
| 15 | import org.onosproject.net.flow.FlowRuleService; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 16 | |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 17 | import com.google.common.collect.ImmutableSet; |
| 18 | import com.google.common.collect.Sets; |
| 19 | import com.google.common.util.concurrent.Futures; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 20 | |
| 21 | |
| 22 | public class MockFlowRuleService implements FlowRuleService { |
| 23 | |
| 24 | private Future<CompletedBatchOperation> future; |
| 25 | final Set<FlowRule> flows = Sets.newHashSet(); |
| 26 | |
| 27 | public void setFuture(boolean success) { |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 28 | setFuture(success, 0); |
| 29 | } |
| 30 | |
| 31 | public void setFuture(boolean success, long intentId) { |
| 32 | if (success) { |
| 33 | future = Futures.immediateFuture(new CompletedBatchOperation(true, Collections.emptySet())); |
| 34 | } else { |
| 35 | final Set<Long> failedIds = ImmutableSet.of(intentId); |
| 36 | future = Futures.immediateFuture( |
| 37 | new CompletedBatchOperation(false, flows, failedIds)); |
| 38 | } |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public Future<CompletedBatchOperation> applyBatch(FlowRuleBatchOperation batch) { |
| 43 | for (FlowRuleBatchEntry fbe : batch.getOperations()) { |
| 44 | FlowRule fr = fbe.getTarget(); |
| 45 | switch (fbe.getOperator()) { |
| 46 | case ADD: |
| 47 | flows.add(fr); |
| 48 | break; |
| 49 | case REMOVE: |
| 50 | flows.remove(fr); |
| 51 | break; |
| 52 | case MODIFY: |
| 53 | break; |
| 54 | default: |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | return future; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public int getFlowRuleCount() { |
| 63 | return flows.size(); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
| 68 | return null; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void applyFlowRules(FlowRule... flowRules) { |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void removeFlowRules(FlowRule... flowRules) { |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public void removeFlowRulesById(ApplicationId appId) { |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public Iterable<FlowRule> getFlowRulesById(ApplicationId id) { |
| 85 | return null; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) { |
| 90 | return null; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public void addListener(FlowRuleListener listener) { |
| 95 | |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void removeListener(FlowRuleListener listener) { |
| 100 | |
| 101 | } |
| 102 | } |
| 103 | |