blob: 5e3e155776eb51614f62a4a74f678911af538a4f [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
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020019import com.google.common.collect.ImmutableList;
20import com.google.common.collect.Lists;
Carmelo Cascone33b27bc2018-09-09 22:56:14 -070021import com.google.common.util.concurrent.Striped;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080022import org.onlab.util.SharedExecutors;
23import org.onosproject.drivers.p4runtime.mirror.P4RuntimeTableMirror;
24import org.onosproject.drivers.p4runtime.mirror.TimedEntry;
Frank Wang0e805082017-07-21 14:37:35 +080025import org.onosproject.net.flow.DefaultFlowEntry;
26import org.onosproject.net.flow.FlowEntry;
27import org.onosproject.net.flow.FlowRule;
28import org.onosproject.net.flow.FlowRuleProgrammable;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020029import org.onosproject.net.pi.model.PiPipelineModel;
Carmelo Cascone87892e22017-11-13 16:01:29 -080030import org.onosproject.net.pi.model.PiTableId;
Carmelo Cascone7f75be42017-09-07 14:37:02 +020031import org.onosproject.net.pi.runtime.PiCounterCellData;
32import org.onosproject.net.pi.runtime.PiCounterCellId;
Frank Wang0e805082017-07-21 14:37:35 +080033import org.onosproject.net.pi.runtime.PiTableEntry;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080034import org.onosproject.net.pi.runtime.PiTableEntryHandle;
35import org.onosproject.net.pi.service.PiFlowRuleTranslator;
36import org.onosproject.net.pi.service.PiTranslatedEntity;
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080037import org.onosproject.net.pi.service.PiTranslationException;
Frank Wang0e805082017-07-21 14:37:35 +080038import org.onosproject.p4runtime.api.P4RuntimeClient.WriteOperationType;
Frank Wang0e805082017-07-21 14:37:35 +080039
40import java.util.Collection;
41import java.util.Collections;
Manjunath Vanaraj59ad6572017-12-26 11:10:57 +053042import java.util.List;
Carmelo Cascone3da671a2018-02-12 10:43:35 -080043import java.util.Map;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080044import java.util.Optional;
Carmelo Cascone7f75be42017-09-07 14:37:02 +020045import java.util.Set;
Carmelo Casconee5b28722018-06-22 17:28:28 +020046import java.util.concurrent.CompletableFuture;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020047import java.util.concurrent.locks.Lock;
Carmelo Casconefe99be92017-09-11 21:55:54 +020048import java.util.stream.Collectors;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020049
50import static com.google.common.collect.Lists.newArrayList;
Andrea Campanella0288c872017-08-07 18:32:51 +020051import static org.onosproject.drivers.p4runtime.P4RuntimeFlowRuleProgrammable.Operation.APPLY;
52import static org.onosproject.drivers.p4runtime.P4RuntimeFlowRuleProgrammable.Operation.REMOVE;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020053import static org.onosproject.net.flow.FlowEntry.FlowEntryState.ADDED;
Carmelo Cascone87892e22017-11-13 16:01:29 -080054import static org.onosproject.p4runtime.api.P4RuntimeClient.WriteOperationType.DELETE;
55import static org.onosproject.p4runtime.api.P4RuntimeClient.WriteOperationType.INSERT;
56import static org.onosproject.p4runtime.api.P4RuntimeClient.WriteOperationType.MODIFY;
Frank Wang0e805082017-07-21 14:37:35 +080057
58/**
Carmelo Casconee3a7c742017-09-01 01:25:52 +020059 * Implementation of the flow rule programmable behaviour for P4Runtime.
Frank Wang0e805082017-07-21 14:37:35 +080060 */
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080061public class P4RuntimeFlowRuleProgrammable
62 extends AbstractP4RuntimeHandlerBehaviour
63 implements FlowRuleProgrammable {
Frank Wang0e805082017-07-21 14:37:35 +080064
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080065 // When updating an existing rule, if true, we issue a DELETE operation
66 // before inserting the new one, otherwise we issue a MODIFY operation. This
67 // is useful fore devices that do not support MODIFY operations for table
68 // entries.
Carmelo Cascone3da671a2018-02-12 10:43:35 -080069 private static final String DELETE_BEFORE_UPDATE = "tableDeleteBeforeUpdate";
70 private static final boolean DEFAULT_DELETE_BEFORE_UPDATE = false;
Carmelo Cascone2308e522017-08-25 02:35:12 +020071
Carmelo Cascone81929aa2018-04-07 01:38:55 -070072 // If true, we ignore re-installing rules that already exist in the
73 // device mirror, i.e. same match key and action.
Carmelo Cascone3da671a2018-02-12 10:43:35 -080074 private static final String IGNORE_SAME_ENTRY_UPDATE = "tableIgnoreSameEntryUpdate";
75 private static final boolean DEFAULT_IGNORE_SAME_ENTRY_UPDATE = false;
Carmelo Cascone2308e522017-08-25 02:35:12 +020076
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080077 // If true, we avoid querying the device and return what's already known by
78 // the ONOS store.
Carmelo Cascone3da671a2018-02-12 10:43:35 -080079 private static final String READ_FROM_MIRROR = "tableReadFromMirror";
80 private static final boolean DEFAULT_READ_FROM_MIRROR = false;
Carmelo Casconefe99be92017-09-11 21:55:54 +020081
Carmelo Cascone255125d2018-04-11 14:03:22 -070082 // If true, we read counters when reading table entries (if table has
83 // counters). Otherwise, we don't.
84 private static final String SUPPORT_TABLE_COUNTERS = "supportTableCounters";
85 private static final boolean DEFAULT_SUPPORT_TABLE_COUNTERS = true;
86
Carmelo Cascone3da671a2018-02-12 10:43:35 -080087 // If true, we read all direct counters of a table with one request.
88 // Otherwise, we send as many requests as the number of table entries.
89 private static final String READ_ALL_DIRECT_COUNTERS = "tableReadAllDirectCounters";
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080090 // FIXME: set to true as soon as the feature is implemented in P4Runtime.
Carmelo Cascone3da671a2018-02-12 10:43:35 -080091 private static final boolean DEFAULT_READ_ALL_DIRECT_COUNTERS = false;
Carmelo Cascone7f75be42017-09-07 14:37:02 +020092
Manjunath Vanaraj59ad6572017-12-26 11:10:57 +053093 // Needed to synchronize operations over the same table entry.
Carmelo Cascone33b27bc2018-09-09 22:56:14 -070094 private static final Striped<Lock> ENTRY_LOCKS = Striped.lock(30);
95
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020096 private PiPipelineModel pipelineModel;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080097 private P4RuntimeTableMirror tableMirror;
98 private PiFlowRuleTranslator translator;
Frank Wang0e805082017-07-21 14:37:35 +080099
Carmelo Casconee3a7c742017-09-01 01:25:52 +0200100 @Override
101 protected boolean setupBehaviour() {
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200102
Carmelo Casconee3a7c742017-09-01 01:25:52 +0200103 if (!super.setupBehaviour()) {
Frank Wang0e805082017-07-21 14:37:35 +0800104 return false;
105 }
106
Carmelo Casconee3a7c742017-09-01 01:25:52 +0200107 pipelineModel = pipeconf.pipelineModel();
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800108 tableMirror = handler().get(P4RuntimeTableMirror.class);
109 translator = piTranslationService.flowRuleTranslator();
Frank Wang0e805082017-07-21 14:37:35 +0800110 return true;
111 }
112
113 @Override
114 public Collection<FlowEntry> getFlowEntries() {
115
Carmelo Casconee3a7c742017-09-01 01:25:52 +0200116 if (!setupBehaviour()) {
Frank Wang0e805082017-07-21 14:37:35 +0800117 return Collections.emptyList();
118 }
119
Carmelo Cascone3da671a2018-02-12 10:43:35 -0800120 if (driverBoolProperty(READ_FROM_MIRROR, DEFAULT_READ_FROM_MIRROR)) {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800121 return getFlowEntriesFromMirror();
Carmelo Casconefe99be92017-09-11 21:55:54 +0200122 }
123
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800124 final ImmutableList.Builder<FlowEntry> result = ImmutableList.builder();
125 final List<PiTableEntry> inconsistentEntries = Lists.newArrayList();
Frank Wang0e805082017-07-21 14:37:35 +0800126
Carmelo Casconee5b28722018-06-22 17:28:28 +0200127 // Read table entries.
Carmelo Casconee5b28722018-06-22 17:28:28 +0200128 // TODO: ONOS-7596 read counters with table entries
Carmelo Cascone158b8c42018-07-04 19:42:37 +0200129 final Collection<PiTableEntry> installedEntries = getFutureWithDeadline(
130 client.dumpAllTables(pipeconf), "dumping all tables",
Carmelo Cascone33b27bc2018-09-09 22:56:14 -0700131 Collections.emptyList())
132 // Filter out entries from constant table.
133 .stream()
134 .filter(e -> !tableIsConstant(e.table()))
135 .collect(Collectors.toList());
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200136
Carmelo Casconee5b28722018-06-22 17:28:28 +0200137 if (installedEntries.isEmpty()) {
138 return Collections.emptyList();
139 }
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200140
Carmelo Casconee5b28722018-06-22 17:28:28 +0200141 // Read table direct counters (if any).
142 final Map<PiTableEntry, PiCounterCellData> counterCellMap =
143 readEntryCounters(installedEntries);
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200144
Carmelo Casconee5b28722018-06-22 17:28:28 +0200145 // Forge flow entries with counter values.
146 for (PiTableEntry installedEntry : installedEntries) {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800147
Carmelo Casconee5b28722018-06-22 17:28:28 +0200148 final FlowEntry flowEntry = forgeFlowEntry(
149 installedEntry, counterCellMap.get(installedEntry));
Carmelo Cascone7f75be42017-09-07 14:37:02 +0200150
Carmelo Casconee5b28722018-06-22 17:28:28 +0200151 if (flowEntry == null) {
152 // Entry is on device but unknown to translation service or
153 // device mirror. Inconsistent. Mark for removal.
154 // TODO: make this behaviour configurable
155 // In some cases it's fine for the device to have rules
156 // that were not installed by us.
157 inconsistentEntries.add(installedEntry);
158 } else {
159 result.add(flowEntry);
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200160 }
161 }
162
163 if (inconsistentEntries.size() > 0) {
Carmelo Cascone33b27bc2018-09-09 22:56:14 -0700164 // Trigger clean up of inconsistent entries.
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800165 SharedExecutors.getSingleThreadExecutor().execute(
166 () -> cleanUpInconsistentEntries(inconsistentEntries));
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200167 }
168
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800169 return result.build();
Frank Wang0e805082017-07-21 14:37:35 +0800170 }
171
172 @Override
173 public Collection<FlowRule> applyFlowRules(Collection<FlowRule> rules) {
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200174 return processFlowRules(rules, APPLY);
Frank Wang0e805082017-07-21 14:37:35 +0800175 }
176
177 @Override
178 public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200179 return processFlowRules(rules, REMOVE);
Frank Wang0e805082017-07-21 14:37:35 +0800180 }
181
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800182 private FlowEntry forgeFlowEntry(PiTableEntry entry,
183 PiCounterCellData cellData) {
184 final PiTableEntryHandle handle = PiTableEntryHandle
185 .of(deviceId, entry);
186 final Optional<PiTranslatedEntity<FlowRule, PiTableEntry>>
187 translatedEntity = translator.lookup(handle);
188 final TimedEntry<PiTableEntry> timedEntry = tableMirror.get(handle);
189
190 if (!translatedEntity.isPresent()) {
191 log.debug("Handle not found in store: {}", handle);
192 return null;
193 }
194
195 if (timedEntry == null) {
196 log.debug("Handle not found in device mirror: {}", handle);
197 return null;
198 }
199
200 if (cellData != null) {
201 return new DefaultFlowEntry(translatedEntity.get().original(),
Carmelo Cascone81929aa2018-04-07 01:38:55 -0700202 ADDED, timedEntry.lifeSec(), cellData.packets(),
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800203 cellData.bytes());
204 } else {
205 return new DefaultFlowEntry(translatedEntity.get().original(),
206 ADDED, timedEntry.lifeSec(), 0, 0);
207 }
208 }
209
210 private Collection<FlowEntry> getFlowEntriesFromMirror() {
211 return tableMirror.getAll(deviceId).stream()
212 .map(timedEntry -> forgeFlowEntry(
213 timedEntry.entry(), null))
214 .collect(Collectors.toList());
215 }
216
217 private void cleanUpInconsistentEntries(Collection<PiTableEntry> piEntries) {
218 log.warn("Found {} entries from {} not on translation store, removing them...",
219 piEntries.size(), deviceId);
220 piEntries.forEach(entry -> {
221 log.debug(entry.toString());
222 applyEntry(PiTableEntryHandle.of(deviceId, entry),
223 entry, null, REMOVE);
224 });
225 }
226
227 private Collection<FlowRule> processFlowRules(Collection<FlowRule> rules,
228 Operation driverOperation) {
Frank Wang0e805082017-07-21 14:37:35 +0800229
Carmelo Casconee3a7c742017-09-01 01:25:52 +0200230 if (!setupBehaviour()) {
Frank Wang0e805082017-07-21 14:37:35 +0800231 return Collections.emptyList();
232 }
233
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800234 final ImmutableList.Builder<FlowRule> result = ImmutableList.builder();
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200235
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800236 // TODO: send writes in bulk (e.g. all entries to insert, modify or delete).
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200237 // Instead of calling the client for each one of them.
238
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800239 for (FlowRule ruleToApply : rules) {
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200240
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800241 final PiTableEntry piEntryToApply;
Frank Wang0e805082017-07-21 14:37:35 +0800242 try {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800243 piEntryToApply = translator.translate(ruleToApply, pipeconf);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -0800244 } catch (PiTranslationException e) {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800245 log.warn("Unable to translate flow rule for pipeconf '{}': {} - {}",
246 pipeconf.id(), e.getMessage(), ruleToApply);
247 // Next rule.
248 continue;
Frank Wang0e805082017-07-21 14:37:35 +0800249 }
Frank Wang0e805082017-07-21 14:37:35 +0800250
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800251 final PiTableEntryHandle handle = PiTableEntryHandle
252 .of(deviceId, piEntryToApply);
Frank Wang0e805082017-07-21 14:37:35 +0800253
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800254 // Serialize operations over the same match key/table/device ID.
Carmelo Cascone33b27bc2018-09-09 22:56:14 -0700255 ENTRY_LOCKS.get(handle).lock();
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200256 try {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800257 if (applyEntry(handle, piEntryToApply,
258 ruleToApply, driverOperation)) {
259 result.add(ruleToApply);
Frank Wang0e805082017-07-21 14:37:35 +0800260 }
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200261 } finally {
Carmelo Cascone33b27bc2018-09-09 22:56:14 -0700262 ENTRY_LOCKS.get(handle).unlock();
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200263 }
264 }
265
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800266 return result.build();
267 }
268
269 /**
270 * Applies the given entry to the device, and returns true if the operation
271 * was successful, false otherwise.
272 */
273 private boolean applyEntry(PiTableEntryHandle handle,
274 PiTableEntry piEntryToApply,
275 FlowRule ruleToApply,
276 Operation driverOperation) {
277 // Depending on the driver operation, and if a matching rule exists on
278 // the device, decide which P4 Runtime write operation to perform for
279 // this entry.
280 final TimedEntry<PiTableEntry> piEntryOnDevice = tableMirror.get(handle);
281 final WriteOperationType p4Operation;
282 if (driverOperation == APPLY) {
283 if (piEntryOnDevice == null) {
284 // Entry is first-timer.
285 p4Operation = INSERT;
286 } else {
Carmelo Cascone3da671a2018-02-12 10:43:35 -0800287 if (driverBoolProperty(IGNORE_SAME_ENTRY_UPDATE,
288 DEFAULT_IGNORE_SAME_ENTRY_UPDATE)
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800289 && piEntryToApply.action().equals(piEntryOnDevice.entry().action())) {
290 log.debug("Ignoring re-apply of existing entry: {}", piEntryToApply);
291 p4Operation = null;
Carmelo Cascone3da671a2018-02-12 10:43:35 -0800292 } else if (driverBoolProperty(DELETE_BEFORE_UPDATE,
293 DEFAULT_DELETE_BEFORE_UPDATE)) {
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800294 // Some devices return error when updating existing
295 // entries. If requested, remove entry before
296 // re-inserting the modified one.
297 applyEntry(handle, piEntryOnDevice.entry(), null, REMOVE);
298 p4Operation = INSERT;
299 } else {
300 p4Operation = MODIFY;
301 }
302 }
303 } else {
304 p4Operation = DELETE;
305 }
306
307 if (p4Operation != null) {
308 if (writeEntry(piEntryToApply, p4Operation)) {
309 updateStores(handle, piEntryToApply, ruleToApply, p4Operation);
310 return true;
311 } else {
312 return false;
313 }
314 } else {
315 // If no operation, let's pretend we applied the rule to the device.
316 return true;
317 }
318 }
319
320 /**
321 * Performs a write operation on the device.
322 */
323 private boolean writeEntry(PiTableEntry entry,
324 WriteOperationType p4Operation) {
Carmelo Casconee5b28722018-06-22 17:28:28 +0200325 final CompletableFuture<Boolean> future = client.writeTableEntries(
326 newArrayList(entry), p4Operation, pipeconf);
327 final Boolean success = getFutureWithDeadline(
328 future, "performing table " + p4Operation.name(), null);
329 if (success == null) {
330 // Error logged by getFutureWithDeadline();
331 return false;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800332 }
Carmelo Casconee5b28722018-06-22 17:28:28 +0200333 if (!success) {
334 log.warn("Unable to {} table entry in {}: {}",
335 p4Operation.name(), deviceId, entry);
336 }
337 return success;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800338 }
339
340 private void updateStores(PiTableEntryHandle handle,
341 PiTableEntry entry,
342 FlowRule rule,
343 WriteOperationType p4Operation) {
344 switch (p4Operation) {
345 case INSERT:
346 case MODIFY:
347 tableMirror.put(handle, entry);
348 translator.learn(handle, new PiTranslatedEntity<>(rule, entry, handle));
349 break;
350 case DELETE:
351 tableMirror.remove(handle);
352 translator.forget(handle);
353 break;
354 default:
355 throw new IllegalArgumentException(
356 "Unknown operation " + p4Operation.name());
357 }
358 }
359
360 private Map<PiTableEntry, PiCounterCellData> readEntryCounters(
Carmelo Cascone255125d2018-04-11 14:03:22 -0700361 Collection<PiTableEntry> tableEntries) {
362 if (!driverBoolProperty(SUPPORT_TABLE_COUNTERS,
Carmelo Casconee5b28722018-06-22 17:28:28 +0200363 DEFAULT_SUPPORT_TABLE_COUNTERS)
364 || tableEntries.isEmpty()) {
Carmelo Cascone255125d2018-04-11 14:03:22 -0700365 return Collections.emptyMap();
366 }
367
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800368 Collection<PiCounterCellData> cellDatas;
Carmelo Casconee5b28722018-06-22 17:28:28 +0200369
370 if (driverBoolProperty(READ_ALL_DIRECT_COUNTERS,
371 DEFAULT_READ_ALL_DIRECT_COUNTERS)) {
372 // FIXME: read counters when dumping table entries ONOS-7596
373 cellDatas = Collections.emptyList();
374 } else {
375 Set<PiCounterCellId> cellIds = tableEntries.stream()
376 .filter(e -> tableHasCounter(e.table()))
377 .map(PiCounterCellId::ofDirect)
378 .collect(Collectors.toSet());
379 cellDatas = getFutureWithDeadline(client.readCounterCells(cellIds, pipeconf),
380 "reading table counters", Collections.emptyList());
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -0800381 }
Carmelo Casconee5b28722018-06-22 17:28:28 +0200382 return cellDatas.stream()
383 .collect(Collectors.toMap(c -> c.cellId().tableEntry(), c -> c));
384
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200385 }
386
Carmelo Cascone255125d2018-04-11 14:03:22 -0700387 private boolean tableHasCounter(PiTableId tableId) {
388 return pipelineModel.table(tableId).isPresent() &&
389 !pipelineModel.table(tableId).get().counters().isEmpty();
390 }
391
Carmelo Cascone33b27bc2018-09-09 22:56:14 -0700392 private boolean tableIsConstant(PiTableId tableId) {
393 return pipelineModel.table(tableId).isPresent() &&
394 pipelineModel.table(tableId).get().isConstantTable();
395 }
396
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +0200397 enum Operation {
398 APPLY, REMOVE
Frank Wang0e805082017-07-21 14:37:35 +0800399 }
Carmelo Cascone87892e22017-11-13 16:01:29 -0800400}