blob: d65513269a1684134a8724773ab4fd2e796e49dd [file] [log] [blame]
Frank Wang0e805082017-07-21 14:37:35 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Frank Wang0e805082017-07-21 14:37:35 +08003 *
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
Andrea Campanella0288c872017-08-07 18:32:51 +020017package org.onosproject.drivers.p4runtime;
Frank Wang0e805082017-07-21 14:37:35 +080018
Manjunath Vanaraj59ad6572017-12-26 11:10:57 +053019import com.google.common.cache.CacheBuilder;
20import com.google.common.cache.CacheLoader;
Carmelo Cascone3da671a2018-02-12 10:43:35 -080021import com.google.common.cache.LoadingCache;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020022import com.google.common.collect.ImmutableList;
23import com.google.common.collect.Lists;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080024import org.onlab.util.SharedExecutors;
25import org.onosproject.drivers.p4runtime.mirror.P4RuntimeTableMirror;
26import org.onosproject.drivers.p4runtime.mirror.TimedEntry;
Frank Wang0e805082017-07-21 14:37:35 +080027import org.onosproject.net.flow.DefaultFlowEntry;
28import org.onosproject.net.flow.FlowEntry;
29import org.onosproject.net.flow.FlowRule;
30import org.onosproject.net.flow.FlowRuleProgrammable;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020031import org.onosproject.net.pi.model.PiPipelineModel;
Carmelo Cascone87892e22017-11-13 16:01:29 -080032import org.onosproject.net.pi.model.PiTableId;
Carmelo Cascone7f75be42017-09-07 14:37:02 +020033import org.onosproject.net.pi.runtime.PiCounterCellData;
34import org.onosproject.net.pi.runtime.PiCounterCellId;
Frank Wang0e805082017-07-21 14:37:35 +080035import org.onosproject.net.pi.runtime.PiTableEntry;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080036import org.onosproject.net.pi.runtime.PiTableEntryHandle;
37import org.onosproject.net.pi.service.PiFlowRuleTranslator;
38import org.onosproject.net.pi.service.PiTranslatedEntity;
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080039import org.onosproject.net.pi.service.PiTranslationException;
Frank Wang0e805082017-07-21 14:37:35 +080040import org.onosproject.p4runtime.api.P4RuntimeClient.WriteOperationType;
Frank Wang0e805082017-07-21 14:37:35 +080041
42import java.util.Collection;
43import java.util.Collections;
Manjunath Vanaraj59ad6572017-12-26 11:10:57 +053044import java.util.List;
Carmelo Cascone3da671a2018-02-12 10:43:35 -080045import java.util.Map;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080046import java.util.Optional;
Carmelo Cascone7f75be42017-09-07 14:37:02 +020047import java.util.Set;
Carmelo Casconee5b28722018-06-22 17:28:28 +020048import java.util.concurrent.CompletableFuture;
Manjunath Vanaraj59ad6572017-12-26 11:10:57 +053049import java.util.concurrent.TimeUnit;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020050import java.util.concurrent.locks.Lock;
51import java.util.concurrent.locks.ReentrantLock;
Carmelo Casconefe99be92017-09-11 21:55:54 +020052import java.util.stream.Collectors;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020053
54import static com.google.common.collect.Lists.newArrayList;
Andrea Campanella0288c872017-08-07 18:32:51 +020055import static org.onosproject.drivers.p4runtime.P4RuntimeFlowRuleProgrammable.Operation.APPLY;
56import static org.onosproject.drivers.p4runtime.P4RuntimeFlowRuleProgrammable.Operation.REMOVE;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020057import static org.onosproject.net.flow.FlowEntry.FlowEntryState.ADDED;
Carmelo Cascone87892e22017-11-13 16:01:29 -080058import static org.onosproject.p4runtime.api.P4RuntimeClient.WriteOperationType.DELETE;
59import static org.onosproject.p4runtime.api.P4RuntimeClient.WriteOperationType.INSERT;
60import static org.onosproject.p4runtime.api.P4RuntimeClient.WriteOperationType.MODIFY;
Frank Wang0e805082017-07-21 14:37:35 +080061
62/**
Carmelo Casconee3a7c742017-09-01 01:25:52 +020063 * Implementation of the flow rule programmable behaviour for P4Runtime.
Frank Wang0e805082017-07-21 14:37:35 +080064 */
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080065public class P4RuntimeFlowRuleProgrammable
66 extends AbstractP4RuntimeHandlerBehaviour
67 implements FlowRuleProgrammable {
Frank Wang0e805082017-07-21 14:37:35 +080068
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080069 // When updating an existing rule, if true, we issue a DELETE operation
70 // before inserting the new one, otherwise we issue a MODIFY operation. This
71 // is useful fore devices that do not support MODIFY operations for table
72 // entries.
Carmelo Cascone3da671a2018-02-12 10:43:35 -080073 private static final String DELETE_BEFORE_UPDATE = "tableDeleteBeforeUpdate";
74 private static final boolean DEFAULT_DELETE_BEFORE_UPDATE = false;
Carmelo Cascone2308e522017-08-25 02:35:12 +020075
Carmelo Cascone81929aa2018-04-07 01:38:55 -070076 // If true, we ignore re-installing rules that already exist in the
77 // device mirror, i.e. same match key and action.
Carmelo Cascone3da671a2018-02-12 10:43:35 -080078 private static final String IGNORE_SAME_ENTRY_UPDATE = "tableIgnoreSameEntryUpdate";
79 private static final boolean DEFAULT_IGNORE_SAME_ENTRY_UPDATE = false;
Carmelo Cascone2308e522017-08-25 02:35:12 +020080
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080081 // If true, we avoid querying the device and return what's already known by
82 // the ONOS store.
Carmelo Cascone3da671a2018-02-12 10:43:35 -080083 private static final String READ_FROM_MIRROR = "tableReadFromMirror";
84 private static final boolean DEFAULT_READ_FROM_MIRROR = false;
Carmelo Casconefe99be92017-09-11 21:55:54 +020085
Carmelo Cascone255125d2018-04-11 14:03:22 -070086 // If true, we read counters when reading table entries (if table has
87 // counters). Otherwise, we don't.
88 private static final String SUPPORT_TABLE_COUNTERS = "supportTableCounters";
89 private static final boolean DEFAULT_SUPPORT_TABLE_COUNTERS = true;
90
Carmelo Cascone3da671a2018-02-12 10:43:35 -080091 // If true, we read all direct counters of a table with one request.
92 // Otherwise, we send as many requests as the number of table entries.
93 private static final String READ_ALL_DIRECT_COUNTERS = "tableReadAllDirectCounters";
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080094 // FIXME: set to true as soon as the feature is implemented in P4Runtime.
Carmelo Cascone3da671a2018-02-12 10:43:35 -080095 private static final boolean DEFAULT_READ_ALL_DIRECT_COUNTERS = false;
Carmelo Cascone7f75be42017-09-07 14:37:02 +020096
Manjunath Vanaraj59ad6572017-12-26 11:10:57 +053097 private static final int TABLE_ENTRY_LOCK_EXPIRE_TIME_IN_MIN = 10;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020098
Manjunath Vanaraj59ad6572017-12-26 11:10:57 +053099 // Needed to synchronize operations over the same table entry.
100 private static final LoadingCache<PiTableEntryHandle, Lock>
101 ENTRY_LOCKS = CacheBuilder.newBuilder()
102 .expireAfterAccess(TABLE_ENTRY_LOCK_EXPIRE_TIME_IN_MIN, TimeUnit.MINUTES)
103 .build(new CacheLoader<PiTableEntryHandle, Lock>() {
104 @Override
105 public Lock load(PiTableEntryHandle handle) {
106 return new ReentrantLock();
107 }
108 });
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200109 private PiPipelineModel pipelineModel;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800110 private P4RuntimeTableMirror tableMirror;
111 private PiFlowRuleTranslator translator;
Frank Wang0e805082017-07-21 14:37:35 +0800112
Carmelo Casconee3a7c742017-09-01 01:25:52 +0200113 @Override
114 protected boolean setupBehaviour() {
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200115
Carmelo Casconee3a7c742017-09-01 01:25:52 +0200116 if (!super.setupBehaviour()) {
Frank Wang0e805082017-07-21 14:37:35 +0800117 return false;
118 }
119
Carmelo Casconee3a7c742017-09-01 01:25:52 +0200120 pipelineModel = pipeconf.pipelineModel();
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800121 tableMirror = handler().get(P4RuntimeTableMirror.class);
122 translator = piTranslationService.flowRuleTranslator();
Frank Wang0e805082017-07-21 14:37:35 +0800123 return true;
124 }
125
126 @Override
127 public Collection<FlowEntry> getFlowEntries() {
128
Carmelo Casconee3a7c742017-09-01 01:25:52 +0200129 if (!setupBehaviour()) {
Frank Wang0e805082017-07-21 14:37:35 +0800130 return Collections.emptyList();
131 }
132
Carmelo Cascone3da671a2018-02-12 10:43:35 -0800133 if (driverBoolProperty(READ_FROM_MIRROR, DEFAULT_READ_FROM_MIRROR)) {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800134 return getFlowEntriesFromMirror();
Carmelo Casconefe99be92017-09-11 21:55:54 +0200135 }
136
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800137 final ImmutableList.Builder<FlowEntry> result = ImmutableList.builder();
138 final List<PiTableEntry> inconsistentEntries = Lists.newArrayList();
Frank Wang0e805082017-07-21 14:37:35 +0800139
Carmelo Casconee5b28722018-06-22 17:28:28 +0200140 // Read table entries.
Carmelo Casconee5b28722018-06-22 17:28:28 +0200141 // TODO: ONOS-7596 read counters with table entries
Carmelo Cascone158b8c42018-07-04 19:42:37 +0200142 final Collection<PiTableEntry> installedEntries = getFutureWithDeadline(
143 client.dumpAllTables(pipeconf), "dumping all tables",
144 Collections.emptyList());
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200145
Carmelo Casconee5b28722018-06-22 17:28:28 +0200146 if (installedEntries.isEmpty()) {
147 return Collections.emptyList();
148 }
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200149
Carmelo Casconee5b28722018-06-22 17:28:28 +0200150 // Read table direct counters (if any).
151 final Map<PiTableEntry, PiCounterCellData> counterCellMap =
152 readEntryCounters(installedEntries);
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200153
Carmelo Casconee5b28722018-06-22 17:28:28 +0200154 // Forge flow entries with counter values.
155 for (PiTableEntry installedEntry : installedEntries) {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800156
Carmelo Casconee5b28722018-06-22 17:28:28 +0200157 final FlowEntry flowEntry = forgeFlowEntry(
158 installedEntry, counterCellMap.get(installedEntry));
Carmelo Cascone7f75be42017-09-07 14:37:02 +0200159
Carmelo Casconee5b28722018-06-22 17:28:28 +0200160 if (flowEntry == null) {
161 // Entry is on device but unknown to translation service or
162 // device mirror. Inconsistent. Mark for removal.
163 // TODO: make this behaviour configurable
164 // In some cases it's fine for the device to have rules
165 // that were not installed by us.
166 inconsistentEntries.add(installedEntry);
167 } else {
168 result.add(flowEntry);
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200169 }
170 }
171
172 if (inconsistentEntries.size() > 0) {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800173 // Async clean up inconsistent entries.
174 SharedExecutors.getSingleThreadExecutor().execute(
175 () -> cleanUpInconsistentEntries(inconsistentEntries));
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200176 }
177
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800178 return result.build();
Frank Wang0e805082017-07-21 14:37:35 +0800179 }
180
181 @Override
182 public Collection<FlowRule> applyFlowRules(Collection<FlowRule> rules) {
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200183 return processFlowRules(rules, APPLY);
Frank Wang0e805082017-07-21 14:37:35 +0800184 }
185
186 @Override
187 public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200188 return processFlowRules(rules, REMOVE);
Frank Wang0e805082017-07-21 14:37:35 +0800189 }
190
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800191 private FlowEntry forgeFlowEntry(PiTableEntry entry,
192 PiCounterCellData cellData) {
193 final PiTableEntryHandle handle = PiTableEntryHandle
194 .of(deviceId, entry);
195 final Optional<PiTranslatedEntity<FlowRule, PiTableEntry>>
196 translatedEntity = translator.lookup(handle);
197 final TimedEntry<PiTableEntry> timedEntry = tableMirror.get(handle);
198
199 if (!translatedEntity.isPresent()) {
200 log.debug("Handle not found in store: {}", handle);
201 return null;
202 }
203
204 if (timedEntry == null) {
205 log.debug("Handle not found in device mirror: {}", handle);
206 return null;
207 }
208
209 if (cellData != null) {
210 return new DefaultFlowEntry(translatedEntity.get().original(),
Carmelo Cascone81929aa2018-04-07 01:38:55 -0700211 ADDED, timedEntry.lifeSec(), cellData.packets(),
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800212 cellData.bytes());
213 } else {
214 return new DefaultFlowEntry(translatedEntity.get().original(),
215 ADDED, timedEntry.lifeSec(), 0, 0);
216 }
217 }
218
219 private Collection<FlowEntry> getFlowEntriesFromMirror() {
220 return tableMirror.getAll(deviceId).stream()
221 .map(timedEntry -> forgeFlowEntry(
222 timedEntry.entry(), null))
223 .collect(Collectors.toList());
224 }
225
226 private void cleanUpInconsistentEntries(Collection<PiTableEntry> piEntries) {
227 log.warn("Found {} entries from {} not on translation store, removing them...",
228 piEntries.size(), deviceId);
229 piEntries.forEach(entry -> {
230 log.debug(entry.toString());
231 applyEntry(PiTableEntryHandle.of(deviceId, entry),
232 entry, null, REMOVE);
233 });
234 }
235
236 private Collection<FlowRule> processFlowRules(Collection<FlowRule> rules,
237 Operation driverOperation) {
Frank Wang0e805082017-07-21 14:37:35 +0800238
Carmelo Casconee3a7c742017-09-01 01:25:52 +0200239 if (!setupBehaviour()) {
Frank Wang0e805082017-07-21 14:37:35 +0800240 return Collections.emptyList();
241 }
242
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800243 final ImmutableList.Builder<FlowRule> result = ImmutableList.builder();
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200244
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800245 // TODO: send writes in bulk (e.g. all entries to insert, modify or delete).
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200246 // Instead of calling the client for each one of them.
247
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800248 for (FlowRule ruleToApply : rules) {
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200249
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800250 final PiTableEntry piEntryToApply;
Frank Wang0e805082017-07-21 14:37:35 +0800251 try {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800252 piEntryToApply = translator.translate(ruleToApply, pipeconf);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -0800253 } catch (PiTranslationException e) {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800254 log.warn("Unable to translate flow rule for pipeconf '{}': {} - {}",
255 pipeconf.id(), e.getMessage(), ruleToApply);
256 // Next rule.
257 continue;
Frank Wang0e805082017-07-21 14:37:35 +0800258 }
Frank Wang0e805082017-07-21 14:37:35 +0800259
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800260 final PiTableEntryHandle handle = PiTableEntryHandle
261 .of(deviceId, piEntryToApply);
Frank Wang0e805082017-07-21 14:37:35 +0800262
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800263 // Serialize operations over the same match key/table/device ID.
Manjunath Vanaraj59ad6572017-12-26 11:10:57 +0530264 ENTRY_LOCKS.getUnchecked(handle).lock();
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200265 try {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800266 if (applyEntry(handle, piEntryToApply,
267 ruleToApply, driverOperation)) {
268 result.add(ruleToApply);
Frank Wang0e805082017-07-21 14:37:35 +0800269 }
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200270 } finally {
Manjunath Vanaraj59ad6572017-12-26 11:10:57 +0530271 ENTRY_LOCKS.getUnchecked(handle).unlock();
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200272 }
273 }
274
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800275 return result.build();
276 }
277
278 /**
279 * Applies the given entry to the device, and returns true if the operation
280 * was successful, false otherwise.
281 */
282 private boolean applyEntry(PiTableEntryHandle handle,
283 PiTableEntry piEntryToApply,
284 FlowRule ruleToApply,
285 Operation driverOperation) {
286 // Depending on the driver operation, and if a matching rule exists on
287 // the device, decide which P4 Runtime write operation to perform for
288 // this entry.
289 final TimedEntry<PiTableEntry> piEntryOnDevice = tableMirror.get(handle);
290 final WriteOperationType p4Operation;
291 if (driverOperation == APPLY) {
292 if (piEntryOnDevice == null) {
293 // Entry is first-timer.
294 p4Operation = INSERT;
295 } else {
Carmelo Cascone3da671a2018-02-12 10:43:35 -0800296 if (driverBoolProperty(IGNORE_SAME_ENTRY_UPDATE,
297 DEFAULT_IGNORE_SAME_ENTRY_UPDATE)
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800298 && piEntryToApply.action().equals(piEntryOnDevice.entry().action())) {
299 log.debug("Ignoring re-apply of existing entry: {}", piEntryToApply);
300 p4Operation = null;
Carmelo Cascone3da671a2018-02-12 10:43:35 -0800301 } else if (driverBoolProperty(DELETE_BEFORE_UPDATE,
302 DEFAULT_DELETE_BEFORE_UPDATE)) {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800303 // Some devices return error when updating existing
304 // entries. If requested, remove entry before
305 // re-inserting the modified one.
306 applyEntry(handle, piEntryOnDevice.entry(), null, REMOVE);
307 p4Operation = INSERT;
308 } else {
309 p4Operation = MODIFY;
310 }
311 }
312 } else {
313 p4Operation = DELETE;
314 }
315
316 if (p4Operation != null) {
317 if (writeEntry(piEntryToApply, p4Operation)) {
318 updateStores(handle, piEntryToApply, ruleToApply, p4Operation);
319 return true;
320 } else {
321 return false;
322 }
323 } else {
324 // If no operation, let's pretend we applied the rule to the device.
325 return true;
326 }
327 }
328
329 /**
330 * Performs a write operation on the device.
331 */
332 private boolean writeEntry(PiTableEntry entry,
333 WriteOperationType p4Operation) {
Carmelo Casconee5b28722018-06-22 17:28:28 +0200334 final CompletableFuture<Boolean> future = client.writeTableEntries(
335 newArrayList(entry), p4Operation, pipeconf);
336 final Boolean success = getFutureWithDeadline(
337 future, "performing table " + p4Operation.name(), null);
338 if (success == null) {
339 // Error logged by getFutureWithDeadline();
340 return false;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800341 }
Carmelo Casconee5b28722018-06-22 17:28:28 +0200342 if (!success) {
343 log.warn("Unable to {} table entry in {}: {}",
344 p4Operation.name(), deviceId, entry);
345 }
346 return success;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800347 }
348
349 private void updateStores(PiTableEntryHandle handle,
350 PiTableEntry entry,
351 FlowRule rule,
352 WriteOperationType p4Operation) {
353 switch (p4Operation) {
354 case INSERT:
355 case MODIFY:
356 tableMirror.put(handle, entry);
357 translator.learn(handle, new PiTranslatedEntity<>(rule, entry, handle));
358 break;
359 case DELETE:
360 tableMirror.remove(handle);
361 translator.forget(handle);
362 break;
363 default:
364 throw new IllegalArgumentException(
365 "Unknown operation " + p4Operation.name());
366 }
367 }
368
369 private Map<PiTableEntry, PiCounterCellData> readEntryCounters(
Carmelo Cascone255125d2018-04-11 14:03:22 -0700370 Collection<PiTableEntry> tableEntries) {
371 if (!driverBoolProperty(SUPPORT_TABLE_COUNTERS,
Carmelo Casconee5b28722018-06-22 17:28:28 +0200372 DEFAULT_SUPPORT_TABLE_COUNTERS)
373 || tableEntries.isEmpty()) {
Carmelo Cascone255125d2018-04-11 14:03:22 -0700374 return Collections.emptyMap();
375 }
376
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800377 Collection<PiCounterCellData> cellDatas;
Carmelo Casconee5b28722018-06-22 17:28:28 +0200378
379 if (driverBoolProperty(READ_ALL_DIRECT_COUNTERS,
380 DEFAULT_READ_ALL_DIRECT_COUNTERS)) {
381 // FIXME: read counters when dumping table entries ONOS-7596
382 cellDatas = Collections.emptyList();
383 } else {
384 Set<PiCounterCellId> cellIds = tableEntries.stream()
385 .filter(e -> tableHasCounter(e.table()))
386 .map(PiCounterCellId::ofDirect)
387 .collect(Collectors.toSet());
388 cellDatas = getFutureWithDeadline(client.readCounterCells(cellIds, pipeconf),
389 "reading table counters", Collections.emptyList());
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800390 }
Carmelo Casconee5b28722018-06-22 17:28:28 +0200391 return cellDatas.stream()
392 .collect(Collectors.toMap(c -> c.cellId().tableEntry(), c -> c));
393
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200394 }
395
Carmelo Cascone255125d2018-04-11 14:03:22 -0700396 private boolean tableHasCounter(PiTableId tableId) {
397 return pipelineModel.table(tableId).isPresent() &&
398 !pipelineModel.table(tableId).get().counters().isEmpty();
399 }
400
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200401 enum Operation {
402 APPLY, REMOVE
Frank Wang0e805082017-07-21 14:37:35 +0800403 }
Carmelo Cascone87892e22017-11-13 16:01:29 -0800404}