use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class OpenFlowMeterProvider method pushMeterStats.
private void pushMeterStats(Dpid dpid, OFStatsReply msg) {
DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
if (msg.getStatsType() == OFStatsType.METER) {
OFMeterStatsReply reply = (OFMeterStatsReply) msg;
Collection<Meter> meters = buildMeters(deviceId, reply.getEntries());
// TODO do meter accounting here.
providerService.pushMeterMetrics(deviceId, meters);
} else if (msg.getStatsType() == OFStatsType.METER_CONFIG) {
OFMeterConfigStatsReply reply = (OFMeterConfigStatsReply) msg;
// FIXME: Map<Long, Meter> meters = collectMeters(deviceId, reply);
}
}
use of org.onosproject.net.meter.Meter 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());
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);
inconsistentOrDefaultCells.forEach(cellId -> request.entity(PiMeterCellConfig.reset(cellId), UpdateType.MODIFY));
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());
}
});
}
return CompletableFuture.completedFuture(meters);
}
use of org.onosproject.net.meter.Meter 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);
// 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;
}
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.meter.Meter in project fabric-tna by stratum.
the class MockMeterService method submit.
@Override
public Meter submit(MeterRequest meter) {
Meter addedMeter = DefaultMeter.builder().forDevice(meter.deviceId()).fromApp(meter.appId()).withUnit(meter.unit()).withBands(meter.bands()).withCellId(PiMeterCellId.ofIndirect(PiMeterId.of(meter.scope().id()), meter.index().get())).build();
((DefaultMeter) addedMeter).setState(MeterState.ADDED);
meters.add(addedMeter);
return addedMeter;
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testStoreMeter.
/**
* Test store meter.
*/
@Test
public void testStoreMeter() {
initMeterStore(false);
MeterCellId idOne = meterStore.allocateMeterId(did1, MeterScope.globalScope());
assertThat(mid1, is(idOne));
Meter meterOne = DefaultMeter.builder().forDevice(did1).fromApp(APP_ID).withId(mid1).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(b1)).build();
((DefaultMeter) meterOne).setState(MeterState.PENDING_ADD);
meterStore.addOrUpdateMeter(meterOne);
MeterKey meterKey = MeterKey.key(did1, mid1);
assertThat(1, is(meterStore.getAllMeters().size()));
assertThat(1, is(meterStore.getAllMeters(did1).size()));
assertThat(m1, is(meterStore.getMeter(meterKey)));
}
Aggregations