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; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 30 | import org.onosproject.net.flow.FlowRuleOperations; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.net.flow.FlowRuleService; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 32 | |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 33 | import com.google.common.collect.ImmutableSet; |
| 34 | import com.google.common.collect.Sets; |
| 35 | import com.google.common.util.concurrent.Futures; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 36 | |
| 37 | |
| 38 | public 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 Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 44 | setFuture(success, 0); |
| 45 | } |
| 46 | |
| 47 | public void setFuture(boolean success, long intentId) { |
| 48 | if (success) { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 49 | future = Futures.immediateFuture(new CompletedBatchOperation(true, Collections.emptySet(), null)); |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 50 | } else { |
| 51 | final Set<Long> failedIds = ImmutableSet.of(intentId); |
| 52 | future = Futures.immediateFuture( |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 53 | new CompletedBatchOperation(false, flows, failedIds, null)); |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 54 | } |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public Future<CompletedBatchOperation> applyBatch(FlowRuleBatchOperation batch) { |
| 59 | for (FlowRuleBatchEntry fbe : batch.getOperations()) { |
Sho SHIMIZU | aba9d00 | 2015-01-29 14:51:04 -0800 | [diff] [blame] | 60 | FlowRule fr = fbe.target(); |
| 61 | switch (fbe.operator()) { |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 62 | 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'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 78 | public void apply(FlowRuleOperations ops) { |
| 79 | |
| 80 | } |
| 81 | |
| 82 | @Override |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 83 | 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 | |