blob: 1da849e8bb9cbe02da78e4f3c28611638caa5ad7 [file] [log] [blame]
alshabibab984662014-12-04 18:56:18 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent.impl;
Brian O'Connor427a1762014-11-19 18:40:32 -080017
Ray Milkey93508c22014-12-02 11:35:56 -080018import java.util.Collections;
19import java.util.Set;
20import java.util.concurrent.Future;
21
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.flow.CompletedBatchOperation;
25import org.onosproject.net.flow.FlowEntry;
26import org.onosproject.net.flow.FlowRule;
27import org.onosproject.net.flow.FlowRuleBatchEntry;
28import org.onosproject.net.flow.FlowRuleBatchOperation;
29import org.onosproject.net.flow.FlowRuleListener;
30import org.onosproject.net.flow.FlowRuleService;
Brian O'Connor427a1762014-11-19 18:40:32 -080031
Ray Milkey93508c22014-12-02 11:35:56 -080032import com.google.common.collect.ImmutableSet;
33import com.google.common.collect.Sets;
34import com.google.common.util.concurrent.Futures;
Brian O'Connor427a1762014-11-19 18:40:32 -080035
36
37public class MockFlowRuleService implements FlowRuleService {
38
39 private Future<CompletedBatchOperation> future;
40 final Set<FlowRule> flows = Sets.newHashSet();
41
42 public void setFuture(boolean success) {
Ray Milkey93508c22014-12-02 11:35:56 -080043 setFuture(success, 0);
44 }
45
46 public void setFuture(boolean success, long intentId) {
47 if (success) {
48 future = Futures.immediateFuture(new CompletedBatchOperation(true, Collections.emptySet()));
49 } else {
50 final Set<Long> failedIds = ImmutableSet.of(intentId);
51 future = Futures.immediateFuture(
52 new CompletedBatchOperation(false, flows, failedIds));
53 }
Brian O'Connor427a1762014-11-19 18:40:32 -080054 }
55
56 @Override
57 public Future<CompletedBatchOperation> applyBatch(FlowRuleBatchOperation batch) {
58 for (FlowRuleBatchEntry fbe : batch.getOperations()) {
59 FlowRule fr = fbe.getTarget();
60 switch (fbe.getOperator()) {
61 case ADD:
62 flows.add(fr);
63 break;
64 case REMOVE:
65 flows.remove(fr);
66 break;
67 case MODIFY:
68 break;
69 default:
70 break;
71 }
72 }
73 return future;
74 }
75
76 @Override
77 public int getFlowRuleCount() {
78 return flows.size();
79 }
80
81 @Override
82 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
83 return null;
84 }
85
86 @Override
87 public void applyFlowRules(FlowRule... flowRules) {
88 }
89
90 @Override
91 public void removeFlowRules(FlowRule... flowRules) {
92 }
93
94 @Override
95 public void removeFlowRulesById(ApplicationId appId) {
96 }
97
98 @Override
99 public Iterable<FlowRule> getFlowRulesById(ApplicationId id) {
100 return null;
101 }
102
103 @Override
104 public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
105 return null;
106 }
107
108 @Override
109 public void addListener(FlowRuleListener listener) {
110
111 }
112
113 @Override
114 public void removeListener(FlowRuleListener listener) {
115
116 }
117}
118