alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame^] | 1 | /* |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.impl; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 17 | |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 18 | import java.util.Collections; |
| 19 | import java.util.Set; |
| 20 | import java.util.concurrent.Future; |
| 21 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.flow.CompletedBatchOperation; |
| 25 | import org.onosproject.net.flow.FlowEntry; |
| 26 | import org.onosproject.net.flow.FlowRule; |
| 27 | import org.onosproject.net.flow.FlowRuleBatchEntry; |
| 28 | import org.onosproject.net.flow.FlowRuleBatchOperation; |
| 29 | import org.onosproject.net.flow.FlowRuleListener; |
| 30 | import org.onosproject.net.flow.FlowRuleService; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 31 | |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 32 | import com.google.common.collect.ImmutableSet; |
| 33 | import com.google.common.collect.Sets; |
| 34 | import com.google.common.util.concurrent.Futures; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 35 | |
| 36 | |
| 37 | public 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 Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 43 | 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'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 54 | } |
| 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 | |