blob: 31b58fbe69866b9ec7d3133d5a8174c36e54a88c [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Thomas Vachuskac97aa612015-06-23 16:00:18 -070016package org.onosproject.store.trivial;
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070017
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080018import com.google.common.cache.Cache;
19import com.google.common.cache.CacheBuilder;
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -080020import com.google.common.cache.RemovalListener;
21import com.google.common.cache.RemovalNotification;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070022import com.google.common.collect.FluentIterable;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070023import com.google.common.collect.ImmutableList;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080024import com.google.common.collect.Sets;
Patryk Konopka7e40c012017-06-06 13:38:06 +020025import com.google.common.collect.Streams;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080026import com.google.common.util.concurrent.SettableFuture;
sangyun-hanc1806862016-04-05 11:42:03 +090027import org.onlab.util.Tools;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.DeviceId;
29import org.onosproject.net.flow.CompletedBatchOperation;
30import org.onosproject.net.flow.DefaultFlowEntry;
31import org.onosproject.net.flow.FlowEntry;
32import org.onosproject.net.flow.FlowEntry.FlowEntryState;
33import org.onosproject.net.flow.FlowId;
34import org.onosproject.net.flow.FlowRule;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.flow.FlowRuleEvent;
36import org.onosproject.net.flow.FlowRuleEvent.Type;
37import org.onosproject.net.flow.FlowRuleStore;
38import org.onosproject.net.flow.FlowRuleStoreDelegate;
39import org.onosproject.net.flow.StoredFlowEntry;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070040import org.onosproject.net.flow.TableStatisticsEntry;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070041import org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry;
42import org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry.FlowRuleOperation;
43import org.onosproject.net.flow.oldbatch.FlowRuleBatchEvent;
44import org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation;
45import org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest;
Brian O'Connorabafb502014-12-02 22:26:20 -080046import org.onosproject.store.AbstractStore;
sangyun-hanc1806862016-04-05 11:42:03 +090047import org.osgi.service.component.ComponentContext;
tom85c612b2014-09-19 19:25:47 -070048import org.slf4j.Logger;
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070049
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080050import java.util.ArrayList;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070051import java.util.Collections;
sangyun-hanc1806862016-04-05 11:42:03 +090052import java.util.Dictionary;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070053import java.util.List;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070054import java.util.concurrent.ConcurrentHashMap;
55import java.util.concurrent.ConcurrentMap;
56import java.util.concurrent.CopyOnWriteArrayList;
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -080057import java.util.concurrent.ExecutionException;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080058import java.util.concurrent.TimeUnit;
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -080059import java.util.concurrent.TimeoutException;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080060import java.util.concurrent.atomic.AtomicInteger;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070061
Brian O'Connorabafb502014-12-02 22:26:20 -080062import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070063import static org.slf4j.LoggerFactory.getLogger;
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -070064
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070065/**
66 * Manages inventory of flow rules using trivial in-memory implementation.
67 */
tomc78acee2014-09-24 15:16:55 -070068public class SimpleFlowRuleStore
Madan Jampani117aaae2014-10-23 10:04:05 -070069 extends AbstractStore<FlowRuleBatchEvent, FlowRuleStoreDelegate>
tomc78acee2014-09-24 15:16:55 -070070 implements FlowRuleStore {
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070071
tom85c612b2014-09-19 19:25:47 -070072 private final Logger log = getLogger(getClass());
73
Yuta HIGUCHI605347c2014-10-17 21:05:23 -070074 // inner Map is Device flow table
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -070075 // inner Map value (FlowId synonym list) must be synchronized before modifying
76 private final ConcurrentMap<DeviceId, ConcurrentMap<FlowId, List<StoredFlowEntry>>>
Yuta HIGUCHI605347c2014-10-17 21:05:23 -070077 flowEntries = new ConcurrentHashMap<>();
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070078
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070079 private final ConcurrentMap<DeviceId, List<TableStatisticsEntry>>
80 deviceTableStats = new ConcurrentHashMap<>();
81
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080082 private final AtomicInteger localBatchIdGen = new AtomicInteger();
83
sangyun-hanc1806862016-04-05 11:42:03 +090084 private static final int DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES = 5;
sangyun-hanc1806862016-04-05 11:42:03 +090085 private int pendingFutureTimeoutMinutes = DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080086
87 private Cache<Integer, SettableFuture<CompletedBatchOperation>> pendingFutures =
88 CacheBuilder.newBuilder()
89 .expireAfterWrite(pendingFutureTimeoutMinutes, TimeUnit.MINUTES)
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -080090 .removalListener(new TimeoutFuture())
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080091 .build();
92
tom85c612b2014-09-19 19:25:47 -070093 public void activate() {
94 log.info("Started");
95 }
96
tom85c612b2014-09-19 19:25:47 -070097 public void deactivate() {
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070098 deviceTableStats.clear();
Yuta HIGUCHI605347c2014-10-17 21:05:23 -070099 flowEntries.clear();
tom85c612b2014-09-19 19:25:47 -0700100 log.info("Stopped");
101 }
102
sangyun-hanc1806862016-04-05 11:42:03 +0900103 public void modified(ComponentContext context) {
sangyun-hanc1806862016-04-05 11:42:03 +0900104 readComponentConfiguration(context);
105
106 // Reset Cache and copy all.
107 Cache<Integer, SettableFuture<CompletedBatchOperation>> prevFutures = pendingFutures;
108 pendingFutures = CacheBuilder.newBuilder()
109 .expireAfterWrite(pendingFutureTimeoutMinutes, TimeUnit.MINUTES)
110 .removalListener(new TimeoutFuture())
111 .build();
112
113 pendingFutures.putAll(prevFutures.asMap());
114 }
115
alshabiba68eb962014-09-24 20:34:13 -0700116
tombe988312014-09-19 18:38:47 -0700117 @Override
tom9b4030d2014-10-06 10:39:03 -0700118 public int getFlowRuleCount() {
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700119 int sum = 0;
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700120 for (ConcurrentMap<FlowId, List<StoredFlowEntry>> ft : flowEntries.values()) {
121 for (List<StoredFlowEntry> fes : ft.values()) {
122 sum += fes.size();
123 }
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700124 }
125 return sum;
126 }
127
sangyun-hanc1806862016-04-05 11:42:03 +0900128 /**
129 * Extracts properties from the component configuration context.
130 *
131 * @param context the component context
132 */
133 private void readComponentConfiguration(ComponentContext context) {
134 Dictionary<?, ?> properties = context.getProperties();
135
136 Integer newPendingFutureTimeoutMinutes =
137 Tools.getIntegerProperty(properties, "pendingFutureTimeoutMinutes");
138 if (newPendingFutureTimeoutMinutes == null) {
139 pendingFutureTimeoutMinutes = DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES;
140 log.info("Pending future timeout is not configured, " +
141 "using current value of {}", pendingFutureTimeoutMinutes);
142 } else {
143 pendingFutureTimeoutMinutes = newPendingFutureTimeoutMinutes;
144 log.info("Configured. Pending future timeout is configured to {}",
145 pendingFutureTimeoutMinutes);
146 }
147 }
148
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700149 /**
150 * Returns the flow table for specified device.
151 *
152 * @param deviceId identifier of the device
153 * @return Map representing Flow Table of given device.
154 */
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700155 private ConcurrentMap<FlowId, List<StoredFlowEntry>> getFlowTable(DeviceId deviceId) {
Yuta HIGUCHIc2e68152016-08-16 13:47:36 -0700156 return flowEntries.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>());
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700157 }
158
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700159 private List<StoredFlowEntry> getFlowEntries(DeviceId deviceId, FlowId flowId) {
160 final ConcurrentMap<FlowId, List<StoredFlowEntry>> flowTable = getFlowTable(deviceId);
161 List<StoredFlowEntry> r = flowTable.get(flowId);
162 if (r == null) {
163 final List<StoredFlowEntry> concurrentlyAdded;
164 r = new CopyOnWriteArrayList<>();
165 concurrentlyAdded = flowTable.putIfAbsent(flowId, r);
166 if (concurrentlyAdded != null) {
167 return concurrentlyAdded;
168 }
169 }
170 return r;
171 }
172
173 private FlowEntry getFlowEntryInternal(DeviceId deviceId, FlowRule rule) {
174 List<StoredFlowEntry> fes = getFlowEntries(deviceId, rule.id());
175 for (StoredFlowEntry fe : fes) {
176 if (fe.equals(rule)) {
177 return fe;
178 }
179 }
180 return null;
tom9b4030d2014-10-06 10:39:03 -0700181 }
182
183 @Override
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700184 public FlowEntry getFlowEntry(FlowRule rule) {
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700185 return getFlowEntryInternal(rule.deviceId(), rule);
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700186 }
187
188 @Override
189 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700190 // flatten and make iterator unmodifiable
191 return FluentIterable.from(getFlowTable(deviceId).values())
Sho SHIMIZU74626412015-09-11 11:46:27 -0700192 .transformAndConcat(Collections::unmodifiableList);
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700193 }
194
195 @Override
Madan Jampani117aaae2014-10-23 10:04:05 -0700196 public void storeFlowRule(FlowRule rule) {
197 storeFlowRuleInternal(rule);
alshabib219ebaa2014-09-22 15:41:24 -0700198 }
199
Madan Jampani117aaae2014-10-23 10:04:05 -0700200 private void storeFlowRuleInternal(FlowRule rule) {
Yuta HIGUCHIf6f50a62014-10-19 15:58:49 -0700201 StoredFlowEntry f = new DefaultFlowEntry(rule);
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700202 final DeviceId did = f.deviceId();
203 final FlowId fid = f.id();
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700204 List<StoredFlowEntry> existing = getFlowEntries(did, fid);
205 synchronized (existing) {
206 for (StoredFlowEntry fe : existing) {
207 if (fe.equals(rule)) {
208 // was already there? ignore
Madan Jampani117aaae2014-10-23 10:04:05 -0700209 return;
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700210 }
211 }
212 // new flow rule added
213 existing.add(f);
alshabiba68eb962014-09-24 20:34:13 -0700214 }
215 }
216
217 @Override
Madan Jampani117aaae2014-10-23 10:04:05 -0700218 public void deleteFlowRule(FlowRule rule) {
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700219
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700220 List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
alshabib2374fc92014-10-22 11:03:23 -0700221
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700222 synchronized (entries) {
223 for (StoredFlowEntry entry : entries) {
224 if (entry.equals(rule)) {
225 synchronized (entry) {
226 entry.setState(FlowEntryState.PENDING_REMOVE);
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700227 }
228 }
229 }
alshabib219ebaa2014-09-22 15:41:24 -0700230 }
Madan Jampani31961c12014-10-23 12:06:58 -0700231
232
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700233 //log.warn("Cannot find rule {}", rule);
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700234 }
235
tombe988312014-09-19 18:38:47 -0700236 @Override
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700237 public FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) {
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700238 // check if this new rule is an update to an existing entry
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700239 List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
240 synchronized (entries) {
241 for (StoredFlowEntry stored : entries) {
242 if (stored.equals(rule)) {
243 synchronized (stored) {
Brian O'Connora3e5cd52015-12-05 15:59:19 -0800244 //FIXME modification of "stored" flow entry outside of flow table
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700245 stored.setBytes(rule.bytes());
246 stored.setLife(rule.life());
247 stored.setPackets(rule.packets());
248 if (stored.state() == FlowEntryState.PENDING_ADD) {
249 stored.setState(FlowEntryState.ADDED);
250 // TODO: Do we need to change `rule` state?
251 return new FlowRuleEvent(Type.RULE_ADDED, rule);
252 }
253 return new FlowRuleEvent(Type.RULE_UPDATED, rule);
254 }
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700255 }
alshabibba5ac482014-10-02 17:15:20 -0700256 }
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700257 }
alshabib219ebaa2014-09-22 15:41:24 -0700258
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700259 // should not reach here
260 // storeFlowRule was expected to be called
261 log.error("FlowRule was not found in store {} to update", rule);
262
alshabib8ca53902014-10-07 13:11:17 -0700263 //flowEntries.put(did, rule);
alshabibba5ac482014-10-02 17:15:20 -0700264 return null;
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700265 }
266
tombe988312014-09-19 18:38:47 -0700267 @Override
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700268 public FlowRuleEvent removeFlowRule(FlowEntry rule) {
alshabib1c319ff2014-10-04 20:29:09 -0700269 // This is where one could mark a rule as removed and still keep it in the store.
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700270 final DeviceId did = rule.deviceId();
271
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700272 List<StoredFlowEntry> entries = getFlowEntries(did, rule.id());
273 synchronized (entries) {
274 if (entries.remove(rule)) {
275 return new FlowRuleEvent(RULE_REMOVED, rule);
276 }
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700277 }
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700278 return null;
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700279 }
Madan Jampani117aaae2014-10-23 10:04:05 -0700280
281 @Override
Charles Chan93fa7272016-01-26 22:27:02 -0800282 public FlowRuleEvent pendingFlowRule(FlowEntry rule) {
283 List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
284 synchronized (entries) {
285 for (StoredFlowEntry entry : entries) {
286 if (entry.equals(rule) &&
287 entry.state() != FlowEntryState.PENDING_ADD) {
288 synchronized (entry) {
289 entry.setState(FlowEntryState.PENDING_ADD);
290 return new FlowRuleEvent(Type.RULE_UPDATED, rule);
291 }
292 }
293 }
294 }
295 return null;
296 }
297
Yuta HIGUCHIc2e68152016-08-16 13:47:36 -0700298 @Override
Charles Chan0c7c43b2016-01-14 17:39:20 -0800299 public void purgeFlowRule(DeviceId deviceId) {
300 flowEntries.remove(deviceId);
301 }
302
Charles Chan93fa7272016-01-26 22:27:02 -0800303 @Override
Victor Silva139bca42016-08-18 11:46:35 -0300304 public void purgeFlowRules() {
305 flowEntries.clear();
306 }
307
308 @Override
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800309 public void storeBatch(
310 FlowRuleBatchOperation operation) {
Brian O'Connor427a1762014-11-19 18:40:32 -0800311 List<FlowRuleBatchEntry> toAdd = new ArrayList<>();
312 List<FlowRuleBatchEntry> toRemove = new ArrayList<>();
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800313
314 for (FlowRuleBatchEntry entry : operation.getOperations()) {
Ray Milkeyf7329c72015-02-17 11:37:01 -0800315 final FlowRule flowRule = entry.target();
316 if (entry.operator().equals(FlowRuleOperation.ADD)) {
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800317 if (!getFlowEntries(flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
318 storeFlowRule(flowRule);
Brian O'Connor427a1762014-11-19 18:40:32 -0800319 toAdd.add(entry);
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800320 }
Sho SHIMIZUaba9d002015-01-29 14:51:04 -0800321 } else if (entry.operator().equals(FlowRuleOperation.REMOVE)) {
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800322 if (getFlowEntries(flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
323 deleteFlowRule(flowRule);
Brian O'Connor427a1762014-11-19 18:40:32 -0800324 toRemove.add(entry);
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800325 }
Madan Jampani117aaae2014-10-23 10:04:05 -0700326 } else {
327 throw new UnsupportedOperationException("Unsupported operation type");
328 }
329 }
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800330
331 if (toAdd.isEmpty() && toRemove.isEmpty()) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800332 notifyDelegate(FlowRuleBatchEvent.completed(
333 new FlowRuleBatchRequest(operation.id(), Collections.emptySet()),
334 new CompletedBatchOperation(true, Collections.emptySet(),
335 operation.deviceId())));
336 return;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800337 }
338
339 SettableFuture<CompletedBatchOperation> r = SettableFuture.create();
340 final int batchId = localBatchIdGen.incrementAndGet();
341
342 pendingFutures.put(batchId, r);
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800343
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800344 toAdd.addAll(toRemove);
345 notifyDelegate(FlowRuleBatchEvent.requested(
346 new FlowRuleBatchRequest(batchId, Sets.newHashSet(toAdd)), operation.deviceId()));
347
Madan Jampani117aaae2014-10-23 10:04:05 -0700348 }
349
350 @Override
351 public void batchOperationComplete(FlowRuleBatchEvent event) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800352 final Long batchId = event.subject().batchId();
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800353 SettableFuture<CompletedBatchOperation> future
354 = pendingFutures.getIfPresent(batchId);
355 if (future != null) {
356 future.set(event.result());
357 pendingFutures.invalidate(batchId);
358 }
Madan Jampani117aaae2014-10-23 10:04:05 -0700359 notifyDelegate(event);
360 }
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -0800361
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700362 @Override
363 public FlowRuleEvent updateTableStatistics(DeviceId deviceId,
364 List<TableStatisticsEntry> tableStats) {
365 deviceTableStats.put(deviceId, tableStats);
366 return null;
367 }
368
369 @Override
370 public Iterable<TableStatisticsEntry> getTableStatistics(DeviceId deviceId) {
371 List<TableStatisticsEntry> tableStats = deviceTableStats.get(deviceId);
372 if (tableStats == null) {
373 return Collections.emptyList();
374 }
375 return ImmutableList.copyOf(tableStats);
376 }
sangyun-hanc1806862016-04-05 11:42:03 +0900377
Patryk Konopka7e40c012017-06-06 13:38:06 +0200378 @Override
379 public long getActiveFlowRuleCount(DeviceId deviceId) {
380 return Streams.stream(getTableStatistics(deviceId))
381 .mapToLong(TableStatisticsEntry::activeFlowEntries)
382 .sum();
383 }
384
sangyun-hanc1806862016-04-05 11:42:03 +0900385 private static final class TimeoutFuture
386 implements RemovalListener<Integer, SettableFuture<CompletedBatchOperation>> {
387 @Override
388 public void onRemoval(RemovalNotification<Integer, SettableFuture<CompletedBatchOperation>> notification) {
389 // wrapping in ExecutionException to support Future.get
390 if (notification.wasEvicted()) {
391 notification.getValue()
392 .setException(new ExecutionException("Timed out",
393 new TimeoutException()));
394 }
395 }
396 }
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700397}