use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.
the class P4RuntimeMeterProgrammable method processMeterOp.
private boolean processMeterOp(MeterOperation meterOp) {
PiMeterCellConfig piMeterCellConfig;
final PiMeterCellHandle handle = PiMeterCellHandle.of(deviceId, (PiMeterCellId) meterOp.meter().meterCellId());
boolean result = true;
WRITE_LOCKS.get(deviceId).lock();
try {
switch(meterOp.type()) {
case ADD:
case MODIFY:
// Create a config for modify operation
try {
piMeterCellConfig = translator.translate(meterOp.meter(), pipeconf);
} catch (PiTranslationException e) {
log.warn("Unable translate meter, aborting meter operation {}: {}", meterOp.type(), e.getMessage());
log.debug("exception", e);
return false;
}
translator.learn(handle, new PiTranslatedEntity<>(meterOp.meter(), piMeterCellConfig, handle));
break;
case REMOVE:
// Create a empty config for reset operation
PiMeterCellId piMeterCellId = (PiMeterCellId) meterOp.meter().meterCellId();
piMeterCellConfig = PiMeterCellConfig.reset(piMeterCellId);
translator.forget(handle);
break;
default:
log.warn("Meter Operation type {} not supported", meterOp.type());
return false;
}
WriteRequest request = client.write(p4DeviceId, pipeconf).entity(piMeterCellConfig, UpdateType.MODIFY);
if (!request.pendingUpdates().isEmpty()) {
result = request.submitSync().isSuccess();
}
} finally {
WRITE_LOCKS.get(deviceId).unlock();
}
return result;
}
Aggregations