Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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.flow.impl; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 17 | |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 18 | import com.google.common.base.Strings; |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 19 | import com.google.common.collect.ArrayListMultimap; |
| 20 | import com.google.common.collect.Iterables; |
| 21 | import com.google.common.collect.Lists; |
| 22 | import com.google.common.collect.Maps; |
| 23 | import com.google.common.collect.Multimap; |
| 24 | import com.google.common.collect.Sets; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 25 | import org.apache.felix.scr.annotations.Activate; |
| 26 | import org.apache.felix.scr.annotations.Component; |
| 27 | import org.apache.felix.scr.annotations.Deactivate; |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 28 | import org.apache.felix.scr.annotations.Modified; |
| 29 | import org.apache.felix.scr.annotations.Property; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 30 | import org.apache.felix.scr.annotations.Reference; |
| 31 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 32 | import org.apache.felix.scr.annotations.Service; |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 33 | import org.onlab.util.Tools; |
| 34 | import org.onosproject.cfg.ComponentConfigService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import org.onosproject.core.ApplicationId; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 36 | import org.onosproject.core.CoreService; |
| 37 | import org.onosproject.core.IdGenerator; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 38 | import org.onosproject.event.AbstractListenerRegistry; |
| 39 | import org.onosproject.event.EventDeliveryService; |
| 40 | import org.onosproject.net.Device; |
| 41 | import org.onosproject.net.DeviceId; |
| 42 | import org.onosproject.net.device.DeviceService; |
| 43 | import org.onosproject.net.flow.CompletedBatchOperation; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 44 | import org.onosproject.net.flow.FlowEntry; |
| 45 | import org.onosproject.net.flow.FlowRule; |
| 46 | import org.onosproject.net.flow.FlowRuleBatchEntry; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 47 | import org.onosproject.net.flow.FlowRuleBatchEvent; |
| 48 | import org.onosproject.net.flow.FlowRuleBatchOperation; |
| 49 | import org.onosproject.net.flow.FlowRuleBatchRequest; |
| 50 | import org.onosproject.net.flow.FlowRuleEvent; |
| 51 | import org.onosproject.net.flow.FlowRuleListener; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 52 | import org.onosproject.net.flow.FlowRuleOperation; |
| 53 | import org.onosproject.net.flow.FlowRuleOperations; |
| 54 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 55 | import org.onosproject.net.flow.FlowRuleProvider; |
| 56 | import org.onosproject.net.flow.FlowRuleProviderRegistry; |
| 57 | import org.onosproject.net.flow.FlowRuleProviderService; |
| 58 | import org.onosproject.net.flow.FlowRuleService; |
| 59 | import org.onosproject.net.flow.FlowRuleStore; |
| 60 | import org.onosproject.net.flow.FlowRuleStoreDelegate; |
| 61 | import org.onosproject.net.provider.AbstractProviderRegistry; |
| 62 | import org.onosproject.net.provider.AbstractProviderService; |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 63 | import org.osgi.service.component.ComponentContext; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 64 | import org.slf4j.Logger; |
| 65 | |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 66 | import java.util.Collections; |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 67 | import java.util.Dictionary; |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 68 | import java.util.List; |
| 69 | import java.util.Map; |
| 70 | import java.util.Set; |
| 71 | import java.util.concurrent.ConcurrentHashMap; |
| 72 | import java.util.concurrent.ExecutorService; |
| 73 | import java.util.concurrent.Executors; |
| 74 | import java.util.concurrent.atomic.AtomicBoolean; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 75 | |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 76 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 77 | import static org.onlab.util.Tools.groupedThreads; |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 78 | import static org.slf4j.LoggerFactory.getLogger; |
alshabib | a7f7ca8 | 2014-09-22 11:41:23 -0700 | [diff] [blame] | 79 | |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 80 | /** |
| 81 | * Provides implementation of the flow NB & SB APIs. |
| 82 | */ |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 83 | @Component(immediate = true, enabled = true) |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 84 | @Service |
tom | 202175a | 2014-09-19 19:00:11 -0700 | [diff] [blame] | 85 | public class FlowRuleManager |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 86 | extends AbstractProviderRegistry<FlowRuleProvider, FlowRuleProviderService> |
| 87 | implements FlowRuleService, FlowRuleProviderRegistry { |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 88 | |
Sho SHIMIZU | 183b12fd | 2015-01-20 14:56:39 -0800 | [diff] [blame] | 89 | enum BatchState { STARTED, FINISHED, CANCELLED } |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 90 | |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 91 | public static final String FLOW_RULE_NULL = "FlowRule cannot be null"; |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 92 | private static final boolean ALLOW_EXTRANEOUS_RULES = false; |
| 93 | |
| 94 | @Property(name = "allowExtraneousRules", boolValue = ALLOW_EXTRANEOUS_RULES, |
| 95 | label = "Allow flow rules in switch not installed by ONOS") |
| 96 | private boolean allowExtraneousRules = ALLOW_EXTRANEOUS_RULES; |
| 97 | |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 98 | private final Logger log = getLogger(getClass()); |
| 99 | |
| 100 | private final AbstractListenerRegistry<FlowRuleEvent, FlowRuleListener> |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 101 | listenerRegistry = new AbstractListenerRegistry<>(); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 102 | |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 103 | private final FlowRuleStoreDelegate delegate = new InternalStoreDelegate(); |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 104 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 105 | protected ExecutorService deviceInstallers = |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 106 | Executors.newFixedThreadPool(32, groupedThreads("onos/flowservice", "device-installer-%d")); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 107 | |
| 108 | protected ExecutorService operationsService = |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 109 | Executors.newFixedThreadPool(32, groupedThreads("onos/flowservice", "operations-%d")); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 110 | |
| 111 | private IdGenerator idGenerator; |
| 112 | |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 113 | private Map<Long, FlowOperationsProcessor> pendingFlowOperations |
| 114 | = new ConcurrentHashMap<>(); |
Yuta HIGUCHI | 9def047 | 2014-10-23 15:51:10 -0700 | [diff] [blame] | 115 | |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 116 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 117 | protected FlowRuleStore store; |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 118 | |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 119 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 120 | protected EventDeliveryService eventDispatcher; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 121 | |
| 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 123 | protected DeviceService deviceService; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 124 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 126 | protected CoreService coreService; |
| 127 | |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 128 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 129 | protected ComponentConfigService cfgService; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 130 | |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 131 | @Activate |
| 132 | public void activate(ComponentContext context) { |
| 133 | cfgService.registerProperties(getClass()); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 134 | idGenerator = coreService.getIdGenerator(FLOW_OP_TOPIC); |
| 135 | |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 136 | modified(context); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 137 | |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 138 | store.setDelegate(delegate); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 139 | eventDispatcher.addSink(FlowRuleEvent.class, listenerRegistry); |
| 140 | log.info("Started"); |
| 141 | } |
| 142 | |
| 143 | @Deactivate |
| 144 | public void deactivate() { |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 145 | cfgService.unregisterProperties(getClass(), false); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 146 | deviceInstallers.shutdownNow(); |
| 147 | operationsService.shutdownNow(); |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 148 | store.unsetDelegate(delegate); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 149 | eventDispatcher.removeSink(FlowRuleEvent.class); |
| 150 | log.info("Stopped"); |
| 151 | } |
| 152 | |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 153 | @Modified |
| 154 | public void modified(ComponentContext context) { |
| 155 | if (context == null) { |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | Dictionary<?, ?> properties = context.getProperties(); |
| 160 | |
| 161 | String s = Tools.get(properties, "allowExtraneousRules"); |
| 162 | allowExtraneousRules = Strings.isNullOrEmpty(s) ? ALLOW_EXTRANEOUS_RULES : Boolean.valueOf(s); |
| 163 | |
| 164 | if (allowExtraneousRules) { |
| 165 | log.info("Allowing flow rules not installed by ONOS"); |
| 166 | } |
| 167 | } |
| 168 | |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 169 | @Override |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 170 | public int getFlowRuleCount() { |
| 171 | return store.getFlowRuleCount(); |
| 172 | } |
| 173 | |
| 174 | @Override |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 175 | public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 176 | return store.getFlowEntries(deviceId); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | @Override |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 180 | public void applyFlowRules(FlowRule... flowRules) { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 181 | FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 182 | for (int i = 0; i < flowRules.length; i++) { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 183 | builder.add(flowRules[i]); |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 184 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 185 | apply(builder.build()); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public void removeFlowRules(FlowRule... flowRules) { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 190 | FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 191 | for (int i = 0; i < flowRules.length; i++) { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 192 | builder.remove(flowRules[i]); |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 193 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 194 | apply(builder.build()); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 195 | } |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 196 | |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 197 | @Override |
| 198 | public void removeFlowRulesById(ApplicationId id) { |
Madan Jampani | 6a45616 | 2014-10-24 11:36:17 -0700 | [diff] [blame] | 199 | removeFlowRules(Iterables.toArray(getFlowRulesById(id), FlowRule.class)); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | @Override |
| 203 | public Iterable<FlowRule> getFlowRulesById(ApplicationId id) { |
Madan Jampani | 6a45616 | 2014-10-24 11:36:17 -0700 | [diff] [blame] | 204 | Set<FlowRule> flowEntries = Sets.newHashSet(); |
| 205 | for (Device d : deviceService.getDevices()) { |
| 206 | for (FlowEntry flowEntry : store.getFlowEntries(d.id())) { |
| 207 | if (flowEntry.appId() == id.id()) { |
| 208 | flowEntries.add(flowEntry); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | return flowEntries; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | @Override |
alshabib | aa7e7de | 2014-11-12 19:20:44 -0800 | [diff] [blame] | 216 | public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) { |
| 217 | Set<FlowRule> matches = Sets.newHashSet(); |
| 218 | long toLookUp = ((long) appId.id() << 16) | groupId; |
| 219 | for (Device d : deviceService.getDevices()) { |
| 220 | for (FlowEntry flowEntry : store.getFlowEntries(d.id())) { |
| 221 | if ((flowEntry.id().value() >>> 32) == toLookUp) { |
| 222 | matches.add(flowEntry); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | return matches; |
| 227 | } |
| 228 | |
| 229 | @Override |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 230 | public void apply(FlowRuleOperations ops) { |
| 231 | operationsService.submit(new FlowOperationsProcessor(ops)); |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | @Override |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 235 | public void addListener(FlowRuleListener listener) { |
| 236 | listenerRegistry.addListener(listener); |
| 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void removeListener(FlowRuleListener listener) { |
| 241 | listenerRegistry.removeListener(listener); |
| 242 | } |
| 243 | |
| 244 | @Override |
| 245 | protected FlowRuleProviderService createProviderService( |
| 246 | FlowRuleProvider provider) { |
| 247 | return new InternalFlowRuleProviderService(provider); |
| 248 | } |
| 249 | |
| 250 | private class InternalFlowRuleProviderService |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 251 | extends AbstractProviderService<FlowRuleProvider> |
| 252 | implements FlowRuleProviderService { |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 253 | |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 254 | final Map<FlowEntry, Long> lastSeen = Maps.newConcurrentMap(); |
| 255 | |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 256 | protected InternalFlowRuleProviderService(FlowRuleProvider provider) { |
| 257 | super(provider); |
| 258 | } |
| 259 | |
| 260 | @Override |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 261 | public void flowRemoved(FlowEntry flowEntry) { |
| 262 | checkNotNull(flowEntry, FLOW_RULE_NULL); |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 263 | checkValidity(); |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 264 | lastSeen.remove(flowEntry); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 265 | FlowEntry stored = store.getFlowEntry(flowEntry); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 266 | if (stored == null) { |
Yuta HIGUCHI | 82e5326 | 2014-11-27 10:28:51 -0800 | [diff] [blame] | 267 | log.debug("Rule already evicted from store: {}", flowEntry); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 268 | return; |
| 269 | } |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 270 | Device device = deviceService.getDevice(flowEntry.deviceId()); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 271 | FlowRuleProvider frp = getProvider(device.providerId()); |
| 272 | FlowRuleEvent event = null; |
| 273 | switch (stored.state()) { |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 274 | case ADDED: |
| 275 | case PENDING_ADD: |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 276 | frp.applyFlowRule(stored); |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 277 | break; |
| 278 | case PENDING_REMOVE: |
| 279 | case REMOVED: |
| 280 | event = store.removeFlowRule(stored); |
| 281 | break; |
| 282 | default: |
| 283 | break; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 284 | |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 285 | } |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 286 | if (event != null) { |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 287 | log.debug("Flow {} removed", flowEntry); |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 288 | post(event); |
| 289 | } |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 290 | } |
| 291 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 292 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 293 | private void flowMissing(FlowEntry flowRule) { |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 294 | checkNotNull(flowRule, FLOW_RULE_NULL); |
| 295 | checkValidity(); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 296 | Device device = deviceService.getDevice(flowRule.deviceId()); |
| 297 | FlowRuleProvider frp = getProvider(device.providerId()); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 298 | FlowRuleEvent event = null; |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 299 | switch (flowRule.state()) { |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 300 | case PENDING_REMOVE: |
| 301 | case REMOVED: |
| 302 | event = store.removeFlowRule(flowRule); |
| 303 | frp.removeFlowRule(flowRule); |
| 304 | break; |
| 305 | case ADDED: |
| 306 | case PENDING_ADD: |
| 307 | frp.applyFlowRule(flowRule); |
| 308 | break; |
| 309 | default: |
| 310 | log.debug("Flow {} has not been installed.", flowRule); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 311 | } |
| 312 | |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 313 | if (event != null) { |
| 314 | log.debug("Flow {} removed", flowRule); |
| 315 | post(event); |
| 316 | } |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 317 | |
| 318 | } |
| 319 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 320 | |
| 321 | private void extraneousFlow(FlowRule flowRule) { |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 322 | checkNotNull(flowRule, FLOW_RULE_NULL); |
| 323 | checkValidity(); |
alshabib | 2374fc9 | 2014-10-22 11:03:23 -0700 | [diff] [blame] | 324 | FlowRuleProvider frp = getProvider(flowRule.deviceId()); |
| 325 | frp.removeFlowRule(flowRule); |
alshabib | 54ce589 | 2014-09-23 17:50:51 -0700 | [diff] [blame] | 326 | log.debug("Flow {} is on switch but not in store.", flowRule); |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 327 | } |
| 328 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 329 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 330 | private void flowAdded(FlowEntry flowEntry) { |
| 331 | checkNotNull(flowEntry, FLOW_RULE_NULL); |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 332 | checkValidity(); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 333 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 334 | if (checkRuleLiveness(flowEntry, store.getFlowEntry(flowEntry))) { |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 335 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 336 | FlowRuleEvent event = store.addOrUpdateFlowRule(flowEntry); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 337 | if (event == null) { |
| 338 | log.debug("No flow store event generated."); |
| 339 | } else { |
Jonathan Hart | 58682dd | 2014-11-24 20:11:16 -0800 | [diff] [blame] | 340 | log.trace("Flow {} {}", flowEntry, event.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 341 | post(event); |
| 342 | } |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 343 | } else { |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 344 | log.debug("Removing flow rules...."); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 345 | removeFlowRules(flowEntry); |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 346 | } |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 347 | |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 348 | } |
| 349 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 350 | private boolean checkRuleLiveness(FlowEntry swRule, FlowEntry storedRule) { |
| 351 | if (storedRule == null) { |
| 352 | return false; |
| 353 | } |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 354 | if (storedRule.isPermanent()) { |
| 355 | return true; |
| 356 | } |
| 357 | |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 358 | final long timeout = storedRule.timeout() * 1000; |
| 359 | final long currentTime = System.currentTimeMillis(); |
alshabib | 85c4197 | 2014-10-03 13:48:39 -0700 | [diff] [blame] | 360 | if (storedRule.packets() != swRule.packets()) { |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 361 | lastSeen.put(storedRule, currentTime); |
alshabib | 85c4197 | 2014-10-03 13:48:39 -0700 | [diff] [blame] | 362 | return true; |
| 363 | } |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 364 | if (!lastSeen.containsKey(storedRule)) { |
| 365 | // checking for the first time |
| 366 | lastSeen.put(storedRule, storedRule.lastSeen()); |
| 367 | // Use following if lastSeen attr. was removed. |
| 368 | //lastSeen.put(storedRule, currentTime); |
| 369 | } |
| 370 | Long last = lastSeen.get(storedRule); |
| 371 | if (last == null) { |
| 372 | // concurrently removed? let the liveness check fail |
| 373 | return false; |
| 374 | } |
alshabib | 85c4197 | 2014-10-03 13:48:39 -0700 | [diff] [blame] | 375 | |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 376 | if ((currentTime - last) <= timeout) { |
alshabib | c274c90 | 2014-10-03 14:58:27 -0700 | [diff] [blame] | 377 | return true; |
| 378 | } |
| 379 | return false; |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 382 | // Posts the specified event to the local event dispatcher. |
| 383 | private void post(FlowRuleEvent event) { |
| 384 | if (event != null) { |
| 385 | eventDispatcher.post(event); |
| 386 | } |
| 387 | } |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 388 | |
| 389 | @Override |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 390 | public void pushFlowMetrics(DeviceId deviceId, Iterable<FlowEntry> flowEntries) { |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 391 | Set<FlowEntry> storedRules = Sets.newHashSet(store.getFlowEntries(deviceId)); |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 392 | for (FlowEntry rule : flowEntries) { |
| 393 | try { |
| 394 | if (storedRules.remove(rule)) { |
| 395 | // we both have the rule, let's update some info then. |
| 396 | flowAdded(rule); |
| 397 | } else { |
| 398 | // the device has a rule the store does not have |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame^] | 399 | if (!allowExtraneousRules) { |
| 400 | extraneousFlow(rule); |
| 401 | } |
alshabib | 93cb57f | 2015-02-12 17:43:26 -0800 | [diff] [blame] | 402 | } |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 403 | } catch (Throwable e) { |
| 404 | log.debug("Can't process added or extra rule {}", e.getMessage()); |
| 405 | continue; |
alshabib | 93cb57f | 2015-02-12 17:43:26 -0800 | [diff] [blame] | 406 | } |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 407 | } |
| 408 | for (FlowEntry rule : storedRules) { |
| 409 | try { |
| 410 | // there are rules in the store that aren't on the switch |
| 411 | flowMissing(rule); |
| 412 | } catch (Throwable e) { |
| 413 | log.debug("Can't add missing flow rule {}", e.getMessage()); |
| 414 | continue; |
alshabib | 93cb57f | 2015-02-12 17:43:26 -0800 | [diff] [blame] | 415 | } |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 416 | } |
alshabib | 93cb57f | 2015-02-12 17:43:26 -0800 | [diff] [blame] | 417 | |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 418 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 419 | |
| 420 | @Override |
| 421 | public void batchOperationCompleted(long batchId, CompletedBatchOperation operation) { |
| 422 | store.batchOperationComplete(FlowRuleBatchEvent.completed( |
| 423 | new FlowRuleBatchRequest(batchId, Collections.emptySet()), |
| 424 | operation |
| 425 | )); |
| 426 | } |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 427 | } |
| 428 | |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 429 | // Store delegate to re-post events emitted from the store. |
| 430 | private class InternalStoreDelegate implements FlowRuleStoreDelegate { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 431 | |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 432 | |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 433 | // TODO: Right now we only dispatch events at individual flowEntry level. |
| 434 | // It may be more efficient for also dispatch events as a batch. |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 435 | @Override |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 436 | public void notify(FlowRuleBatchEvent event) { |
| 437 | final FlowRuleBatchRequest request = event.subject(); |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 438 | switch (event.type()) { |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 439 | case BATCH_OPERATION_REQUESTED: |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 440 | // Request has been forwarded to MASTER Node, and was |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 441 | request.ops().stream().forEach( |
| 442 | op -> { |
Ray Milkey | f7329c7 | 2015-02-17 11:37:01 -0800 | [diff] [blame] | 443 | switch (op.operator()) { |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 444 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 445 | case ADD: |
| 446 | eventDispatcher.post( |
| 447 | new FlowRuleEvent( |
| 448 | FlowRuleEvent.Type.RULE_ADD_REQUESTED, |
Ray Milkey | f7329c7 | 2015-02-17 11:37:01 -0800 | [diff] [blame] | 449 | op.target())); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 450 | break; |
| 451 | case REMOVE: |
| 452 | eventDispatcher.post( |
| 453 | new FlowRuleEvent( |
| 454 | FlowRuleEvent.Type.RULE_REMOVE_REQUESTED, |
Ray Milkey | f7329c7 | 2015-02-17 11:37:01 -0800 | [diff] [blame] | 455 | op.target())); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 456 | break; |
| 457 | case MODIFY: |
| 458 | //TODO: do something here when the time comes. |
| 459 | break; |
| 460 | default: |
Ray Milkey | f7329c7 | 2015-02-17 11:37:01 -0800 | [diff] [blame] | 461 | log.warn("Unknown flow operation operator: {}", op.operator()); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | ); |
| 465 | |
| 466 | DeviceId deviceId = event.deviceId(); |
| 467 | |
| 468 | FlowRuleBatchOperation batchOperation = |
| 469 | request.asBatchOperation(deviceId); |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 470 | |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 471 | FlowRuleProvider flowRuleProvider = |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 472 | getProvider(deviceId); |
Yuta HIGUCHI | f1ccee8 | 2014-11-11 20:39:58 -0800 | [diff] [blame] | 473 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 474 | flowRuleProvider.executeBatch(batchOperation); |
| 475 | |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 476 | break; |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 477 | |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 478 | case BATCH_OPERATION_COMPLETED: |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 479 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 480 | FlowOperationsProcessor fops = pendingFlowOperations.remove( |
| 481 | event.subject().batchId()); |
| 482 | if (event.result().isSuccess()) { |
| 483 | if (fops != null) { |
| 484 | fops.satisfy(event.deviceId()); |
| 485 | } |
| 486 | } else { |
| 487 | fops.fail(event.deviceId(), event.result().failedItems()); |
| 488 | } |
| 489 | |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 490 | break; |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 491 | |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 492 | default: |
| 493 | break; |
| 494 | } |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 495 | } |
| 496 | } |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 497 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 498 | private class FlowOperationsProcessor implements Runnable { |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 499 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 500 | private final List<Set<FlowRuleOperation>> stages; |
| 501 | private final FlowRuleOperationsContext context; |
| 502 | private final FlowRuleOperations fops; |
| 503 | private final AtomicBoolean hasFailed = new AtomicBoolean(false); |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 504 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 505 | private Set<DeviceId> pendingDevices; |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 506 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 507 | public FlowOperationsProcessor(FlowRuleOperations ops) { |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 508 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 509 | this.stages = Lists.newArrayList(ops.stages()); |
| 510 | this.context = ops.callback(); |
| 511 | this.fops = ops; |
| 512 | pendingDevices = Sets.newConcurrentHashSet(); |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 513 | |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 514 | |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | @Override |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 518 | public void run() { |
| 519 | if (stages.size() > 0) { |
| 520 | process(stages.remove(0)); |
| 521 | } else if (!hasFailed.get() && context != null) { |
| 522 | context.onSuccess(fops); |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 523 | } |
| 524 | } |
| 525 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 526 | private void process(Set<FlowRuleOperation> ops) { |
| 527 | Multimap<DeviceId, FlowRuleBatchEntry> perDeviceBatches = |
| 528 | ArrayListMultimap.create(); |
| 529 | |
| 530 | FlowRuleBatchEntry fbe; |
| 531 | for (FlowRuleOperation flowRuleOperation : ops) { |
| 532 | switch (flowRuleOperation.type()) { |
| 533 | // FIXME: Brian needs imagination when creating class names. |
| 534 | case ADD: |
| 535 | fbe = new FlowRuleBatchEntry( |
| 536 | FlowRuleBatchEntry.FlowRuleOperation.ADD, flowRuleOperation.rule()); |
| 537 | break; |
| 538 | case MODIFY: |
| 539 | fbe = new FlowRuleBatchEntry( |
| 540 | FlowRuleBatchEntry.FlowRuleOperation.MODIFY, flowRuleOperation.rule()); |
| 541 | break; |
| 542 | case REMOVE: |
| 543 | fbe = new FlowRuleBatchEntry( |
| 544 | FlowRuleBatchEntry.FlowRuleOperation.REMOVE, flowRuleOperation.rule()); |
| 545 | break; |
| 546 | default: |
| 547 | throw new UnsupportedOperationException("Unknown flow rule type " + flowRuleOperation.type()); |
| 548 | } |
| 549 | pendingDevices.add(flowRuleOperation.rule().deviceId()); |
| 550 | perDeviceBatches.put(flowRuleOperation.rule().deviceId(), fbe); |
| 551 | } |
| 552 | |
| 553 | |
| 554 | for (DeviceId deviceId : perDeviceBatches.keySet()) { |
| 555 | Long id = idGenerator.getNewId(); |
| 556 | final FlowRuleBatchOperation b = new FlowRuleBatchOperation(perDeviceBatches.get(deviceId), |
| 557 | deviceId, id); |
| 558 | pendingFlowOperations.put(id, this); |
| 559 | deviceInstallers.submit(new Runnable() { |
| 560 | @Override |
| 561 | public void run() { |
| 562 | store.storeBatch(b); |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 563 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 564 | }); |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 568 | public void satisfy(DeviceId devId) { |
| 569 | pendingDevices.remove(devId); |
| 570 | if (pendingDevices.isEmpty()) { |
| 571 | operationsService.submit(this); |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 572 | } |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 573 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 574 | |
| 575 | |
| 576 | |
| 577 | public void fail(DeviceId devId, Set<? extends FlowRule> failures) { |
| 578 | hasFailed.set(true); |
| 579 | pendingDevices.remove(devId); |
| 580 | if (pendingDevices.isEmpty()) { |
| 581 | operationsService.submit(this); |
| 582 | } |
| 583 | |
| 584 | if (context != null) { |
| 585 | final FlowRuleOperations.Builder failedOpsBuilder = |
| 586 | FlowRuleOperations.builder(); |
| 587 | failures.stream().forEach(failedOpsBuilder::add); |
| 588 | |
| 589 | context.onError(failedOpsBuilder.build()); |
| 590 | } |
| 591 | } |
| 592 | |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 593 | } |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 594 | } |