use of org.onosproject.net.pi.runtime.PiMeterCellConfig in project onos by opennetworkinglab.
the class TofinoMeterProgrammableTest method testWrongIsRateSimilar.
/**
* Test wrong isRateSimilar of the tofino behavior.
*/
@Test
public void testWrongIsRateSimilar() {
PiMeterBand onosMeterBand;
PiMeterBand deviceMeterBand;
PiMeterCellConfig onosMeter;
PiMeterCellConfig deviceMeter;
for (Map.Entry<Long, Long> entry : WRONG_RATES.entrySet()) {
onosMeterBand = new PiMeterBand(PiMeterBandType.COMMITTED, entry.getKey(), 0);
deviceMeterBand = new PiMeterBand(PiMeterBandType.COMMITTED, entry.getValue(), 0);
onosMeter = PiMeterCellConfig.builder().withMeterCellId(meterCellId).withMeterBand(onosMeterBand).withMeterBand(new PiMeterBand(PiMeterBandType.PEAK, 0, 0)).build();
deviceMeter = PiMeterCellConfig.builder().withMeterCellId(meterCellId).withMeterBand(deviceMeterBand).withMeterBand(new PiMeterBand(PiMeterBandType.PEAK, 0, 0)).build();
assertFalse(meterProgrammable.isSimilar(onosMeter, deviceMeter));
}
}
use of org.onosproject.net.pi.runtime.PiMeterCellConfig in project onos by opennetworkinglab.
the class P4RuntimeMeterProgrammable method forgeMeter.
private Meter forgeMeter(PiMeterCellConfig config, PiMeterCellHandle handle) {
final Optional<PiTranslatedEntity<Meter, PiMeterCellConfig>> translatedEntity = translator.lookup(handle);
final TimedEntry<PiMeterCellConfig> timedEntry = meterMirror.get(handle);
// is default configuration.
if (translatedEntity.isEmpty()) {
if (!config.isDefaultConfig()) {
log.warn("Meter Cell Config obtained from device {} is different from " + "one in in translation store: device={}, store=Default", deviceId, config);
} else {
log.debug("Configs for {} obtained from device: {} and from the store are default, " + "skipping the forge section", config.cellId(), deviceId);
}
return null;
}
// that config from devices can be default which means no band
if (!isSimilar(translatedEntity.get().translated(), config)) {
log.warn("Meter Cell Config obtained from device {} is different from " + "one in in translation store: device={}, store={}", deviceId, config, translatedEntity.get().translated());
return null;
}
// the eventual consistent maps used in the AbstractDistributedP4RuntimeMirror
if (timedEntry == null) {
log.warn("Meter entry handle not found in device mirror: {}", handle);
return null;
}
Meter original = translatedEntity.get().original();
// Forge a meter with MeterCellId, Bands and DeviceId using the original value.
DefaultMeter meter = (DefaultMeter) DefaultMeter.builder().withBands(original.bands()).withCellId(original.meterCellId()).forDevice(deviceId).build();
meter.setState(MeterState.ADDED);
return meter;
}
use of org.onosproject.net.pi.runtime.PiMeterCellConfig 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.PiMeterCellConfig in project up4 by omec-project.
the class Up4NorthComponentTest method sessionMeterModification.
// ------------------- MODIFICATION TESTS ----------------------------------
@Test
public void sessionMeterModification() throws Exception {
// Meter cannot be inserted!
PiMeterCellConfig meterEntry = TestImplConstants.UP4_SESSION_METER;
modificationTest(meterEntry);
assertThat(mockUp4Service.readAll(UpfEntityType.SESSION_METER).size(), equalTo(1));
}
use of org.onosproject.net.pi.runtime.PiMeterCellConfig in project up4 by omec-project.
the class Up4NorthComponentTest method appMeterModification.
@Test
public void appMeterModification() throws Exception {
// Meter cannot be inserted!
PiMeterCellConfig meterEntry = TestImplConstants.UP4_APP_METER;
modificationTest(meterEntry);
assertThat(mockUp4Service.readAll(UpfEntityType.APPLICATION_METER).size(), equalTo(1));
}
Aggregations