Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
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 | |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ArrayListMultimap; |
| 19 | import com.google.common.collect.Iterables; |
| 20 | import com.google.common.collect.Lists; |
| 21 | import com.google.common.collect.Maps; |
| 22 | import com.google.common.collect.Multimap; |
| 23 | import com.google.common.collect.Sets; |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 24 | import org.onlab.util.Tools; |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 25 | import org.onosproject.cfg.ComponentConfigService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import org.onosproject.core.ApplicationId; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 27 | import org.onosproject.core.CoreService; |
| 28 | import org.onosproject.core.IdGenerator; |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 29 | import org.onosproject.mastership.MastershipService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.net.Device; |
| 31 | import org.onosproject.net.DeviceId; |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 32 | import org.onosproject.net.device.DeviceEvent; |
| 33 | import org.onosproject.net.device.DeviceListener; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.net.device.DeviceService; |
Jordan Halterman | 4f3193a | 2017-07-11 20:32:49 -0700 | [diff] [blame] | 35 | import org.onosproject.net.driver.DriverService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 36 | import org.onosproject.net.flow.CompletedBatchOperation; |
Charles M.C. Chan | 1229eca | 2015-05-18 06:27:52 +0800 | [diff] [blame] | 37 | import org.onosproject.net.flow.DefaultFlowEntry; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 38 | import org.onosproject.net.flow.FlowEntry; |
| 39 | import org.onosproject.net.flow.FlowRule; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 40 | import org.onosproject.net.flow.FlowRuleEvent; |
| 41 | import org.onosproject.net.flow.FlowRuleListener; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 42 | import org.onosproject.net.flow.FlowRuleOperation; |
| 43 | import org.onosproject.net.flow.FlowRuleOperations; |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 44 | import org.onosproject.net.flow.FlowRuleProgrammable; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 45 | import org.onosproject.net.flow.FlowRuleProvider; |
| 46 | import org.onosproject.net.flow.FlowRuleProviderRegistry; |
| 47 | import org.onosproject.net.flow.FlowRuleProviderService; |
| 48 | import org.onosproject.net.flow.FlowRuleService; |
| 49 | import org.onosproject.net.flow.FlowRuleStore; |
| 50 | import org.onosproject.net.flow.FlowRuleStoreDelegate; |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 51 | import org.onosproject.net.flow.TableStatisticsEntry; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 52 | import org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry; |
| 53 | import org.onosproject.net.flow.oldbatch.FlowRuleBatchEvent; |
| 54 | import org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation; |
| 55 | import org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest; |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 56 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 57 | import org.onosproject.net.provider.AbstractProviderService; |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 58 | import org.onosproject.net.provider.ProviderId; |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 59 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 60 | import org.osgi.service.component.annotations.Activate; |
| 61 | import org.osgi.service.component.annotations.Component; |
| 62 | import org.osgi.service.component.annotations.Deactivate; |
| 63 | import org.osgi.service.component.annotations.Modified; |
| 64 | import org.osgi.service.component.annotations.Reference; |
| 65 | import org.osgi.service.component.annotations.ReferenceCardinality; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 66 | import org.slf4j.Logger; |
| 67 | |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 68 | import java.util.Collections; |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 69 | import java.util.Dictionary; |
Sho SHIMIZU | b837cb7 | 2016-08-30 14:44:50 -0700 | [diff] [blame] | 70 | import java.util.HashSet; |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 71 | import java.util.List; |
| 72 | import java.util.Map; |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 73 | import java.util.Optional; |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 74 | import java.util.Set; |
| 75 | import java.util.concurrent.ConcurrentHashMap; |
| 76 | import java.util.concurrent.ExecutorService; |
| 77 | import java.util.concurrent.Executors; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 78 | |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 79 | import static com.google.common.base.Preconditions.checkNotNull; |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 80 | import static com.google.common.base.Strings.isNullOrEmpty; |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 81 | import static org.onlab.util.Tools.get; |
Brian O'Connor | d12267c | 2015-02-17 18:17:08 -0800 | [diff] [blame] | 82 | import static org.onlab.util.Tools.groupedThreads; |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 83 | import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_ADD_REQUESTED; |
| 84 | import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVE_REQUESTED; |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 85 | import static org.onosproject.security.AppGuard.checkPermission; |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 86 | import static org.onosproject.security.AppPermission.Type.FLOWRULE_READ; |
| 87 | import static org.onosproject.security.AppPermission.Type.FLOWRULE_WRITE; |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 88 | import static org.slf4j.LoggerFactory.getLogger; |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 89 | |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 90 | /** |
| 91 | * Provides implementation of the flow NB & SB APIs. |
| 92 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 93 | @Component(immediate = true, service = { FlowRuleService.class, FlowRuleProviderRegistry.class }) |
tom | 202175a | 2014-09-19 19:00:11 -0700 | [diff] [blame] | 94 | public class FlowRuleManager |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 95 | extends AbstractListenerProviderRegistry<FlowRuleEvent, FlowRuleListener, |
| 96 | FlowRuleProvider, FlowRuleProviderService> |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 97 | implements FlowRuleService, FlowRuleProviderRegistry { |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 98 | |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 99 | private final Logger log = getLogger(getClass()); |
| 100 | |
Thomas Vachuska | 227943d | 2018-03-19 09:37:28 -0700 | [diff] [blame] | 101 | private static final String DEVICE_ID_NULL = "Device ID cannot be null"; |
| 102 | private static final String FLOW_RULE_NULL = "FlowRule cannot be null"; |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 103 | private static final boolean ALLOW_EXTRANEOUS_RULES = false; |
| 104 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 105 | //@Property(name = "allowExtraneousRules", boolValue = ALLOW_EXTRANEOUS_RULES, |
| 106 | // label = "Allow flow rules in switch not installed by ONOS") |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 107 | private boolean allowExtraneousRules = ALLOW_EXTRANEOUS_RULES; |
| 108 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 109 | //@Property(name = "purgeOnDisconnection", boolValue = false, |
| 110 | // label = "Purge entries associated with a device when the device goes offline") |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 111 | private boolean purgeOnDisconnection = false; |
| 112 | |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 113 | private static final int DEFAULT_POLL_FREQUENCY = 30; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 114 | //@Property(name = "fallbackFlowPollFrequency", intValue = DEFAULT_POLL_FREQUENCY, |
| 115 | // label = "Frequency (in seconds) for polling flow statistics via fallback provider") |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 116 | private int fallbackFlowPollFrequency = DEFAULT_POLL_FREQUENCY; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 117 | |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 118 | private final FlowRuleStoreDelegate delegate = new InternalStoreDelegate(); |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 119 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 120 | |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 121 | private final FlowRuleDriverProvider driverProvider = new FlowRuleDriverProvider(); |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 122 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 123 | protected ExecutorService deviceInstallers = |
HIGUCHI Yuta | 060da9a | 2016-03-11 19:16:35 -0800 | [diff] [blame] | 124 | Executors.newFixedThreadPool(32, groupedThreads("onos/flowservice", "device-installer-%d", log)); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 125 | |
| 126 | protected ExecutorService operationsService = |
HIGUCHI Yuta | d9e0105 | 2016-04-14 09:31:42 -0700 | [diff] [blame] | 127 | Executors.newFixedThreadPool(32, groupedThreads("onos/flowservice", "operations-%d", log)); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 128 | |
| 129 | private IdGenerator idGenerator; |
| 130 | |
Sho SHIMIZU | 9f95074 | 2016-09-01 09:55:38 -0700 | [diff] [blame] | 131 | private final Map<Long, FlowOperationsProcessor> pendingFlowOperations = new ConcurrentHashMap<>(); |
Yuta HIGUCHI | 9def047 | 2014-10-23 15:51:10 -0700 | [diff] [blame] | 132 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 133 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 134 | protected FlowRuleStore store; |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 135 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 136 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 137 | protected DeviceService deviceService; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 138 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 139 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 140 | protected CoreService coreService; |
| 141 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 142 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 143 | protected MastershipService mastershipService; |
| 144 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 145 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 146 | protected ComponentConfigService cfgService; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 147 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 148 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jordan Halterman | 4f3193a | 2017-07-11 20:32:49 -0700 | [diff] [blame] | 149 | protected DriverService driverService; |
| 150 | |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 151 | @Activate |
| 152 | public void activate(ComponentContext context) { |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 153 | modified(context); |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 154 | store.setDelegate(delegate); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 155 | eventDispatcher.addSink(FlowRuleEvent.class, listenerRegistry); |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 156 | deviceService.addListener(deviceListener); |
| 157 | cfgService.registerProperties(getClass()); |
| 158 | idGenerator = coreService.getIdGenerator(FLOW_OP_TOPIC); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 159 | log.info("Started"); |
| 160 | } |
| 161 | |
| 162 | @Deactivate |
| 163 | public void deactivate() { |
Andrea Campanella | 5a3c09c | 2017-12-01 13:57:48 +0100 | [diff] [blame] | 164 | driverProvider.terminate(); |
Andrea Campanella | 3f1c61e | 2016-04-01 17:30:12 -0700 | [diff] [blame] | 165 | deviceService.removeListener(deviceListener); |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 166 | cfgService.unregisterProperties(getClass(), false); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 167 | deviceInstallers.shutdownNow(); |
| 168 | operationsService.shutdownNow(); |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 169 | store.unsetDelegate(delegate); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 170 | eventDispatcher.removeSink(FlowRuleEvent.class); |
| 171 | log.info("Stopped"); |
| 172 | } |
| 173 | |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 174 | @Modified |
| 175 | public void modified(ComponentContext context) { |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 176 | if (context != null) { |
| 177 | readComponentConfiguration(context); |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 178 | } |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 179 | driverProvider.init(new InternalFlowRuleProviderService(driverProvider), |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 180 | deviceService, mastershipService, fallbackFlowPollFrequency); |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | protected FlowRuleProvider defaultProvider() { |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 185 | return driverProvider; |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 186 | } |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 187 | |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 188 | /** |
| 189 | * Extracts properties from the component configuration context. |
| 190 | * |
| 191 | * @param context the component context |
| 192 | */ |
| 193 | private void readComponentConfiguration(ComponentContext context) { |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 194 | Dictionary<?, ?> properties = context.getProperties(); |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 195 | Boolean flag; |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 196 | |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 197 | flag = Tools.isPropertyEnabled(properties, "allowExtraneousRules"); |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 198 | if (flag == null) { |
| 199 | log.info("AllowExtraneousRules is not configured, " + |
| 200 | "using current value of {}", allowExtraneousRules); |
| 201 | } else { |
| 202 | allowExtraneousRules = flag; |
| 203 | log.info("Configured. AllowExtraneousRules is {}", |
| 204 | allowExtraneousRules ? "enabled" : "disabled"); |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 205 | } |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 206 | |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 207 | flag = Tools.isPropertyEnabled(properties, "purgeOnDisconnection"); |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 208 | if (flag == null) { |
| 209 | log.info("PurgeOnDisconnection is not configured, " + |
| 210 | "using current value of {}", purgeOnDisconnection); |
| 211 | } else { |
| 212 | purgeOnDisconnection = flag; |
| 213 | log.info("Configured. PurgeOnDisconnection is {}", |
| 214 | purgeOnDisconnection ? "enabled" : "disabled"); |
| 215 | } |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 216 | |
| 217 | String s = get(properties, "fallbackFlowPollFrequency"); |
Carmelo Cascone | e6a9754 | 2018-06-20 16:48:00 +0200 | [diff] [blame] | 218 | if (isNullOrEmpty(s)) { |
| 219 | log.info("fallbackFlowPollFrequency is not configured, " + |
| 220 | "using current value of {} seconds", |
| 221 | fallbackFlowPollFrequency); |
| 222 | } else { |
| 223 | try { |
| 224 | fallbackFlowPollFrequency = Integer.parseInt(s); |
| 225 | log.info("Configured. FallbackFlowPollFrequency is {} seconds", |
| 226 | fallbackFlowPollFrequency); |
| 227 | } catch (NumberFormatException e) { |
| 228 | log.warn("Configured fallbackFlowPollFrequency value '{}' " + |
| 229 | "is not a number, using current value of {} seconds", |
| 230 | fallbackFlowPollFrequency); |
| 231 | } |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 232 | } |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 233 | } |
| 234 | |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 235 | @Override |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 236 | public int getFlowRuleCount() { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 237 | checkPermission(FLOWRULE_READ); |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 238 | return store.getFlowRuleCount(); |
| 239 | } |
| 240 | |
| 241 | @Override |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 242 | public int getFlowRuleCount(DeviceId deviceId) { |
| 243 | checkPermission(FLOWRULE_READ); |
Thomas Vachuska | 227943d | 2018-03-19 09:37:28 -0700 | [diff] [blame] | 244 | checkNotNull(deviceId, DEVICE_ID_NULL); |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 245 | return store.getFlowRuleCount(deviceId); |
| 246 | } |
| 247 | |
| 248 | @Override |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 249 | public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 250 | checkPermission(FLOWRULE_READ); |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 251 | checkNotNull(deviceId, DEVICE_ID_NULL); |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 252 | return store.getFlowEntries(deviceId); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | @Override |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 256 | public void applyFlowRules(FlowRule... flowRules) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 257 | checkPermission(FLOWRULE_WRITE); |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 258 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 259 | FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 260 | for (FlowRule flowRule : flowRules) { |
| 261 | builder.add(flowRule); |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 262 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 263 | apply(builder.build()); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | @Override |
Kavitha Alagesan | c69c66a | 2016-06-15 14:26:04 +0530 | [diff] [blame] | 267 | public void purgeFlowRules(DeviceId deviceId) { |
| 268 | checkPermission(FLOWRULE_WRITE); |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 269 | checkNotNull(deviceId, DEVICE_ID_NULL); |
Kavitha Alagesan | c69c66a | 2016-06-15 14:26:04 +0530 | [diff] [blame] | 270 | store.purgeFlowRule(deviceId); |
| 271 | } |
| 272 | |
| 273 | @Override |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 274 | public void removeFlowRules(FlowRule... flowRules) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 275 | checkPermission(FLOWRULE_WRITE); |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 276 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 277 | FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 278 | for (FlowRule flowRule : flowRules) { |
| 279 | builder.remove(flowRule); |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 280 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 281 | apply(builder.build()); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 282 | } |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 283 | |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 284 | @Override |
| 285 | public void removeFlowRulesById(ApplicationId id) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 286 | checkPermission(FLOWRULE_WRITE); |
Madan Jampani | 6a45616 | 2014-10-24 11:36:17 -0700 | [diff] [blame] | 287 | removeFlowRules(Iterables.toArray(getFlowRulesById(id), FlowRule.class)); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Bharath Thiruveedula | 99849dc | 2016-11-17 22:04:38 +0530 | [diff] [blame] | 290 | @Deprecated |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 291 | @Override |
| 292 | public Iterable<FlowRule> getFlowRulesById(ApplicationId id) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 293 | checkPermission(FLOWRULE_READ); |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 294 | |
Madan Jampani | 6a45616 | 2014-10-24 11:36:17 -0700 | [diff] [blame] | 295 | Set<FlowRule> flowEntries = Sets.newHashSet(); |
| 296 | for (Device d : deviceService.getDevices()) { |
| 297 | for (FlowEntry flowEntry : store.getFlowEntries(d.id())) { |
| 298 | if (flowEntry.appId() == id.id()) { |
| 299 | flowEntries.add(flowEntry); |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | return flowEntries; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | @Override |
Bharath Thiruveedula | 99849dc | 2016-11-17 22:04:38 +0530 | [diff] [blame] | 307 | public Iterable<FlowEntry> getFlowEntriesById(ApplicationId id) { |
| 308 | checkPermission(FLOWRULE_READ); |
| 309 | |
| 310 | Set<FlowEntry> flowEntries = Sets.newHashSet(); |
| 311 | for (Device d : deviceService.getDevices()) { |
| 312 | for (FlowEntry flowEntry : store.getFlowEntries(d.id())) { |
| 313 | if (flowEntry.appId() == id.id()) { |
| 314 | flowEntries.add(flowEntry); |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | return flowEntries; |
| 319 | } |
| 320 | |
| 321 | @Override |
alshabib | aa7e7de | 2014-11-12 19:20:44 -0800 | [diff] [blame] | 322 | public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 323 | checkPermission(FLOWRULE_READ); |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 324 | |
alshabib | aa7e7de | 2014-11-12 19:20:44 -0800 | [diff] [blame] | 325 | Set<FlowRule> matches = Sets.newHashSet(); |
| 326 | long toLookUp = ((long) appId.id() << 16) | groupId; |
| 327 | for (Device d : deviceService.getDevices()) { |
| 328 | for (FlowEntry flowEntry : store.getFlowEntries(d.id())) { |
| 329 | if ((flowEntry.id().value() >>> 32) == toLookUp) { |
| 330 | matches.add(flowEntry); |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | return matches; |
| 335 | } |
| 336 | |
| 337 | @Override |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 338 | public void apply(FlowRuleOperations ops) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 339 | checkPermission(FLOWRULE_WRITE); |
HIGUCHI Yuta | d9e0105 | 2016-04-14 09:31:42 -0700 | [diff] [blame] | 340 | operationsService.execute(new FlowOperationsProcessor(ops)); |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | @Override |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 344 | protected FlowRuleProviderService createProviderService( |
| 345 | FlowRuleProvider provider) { |
| 346 | return new InternalFlowRuleProviderService(provider); |
| 347 | } |
| 348 | |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 349 | @Override |
| 350 | protected synchronized FlowRuleProvider getProvider(ProviderId pid) { |
| 351 | log.warn("should not be calling getProvider(ProviderId)"); |
| 352 | return super.getProvider(pid); |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * {@inheritDoc} |
| 357 | * if the Device does not support {@link FlowRuleProgrammable}. |
| 358 | */ |
| 359 | @Override |
| 360 | protected synchronized FlowRuleProvider getProvider(DeviceId deviceId) { |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 361 | checkNotNull(deviceId, DEVICE_ID_NULL); |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 362 | // if device supports FlowRuleProgrammable, |
| 363 | // use FlowRuleProgrammable via FlowRuleDriverProvider |
| 364 | return Optional.ofNullable(deviceService.getDevice(deviceId)) |
| 365 | .filter(dev -> dev.is(FlowRuleProgrammable.class)) |
| 366 | .<FlowRuleProvider>map(x -> driverProvider) |
| 367 | .orElseGet(() -> super.getProvider(deviceId)); |
| 368 | } |
| 369 | |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 370 | private class InternalFlowRuleProviderService |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 371 | extends AbstractProviderService<FlowRuleProvider> |
| 372 | implements FlowRuleProviderService { |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 373 | |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 374 | final Map<FlowEntry, Long> firstSeen = Maps.newConcurrentMap(); |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 375 | final Map<FlowEntry, Long> lastSeen = Maps.newConcurrentMap(); |
| 376 | |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 377 | |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 378 | protected InternalFlowRuleProviderService(FlowRuleProvider provider) { |
| 379 | super(provider); |
| 380 | } |
| 381 | |
| 382 | @Override |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 383 | public void flowRemoved(FlowEntry flowEntry) { |
| 384 | checkNotNull(flowEntry, FLOW_RULE_NULL); |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 385 | checkValidity(); |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 386 | lastSeen.remove(flowEntry); |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 387 | firstSeen.remove(flowEntry); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 388 | FlowEntry stored = store.getFlowEntry(flowEntry); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 389 | if (stored == null) { |
Yuta HIGUCHI | 82e5326 | 2014-11-27 10:28:51 -0800 | [diff] [blame] | 390 | log.debug("Rule already evicted from store: {}", flowEntry); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 391 | return; |
| 392 | } |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 393 | if (flowEntry.reason() == FlowEntry.FlowRemoveReason.HARD_TIMEOUT) { |
| 394 | ((DefaultFlowEntry) stored).setState(FlowEntry.FlowEntryState.REMOVED); |
| 395 | } |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 396 | FlowRuleProvider frp = getProvider(flowEntry.deviceId()); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 397 | FlowRuleEvent event = null; |
| 398 | switch (stored.state()) { |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 399 | case ADDED: |
| 400 | case PENDING_ADD: |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 401 | frp.applyFlowRule(stored); |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 402 | break; |
| 403 | case PENDING_REMOVE: |
| 404 | case REMOVED: |
| 405 | event = store.removeFlowRule(stored); |
| 406 | break; |
| 407 | default: |
| 408 | break; |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 409 | |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 410 | } |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 411 | if (event != null) { |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 412 | log.debug("Flow {} removed", flowEntry); |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 413 | post(event); |
| 414 | } |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 415 | } |
| 416 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 417 | |
Sivachidambaram Subramanian | 605104e | 2017-06-21 07:40:04 +0530 | [diff] [blame] | 418 | private void flowMissing(FlowEntry flowRule, boolean isFlowOnlyInStore) { |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 419 | checkNotNull(flowRule, FLOW_RULE_NULL); |
| 420 | checkValidity(); |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 421 | FlowRuleProvider frp = getProvider(flowRule.deviceId()); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 422 | FlowRuleEvent event = null; |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 423 | switch (flowRule.state()) { |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 424 | case PENDING_REMOVE: |
| 425 | case REMOVED: |
| 426 | event = store.removeFlowRule(flowRule); |
Sivachidambaram Subramanian | 605104e | 2017-06-21 07:40:04 +0530 | [diff] [blame] | 427 | log.debug("Flow {} removed", flowRule); |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 428 | break; |
| 429 | case ADDED: |
| 430 | case PENDING_ADD: |
Charles Chan | 93fa727 | 2016-01-26 22:27:02 -0800 | [diff] [blame] | 431 | event = store.pendingFlowRule(flowRule); |
Sivachidambaram Subramanian | 605104e | 2017-06-21 07:40:04 +0530 | [diff] [blame] | 432 | if (isFlowOnlyInStore) { |
| 433 | // Publishing RULE_ADD_REQUESTED event facilitates |
| 434 | // preparation of statistics for the concerned rule |
| 435 | if (event == null) { |
| 436 | event = new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADD_REQUESTED, flowRule); |
| 437 | } |
| 438 | } |
Charles M.C. Chan | 1229eca | 2015-05-18 06:27:52 +0800 | [diff] [blame] | 439 | try { |
| 440 | frp.applyFlowRule(flowRule); |
| 441 | } catch (UnsupportedOperationException e) { |
Yuta HIGUCHI | f76f6d5 | 2017-05-15 18:02:09 -0700 | [diff] [blame] | 442 | log.warn("Unsupported operation", e); |
Charles M.C. Chan | 1229eca | 2015-05-18 06:27:52 +0800 | [diff] [blame] | 443 | if (flowRule instanceof DefaultFlowEntry) { |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 444 | //FIXME modification of "stored" flow entry outside of store |
Charles M.C. Chan | 1229eca | 2015-05-18 06:27:52 +0800 | [diff] [blame] | 445 | ((DefaultFlowEntry) flowRule).setState(FlowEntry.FlowEntryState.FAILED); |
| 446 | } |
| 447 | } |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 448 | break; |
| 449 | default: |
| 450 | log.debug("Flow {} has not been installed.", flowRule); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 451 | } |
| 452 | |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 453 | if (event != null) { |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 454 | post(event); |
| 455 | } |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 456 | } |
| 457 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 458 | private void extraneousFlow(FlowRule flowRule) { |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 459 | checkNotNull(flowRule, FLOW_RULE_NULL); |
| 460 | checkValidity(); |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 461 | // getProvider is customized to favor driverProvider |
alshabib | 2374fc9 | 2014-10-22 11:03:23 -0700 | [diff] [blame] | 462 | FlowRuleProvider frp = getProvider(flowRule.deviceId()); |
| 463 | frp.removeFlowRule(flowRule); |
alshabib | 54ce589 | 2014-09-23 17:50:51 -0700 | [diff] [blame] | 464 | log.debug("Flow {} is on switch but not in store.", flowRule); |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 465 | } |
| 466 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 467 | private void flowAdded(FlowEntry flowEntry) { |
| 468 | checkNotNull(flowEntry, FLOW_RULE_NULL); |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 469 | checkValidity(); |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 470 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 471 | if (checkRuleLiveness(flowEntry, store.getFlowEntry(flowEntry))) { |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 472 | FlowRuleEvent event = store.addOrUpdateFlowRule(flowEntry); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 473 | if (event == null) { |
| 474 | log.debug("No flow store event generated."); |
| 475 | } else { |
Jonathan Hart | 58682dd | 2014-11-24 20:11:16 -0800 | [diff] [blame] | 476 | log.trace("Flow {} {}", flowEntry, event.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 477 | post(event); |
| 478 | } |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 479 | } else { |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 480 | log.debug("Removing flow rules...."); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 481 | removeFlowRules(flowEntry); |
Ayaka Koshibe | 08eabaa | 2014-09-17 14:59:25 -0700 | [diff] [blame] | 482 | } |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 483 | } |
| 484 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 485 | private boolean checkRuleLiveness(FlowEntry swRule, FlowEntry storedRule) { |
| 486 | if (storedRule == null) { |
| 487 | return false; |
| 488 | } |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 489 | if (storedRule.isPermanent()) { |
| 490 | return true; |
| 491 | } |
| 492 | |
Ray Milkey | 3717e60 | 2018-02-01 13:49:47 -0800 | [diff] [blame] | 493 | final long timeout = storedRule.timeout() * 1000L; |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 494 | final long currentTime = System.currentTimeMillis(); |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 495 | |
| 496 | // Checking flow with hardTimeout |
| 497 | if (storedRule.hardTimeout() != 0) { |
| 498 | if (!firstSeen.containsKey(storedRule)) { |
| 499 | // First time rule adding |
| 500 | firstSeen.put(storedRule, currentTime); |
| 501 | } else { |
| 502 | Long first = firstSeen.get(storedRule); |
Ray Milkey | 3717e60 | 2018-02-01 13:49:47 -0800 | [diff] [blame] | 503 | final long hardTimeout = storedRule.hardTimeout() * 1000L; |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 504 | if ((currentTime - first) > hardTimeout) { |
| 505 | return false; |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
Gamze Abaka | 8d03f18 | 2017-07-20 15:09:24 +0000 | [diff] [blame] | 510 | if (storedRule.packets() != swRule.packets() || storedRule.bytes() != swRule.bytes()) { |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 511 | lastSeen.put(storedRule, currentTime); |
alshabib | 85c4197 | 2014-10-03 13:48:39 -0700 | [diff] [blame] | 512 | return true; |
| 513 | } |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 514 | if (!lastSeen.containsKey(storedRule)) { |
| 515 | // checking for the first time |
| 516 | lastSeen.put(storedRule, storedRule.lastSeen()); |
| 517 | // Use following if lastSeen attr. was removed. |
| 518 | //lastSeen.put(storedRule, currentTime); |
| 519 | } |
| 520 | Long last = lastSeen.get(storedRule); |
alshabib | 85c4197 | 2014-10-03 13:48:39 -0700 | [diff] [blame] | 521 | |
Thomas Vachuska | c4ee737 | 2016-02-02 16:10:09 -0800 | [diff] [blame] | 522 | // concurrently removed? let the liveness check fail |
| 523 | return last != null && (currentTime - last) <= timeout; |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 524 | } |
| 525 | |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 526 | @Override |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 527 | public void pushFlowMetrics(DeviceId deviceId, Iterable<FlowEntry> flowEntries) { |
ssyoon90 | 30fbcd9 | 2015-08-17 10:42:07 +0900 | [diff] [blame] | 528 | pushFlowMetricsInternal(deviceId, flowEntries, true); |
| 529 | } |
| 530 | |
| 531 | @Override |
| 532 | public void pushFlowMetricsWithoutFlowMissing(DeviceId deviceId, Iterable<FlowEntry> flowEntries) { |
| 533 | pushFlowMetricsInternal(deviceId, flowEntries, false); |
| 534 | } |
| 535 | |
| 536 | private void pushFlowMetricsInternal(DeviceId deviceId, Iterable<FlowEntry> flowEntries, |
| 537 | boolean useMissingFlow) { |
Jonathan Hart | f44e42c | 2015-08-04 09:58:46 -0700 | [diff] [blame] | 538 | Map<FlowEntry, FlowEntry> storedRules = Maps.newHashMap(); |
| 539 | store.getFlowEntries(deviceId).forEach(f -> storedRules.put(f, f)); |
| 540 | |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 541 | for (FlowEntry rule : flowEntries) { |
| 542 | try { |
Jonathan Hart | f44e42c | 2015-08-04 09:58:46 -0700 | [diff] [blame] | 543 | FlowEntry storedRule = storedRules.remove(rule); |
| 544 | if (storedRule != null) { |
| 545 | if (storedRule.exactMatch(rule)) { |
| 546 | // we both have the rule, let's update some info then. |
| 547 | flowAdded(rule); |
| 548 | } else { |
| 549 | // the two rules are not an exact match - remove the |
| 550 | // switch's rule and install our rule |
| 551 | extraneousFlow(rule); |
Sivachidambaram Subramanian | 605104e | 2017-06-21 07:40:04 +0530 | [diff] [blame] | 552 | flowMissing(storedRule, false); |
Jonathan Hart | f44e42c | 2015-08-04 09:58:46 -0700 | [diff] [blame] | 553 | } |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 554 | } else { |
| 555 | // the device has a rule the store does not have |
Marc De Leenheer | de47caa | 2015-04-24 11:27:44 -0700 | [diff] [blame] | 556 | if (!allowExtraneousRules) { |
| 557 | extraneousFlow(rule); |
| 558 | } |
alshabib | 93cb57f | 2015-02-12 17:43:26 -0800 | [diff] [blame] | 559 | } |
Sho SHIMIZU | 24a00d9 | 2015-05-05 11:11:13 -0700 | [diff] [blame] | 560 | } catch (Exception e) { |
Jon Hall | 274cecb | 2017-08-09 12:15:48 -0700 | [diff] [blame] | 561 | log.warn("Can't process added or extra rule {} for device {}:{}", |
| 562 | rule, deviceId, e); |
alshabib | 93cb57f | 2015-02-12 17:43:26 -0800 | [diff] [blame] | 563 | } |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 564 | } |
ssyoon90 | 30fbcd9 | 2015-08-17 10:42:07 +0900 | [diff] [blame] | 565 | |
| 566 | // DO NOT reinstall |
| 567 | if (useMissingFlow) { |
| 568 | for (FlowEntry rule : storedRules.keySet()) { |
| 569 | try { |
| 570 | // there are rules in the store that aren't on the switch |
Sivachidambaram Subramanian | 605104e | 2017-06-21 07:40:04 +0530 | [diff] [blame] | 571 | log.debug("Adding the rule that is present in store but not on switch : {}", rule); |
| 572 | flowMissing(rule, true); |
ssyoon90 | 30fbcd9 | 2015-08-17 10:42:07 +0900 | [diff] [blame] | 573 | } catch (Exception e) { |
Yuta HIGUCHI | f76f6d5 | 2017-05-15 18:02:09 -0700 | [diff] [blame] | 574 | log.warn("Can't add missing flow rule:", e); |
ssyoon90 | 30fbcd9 | 2015-08-17 10:42:07 +0900 | [diff] [blame] | 575 | } |
alshabib | 93cb57f | 2015-02-12 17:43:26 -0800 | [diff] [blame] | 576 | } |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 577 | } |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 578 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 579 | |
| 580 | @Override |
| 581 | public void batchOperationCompleted(long batchId, CompletedBatchOperation operation) { |
| 582 | store.batchOperationComplete(FlowRuleBatchEvent.completed( |
| 583 | new FlowRuleBatchRequest(batchId, Collections.emptySet()), |
| 584 | operation |
| 585 | )); |
| 586 | } |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 587 | |
| 588 | @Override |
| 589 | public void pushTableStatistics(DeviceId deviceId, |
| 590 | List<TableStatisticsEntry> tableStats) { |
| 591 | store.updateTableStatistics(deviceId, tableStats); |
| 592 | } |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 593 | } |
| 594 | |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 595 | // Store delegate to re-post events emitted from the store. |
| 596 | private class InternalStoreDelegate implements FlowRuleStoreDelegate { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 597 | |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 598 | |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 599 | // TODO: Right now we only dispatch events at individual flowEntry level. |
| 600 | // It may be more efficient for also dispatch events as a batch. |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 601 | @Override |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 602 | public void notify(FlowRuleBatchEvent event) { |
| 603 | final FlowRuleBatchRequest request = event.subject(); |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 604 | switch (event.type()) { |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 605 | case BATCH_OPERATION_REQUESTED: |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 606 | // Request has been forwarded to MASTER Node, and was |
Sho SHIMIZU | a09e1bb | 2016-08-01 14:25:25 -0700 | [diff] [blame] | 607 | request.ops().forEach( |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 608 | op -> { |
Ray Milkey | f7329c7 | 2015-02-17 11:37:01 -0800 | [diff] [blame] | 609 | switch (op.operator()) { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 610 | case ADD: |
Sho SHIMIZU | 8efc896 | 2016-08-31 15:17:44 -0700 | [diff] [blame] | 611 | post(new FlowRuleEvent(RULE_ADD_REQUESTED, op.target())); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 612 | break; |
| 613 | case REMOVE: |
Sho SHIMIZU | 8efc896 | 2016-08-31 15:17:44 -0700 | [diff] [blame] | 614 | post(new FlowRuleEvent(RULE_REMOVE_REQUESTED, op.target())); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 615 | break; |
| 616 | case MODIFY: |
| 617 | //TODO: do something here when the time comes. |
| 618 | break; |
| 619 | default: |
Ray Milkey | f7329c7 | 2015-02-17 11:37:01 -0800 | [diff] [blame] | 620 | log.warn("Unknown flow operation operator: {}", op.operator()); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | ); |
| 624 | |
| 625 | DeviceId deviceId = event.deviceId(); |
Sho SHIMIZU | 8efc896 | 2016-08-31 15:17:44 -0700 | [diff] [blame] | 626 | FlowRuleBatchOperation batchOperation = request.asBatchOperation(deviceId); |
Yuta HIGUCHI | 48dcd37 | 2017-02-27 22:55:53 -0800 | [diff] [blame] | 627 | // getProvider is customized to favor driverProvider |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 628 | FlowRuleProvider flowRuleProvider = getProvider(deviceId); |
| 629 | if (flowRuleProvider != null) { |
| 630 | flowRuleProvider.executeBatch(batchOperation); |
| 631 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 632 | |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 633 | break; |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 634 | |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 635 | case BATCH_OPERATION_COMPLETED: |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 636 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 637 | FlowOperationsProcessor fops = pendingFlowOperations.remove( |
| 638 | event.subject().batchId()); |
| 639 | if (event.result().isSuccess()) { |
| 640 | if (fops != null) { |
| 641 | fops.satisfy(event.deviceId()); |
| 642 | } |
| 643 | } else { |
| 644 | fops.fail(event.deviceId(), event.result().failedItems()); |
| 645 | } |
| 646 | |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 647 | break; |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 648 | |
Yuta HIGUCHI | f3d51bd | 2014-10-21 01:05:33 -0700 | [diff] [blame] | 649 | default: |
| 650 | break; |
| 651 | } |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 652 | } |
| 653 | } |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 654 | |
Sho SHIMIZU | 5711ce1 | 2016-08-31 13:57:12 -0700 | [diff] [blame] | 655 | private static FlowRuleBatchEntry.FlowRuleOperation mapOperationType(FlowRuleOperation.Type input) { |
| 656 | switch (input) { |
| 657 | case ADD: |
| 658 | return FlowRuleBatchEntry.FlowRuleOperation.ADD; |
| 659 | case MODIFY: |
| 660 | return FlowRuleBatchEntry.FlowRuleOperation.MODIFY; |
| 661 | case REMOVE: |
| 662 | return FlowRuleBatchEntry.FlowRuleOperation.REMOVE; |
| 663 | default: |
| 664 | throw new UnsupportedOperationException("Unknown flow rule type " + input); |
| 665 | } |
| 666 | } |
| 667 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 668 | private class FlowOperationsProcessor implements Runnable { |
Sho SHIMIZU | 5f70942 | 2016-09-07 09:54:46 -0700 | [diff] [blame] | 669 | // Immutable |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 670 | private final FlowRuleOperations fops; |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 671 | |
Sho SHIMIZU | 5f70942 | 2016-09-07 09:54:46 -0700 | [diff] [blame] | 672 | // Mutable |
| 673 | private final List<Set<FlowRuleOperation>> stages; |
Sho SHIMIZU | c0bfe7c | 2016-09-14 16:54:30 -0700 | [diff] [blame] | 674 | private final Set<DeviceId> pendingDevices = new HashSet<>(); |
Sho SHIMIZU | 5f70942 | 2016-09-07 09:54:46 -0700 | [diff] [blame] | 675 | private boolean hasFailed = false; |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 676 | |
Sho SHIMIZU | 7c9b73a | 2016-08-30 14:08:28 -0700 | [diff] [blame] | 677 | FlowOperationsProcessor(FlowRuleOperations ops) { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 678 | this.stages = Lists.newArrayList(ops.stages()); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 679 | this.fops = ops; |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | @Override |
Sho SHIMIZU | 2d7c539 | 2016-08-30 14:14:39 -0700 | [diff] [blame] | 683 | public synchronized void run() { |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 684 | if (!stages.isEmpty()) { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 685 | process(stages.remove(0)); |
Sho SHIMIZU | ad4f2cd | 2016-09-01 13:05:56 -0700 | [diff] [blame] | 686 | } else if (!hasFailed) { |
Sho SHIMIZU | c9e4bb0 | 2016-09-01 12:43:39 -0700 | [diff] [blame] | 687 | fops.callback().onSuccess(fops); |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 691 | private void process(Set<FlowRuleOperation> ops) { |
Sho SHIMIZU | 8efc896 | 2016-08-31 15:17:44 -0700 | [diff] [blame] | 692 | Multimap<DeviceId, FlowRuleBatchEntry> perDeviceBatches = ArrayListMultimap.create(); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 693 | |
Sho SHIMIZU | f4fd3de | 2016-08-31 15:47:56 -0700 | [diff] [blame] | 694 | for (FlowRuleOperation op : ops) { |
| 695 | perDeviceBatches.put(op.rule().deviceId(), |
| 696 | new FlowRuleBatchEntry(mapOperationType(op.type()), op.rule())); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 697 | } |
Brian O'Connor | c9b64dc | 2016-09-13 23:01:07 +0000 | [diff] [blame] | 698 | pendingDevices.addAll(perDeviceBatches.keySet()); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 699 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 700 | for (DeviceId deviceId : perDeviceBatches.keySet()) { |
Sho SHIMIZU | 3a70431 | 2015-05-27 13:36:01 -0700 | [diff] [blame] | 701 | long id = idGenerator.getNewId(); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 702 | final FlowRuleBatchOperation b = new FlowRuleBatchOperation(perDeviceBatches.get(deviceId), |
| 703 | deviceId, id); |
Brian O'Connor | c9b64dc | 2016-09-13 23:01:07 +0000 | [diff] [blame] | 704 | pendingFlowOperations.put(id, this); |
HIGUCHI Yuta | d9e0105 | 2016-04-14 09:31:42 -0700 | [diff] [blame] | 705 | deviceInstallers.execute(() -> store.storeBatch(b)); |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
Sho SHIMIZU | 2d7c539 | 2016-08-30 14:14:39 -0700 | [diff] [blame] | 709 | synchronized void satisfy(DeviceId devId) { |
Brian O'Connor | c9b64dc | 2016-09-13 23:01:07 +0000 | [diff] [blame] | 710 | pendingDevices.remove(devId); |
| 711 | if (pendingDevices.isEmpty()) { |
Sho SHIMIZU | c0bfe7c | 2016-09-14 16:54:30 -0700 | [diff] [blame] | 712 | operationsService.execute(this); |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 713 | } |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 714 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 715 | |
Sho SHIMIZU | 2d7c539 | 2016-08-30 14:14:39 -0700 | [diff] [blame] | 716 | synchronized void fail(DeviceId devId, Set<? extends FlowRule> failures) { |
Sho SHIMIZU | b9e0ab7 | 2016-09-14 16:54:13 -0700 | [diff] [blame] | 717 | hasFailed = true; |
Brian O'Connor | c9b64dc | 2016-09-13 23:01:07 +0000 | [diff] [blame] | 718 | pendingDevices.remove(devId); |
| 719 | if (pendingDevices.isEmpty()) { |
Sho SHIMIZU | c0bfe7c | 2016-09-14 16:54:30 -0700 | [diff] [blame] | 720 | operationsService.execute(this); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 721 | } |
| 722 | |
Sho SHIMIZU | ad4f2cd | 2016-09-01 13:05:56 -0700 | [diff] [blame] | 723 | FlowRuleOperations.Builder failedOpsBuilder = FlowRuleOperations.builder(); |
| 724 | failures.forEach(failedOpsBuilder::add); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 725 | |
Sho SHIMIZU | ad4f2cd | 2016-09-01 13:05:56 -0700 | [diff] [blame] | 726 | fops.callback().onError(failedOpsBuilder.build()); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 727 | } |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 728 | } |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 729 | |
| 730 | @Override |
| 731 | public Iterable<TableStatisticsEntry> getFlowTableStatistics(DeviceId deviceId) { |
| 732 | checkPermission(FLOWRULE_READ); |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 733 | checkNotNull(deviceId, DEVICE_ID_NULL); |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 734 | return store.getTableStatistics(deviceId); |
| 735 | } |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 736 | |
Patryk Konopka | 7e40c01 | 2017-06-06 13:38:06 +0200 | [diff] [blame] | 737 | @Override |
| 738 | public long getActiveFlowRuleCount(DeviceId deviceId) { |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 739 | checkNotNull(deviceId, DEVICE_ID_NULL); |
Patryk Konopka | 7e40c01 | 2017-06-06 13:38:06 +0200 | [diff] [blame] | 740 | return store.getActiveFlowRuleCount(deviceId); |
| 741 | } |
| 742 | |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 743 | private class InternalDeviceListener implements DeviceListener { |
| 744 | @Override |
| 745 | public void event(DeviceEvent event) { |
| 746 | switch (event.type()) { |
| 747 | case DEVICE_REMOVED: |
| 748 | case DEVICE_AVAILABILITY_CHANGED: |
| 749 | DeviceId deviceId = event.subject().id(); |
| 750 | if (!deviceService.isAvailable(deviceId)) { |
| 751 | if (purgeOnDisconnection) { |
| 752 | store.purgeFlowRule(deviceId); |
| 753 | } |
| 754 | } |
| 755 | break; |
| 756 | default: |
| 757 | break; |
| 758 | } |
| 759 | } |
| 760 | } |
alshabib | 57044ba | 2014-09-16 15:58:01 -0700 | [diff] [blame] | 761 | } |