Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -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 | */ |
| 16 | package org.onosproject.store.flow.impl; |
| 17 | |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 18 | import java.util.Collections; |
Ray Milkey | 2b6ff42 | 2016-08-26 13:03:15 -0700 | [diff] [blame] | 19 | import java.util.Dictionary; |
| 20 | import java.util.HashSet; |
| 21 | import java.util.List; |
| 22 | import java.util.Map; |
| 23 | import java.util.Objects; |
| 24 | import java.util.Set; |
| 25 | import java.util.concurrent.ExecutorService; |
| 26 | import java.util.concurrent.Executors; |
| 27 | import java.util.concurrent.ScheduledExecutorService; |
| 28 | import java.util.concurrent.ScheduledFuture; |
| 29 | import java.util.concurrent.TimeUnit; |
| 30 | import java.util.concurrent.atomic.AtomicInteger; |
| 31 | import java.util.concurrent.atomic.AtomicReference; |
| 32 | import java.util.stream.Collectors; |
| 33 | |
Patryk Konopka | 7e40c01 | 2017-06-06 13:38:06 +0200 | [diff] [blame^] | 34 | import com.google.common.collect.Streams; |
Ray Milkey | 2b6ff42 | 2016-08-26 13:03:15 -0700 | [diff] [blame] | 35 | import org.apache.felix.scr.annotations.Activate; |
| 36 | import org.apache.felix.scr.annotations.Component; |
| 37 | import org.apache.felix.scr.annotations.Deactivate; |
| 38 | import org.apache.felix.scr.annotations.Modified; |
| 39 | import org.apache.felix.scr.annotations.Property; |
| 40 | import org.apache.felix.scr.annotations.Reference; |
| 41 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 42 | import org.apache.felix.scr.annotations.Service; |
| 43 | import org.onlab.util.KryoNamespace; |
| 44 | import org.onlab.util.Tools; |
| 45 | import org.onosproject.cfg.ComponentConfigService; |
| 46 | import org.onosproject.cluster.ClusterService; |
| 47 | import org.onosproject.cluster.NodeId; |
| 48 | import org.onosproject.core.CoreService; |
| 49 | import org.onosproject.core.IdGenerator; |
| 50 | import org.onosproject.mastership.MastershipService; |
| 51 | import org.onosproject.net.DeviceId; |
| 52 | import org.onosproject.net.device.DeviceService; |
| 53 | import org.onosproject.net.flow.CompletedBatchOperation; |
| 54 | import org.onosproject.net.flow.DefaultFlowEntry; |
| 55 | import org.onosproject.net.flow.FlowEntry; |
| 56 | import org.onosproject.net.flow.FlowEntry.FlowEntryState; |
| 57 | import org.onosproject.net.flow.FlowId; |
| 58 | import org.onosproject.net.flow.FlowRule; |
| 59 | import org.onosproject.net.flow.FlowRuleBatchEntry; |
| 60 | import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation; |
| 61 | import org.onosproject.net.flow.FlowRuleBatchEvent; |
| 62 | import org.onosproject.net.flow.FlowRuleBatchOperation; |
| 63 | import org.onosproject.net.flow.FlowRuleBatchRequest; |
| 64 | import org.onosproject.net.flow.FlowRuleEvent; |
| 65 | import org.onosproject.net.flow.FlowRuleEvent.Type; |
| 66 | import org.onosproject.net.flow.FlowRuleService; |
| 67 | import org.onosproject.net.flow.FlowRuleStore; |
| 68 | import org.onosproject.net.flow.FlowRuleStoreDelegate; |
| 69 | import org.onosproject.net.flow.StoredFlowEntry; |
| 70 | import org.onosproject.net.flow.TableStatisticsEntry; |
| 71 | import org.onosproject.persistence.PersistenceService; |
| 72 | import org.onosproject.store.AbstractStore; |
| 73 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
| 74 | import org.onosproject.store.cluster.messaging.ClusterMessage; |
| 75 | import org.onosproject.store.cluster.messaging.ClusterMessageHandler; |
| 76 | import org.onosproject.store.flow.ReplicaInfoEvent; |
| 77 | import org.onosproject.store.flow.ReplicaInfoEventListener; |
| 78 | import org.onosproject.store.flow.ReplicaInfoService; |
| 79 | import org.onosproject.store.impl.MastershipBasedTimestamp; |
| 80 | import org.onosproject.store.serializers.KryoNamespaces; |
| 81 | import org.onosproject.store.service.EventuallyConsistentMap; |
| 82 | import org.onosproject.store.service.EventuallyConsistentMapEvent; |
| 83 | import org.onosproject.store.service.EventuallyConsistentMapListener; |
| 84 | import org.onosproject.store.service.Serializer; |
| 85 | import org.onosproject.store.service.StorageService; |
| 86 | import org.onosproject.store.service.WallClockTimestamp; |
| 87 | import org.osgi.service.component.ComponentContext; |
| 88 | import org.slf4j.Logger; |
| 89 | |
| 90 | import com.google.common.collect.ImmutableList; |
| 91 | import com.google.common.collect.Iterables; |
| 92 | import com.google.common.collect.Maps; |
| 93 | import com.google.common.collect.Sets; |
| 94 | import com.google.common.util.concurrent.Futures; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 95 | |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 96 | import static com.google.common.base.Strings.isNullOrEmpty; |
Ray Milkey | 2b6ff42 | 2016-08-26 13:03:15 -0700 | [diff] [blame] | 97 | import static org.onlab.util.Tools.get; |
| 98 | import static org.onlab.util.Tools.groupedThreads; |
| 99 | import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED; |
| 100 | import static org.onosproject.store.flow.ReplicaInfoEvent.Type.MASTER_CHANGED; |
| 101 | import static org.onosproject.store.flow.impl.FlowStoreMessageSubjects.APPLY_BATCH_FLOWS; |
| 102 | import static org.onosproject.store.flow.impl.FlowStoreMessageSubjects.FLOW_TABLE_BACKUP; |
| 103 | import static org.onosproject.store.flow.impl.FlowStoreMessageSubjects.GET_DEVICE_FLOW_ENTRIES; |
| 104 | import static org.onosproject.store.flow.impl.FlowStoreMessageSubjects.GET_FLOW_ENTRY; |
| 105 | import static org.onosproject.store.flow.impl.FlowStoreMessageSubjects.REMOTE_APPLY_COMPLETED; |
| 106 | import static org.onosproject.store.flow.impl.FlowStoreMessageSubjects.REMOVE_FLOW_ENTRY; |
| 107 | import static org.slf4j.LoggerFactory.getLogger; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Manages inventory of flow rules using a distributed state management protocol. |
| 111 | */ |
Sho SHIMIZU | 5c396e3 | 2016-08-12 15:19:12 -0700 | [diff] [blame] | 112 | @Component(immediate = true) |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 113 | @Service |
Madan Jampani | 37d04c6 | 2016-04-25 15:53:55 -0700 | [diff] [blame] | 114 | public class DistributedFlowRuleStore |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 115 | extends AbstractStore<FlowRuleBatchEvent, FlowRuleStoreDelegate> |
| 116 | implements FlowRuleStore { |
| 117 | |
| 118 | private final Logger log = getLogger(getClass()); |
| 119 | |
| 120 | private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 8; |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 121 | private static final int DEFAULT_MAX_BACKUP_COUNT = 2; |
Aaron Kruglikov | a62fdbb | 2015-10-27 16:32:06 -0700 | [diff] [blame] | 122 | private static final boolean DEFAULT_PERSISTENCE_ENABLED = false; |
Madan Jampani | 08bf17b | 2015-05-06 16:25:26 -0700 | [diff] [blame] | 123 | private static final int DEFAULT_BACKUP_PERIOD_MILLIS = 2000; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 124 | private static final long FLOW_RULE_STORE_TIMEOUT_MILLIS = 5000; |
Madan Jampani | adea890 | 2015-06-04 17:39:45 -0700 | [diff] [blame] | 125 | // number of devices whose flow entries will be backed up in one communication round |
| 126 | private static final int FLOW_TABLE_BACKUP_BATCH_SIZE = 1; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 127 | |
| 128 | @Property(name = "msgHandlerPoolSize", intValue = MESSAGE_HANDLER_THREAD_POOL_SIZE, |
| 129 | label = "Number of threads in the message handler pool") |
| 130 | private int msgHandlerPoolSize = MESSAGE_HANDLER_THREAD_POOL_SIZE; |
| 131 | |
Madan Jampani | 08bf17b | 2015-05-06 16:25:26 -0700 | [diff] [blame] | 132 | @Property(name = "backupPeriod", intValue = DEFAULT_BACKUP_PERIOD_MILLIS, |
| 133 | label = "Delay in ms between successive backup runs") |
| 134 | private int backupPeriod = DEFAULT_BACKUP_PERIOD_MILLIS; |
Aaron Kruglikov | a62fdbb | 2015-10-27 16:32:06 -0700 | [diff] [blame] | 135 | @Property(name = "persistenceEnabled", boolValue = false, |
| 136 | label = "Indicates whether or not changes in the flow table should be persisted to disk.") |
| 137 | private boolean persistenceEnabled = DEFAULT_PERSISTENCE_ENABLED; |
Madan Jampani | 08bf17b | 2015-05-06 16:25:26 -0700 | [diff] [blame] | 138 | |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 139 | @Property(name = "backupCount", intValue = DEFAULT_MAX_BACKUP_COUNT, |
| 140 | label = "Max number of backup copies for each device") |
| 141 | private volatile int backupCount = DEFAULT_MAX_BACKUP_COUNT; |
| 142 | |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 143 | private InternalFlowTable flowTable = new InternalFlowTable(); |
| 144 | |
| 145 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 146 | protected ReplicaInfoService replicaInfoManager; |
| 147 | |
| 148 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 149 | protected ClusterCommunicationService clusterCommunicator; |
| 150 | |
| 151 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 152 | protected ClusterService clusterService; |
| 153 | |
| 154 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 155 | protected DeviceService deviceService; |
| 156 | |
| 157 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 158 | protected CoreService coreService; |
| 159 | |
| 160 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 161 | protected ComponentConfigService configService; |
| 162 | |
| 163 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 164 | protected MastershipService mastershipService; |
| 165 | |
Aaron Kruglikov | a62fdbb | 2015-10-27 16:32:06 -0700 | [diff] [blame] | 166 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 167 | protected PersistenceService persistenceService; |
| 168 | |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 169 | private Map<Long, NodeId> pendingResponses = Maps.newConcurrentMap(); |
| 170 | private ExecutorService messageHandlingExecutor; |
Madan Jampani | 71c32ca | 2016-06-22 08:23:18 -0700 | [diff] [blame] | 171 | private ExecutorService eventHandler; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 172 | |
Madan Jampani | 08bf17b | 2015-05-06 16:25:26 -0700 | [diff] [blame] | 173 | private ScheduledFuture<?> backupTask; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 174 | private final ScheduledExecutorService backupSenderExecutor = |
HIGUCHI Yuta | d9e0105 | 2016-04-14 09:31:42 -0700 | [diff] [blame] | 175 | Executors.newSingleThreadScheduledExecutor(groupedThreads("onos/flow", "backup-sender", log)); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 176 | |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 177 | private EventuallyConsistentMap<DeviceId, List<TableStatisticsEntry>> deviceTableStats; |
| 178 | private final EventuallyConsistentMapListener<DeviceId, List<TableStatisticsEntry>> tableStatsListener = |
| 179 | new InternalTableStatsListener(); |
| 180 | |
| 181 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 182 | protected StorageService storageService; |
| 183 | |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 184 | protected final Serializer serializer = Serializer.using(KryoNamespaces.API); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 185 | |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 186 | protected final KryoNamespace.Builder serializerBuilder = KryoNamespace.newBuilder() |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 187 | .register(KryoNamespaces.API) |
| 188 | .register(MastershipBasedTimestamp.class); |
| 189 | |
| 190 | |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 191 | private IdGenerator idGenerator; |
| 192 | private NodeId local; |
| 193 | |
| 194 | @Activate |
| 195 | public void activate(ComponentContext context) { |
| 196 | configService.registerProperties(getClass()); |
| 197 | |
| 198 | idGenerator = coreService.getIdGenerator(FlowRuleService.FLOW_OP_TOPIC); |
| 199 | |
| 200 | local = clusterService.getLocalNode().id(); |
| 201 | |
Madan Jampani | 71c32ca | 2016-06-22 08:23:18 -0700 | [diff] [blame] | 202 | eventHandler = Executors.newSingleThreadExecutor( |
| 203 | groupedThreads("onos/flow", "event-handler", log)); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 204 | messageHandlingExecutor = Executors.newFixedThreadPool( |
HIGUCHI Yuta | d9e0105 | 2016-04-14 09:31:42 -0700 | [diff] [blame] | 205 | msgHandlerPoolSize, groupedThreads("onos/store/flow", "message-handlers", log)); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 206 | |
| 207 | registerMessageHandlers(messageHandlingExecutor); |
| 208 | |
sivachidambaram subramanian | 0b33c08 | 2017-04-06 13:26:44 +0530 | [diff] [blame] | 209 | replicaInfoManager.addListener(flowTable); |
| 210 | backupTask = backupSenderExecutor.scheduleWithFixedDelay( |
| 211 | flowTable::backup, |
| 212 | 0, |
| 213 | backupPeriod, |
| 214 | TimeUnit.MILLISECONDS); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 215 | |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 216 | deviceTableStats = storageService.<DeviceId, List<TableStatisticsEntry>>eventuallyConsistentMapBuilder() |
| 217 | .withName("onos-flow-table-stats") |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 218 | .withSerializer(serializerBuilder) |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 219 | .withAntiEntropyPeriod(5, TimeUnit.SECONDS) |
| 220 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 221 | .withTombstonesDisabled() |
| 222 | .build(); |
| 223 | deviceTableStats.addListener(tableStatsListener); |
| 224 | |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 225 | logConfig("Started"); |
| 226 | } |
| 227 | |
| 228 | @Deactivate |
| 229 | public void deactivate(ComponentContext context) { |
sivachidambaram subramanian | 0b33c08 | 2017-04-06 13:26:44 +0530 | [diff] [blame] | 230 | replicaInfoManager.removeListener(flowTable); |
| 231 | backupTask.cancel(true); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 232 | configService.unregisterProperties(getClass(), false); |
| 233 | unregisterMessageHandlers(); |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 234 | deviceTableStats.removeListener(tableStatsListener); |
| 235 | deviceTableStats.destroy(); |
Madan Jampani | 71c32ca | 2016-06-22 08:23:18 -0700 | [diff] [blame] | 236 | eventHandler.shutdownNow(); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 237 | messageHandlingExecutor.shutdownNow(); |
| 238 | backupSenderExecutor.shutdownNow(); |
| 239 | log.info("Stopped"); |
| 240 | } |
| 241 | |
| 242 | @SuppressWarnings("rawtypes") |
| 243 | @Modified |
| 244 | public void modified(ComponentContext context) { |
| 245 | if (context == null) { |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 246 | logConfig("Default config"); |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | Dictionary properties = context.getProperties(); |
| 251 | int newPoolSize; |
Madan Jampani | 08bf17b | 2015-05-06 16:25:26 -0700 | [diff] [blame] | 252 | int newBackupPeriod; |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 253 | int newBackupCount; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 254 | try { |
| 255 | String s = get(properties, "msgHandlerPoolSize"); |
| 256 | newPoolSize = isNullOrEmpty(s) ? msgHandlerPoolSize : Integer.parseInt(s.trim()); |
| 257 | |
Madan Jampani | 08bf17b | 2015-05-06 16:25:26 -0700 | [diff] [blame] | 258 | s = get(properties, "backupPeriod"); |
| 259 | newBackupPeriod = isNullOrEmpty(s) ? backupPeriod : Integer.parseInt(s.trim()); |
| 260 | |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 261 | s = get(properties, "backupCount"); |
| 262 | newBackupCount = isNullOrEmpty(s) ? backupCount : Integer.parseInt(s.trim()); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 263 | } catch (NumberFormatException | ClassCastException e) { |
| 264 | newPoolSize = MESSAGE_HANDLER_THREAD_POOL_SIZE; |
Madan Jampani | 08bf17b | 2015-05-06 16:25:26 -0700 | [diff] [blame] | 265 | newBackupPeriod = DEFAULT_BACKUP_PERIOD_MILLIS; |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 266 | newBackupCount = DEFAULT_MAX_BACKUP_COUNT; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Madan Jampani | 08bf17b | 2015-05-06 16:25:26 -0700 | [diff] [blame] | 269 | boolean restartBackupTask = false; |
sivachidambaram subramanian | 0b33c08 | 2017-04-06 13:26:44 +0530 | [diff] [blame] | 270 | |
Madan Jampani | 08bf17b | 2015-05-06 16:25:26 -0700 | [diff] [blame] | 271 | if (newBackupPeriod != backupPeriod) { |
| 272 | backupPeriod = newBackupPeriod; |
sivachidambaram subramanian | 0b33c08 | 2017-04-06 13:26:44 +0530 | [diff] [blame] | 273 | restartBackupTask = true; |
Madan Jampani | 08bf17b | 2015-05-06 16:25:26 -0700 | [diff] [blame] | 274 | } |
| 275 | if (restartBackupTask) { |
| 276 | if (backupTask != null) { |
| 277 | // cancel previously running task |
| 278 | backupTask.cancel(false); |
| 279 | } |
| 280 | backupTask = backupSenderExecutor.scheduleWithFixedDelay( |
| 281 | flowTable::backup, |
| 282 | 0, |
| 283 | backupPeriod, |
| 284 | TimeUnit.MILLISECONDS); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 285 | } |
| 286 | if (newPoolSize != msgHandlerPoolSize) { |
| 287 | msgHandlerPoolSize = newPoolSize; |
| 288 | ExecutorService oldMsgHandler = messageHandlingExecutor; |
| 289 | messageHandlingExecutor = Executors.newFixedThreadPool( |
HIGUCHI Yuta | 060da9a | 2016-03-11 19:16:35 -0800 | [diff] [blame] | 290 | msgHandlerPoolSize, groupedThreads("onos/store/flow", "message-handlers", log)); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 291 | |
| 292 | // replace previously registered handlers. |
| 293 | registerMessageHandlers(messageHandlingExecutor); |
| 294 | oldMsgHandler.shutdown(); |
| 295 | } |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 296 | if (backupCount != newBackupCount) { |
| 297 | backupCount = newBackupCount; |
| 298 | } |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 299 | logConfig("Reconfigured"); |
| 300 | } |
| 301 | |
| 302 | private void registerMessageHandlers(ExecutorService executor) { |
| 303 | |
| 304 | clusterCommunicator.addSubscriber(APPLY_BATCH_FLOWS, new OnStoreBatch(), executor); |
| 305 | clusterCommunicator.<FlowRuleBatchEvent>addSubscriber( |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 306 | REMOTE_APPLY_COMPLETED, serializer::decode, this::notifyDelegate, executor); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 307 | clusterCommunicator.addSubscriber( |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 308 | GET_FLOW_ENTRY, serializer::decode, flowTable::getFlowEntry, serializer::encode, executor); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 309 | clusterCommunicator.addSubscriber( |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 310 | GET_DEVICE_FLOW_ENTRIES, serializer::decode, flowTable::getFlowEntries, serializer::encode, executor); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 311 | clusterCommunicator.addSubscriber( |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 312 | REMOVE_FLOW_ENTRY, serializer::decode, this::removeFlowRuleInternal, serializer::encode, executor); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 313 | clusterCommunicator.addSubscriber( |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 314 | FLOW_TABLE_BACKUP, serializer::decode, flowTable::onBackupReceipt, serializer::encode, executor); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | private void unregisterMessageHandlers() { |
| 318 | clusterCommunicator.removeSubscriber(REMOVE_FLOW_ENTRY); |
| 319 | clusterCommunicator.removeSubscriber(GET_DEVICE_FLOW_ENTRIES); |
| 320 | clusterCommunicator.removeSubscriber(GET_FLOW_ENTRY); |
| 321 | clusterCommunicator.removeSubscriber(APPLY_BATCH_FLOWS); |
| 322 | clusterCommunicator.removeSubscriber(REMOTE_APPLY_COMPLETED); |
| 323 | clusterCommunicator.removeSubscriber(FLOW_TABLE_BACKUP); |
| 324 | } |
| 325 | |
| 326 | private void logConfig(String prefix) { |
sivachidambaram subramanian | 0b33c08 | 2017-04-06 13:26:44 +0530 | [diff] [blame] | 327 | log.info("{} with msgHandlerPoolSize = {}; backupPeriod = {}, backupCount = {}", |
| 328 | prefix, msgHandlerPoolSize, backupPeriod, backupCount); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | // This is not a efficient operation on a distributed sharded |
| 332 | // flow store. We need to revisit the need for this operation or at least |
| 333 | // make it device specific. |
| 334 | @Override |
| 335 | public int getFlowRuleCount() { |
| 336 | AtomicInteger sum = new AtomicInteger(0); |
| 337 | deviceService.getDevices().forEach(device -> sum.addAndGet(Iterables.size(getFlowEntries(device.id())))); |
| 338 | return sum.get(); |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | public FlowEntry getFlowEntry(FlowRule rule) { |
Madan Jampani | 6bd2d9f | 2015-05-14 14:10:42 -0700 | [diff] [blame] | 343 | NodeId master = mastershipService.getMasterFor(rule.deviceId()); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 344 | |
| 345 | if (master == null) { |
Thomas Vachuska | 88fd690 | 2015-08-04 10:08:34 -0700 | [diff] [blame] | 346 | log.debug("Failed to getFlowEntry: No master for {}", rule.deviceId()); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 347 | return null; |
| 348 | } |
| 349 | |
Sho SHIMIZU | 828bc16 | 2016-01-13 23:10:43 -0800 | [diff] [blame] | 350 | if (Objects.equals(local, master)) { |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 351 | return flowTable.getFlowEntry(rule); |
| 352 | } |
| 353 | |
| 354 | log.trace("Forwarding getFlowEntry to {}, which is the primary (master) for device {}", |
| 355 | master, rule.deviceId()); |
| 356 | |
| 357 | return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(rule, |
| 358 | FlowStoreMessageSubjects.GET_FLOW_ENTRY, |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 359 | serializer::encode, |
| 360 | serializer::decode, |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 361 | master), |
| 362 | FLOW_RULE_STORE_TIMEOUT_MILLIS, |
| 363 | TimeUnit.MILLISECONDS, |
| 364 | null); |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
Madan Jampani | 6bd2d9f | 2015-05-14 14:10:42 -0700 | [diff] [blame] | 369 | NodeId master = mastershipService.getMasterFor(deviceId); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 370 | |
| 371 | if (master == null) { |
Thomas Vachuska | 88fd690 | 2015-08-04 10:08:34 -0700 | [diff] [blame] | 372 | log.debug("Failed to getFlowEntries: No master for {}", deviceId); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 373 | return Collections.emptyList(); |
| 374 | } |
| 375 | |
Sho SHIMIZU | 828bc16 | 2016-01-13 23:10:43 -0800 | [diff] [blame] | 376 | if (Objects.equals(local, master)) { |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 377 | return flowTable.getFlowEntries(deviceId); |
| 378 | } |
| 379 | |
| 380 | log.trace("Forwarding getFlowEntries to {}, which is the primary (master) for device {}", |
| 381 | master, deviceId); |
| 382 | |
| 383 | return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(deviceId, |
| 384 | FlowStoreMessageSubjects.GET_DEVICE_FLOW_ENTRIES, |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 385 | serializer::encode, |
| 386 | serializer::decode, |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 387 | master), |
| 388 | FLOW_RULE_STORE_TIMEOUT_MILLIS, |
| 389 | TimeUnit.MILLISECONDS, |
| 390 | Collections.emptyList()); |
| 391 | } |
| 392 | |
| 393 | @Override |
| 394 | public void storeFlowRule(FlowRule rule) { |
| 395 | storeBatch(new FlowRuleBatchOperation( |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 396 | Collections.singletonList(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule)), |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 397 | rule.deviceId(), idGenerator.getNewId())); |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public void storeBatch(FlowRuleBatchOperation operation) { |
| 402 | if (operation.getOperations().isEmpty()) { |
| 403 | notifyDelegate(FlowRuleBatchEvent.completed( |
| 404 | new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), |
| 405 | new CompletedBatchOperation(true, Collections.emptySet(), operation.deviceId()))); |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | DeviceId deviceId = operation.deviceId(); |
Madan Jampani | 6bd2d9f | 2015-05-14 14:10:42 -0700 | [diff] [blame] | 410 | NodeId master = mastershipService.getMasterFor(deviceId); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 411 | |
| 412 | if (master == null) { |
| 413 | log.warn("No master for {} : flows will be marked for removal", deviceId); |
| 414 | |
| 415 | updateStoreInternal(operation); |
| 416 | |
| 417 | notifyDelegate(FlowRuleBatchEvent.completed( |
| 418 | new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), |
| 419 | new CompletedBatchOperation(true, Collections.emptySet(), operation.deviceId()))); |
| 420 | return; |
| 421 | } |
| 422 | |
Sho SHIMIZU | 828bc16 | 2016-01-13 23:10:43 -0800 | [diff] [blame] | 423 | if (Objects.equals(local, master)) { |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 424 | storeBatchInternal(operation); |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | log.trace("Forwarding storeBatch to {}, which is the primary (master) for device {}", |
| 429 | master, deviceId); |
| 430 | |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 431 | clusterCommunicator.unicast(operation, |
| 432 | APPLY_BATCH_FLOWS, |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 433 | serializer::encode, |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 434 | master) |
| 435 | .whenComplete((result, error) -> { |
Thomas Vachuska | a267ce4 | 2015-05-27 16:14:23 -0700 | [diff] [blame] | 436 | if (error != null) { |
Madan Jampani | 15f1bc4 | 2015-05-28 10:51:52 -0700 | [diff] [blame] | 437 | log.warn("Failed to storeBatch: {} to {}", operation, master, error); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 438 | |
Thomas Vachuska | a267ce4 | 2015-05-27 16:14:23 -0700 | [diff] [blame] | 439 | Set<FlowRule> allFailures = operation.getOperations() |
| 440 | .stream() |
| 441 | .map(op -> op.target()) |
| 442 | .collect(Collectors.toSet()); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 443 | |
Thomas Vachuska | a267ce4 | 2015-05-27 16:14:23 -0700 | [diff] [blame] | 444 | notifyDelegate(FlowRuleBatchEvent.completed( |
| 445 | new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), |
| 446 | new CompletedBatchOperation(false, allFailures, deviceId))); |
| 447 | } |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 448 | }); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | private void storeBatchInternal(FlowRuleBatchOperation operation) { |
| 452 | |
| 453 | final DeviceId did = operation.deviceId(); |
| 454 | //final Collection<FlowEntry> ft = flowTable.getFlowEntries(did); |
| 455 | Set<FlowRuleBatchEntry> currentOps = updateStoreInternal(operation); |
| 456 | if (currentOps.isEmpty()) { |
| 457 | batchOperationComplete(FlowRuleBatchEvent.completed( |
| 458 | new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), |
| 459 | new CompletedBatchOperation(true, Collections.emptySet(), did))); |
| 460 | return; |
| 461 | } |
| 462 | |
| 463 | notifyDelegate(FlowRuleBatchEvent.requested(new |
| 464 | FlowRuleBatchRequest(operation.id(), |
| 465 | currentOps), operation.deviceId())); |
| 466 | } |
| 467 | |
| 468 | private Set<FlowRuleBatchEntry> updateStoreInternal(FlowRuleBatchOperation operation) { |
| 469 | return operation.getOperations().stream().map( |
| 470 | op -> { |
| 471 | StoredFlowEntry entry; |
| 472 | switch (op.operator()) { |
| 473 | case ADD: |
| 474 | entry = new DefaultFlowEntry(op.target()); |
| 475 | // always add requested FlowRule |
| 476 | // Note: 2 equal FlowEntry may have different treatment |
| 477 | flowTable.remove(entry.deviceId(), entry); |
| 478 | flowTable.add(entry); |
| 479 | |
| 480 | return op; |
| 481 | case REMOVE: |
| 482 | entry = flowTable.getFlowEntry(op.target()); |
| 483 | if (entry != null) { |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 484 | //FIXME modification of "stored" flow entry outside of flow table |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 485 | entry.setState(FlowEntryState.PENDING_REMOVE); |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 486 | log.debug("Setting state of rule to pending remove: {}", entry); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 487 | return op; |
| 488 | } |
| 489 | break; |
| 490 | case MODIFY: |
| 491 | //TODO: figure this out at some point |
| 492 | break; |
| 493 | default: |
| 494 | log.warn("Unknown flow operation operator: {}", op.operator()); |
| 495 | } |
| 496 | return null; |
| 497 | } |
Sho SHIMIZU | 828bc16 | 2016-01-13 23:10:43 -0800 | [diff] [blame] | 498 | ).filter(Objects::nonNull).collect(Collectors.toSet()); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | @Override |
| 502 | public void deleteFlowRule(FlowRule rule) { |
| 503 | storeBatch( |
| 504 | new FlowRuleBatchOperation( |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 505 | Collections.singletonList( |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 506 | new FlowRuleBatchEntry( |
| 507 | FlowRuleOperation.REMOVE, |
| 508 | rule)), rule.deviceId(), idGenerator.getNewId())); |
| 509 | } |
| 510 | |
| 511 | @Override |
Charles Chan | 93fa727 | 2016-01-26 22:27:02 -0800 | [diff] [blame] | 512 | public FlowRuleEvent pendingFlowRule(FlowEntry rule) { |
| 513 | if (mastershipService.isLocalMaster(rule.deviceId())) { |
| 514 | StoredFlowEntry stored = flowTable.getFlowEntry(rule); |
| 515 | if (stored != null && |
| 516 | stored.state() != FlowEntryState.PENDING_ADD) { |
| 517 | stored.setState(FlowEntryState.PENDING_ADD); |
| 518 | return new FlowRuleEvent(Type.RULE_UPDATED, rule); |
| 519 | } |
| 520 | } |
| 521 | return null; |
| 522 | } |
| 523 | |
| 524 | @Override |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 525 | public FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) { |
Madan Jampani | 6bd2d9f | 2015-05-14 14:10:42 -0700 | [diff] [blame] | 526 | NodeId master = mastershipService.getMasterFor(rule.deviceId()); |
Sho SHIMIZU | 828bc16 | 2016-01-13 23:10:43 -0800 | [diff] [blame] | 527 | if (Objects.equals(local, master)) { |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 528 | return addOrUpdateFlowRuleInternal(rule); |
| 529 | } |
| 530 | |
| 531 | log.warn("Tried to update FlowRule {} state," |
| 532 | + " while the Node was not the master.", rule); |
| 533 | return null; |
| 534 | } |
| 535 | |
| 536 | private FlowRuleEvent addOrUpdateFlowRuleInternal(FlowEntry rule) { |
| 537 | // check if this new rule is an update to an existing entry |
| 538 | StoredFlowEntry stored = flowTable.getFlowEntry(rule); |
| 539 | if (stored != null) { |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 540 | //FIXME modification of "stored" flow entry outside of flow table |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 541 | stored.setBytes(rule.bytes()); |
Thiago Santos | 877914d | 2016-07-20 18:29:29 -0300 | [diff] [blame] | 542 | stored.setLife(rule.life(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS); |
Sangsik Yoon | b1b823f | 2016-05-16 18:55:39 +0900 | [diff] [blame] | 543 | stored.setLiveType(rule.liveType()); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 544 | stored.setPackets(rule.packets()); |
Jonathan Hart | 89e981f | 2016-01-04 13:59:55 -0800 | [diff] [blame] | 545 | stored.setLastSeen(); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 546 | if (stored.state() == FlowEntryState.PENDING_ADD) { |
| 547 | stored.setState(FlowEntryState.ADDED); |
| 548 | return new FlowRuleEvent(Type.RULE_ADDED, rule); |
| 549 | } |
| 550 | return new FlowRuleEvent(Type.RULE_UPDATED, rule); |
| 551 | } |
| 552 | |
| 553 | // TODO: Confirm if this behavior is correct. See SimpleFlowRuleStore |
| 554 | // TODO: also update backup if the behavior is correct. |
| 555 | flowTable.add(rule); |
| 556 | return null; |
| 557 | } |
| 558 | |
| 559 | @Override |
| 560 | public FlowRuleEvent removeFlowRule(FlowEntry rule) { |
| 561 | final DeviceId deviceId = rule.deviceId(); |
Madan Jampani | 6bd2d9f | 2015-05-14 14:10:42 -0700 | [diff] [blame] | 562 | NodeId master = mastershipService.getMasterFor(deviceId); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 563 | |
Sho SHIMIZU | 828bc16 | 2016-01-13 23:10:43 -0800 | [diff] [blame] | 564 | if (Objects.equals(local, master)) { |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 565 | // bypass and handle it locally |
| 566 | return removeFlowRuleInternal(rule); |
| 567 | } |
| 568 | |
| 569 | if (master == null) { |
| 570 | log.warn("Failed to removeFlowRule: No master for {}", deviceId); |
| 571 | // TODO: revisit if this should be null (="no-op") or Exception |
| 572 | return null; |
| 573 | } |
| 574 | |
| 575 | log.trace("Forwarding removeFlowRule to {}, which is the master for device {}", |
| 576 | master, deviceId); |
| 577 | |
Madan Jampani | 222229e | 2016-07-14 10:43:25 -0700 | [diff] [blame] | 578 | return Futures.getUnchecked(clusterCommunicator.sendAndReceive( |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 579 | rule, |
| 580 | REMOVE_FLOW_ENTRY, |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 581 | serializer::encode, |
| 582 | serializer::decode, |
Madan Jampani | 222229e | 2016-07-14 10:43:25 -0700 | [diff] [blame] | 583 | master)); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | private FlowRuleEvent removeFlowRuleInternal(FlowEntry rule) { |
| 587 | final DeviceId deviceId = rule.deviceId(); |
| 588 | // This is where one could mark a rule as removed and still keep it in the store. |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 589 | final FlowEntry removed = flowTable.remove(deviceId, rule); |
| 590 | // rule may be partial rule that is missing treatment, we should use rule from store instead |
| 591 | return removed != null ? new FlowRuleEvent(RULE_REMOVED, removed) : null; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | @Override |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 595 | public void purgeFlowRule(DeviceId deviceId) { |
| 596 | flowTable.purgeFlowRule(deviceId); |
| 597 | } |
| 598 | |
| 599 | @Override |
Victor Silva | 139bca4 | 2016-08-18 11:46:35 -0300 | [diff] [blame] | 600 | public void purgeFlowRules() { |
| 601 | flowTable.purgeFlowRules(); |
| 602 | } |
| 603 | |
| 604 | @Override |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 605 | public void batchOperationComplete(FlowRuleBatchEvent event) { |
| 606 | //FIXME: need a per device pending response |
| 607 | NodeId nodeId = pendingResponses.remove(event.subject().batchId()); |
| 608 | if (nodeId == null) { |
| 609 | notifyDelegate(event); |
| 610 | } else { |
| 611 | // TODO check unicast return value |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 612 | clusterCommunicator.unicast(event, REMOTE_APPLY_COMPLETED, serializer::encode, nodeId); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 613 | //error log: log.warn("Failed to respond to peer for batch operation result"); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | private final class OnStoreBatch implements ClusterMessageHandler { |
| 618 | |
| 619 | @Override |
| 620 | public void handle(final ClusterMessage message) { |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 621 | FlowRuleBatchOperation operation = serializer.decode(message.payload()); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 622 | log.debug("received batch request {}", operation); |
| 623 | |
| 624 | final DeviceId deviceId = operation.deviceId(); |
Madan Jampani | 6bd2d9f | 2015-05-14 14:10:42 -0700 | [diff] [blame] | 625 | NodeId master = mastershipService.getMasterFor(deviceId); |
Sho SHIMIZU | 828bc16 | 2016-01-13 23:10:43 -0800 | [diff] [blame] | 626 | if (!Objects.equals(local, master)) { |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 627 | Set<FlowRule> failures = new HashSet<>(operation.size()); |
| 628 | for (FlowRuleBatchEntry op : operation.getOperations()) { |
| 629 | failures.add(op.target()); |
| 630 | } |
| 631 | CompletedBatchOperation allFailed = new CompletedBatchOperation(false, failures, deviceId); |
| 632 | // This node is no longer the master, respond as all failed. |
| 633 | // TODO: we might want to wrap response in envelope |
| 634 | // to distinguish sw programming failure and hand over |
| 635 | // it make sense in the latter case to retry immediately. |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 636 | message.respond(serializer.encode(allFailed)); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 637 | return; |
| 638 | } |
| 639 | |
| 640 | pendingResponses.put(operation.id(), message.sender()); |
| 641 | storeBatchInternal(operation); |
| 642 | } |
| 643 | } |
| 644 | |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 645 | private class BackupOperation { |
| 646 | private final NodeId nodeId; |
| 647 | private final DeviceId deviceId; |
| 648 | |
| 649 | public BackupOperation(NodeId nodeId, DeviceId deviceId) { |
| 650 | this.nodeId = nodeId; |
| 651 | this.deviceId = deviceId; |
| 652 | } |
| 653 | |
| 654 | @Override |
| 655 | public int hashCode() { |
| 656 | return Objects.hash(nodeId, deviceId); |
| 657 | } |
| 658 | |
| 659 | @Override |
| 660 | public boolean equals(Object other) { |
| 661 | if (other != null && other instanceof BackupOperation) { |
| 662 | BackupOperation that = (BackupOperation) other; |
| 663 | return this.nodeId.equals(that.nodeId) && |
| 664 | this.deviceId.equals(that.deviceId); |
| 665 | } else { |
| 666 | return false; |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
Madan Jampani | f7536ab | 2015-05-07 23:23:23 -0700 | [diff] [blame] | 671 | private class InternalFlowTable implements ReplicaInfoEventListener { |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 672 | |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 673 | //TODO replace the Map<V,V> with ExtendedSet |
| 674 | private final Map<DeviceId, Map<FlowId, Map<StoredFlowEntry, StoredFlowEntry>>> |
Madan Jampani | 5c3766c | 2015-06-02 15:54:41 -0700 | [diff] [blame] | 675 | flowEntries = Maps.newConcurrentMap(); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 676 | |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 677 | private final Map<BackupOperation, Long> lastBackupTimes = Maps.newConcurrentMap(); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 678 | private final Map<DeviceId, Long> lastUpdateTimes = Maps.newConcurrentMap(); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 679 | |
Madan Jampani | f7536ab | 2015-05-07 23:23:23 -0700 | [diff] [blame] | 680 | @Override |
| 681 | public void event(ReplicaInfoEvent event) { |
Madan Jampani | 71c32ca | 2016-06-22 08:23:18 -0700 | [diff] [blame] | 682 | eventHandler.execute(() -> handleEvent(event)); |
| 683 | } |
| 684 | |
| 685 | private void handleEvent(ReplicaInfoEvent event) { |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 686 | DeviceId deviceId = event.subject(); |
sivachidambaram subramanian | 0b33c08 | 2017-04-06 13:26:44 +0530 | [diff] [blame] | 687 | if (!mastershipService.isLocalMaster(deviceId)) { |
Madan Jampani | a98bf93 | 2015-06-02 12:01:36 -0700 | [diff] [blame] | 688 | return; |
| 689 | } |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 690 | if (event.type() == MASTER_CHANGED) { |
| 691 | lastUpdateTimes.put(deviceId, System.currentTimeMillis()); |
Madan Jampani | f7536ab | 2015-05-07 23:23:23 -0700 | [diff] [blame] | 692 | } |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 693 | backupSenderExecutor.schedule(this::backup, 0, TimeUnit.SECONDS); |
Madan Jampani | f7536ab | 2015-05-07 23:23:23 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Madan Jampani | adea890 | 2015-06-04 17:39:45 -0700 | [diff] [blame] | 696 | private void sendBackups(NodeId nodeId, Set<DeviceId> deviceIds) { |
| 697 | // split up the devices into smaller batches and send them separately. |
| 698 | Iterables.partition(deviceIds, FLOW_TABLE_BACKUP_BATCH_SIZE) |
| 699 | .forEach(ids -> backupFlowEntries(nodeId, Sets.newHashSet(ids))); |
| 700 | } |
| 701 | |
Madan Jampani | f7536ab | 2015-05-07 23:23:23 -0700 | [diff] [blame] | 702 | private void backupFlowEntries(NodeId nodeId, Set<DeviceId> deviceIds) { |
Madan Jampani | adea890 | 2015-06-04 17:39:45 -0700 | [diff] [blame] | 703 | if (deviceIds.isEmpty()) { |
| 704 | return; |
| 705 | } |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 706 | log.debug("Sending flowEntries for devices {} to {} for backup.", deviceIds, nodeId); |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 707 | Map<DeviceId, Map<FlowId, Map<StoredFlowEntry, StoredFlowEntry>>> |
| 708 | deviceFlowEntries = Maps.newConcurrentMap(); |
Ray Milkey | 2b6ff42 | 2016-08-26 13:03:15 -0700 | [diff] [blame] | 709 | deviceIds.forEach(id -> deviceFlowEntries.put(id, getFlowTableCopy(id))); |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 710 | clusterCommunicator.<Map<DeviceId, |
| 711 | Map<FlowId, Map<StoredFlowEntry, StoredFlowEntry>>>, |
| 712 | Set<DeviceId>> |
| 713 | sendAndReceive(deviceFlowEntries, |
| 714 | FLOW_TABLE_BACKUP, |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 715 | serializer::encode, |
| 716 | serializer::decode, |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 717 | nodeId) |
| 718 | .whenComplete((backedupDevices, error) -> { |
| 719 | Set<DeviceId> devicesNotBackedup = error != null ? |
| 720 | deviceFlowEntries.keySet() : |
| 721 | Sets.difference(deviceFlowEntries.keySet(), backedupDevices); |
| 722 | if (devicesNotBackedup.size() > 0) { |
Ray Milkey | 2b6ff42 | 2016-08-26 13:03:15 -0700 | [diff] [blame] | 723 | log.warn("Failed to backup devices: {}. Reason: {}, Node: {}", |
| 724 | devicesNotBackedup, error != null ? error.getMessage() : "none", |
| 725 | nodeId); |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 726 | } |
| 727 | if (backedupDevices != null) { |
| 728 | backedupDevices.forEach(id -> { |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 729 | lastBackupTimes.put(new BackupOperation(nodeId, id), System.currentTimeMillis()); |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 730 | }); |
| 731 | } |
| 732 | }); |
Madan Jampani | f7536ab | 2015-05-07 23:23:23 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 735 | /** |
| 736 | * Returns the flow table for specified device. |
| 737 | * |
| 738 | * @param deviceId identifier of the device |
| 739 | * @return Map representing Flow Table of given device. |
| 740 | */ |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 741 | private Map<FlowId, Map<StoredFlowEntry, StoredFlowEntry>> getFlowTable(DeviceId deviceId) { |
Aaron Kruglikov | a62fdbb | 2015-10-27 16:32:06 -0700 | [diff] [blame] | 742 | if (persistenceEnabled) { |
| 743 | return flowEntries.computeIfAbsent(deviceId, id -> persistenceService |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 744 | .<FlowId, Map<StoredFlowEntry, StoredFlowEntry>>persistentMapBuilder() |
Aaron Kruglikov | a62fdbb | 2015-10-27 16:32:06 -0700 | [diff] [blame] | 745 | .withName("FlowTable:" + deviceId.toString()) |
| 746 | .withSerializer(new Serializer() { |
| 747 | @Override |
| 748 | public <T> byte[] encode(T object) { |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 749 | return serializer.encode(object); |
Aaron Kruglikov | a62fdbb | 2015-10-27 16:32:06 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | @Override |
| 753 | public <T> T decode(byte[] bytes) { |
Madan Jampani | 884d443 | 2016-08-23 10:46:55 -0700 | [diff] [blame] | 754 | return serializer.decode(bytes); |
Aaron Kruglikov | a62fdbb | 2015-10-27 16:32:06 -0700 | [diff] [blame] | 755 | } |
| 756 | }) |
| 757 | .build()); |
| 758 | } else { |
| 759 | return flowEntries.computeIfAbsent(deviceId, id -> Maps.newConcurrentMap()); |
| 760 | } |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Ray Milkey | 2b6ff42 | 2016-08-26 13:03:15 -0700 | [diff] [blame] | 763 | private Map<FlowId, Map<StoredFlowEntry, StoredFlowEntry>> getFlowTableCopy(DeviceId deviceId) { |
| 764 | Map<FlowId, Map<StoredFlowEntry, StoredFlowEntry>> copy = Maps.newHashMap(); |
| 765 | if (persistenceEnabled) { |
| 766 | return flowEntries.computeIfAbsent(deviceId, id -> persistenceService |
| 767 | .<FlowId, Map<StoredFlowEntry, StoredFlowEntry>>persistentMapBuilder() |
| 768 | .withName("FlowTable:" + deviceId.toString()) |
| 769 | .withSerializer(new Serializer() { |
| 770 | @Override |
| 771 | public <T> byte[] encode(T object) { |
| 772 | return serializer.encode(object); |
| 773 | } |
| 774 | |
| 775 | @Override |
| 776 | public <T> T decode(byte[] bytes) { |
| 777 | return serializer.decode(bytes); |
| 778 | } |
| 779 | }) |
| 780 | .build()); |
| 781 | } else { |
| 782 | flowEntries.computeIfAbsent(deviceId, id -> Maps.newConcurrentMap()).forEach((k, v) -> { |
| 783 | copy.put(k, Maps.newHashMap(v)); |
| 784 | }); |
| 785 | return copy; |
| 786 | } |
| 787 | } |
| 788 | |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 789 | private Map<StoredFlowEntry, StoredFlowEntry> getFlowEntriesInternal(DeviceId deviceId, FlowId flowId) { |
| 790 | return getFlowTable(deviceId).computeIfAbsent(flowId, id -> Maps.newConcurrentMap()); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | private StoredFlowEntry getFlowEntryInternal(FlowRule rule) { |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 794 | return getFlowEntriesInternal(rule.deviceId(), rule.id()).get(rule); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | private Set<FlowEntry> getFlowEntriesInternal(DeviceId deviceId) { |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 798 | return getFlowTable(deviceId).values().stream() |
| 799 | .flatMap(m -> m.values().stream()) |
| 800 | .collect(Collectors.toSet()); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | public StoredFlowEntry getFlowEntry(FlowRule rule) { |
| 804 | return getFlowEntryInternal(rule); |
| 805 | } |
| 806 | |
| 807 | public Set<FlowEntry> getFlowEntries(DeviceId deviceId) { |
| 808 | return getFlowEntriesInternal(deviceId); |
| 809 | } |
| 810 | |
| 811 | public void add(FlowEntry rule) { |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 812 | getFlowEntriesInternal(rule.deviceId(), rule.id()) |
| 813 | .compute((StoredFlowEntry) rule, (k, stored) -> { |
| 814 | //TODO compare stored and rule timestamps |
| 815 | //TODO the key is not updated |
| 816 | return (StoredFlowEntry) rule; |
| 817 | }); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 818 | lastUpdateTimes.put(rule.deviceId(), System.currentTimeMillis()); |
| 819 | } |
| 820 | |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 821 | public FlowEntry remove(DeviceId deviceId, FlowEntry rule) { |
| 822 | final AtomicReference<FlowEntry> removedRule = new AtomicReference<>(); |
| 823 | getFlowEntriesInternal(rule.deviceId(), rule.id()) |
| 824 | .computeIfPresent((StoredFlowEntry) rule, (k, stored) -> { |
| 825 | if (rule instanceof DefaultFlowEntry) { |
| 826 | DefaultFlowEntry toRemove = (DefaultFlowEntry) rule; |
| 827 | if (stored instanceof DefaultFlowEntry) { |
| 828 | DefaultFlowEntry storedEntry = (DefaultFlowEntry) stored; |
| 829 | if (toRemove.created() < storedEntry.created()) { |
| 830 | log.debug("Trying to remove more recent flow entry {} (stored: {})", |
| 831 | toRemove, stored); |
| 832 | // the key is not updated, removedRule remains null |
| 833 | return stored; |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | removedRule.set(stored); |
| 838 | return null; |
| 839 | }); |
| 840 | |
| 841 | if (removedRule.get() != null) { |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 842 | lastUpdateTimes.put(deviceId, System.currentTimeMillis()); |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 843 | return removedRule.get(); |
| 844 | } else { |
| 845 | return null; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 849 | public void purgeFlowRule(DeviceId deviceId) { |
| 850 | flowEntries.remove(deviceId); |
| 851 | } |
| 852 | |
Victor Silva | 139bca4 | 2016-08-18 11:46:35 -0300 | [diff] [blame] | 853 | public void purgeFlowRules() { |
| 854 | flowEntries.clear(); |
| 855 | } |
| 856 | |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 857 | private List<NodeId> getBackupNodes(DeviceId deviceId) { |
| 858 | // The returned backup node list is in the order of preference i.e. next likely master first. |
| 859 | List<NodeId> allPossibleBackupNodes = replicaInfoManager.getReplicaInfoFor(deviceId).backups(); |
| 860 | return ImmutableList.copyOf(allPossibleBackupNodes) |
| 861 | .subList(0, Math.min(allPossibleBackupNodes.size(), backupCount)); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | private void backup() { |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 865 | try { |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 866 | // compute a mapping from node to the set of devices whose flow entries it should backup |
| 867 | Map<NodeId, Set<DeviceId>> devicesToBackupByNode = Maps.newHashMap(); |
Sho SHIMIZU | a09e1bb | 2016-08-01 14:25:25 -0700 | [diff] [blame] | 868 | flowEntries.keySet().forEach(deviceId -> { |
Madan Jampani | c6d69f7 | 2016-07-15 15:47:12 -0700 | [diff] [blame] | 869 | List<NodeId> backupNodes = getBackupNodes(deviceId); |
| 870 | backupNodes.forEach(backupNode -> { |
| 871 | if (lastBackupTimes.getOrDefault(new BackupOperation(backupNode, deviceId), 0L) |
| 872 | < lastUpdateTimes.getOrDefault(deviceId, 0L)) { |
| 873 | devicesToBackupByNode.computeIfAbsent(backupNode, |
| 874 | nodeId -> Sets.newHashSet()).add(deviceId); |
| 875 | } |
| 876 | }); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 877 | }); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 878 | // send the device flow entries to their respective backup nodes |
Madan Jampani | adea890 | 2015-06-04 17:39:45 -0700 | [diff] [blame] | 879 | devicesToBackupByNode.forEach(this::sendBackups); |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 880 | } catch (Exception e) { |
| 881 | log.error("Backup failed.", e); |
| 882 | } |
| 883 | } |
| 884 | |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 885 | private Set<DeviceId> onBackupReceipt(Map<DeviceId, |
| 886 | Map<FlowId, Map<StoredFlowEntry, StoredFlowEntry>>> flowTables) { |
Madan Jampani | 7267c55 | 2015-05-20 22:39:17 -0700 | [diff] [blame] | 887 | log.debug("Received flowEntries for {} to backup", flowTables.keySet()); |
Madan Jampani | 654b58a | 2015-05-22 11:28:11 -0700 | [diff] [blame] | 888 | Set<DeviceId> backedupDevices = Sets.newHashSet(); |
| 889 | try { |
Madan Jampani | a98bf93 | 2015-06-02 12:01:36 -0700 | [diff] [blame] | 890 | flowTables.forEach((deviceId, deviceFlowTable) -> { |
| 891 | // Only process those devices are that not managed by the local node. |
Sho SHIMIZU | 828bc16 | 2016-01-13 23:10:43 -0800 | [diff] [blame] | 892 | if (!Objects.equals(local, mastershipService.getMasterFor(deviceId))) { |
Brian O'Connor | a3e5cd5 | 2015-12-05 15:59:19 -0800 | [diff] [blame] | 893 | Map<FlowId, Map<StoredFlowEntry, StoredFlowEntry>> backupFlowTable = |
| 894 | getFlowTable(deviceId); |
Madan Jampani | a98bf93 | 2015-06-02 12:01:36 -0700 | [diff] [blame] | 895 | backupFlowTable.clear(); |
| 896 | backupFlowTable.putAll(deviceFlowTable); |
| 897 | backedupDevices.add(deviceId); |
| 898 | } |
Madan Jampani | 08bf17b | 2015-05-06 16:25:26 -0700 | [diff] [blame] | 899 | }); |
Madan Jampani | 654b58a | 2015-05-22 11:28:11 -0700 | [diff] [blame] | 900 | } catch (Exception e) { |
| 901 | log.warn("Failure processing backup request", e); |
| 902 | } |
| 903 | return backedupDevices; |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 904 | } |
| 905 | } |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 906 | |
| 907 | @Override |
| 908 | public FlowRuleEvent updateTableStatistics(DeviceId deviceId, |
| 909 | List<TableStatisticsEntry> tableStats) { |
| 910 | deviceTableStats.put(deviceId, tableStats); |
| 911 | return null; |
| 912 | } |
| 913 | |
| 914 | @Override |
| 915 | public Iterable<TableStatisticsEntry> getTableStatistics(DeviceId deviceId) { |
| 916 | NodeId master = mastershipService.getMasterFor(deviceId); |
| 917 | |
| 918 | if (master == null) { |
| 919 | log.debug("Failed to getTableStats: No master for {}", deviceId); |
| 920 | return Collections.emptyList(); |
| 921 | } |
| 922 | |
| 923 | List<TableStatisticsEntry> tableStats = deviceTableStats.get(deviceId); |
| 924 | if (tableStats == null) { |
| 925 | return Collections.emptyList(); |
| 926 | } |
| 927 | return ImmutableList.copyOf(tableStats); |
| 928 | } |
| 929 | |
Patryk Konopka | 7e40c01 | 2017-06-06 13:38:06 +0200 | [diff] [blame^] | 930 | @Override |
| 931 | public long getActiveFlowRuleCount(DeviceId deviceId) { |
| 932 | return Streams.stream(getTableStatistics(deviceId)) |
| 933 | .mapToLong(TableStatisticsEntry::activeFlowEntries) |
| 934 | .sum(); |
| 935 | } |
| 936 | |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 937 | private class InternalTableStatsListener |
| 938 | implements EventuallyConsistentMapListener<DeviceId, List<TableStatisticsEntry>> { |
| 939 | @Override |
| 940 | public void event(EventuallyConsistentMapEvent<DeviceId, |
| 941 | List<TableStatisticsEntry>> event) { |
| 942 | //TODO: Generate an event to listeners (do we need?) |
| 943 | } |
| 944 | } |
Madan Jampani | 86940d9 | 2015-05-06 11:47:57 -0700 | [diff] [blame] | 945 | } |