use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testStoreMeterInUserDefinedIndexMode.
/**
* Test store meter in user defined index mode.
*/
@Test
public void testStoreMeterInUserDefinedIndexMode() {
initMeterStore(true);
Meter meterOne = DefaultMeter.builder().forDevice(did3).fromApp(APP_ID).withCellId(cid4).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(b1)).build();
((DefaultMeter) meterOne).setState(MeterState.PENDING_ADD);
meterStore.addOrUpdateMeter(meterOne);
MeterKey meterKey = MeterKey.key(did3, cid4);
assertThat(1, is(meterStore.getAllMeters().size()));
assertThat(1, is(meterStore.getAllMeters(did3).size()));
assertThat(m4, is(meterStore.getMeter(meterKey)));
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testInvalidCellId.
/**
* Test invalid allocation of a cell id.
*/
@Test(expected = IllegalArgumentException.class)
public void testInvalidCellId() {
initMeterStore(true);
// MF defines an end index equals to 10
Meter meterBad = DefaultMeter.builder().forDevice(did3).fromApp(APP_ID).withCellId(invalidCid).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(b1)).build();
((DefaultMeter) meterBad).setState(MeterState.PENDING_ADD);
meterStore.addOrUpdateMeter(meterBad);
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class SimpleVirtualMeterStore method deleteMeter.
@Override
public CompletableFuture<MeterStoreResult> deleteMeter(NetworkId networkId, Meter meter) {
ConcurrentMap<MeterKey, MeterData> meters = getMetersByNetwork(networkId);
ConcurrentMap<MeterKey, CompletableFuture<MeterStoreResult>> futures = getFuturesByNetwork(networkId);
CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
futures.put(key, future);
MeterData data = new MeterData(meter, null, local);
// that it has been removed from the dataplane.
try {
if (meters.computeIfPresent(key, (k, v) -> data) == null) {
future.complete(MeterStoreResult.success());
}
} catch (StorageException e) {
future.completeExceptionally(e);
}
return future;
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class CorsaPipelineV3 method processMeterTable.
protected void processMeterTable(boolean install) {
// Green meter : Pass all traffic
Band dropBand = DefaultBand.builder().ofType(Band.Type.DROP).withRate(0xFFFFFFFF).build();
MeterRequest.Builder ops = DefaultMeterRequest.builder().forDevice(deviceId).withBands(Collections.singletonList(dropBand)).fromApp(appId);
Meter meter = meterService.submit(install ? ops.add() : ops.remove());
defaultMeterId = meter.id();
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class MeterManager method submit.
@Override
public Meter submit(MeterRequest request) {
checkNotNull(request, "request cannot be null.");
MeterCellId cellId;
if (request.index().isPresent()) {
checkArgument(userDefinedIndex, "Index cannot be provided when userDefinedIndex mode is disabled");
// User provides index
if (request.scope().isGlobal()) {
cellId = MeterId.meterId(request.index().get());
} else {
cellId = PiMeterCellId.ofIndirect(PiMeterId.of(request.scope().id()), request.index().get());
}
} else {
checkArgument(!userDefinedIndex, "Index cannot be allocated when userDefinedIndex mode is enabled");
// Allocate an id
cellId = allocateMeterId(request.deviceId(), request.scope());
}
Meter.Builder mBuilder = DefaultMeter.builder().forDevice(request.deviceId()).fromApp(request.appId()).withBands(request.bands()).withCellId(cellId).withUnit(request.unit());
if (request.isBurst()) {
mBuilder.burst();
}
if (request.annotations() != null && !request.annotations().keys().isEmpty()) {
mBuilder.withAnnotations(request.annotations());
}
DefaultMeter m = (DefaultMeter) mBuilder.build();
// Meter installation logic (happy ending case)
// PENDING -> stats -> ADDED -> future completes
m.setState(MeterState.PENDING_ADD);
store.addOrUpdateMeter(m).whenComplete((result, error) -> onComplete.accept(request, result, error));
return m;
}
Aggregations