blob: 8924b61ff7e52a46ea95c1f21028238c4ee14d0a [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080025import com.google.common.util.concurrent.SettableFuture;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070026
tom85c612b2014-09-19 19:25:47 -070027import org.apache.felix.scr.annotations.Activate;
28import org.apache.felix.scr.annotations.Component;
29import org.apache.felix.scr.annotations.Deactivate;
sangyun-hanc1806862016-04-05 11:42:03 +090030import org.apache.felix.scr.annotations.Modified;
31import org.apache.felix.scr.annotations.Property;
tom85c612b2014-09-19 19:25:47 -070032import org.apache.felix.scr.annotations.Service;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080033import org.onlab.util.NewConcurrentHashMap;
sangyun-hanc1806862016-04-05 11:42:03 +090034import org.onlab.util.Tools;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.DeviceId;
36import org.onosproject.net.flow.CompletedBatchOperation;
37import org.onosproject.net.flow.DefaultFlowEntry;
38import org.onosproject.net.flow.FlowEntry;
39import org.onosproject.net.flow.FlowEntry.FlowEntryState;
40import org.onosproject.net.flow.FlowId;
41import org.onosproject.net.flow.FlowRule;
42import org.onosproject.net.flow.FlowRuleBatchEntry;
43import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
44import org.onosproject.net.flow.FlowRuleBatchEvent;
45import org.onosproject.net.flow.FlowRuleBatchOperation;
46import org.onosproject.net.flow.FlowRuleBatchRequest;
47import org.onosproject.net.flow.FlowRuleEvent;
48import org.onosproject.net.flow.FlowRuleEvent.Type;
49import org.onosproject.net.flow.FlowRuleStore;
50import org.onosproject.net.flow.FlowRuleStoreDelegate;
51import org.onosproject.net.flow.StoredFlowEntry;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070052import org.onosproject.net.flow.TableStatisticsEntry;
Brian O'Connorabafb502014-12-02 22:26:20 -080053import org.onosproject.store.AbstractStore;
sangyun-hanc1806862016-04-05 11:42:03 +090054import org.osgi.service.component.ComponentContext;
tom85c612b2014-09-19 19:25:47 -070055import org.slf4j.Logger;
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070056
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080057import java.util.ArrayList;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070058import java.util.Collections;
sangyun-hanc1806862016-04-05 11:42:03 +090059import java.util.Dictionary;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070060import java.util.List;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070061import java.util.concurrent.ConcurrentHashMap;
62import java.util.concurrent.ConcurrentMap;
63import java.util.concurrent.CopyOnWriteArrayList;
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -080064import java.util.concurrent.ExecutionException;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080065import java.util.concurrent.TimeUnit;
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -080066import java.util.concurrent.TimeoutException;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080067import java.util.concurrent.atomic.AtomicInteger;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070068
69import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked;
Brian O'Connorabafb502014-12-02 22:26:20 -080070import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070071import static org.slf4j.LoggerFactory.getLogger;
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -070072
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070073/**
74 * Manages inventory of flow rules using trivial in-memory implementation.
75 */
tom85c612b2014-09-19 19:25:47 -070076@Component(immediate = true)
77@Service
tomc78acee2014-09-24 15:16:55 -070078public class SimpleFlowRuleStore
Madan Jampani117aaae2014-10-23 10:04:05 -070079 extends AbstractStore<FlowRuleBatchEvent, FlowRuleStoreDelegate>
tomc78acee2014-09-24 15:16:55 -070080 implements FlowRuleStore {
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070081
tom85c612b2014-09-19 19:25:47 -070082 private final Logger log = getLogger(getClass());
83
alshabiba68eb962014-09-24 20:34:13 -070084
Yuta HIGUCHI605347c2014-10-17 21:05:23 -070085 // inner Map is Device flow table
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -070086 // inner Map value (FlowId synonym list) must be synchronized before modifying
87 private final ConcurrentMap<DeviceId, ConcurrentMap<FlowId, List<StoredFlowEntry>>>
Yuta HIGUCHI605347c2014-10-17 21:05:23 -070088 flowEntries = new ConcurrentHashMap<>();
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070089
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070090 private final ConcurrentMap<DeviceId, List<TableStatisticsEntry>>
91 deviceTableStats = new ConcurrentHashMap<>();
92
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080093 private final AtomicInteger localBatchIdGen = new AtomicInteger();
94
sangyun-hanc1806862016-04-05 11:42:03 +090095 private static final int DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES = 5;
96 @Property(name = "pendingFutureTimeoutMinutes", intValue = DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES,
97 label = "Expiration time after an entry is created that it should be automatically removed")
98 private int pendingFutureTimeoutMinutes = DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080099
100 private Cache<Integer, SettableFuture<CompletedBatchOperation>> pendingFutures =
101 CacheBuilder.newBuilder()
102 .expireAfterWrite(pendingFutureTimeoutMinutes, TimeUnit.MINUTES)
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -0800103 .removalListener(new TimeoutFuture())
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800104 .build();
105
tom85c612b2014-09-19 19:25:47 -0700106 @Activate
107 public void activate() {
108 log.info("Started");
109 }
110
111 @Deactivate
112 public void deactivate() {
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700113 deviceTableStats.clear();
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700114 flowEntries.clear();
tom85c612b2014-09-19 19:25:47 -0700115 log.info("Stopped");
116 }
117
sangyun-hanc1806862016-04-05 11:42:03 +0900118 @Modified
119 public void modified(ComponentContext context) {
120
121 readComponentConfiguration(context);
122
123 // Reset Cache and copy all.
124 Cache<Integer, SettableFuture<CompletedBatchOperation>> prevFutures = pendingFutures;
125 pendingFutures = CacheBuilder.newBuilder()
126 .expireAfterWrite(pendingFutureTimeoutMinutes, TimeUnit.MINUTES)
127 .removalListener(new TimeoutFuture())
128 .build();
129
130 pendingFutures.putAll(prevFutures.asMap());
131 }
132
alshabiba68eb962014-09-24 20:34:13 -0700133
tombe988312014-09-19 18:38:47 -0700134 @Override
tom9b4030d2014-10-06 10:39:03 -0700135 public int getFlowRuleCount() {
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700136 int sum = 0;
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700137 for (ConcurrentMap<FlowId, List<StoredFlowEntry>> ft : flowEntries.values()) {
138 for (List<StoredFlowEntry> fes : ft.values()) {
139 sum += fes.size();
140 }
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700141 }
142 return sum;
143 }
144
sangyun-hanc1806862016-04-05 11:42:03 +0900145 /**
146 * Extracts properties from the component configuration context.
147 *
148 * @param context the component context
149 */
150 private void readComponentConfiguration(ComponentContext context) {
151 Dictionary<?, ?> properties = context.getProperties();
152
153 Integer newPendingFutureTimeoutMinutes =
154 Tools.getIntegerProperty(properties, "pendingFutureTimeoutMinutes");
155 if (newPendingFutureTimeoutMinutes == null) {
156 pendingFutureTimeoutMinutes = DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES;
157 log.info("Pending future timeout is not configured, " +
158 "using current value of {}", pendingFutureTimeoutMinutes);
159 } else {
160 pendingFutureTimeoutMinutes = newPendingFutureTimeoutMinutes;
161 log.info("Configured. Pending future timeout is configured to {}",
162 pendingFutureTimeoutMinutes);
163 }
164 }
165
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700166 private static NewConcurrentHashMap<FlowId, List<StoredFlowEntry>> lazyEmptyFlowTable() {
167 return NewConcurrentHashMap.<FlowId, List<StoredFlowEntry>>ifNeeded();
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700168 }
169
170 /**
171 * Returns the flow table for specified device.
172 *
173 * @param deviceId identifier of the device
174 * @return Map representing Flow Table of given device.
175 */
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700176 private ConcurrentMap<FlowId, List<StoredFlowEntry>> getFlowTable(DeviceId deviceId) {
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700177 return createIfAbsentUnchecked(flowEntries,
178 deviceId, lazyEmptyFlowTable());
179 }
180
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700181 private List<StoredFlowEntry> getFlowEntries(DeviceId deviceId, FlowId flowId) {
182 final ConcurrentMap<FlowId, List<StoredFlowEntry>> flowTable = getFlowTable(deviceId);
183 List<StoredFlowEntry> r = flowTable.get(flowId);
184 if (r == null) {
185 final List<StoredFlowEntry> concurrentlyAdded;
186 r = new CopyOnWriteArrayList<>();
187 concurrentlyAdded = flowTable.putIfAbsent(flowId, r);
188 if (concurrentlyAdded != null) {
189 return concurrentlyAdded;
190 }
191 }
192 return r;
193 }
194
195 private FlowEntry getFlowEntryInternal(DeviceId deviceId, FlowRule rule) {
196 List<StoredFlowEntry> fes = getFlowEntries(deviceId, rule.id());
197 for (StoredFlowEntry fe : fes) {
198 if (fe.equals(rule)) {
199 return fe;
200 }
201 }
202 return null;
tom9b4030d2014-10-06 10:39:03 -0700203 }
204
205 @Override
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700206 public FlowEntry getFlowEntry(FlowRule rule) {
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700207 return getFlowEntryInternal(rule.deviceId(), rule);
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700208 }
209
210 @Override
211 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700212 // flatten and make iterator unmodifiable
213 return FluentIterable.from(getFlowTable(deviceId).values())
Sho SHIMIZU74626412015-09-11 11:46:27 -0700214 .transformAndConcat(Collections::unmodifiableList);
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700215 }
216
217 @Override
Madan Jampani117aaae2014-10-23 10:04:05 -0700218 public void storeFlowRule(FlowRule rule) {
219 storeFlowRuleInternal(rule);
alshabib219ebaa2014-09-22 15:41:24 -0700220 }
221
Madan Jampani117aaae2014-10-23 10:04:05 -0700222 private void storeFlowRuleInternal(FlowRule rule) {
Yuta HIGUCHIf6f50a62014-10-19 15:58:49 -0700223 StoredFlowEntry f = new DefaultFlowEntry(rule);
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700224 final DeviceId did = f.deviceId();
225 final FlowId fid = f.id();
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700226 List<StoredFlowEntry> existing = getFlowEntries(did, fid);
227 synchronized (existing) {
228 for (StoredFlowEntry fe : existing) {
229 if (fe.equals(rule)) {
230 // was already there? ignore
Madan Jampani117aaae2014-10-23 10:04:05 -0700231 return;
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700232 }
233 }
234 // new flow rule added
235 existing.add(f);
alshabiba68eb962014-09-24 20:34:13 -0700236 }
237 }
238
239 @Override
Madan Jampani117aaae2014-10-23 10:04:05 -0700240 public void deleteFlowRule(FlowRule rule) {
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700241
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700242 List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
alshabib2374fc92014-10-22 11:03:23 -0700243
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700244 synchronized (entries) {
245 for (StoredFlowEntry entry : entries) {
246 if (entry.equals(rule)) {
247 synchronized (entry) {
248 entry.setState(FlowEntryState.PENDING_REMOVE);
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700249 }
250 }
251 }
alshabib219ebaa2014-09-22 15:41:24 -0700252 }
Madan Jampani31961c12014-10-23 12:06:58 -0700253
254
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700255 //log.warn("Cannot find rule {}", rule);
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700256 }
257
tombe988312014-09-19 18:38:47 -0700258 @Override
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700259 public FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) {
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700260 // check if this new rule is an update to an existing entry
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700261 List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
262 synchronized (entries) {
263 for (StoredFlowEntry stored : entries) {
264 if (stored.equals(rule)) {
265 synchronized (stored) {
Brian O'Connora3e5cd52015-12-05 15:59:19 -0800266 //FIXME modification of "stored" flow entry outside of flow table
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700267 stored.setBytes(rule.bytes());
268 stored.setLife(rule.life());
269 stored.setPackets(rule.packets());
270 if (stored.state() == FlowEntryState.PENDING_ADD) {
271 stored.setState(FlowEntryState.ADDED);
272 // TODO: Do we need to change `rule` state?
273 return new FlowRuleEvent(Type.RULE_ADDED, rule);
274 }
275 return new FlowRuleEvent(Type.RULE_UPDATED, rule);
276 }
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700277 }
alshabibba5ac482014-10-02 17:15:20 -0700278 }
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700279 }
alshabib219ebaa2014-09-22 15:41:24 -0700280
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700281 // should not reach here
282 // storeFlowRule was expected to be called
283 log.error("FlowRule was not found in store {} to update", rule);
284
alshabib8ca53902014-10-07 13:11:17 -0700285 //flowEntries.put(did, rule);
alshabibba5ac482014-10-02 17:15:20 -0700286 return null;
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700287 }
288
tombe988312014-09-19 18:38:47 -0700289 @Override
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700290 public FlowRuleEvent removeFlowRule(FlowEntry rule) {
alshabib1c319ff2014-10-04 20:29:09 -0700291 // This is where one could mark a rule as removed and still keep it in the store.
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700292 final DeviceId did = rule.deviceId();
293
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700294 List<StoredFlowEntry> entries = getFlowEntries(did, rule.id());
295 synchronized (entries) {
296 if (entries.remove(rule)) {
297 return new FlowRuleEvent(RULE_REMOVED, rule);
298 }
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700299 }
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700300 return null;
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700301 }
Madan Jampani117aaae2014-10-23 10:04:05 -0700302
303 @Override
Charles Chan93fa7272016-01-26 22:27:02 -0800304 public FlowRuleEvent pendingFlowRule(FlowEntry rule) {
305 List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
306 synchronized (entries) {
307 for (StoredFlowEntry entry : entries) {
308 if (entry.equals(rule) &&
309 entry.state() != FlowEntryState.PENDING_ADD) {
310 synchronized (entry) {
311 entry.setState(FlowEntryState.PENDING_ADD);
312 return new FlowRuleEvent(Type.RULE_UPDATED, rule);
313 }
314 }
315 }
316 }
317 return null;
318 }
319
Charles Chan0c7c43b2016-01-14 17:39:20 -0800320 public void purgeFlowRule(DeviceId deviceId) {
321 flowEntries.remove(deviceId);
322 }
323
Charles Chan93fa7272016-01-26 22:27:02 -0800324 @Override
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800325 public void storeBatch(
326 FlowRuleBatchOperation operation) {
Brian O'Connor427a1762014-11-19 18:40:32 -0800327 List<FlowRuleBatchEntry> toAdd = new ArrayList<>();
328 List<FlowRuleBatchEntry> toRemove = new ArrayList<>();
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800329
330 for (FlowRuleBatchEntry entry : operation.getOperations()) {
Ray Milkeyf7329c72015-02-17 11:37:01 -0800331 final FlowRule flowRule = entry.target();
332 if (entry.operator().equals(FlowRuleOperation.ADD)) {
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800333 if (!getFlowEntries(flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
334 storeFlowRule(flowRule);
Brian O'Connor427a1762014-11-19 18:40:32 -0800335 toAdd.add(entry);
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800336 }
Sho SHIMIZUaba9d002015-01-29 14:51:04 -0800337 } else if (entry.operator().equals(FlowRuleOperation.REMOVE)) {
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800338 if (getFlowEntries(flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
339 deleteFlowRule(flowRule);
Brian O'Connor427a1762014-11-19 18:40:32 -0800340 toRemove.add(entry);
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800341 }
Madan Jampani117aaae2014-10-23 10:04:05 -0700342 } else {
343 throw new UnsupportedOperationException("Unsupported operation type");
344 }
345 }
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800346
347 if (toAdd.isEmpty() && toRemove.isEmpty()) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800348 notifyDelegate(FlowRuleBatchEvent.completed(
349 new FlowRuleBatchRequest(operation.id(), Collections.emptySet()),
350 new CompletedBatchOperation(true, Collections.emptySet(),
351 operation.deviceId())));
352 return;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800353 }
354
355 SettableFuture<CompletedBatchOperation> r = SettableFuture.create();
356 final int batchId = localBatchIdGen.incrementAndGet();
357
358 pendingFutures.put(batchId, r);
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800359
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800360 toAdd.addAll(toRemove);
361 notifyDelegate(FlowRuleBatchEvent.requested(
362 new FlowRuleBatchRequest(batchId, Sets.newHashSet(toAdd)), operation.deviceId()));
363
Madan Jampani117aaae2014-10-23 10:04:05 -0700364 }
365
366 @Override
367 public void batchOperationComplete(FlowRuleBatchEvent event) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800368 final Long batchId = event.subject().batchId();
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800369 SettableFuture<CompletedBatchOperation> future
370 = pendingFutures.getIfPresent(batchId);
371 if (future != null) {
372 future.set(event.result());
373 pendingFutures.invalidate(batchId);
374 }
Madan Jampani117aaae2014-10-23 10:04:05 -0700375 notifyDelegate(event);
376 }
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -0800377
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700378 @Override
379 public FlowRuleEvent updateTableStatistics(DeviceId deviceId,
380 List<TableStatisticsEntry> tableStats) {
381 deviceTableStats.put(deviceId, tableStats);
382 return null;
383 }
384
385 @Override
386 public Iterable<TableStatisticsEntry> getTableStatistics(DeviceId deviceId) {
387 List<TableStatisticsEntry> tableStats = deviceTableStats.get(deviceId);
388 if (tableStats == null) {
389 return Collections.emptyList();
390 }
391 return ImmutableList.copyOf(tableStats);
392 }
sangyun-hanc1806862016-04-05 11:42:03 +0900393
394 private static final class TimeoutFuture
395 implements RemovalListener<Integer, SettableFuture<CompletedBatchOperation>> {
396 @Override
397 public void onRemoval(RemovalNotification<Integer, SettableFuture<CompletedBatchOperation>> notification) {
398 // wrapping in ExecutionException to support Future.get
399 if (notification.wasEvicted()) {
400 notification.getValue()
401 .setException(new ExecutionException("Timed out",
402 new TimeoutException()));
403 }
404 }
405 }
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700406}