use of org.onosproject.p4runtime.api.P4RuntimeWriteClient.UpdateType in project onos by opennetworkinglab.
the class P4RuntimeFlowRuleProgrammable method appendEntryToWriteRequestOrSkip.
private boolean appendEntryToWriteRequestOrSkip(final WriteRequest writeRequest, final PiTableEntryHandle handle, PiTableEntry piEntryToApply, final Operation driverOperation) {
// Depending on the driver operation, and if a matching rule exists on
// the device/mirror, decide which P4Runtime update operation to perform
// for this entry. In some cases, the entry is skipped from the write
// request but we want to return the corresponding flow rule as
// successfully written. In this case, we return true.
final TimedEntry<PiTableEntry> piEntryOnDevice = tableMirror.get(handle);
final UpdateType updateType;
final boolean supportDefaultEntry = driverBoolProperty(SUPPORT_DEFAULT_TABLE_ENTRY, DEFAULT_SUPPORT_DEFAULT_TABLE_ENTRY);
final boolean deleteBeforeUpdate = driverBoolProperty(DELETE_BEFORE_UPDATE, DEFAULT_DELETE_BEFORE_UPDATE);
if (driverOperation == APPLY) {
if (piEntryOnDevice == null) {
// Entry is first-timer, INSERT or MODIFY if default action.
updateType = !piEntryToApply.isDefaultAction() || !supportDefaultEntry ? INSERT : MODIFY;
} else {
if (piEntryToApply.action().equals(piEntryOnDevice.entry().action())) {
// FIXME: should we check for other attributes of the table
// entry? For example can we modify the priority?
log.debug("Ignoring re-apply of existing entry: {}", piEntryToApply);
return true;
} else if (deleteBeforeUpdate && !piEntryToApply.isDefaultAction()) {
// Some devices return error when updating existing entries.
// If requested, remove entry before re-inserting the
// modified one, except the default action entry, that
// cannot be removed.
writeRequest.delete(handle);
updateType = INSERT;
} else {
updateType = MODIFY;
}
}
} else {
// REMOVE.
if (piEntryToApply.isDefaultAction()) {
// Cannot remove default action. Instead we should modify it to
// use the original one as specified in the P4 program.
final PiTableEntry originalDefaultEntry = getOriginalDefaultEntry(piEntryToApply.table());
if (originalDefaultEntry == null) {
return false;
}
return appendEntryToWriteRequestOrSkip(writeRequest, originalDefaultEntry.handle(deviceId), originalDefaultEntry, APPLY);
} else {
if (piEntryOnDevice == null) {
log.debug("Ignoring delete of missing entry: {}", piEntryToApply);
return true;
}
updateType = DELETE;
}
}
writeRequest.entity(piEntryToApply, updateType);
return false;
}
Aggregations