use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.
the class DistributedMeterStore method validIndex.
// Validate index using the meter features, useful mainly
// when user defined index mode is enabled
private boolean validIndex(Meter meter) {
long index;
MeterTableKey key;
if (meter.meterCellId().type() == PIPELINE_INDEPENDENT) {
PiMeterCellId piMeterCellId = (PiMeterCellId) meter.meterCellId();
index = piMeterCellId.index();
key = MeterTableKey.key(meter.deviceId(), MeterScope.of(piMeterCellId.meterId().id()));
} else if (meter.meterCellId().type() == INDEX) {
MeterId meterId = (MeterId) meter.meterCellId();
index = meterId.id();
key = MeterTableKey.key(meter.deviceId(), MeterScope.globalScope());
} else {
log.warn("Unable to validate index unsupported cell type {}", meter.meterCellId().type());
return false;
}
MeterFeatures features = metersFeatures.get(key);
long startIndex = features == null ? -1L : features.startIndex();
long endIndex = features == null ? -1L : features.endIndex();
return index >= startIndex && index <= endIndex;
}
use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.
the class DistributedMeterStore method purgeMeter.
@Override
public void purgeMeter(Meter m) {
// Once we receive the ack from the sb, create the key
// remove definitely the meter and free the id
MeterKey key = MeterKey.key(m.deviceId(), m.meterCellId());
try {
if (Versioned.valueOrNull(meters.remove(key)) != null) {
MeterScope scope;
if (m.meterCellId().type() == PIPELINE_INDEPENDENT) {
PiMeterCellId piMeterCellId = (PiMeterCellId) m.meterCellId();
scope = MeterScope.of(piMeterCellId.meterId().id());
} else {
scope = MeterScope.globalScope();
}
MeterTableKey meterTableKey = MeterTableKey.key(m.deviceId(), scope);
freeMeterId(meterTableKey, m.meterCellId());
}
} catch (StorageException e) {
log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
}
}
use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.
the class DistributedMeterStore method freeMeterId.
protected void freeMeterId(MeterTableKey meterTableKey, MeterCellId meterCellId) {
if (userDefinedIndexMode) {
log.debug("Unable to free meter id when user defined index mode is enabled");
return;
}
long index;
if (meterCellId.type() == PIPELINE_INDEPENDENT) {
PiMeterCellId piMeterCellId = (PiMeterCellId) meterCellId;
index = piMeterCellId.index();
} else if (meterCellId.type() == INDEX) {
MeterId meterId = (MeterId) meterCellId;
index = meterId.id();
} else {
log.warn("Unable to free meter id unsupported cell type {}", meterCellId.type());
return;
}
// Avoid to free meter not allocated
if (meterIdGenerators.get(meterTableKey) <= index) {
return;
}
updateMeterIdAvailability(meterTableKey, meterCellId, true);
}
use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.
the class P4RuntimeMeterProgrammable method getMeters.
@Override
public CompletableFuture<Collection<Meter>> getMeters() {
if (!setupBehaviour("getMeters()")) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
Collection<PiMeterCellConfig> piMeterCellConfigs;
Set<PiMeterId> meterIds = new HashSet<>();
for (PiMeterModel mode : pipelineModel.meters()) {
meterIds.add(mode.id());
}
piMeterCellConfigs = client.read(p4DeviceId, pipeconf).meterCells(meterIds).submitSync().all(PiMeterCellConfig.class).stream().filter(piMeterCellConfig -> !piMeterCellConfig.isDefaultConfig()).collect(Collectors.toList());
meterMirror.sync(deviceId, piMeterCellConfigs);
if (piMeterCellConfigs.isEmpty()) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
List<PiMeterCellId> inconsistentOrDefaultCells = Lists.newArrayList();
List<Meter> meters = Lists.newArrayList();
// Check the consistency of meter config
for (PiMeterCellConfig config : piMeterCellConfigs) {
PiMeterCellHandle handle = PiMeterCellHandle.of(deviceId, config);
DefaultMeter meter = (DefaultMeter) forgeMeter(config, handle);
if (meter == null) {
// A default config cannot be used to forge meter
// because meter has at least 1 band while default config has no band
inconsistentOrDefaultCells.add(config.cellId());
} else {
meters.add(meter);
}
}
// Reset all inconsistent meter cells to the default config
if (!inconsistentOrDefaultCells.isEmpty()) {
WriteRequest request = client.write(p4DeviceId, pipeconf);
for (PiMeterCellId cellId : inconsistentOrDefaultCells) {
PiMeterCellHandle handle = PiMeterCellHandle.of(deviceId, cellId);
appendEntryToWriteRequestOrSkip(request, handle, PiMeterCellConfig.reset(cellId));
}
request.submit().whenComplete((response, ex) -> {
if (ex != null) {
log.error("Exception resetting inconsistent meter entries", ex);
} else {
log.debug("Successfully removed {} out of {} inconsistent meter entries", response.success().size(), response.all().size());
}
response.success().forEach(entity -> meterMirror.remove((PiMeterCellHandle) entity.handle()));
});
}
return CompletableFuture.completedFuture(meters);
}
use of org.onosproject.net.pi.runtime.PiMeterCellId in project up4 by omec-project.
the class Up4DeviceManager method meterToMeterRequestForDevice.
private MeterRequest meterToMeterRequestForDevice(Meter meter, DeviceId deviceId, boolean add) {
assert meter.meterCellId().type().equals(MeterCellId.MeterCellType.PIPELINE_INDEPENDENT);
PiMeterCellId piMeterCellId = (PiMeterCellId) meter.meterCellId();
MeterScope meterScope = MeterScope.of(piMeterCellId.meterId().id());
MeterRequest.Builder mRequestBuilder = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(meter.appId()).withUnit(meter.unit()).withScope(meterScope).withBands(meter.bands()).withIndex(piMeterCellId.index());
if (add) {
return mRequestBuilder.add();
}
return mRequestBuilder.remove();
}
Aggregations