blob: ba74e3199e18399edac5926d07403d67e81302a5 [file] [log] [blame]
Brian O'Connor427a1762014-11-19 18:40:32 -08001package org.onlab.onos.net.intent.impl;
2
Ray Milkey93508c22014-12-02 11:35:56 -08003import java.util.Collections;
4import java.util.Set;
5import java.util.concurrent.Future;
6
Brian O'Connor427a1762014-11-19 18:40:32 -08007import org.onlab.onos.core.ApplicationId;
8import org.onlab.onos.net.DeviceId;
9import org.onlab.onos.net.flow.CompletedBatchOperation;
10import org.onlab.onos.net.flow.FlowEntry;
11import org.onlab.onos.net.flow.FlowRule;
12import org.onlab.onos.net.flow.FlowRuleBatchEntry;
13import org.onlab.onos.net.flow.FlowRuleBatchOperation;
14import org.onlab.onos.net.flow.FlowRuleListener;
15import org.onlab.onos.net.flow.FlowRuleService;
16
Ray Milkey93508c22014-12-02 11:35:56 -080017import com.google.common.collect.ImmutableSet;
18import com.google.common.collect.Sets;
19import com.google.common.util.concurrent.Futures;
Brian O'Connor427a1762014-11-19 18:40:32 -080020
21
22public 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 Milkey93508c22014-12-02 11:35:56 -080028 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'Connor427a1762014-11-19 18:40:32 -080039 }
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