blob: 72de4f0bd2dac09692573986338ddb2dc2a0478e [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;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080030import org.onosproject.net.flow.FlowRuleOperations;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import org.onosproject.net.flow.FlowRuleService;
Brian O'Connor427a1762014-11-19 18:40:32 -080032
Ray Milkey93508c22014-12-02 11:35:56 -080033import com.google.common.collect.ImmutableSet;
34import com.google.common.collect.Sets;
35import com.google.common.util.concurrent.Futures;
Brian O'Connor427a1762014-11-19 18:40:32 -080036
37
38public class MockFlowRuleService implements FlowRuleService {
39
40 private Future<CompletedBatchOperation> future;
41 final Set<FlowRule> flows = Sets.newHashSet();
42
43 public void setFuture(boolean success) {
Ray Milkey93508c22014-12-02 11:35:56 -080044 setFuture(success, 0);
45 }
46
47 public void setFuture(boolean success, long intentId) {
48 if (success) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -080049 future = Futures.immediateFuture(new CompletedBatchOperation(true, Collections.emptySet(), null));
Ray Milkey93508c22014-12-02 11:35:56 -080050 } else {
51 final Set<Long> failedIds = ImmutableSet.of(intentId);
52 future = Futures.immediateFuture(
Brian O'Connor72cb19a2015-01-16 16:14:41 -080053 new CompletedBatchOperation(false, flows, failedIds, null));
Ray Milkey93508c22014-12-02 11:35:56 -080054 }
Brian O'Connor427a1762014-11-19 18:40:32 -080055 }
56
57 @Override
58 public Future<CompletedBatchOperation> applyBatch(FlowRuleBatchOperation batch) {
59 for (FlowRuleBatchEntry fbe : batch.getOperations()) {
Sho SHIMIZUaba9d002015-01-29 14:51:04 -080060 FlowRule fr = fbe.target();
61 switch (fbe.operator()) {
Brian O'Connor427a1762014-11-19 18:40:32 -080062 case ADD:
63 flows.add(fr);
64 break;
65 case REMOVE:
66 flows.remove(fr);
67 break;
68 case MODIFY:
69 break;
70 default:
71 break;
72 }
73 }
74 return future;
75 }
76
77 @Override
Brian O'Connor72cb19a2015-01-16 16:14:41 -080078 public void apply(FlowRuleOperations ops) {
79
80 }
81
82 @Override
Brian O'Connor427a1762014-11-19 18:40:32 -080083 public int getFlowRuleCount() {
84 return flows.size();
85 }
86
87 @Override
88 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
89 return null;
90 }
91
92 @Override
93 public void applyFlowRules(FlowRule... flowRules) {
94 }
95
96 @Override
97 public void removeFlowRules(FlowRule... flowRules) {
98 }
99
100 @Override
101 public void removeFlowRulesById(ApplicationId appId) {
102 }
103
104 @Override
105 public Iterable<FlowRule> getFlowRulesById(ApplicationId id) {
106 return null;
107 }
108
109 @Override
110 public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
111 return null;
112 }
113
114 @Override
115 public void addListener(FlowRuleListener listener) {
116
117 }
118
119 @Override
120 public void removeListener(FlowRuleListener listener) {
121
122 }
123}
124