use of org.onosproject.net.meter.DefaultMeter in project onos by opennetworkinglab.
the class VirtualNetworkMeterManager method withdraw.
@Override
public void withdraw(MeterRequest request, MeterCellId meterCellId) {
Meter.Builder mBuilder = DefaultMeter.builder().forDevice(request.deviceId()).fromApp(request.appId()).withBands(request.bands()).withCellId(meterCellId).withUnit(request.unit());
if (request.isBurst()) {
mBuilder.burst();
}
DefaultMeter m = (DefaultMeter) mBuilder.build();
m.setState(MeterState.PENDING_REMOVE);
store.deleteMeter(networkId(), m).whenComplete((result, error) -> onComplete.accept(request, result, error));
}
use of org.onosproject.net.meter.DefaultMeter 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;
}
use of org.onosproject.net.meter.DefaultMeter 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.DefaultMeter 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.DefaultMeter in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testGetMetersImmutability.
/**
* Test getMeters API immutability.
*/
@Test
public void testGetMetersImmutability() {
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);
Collection<Meter> meters = meterStore.getAllMeters();
Collection<Meter> metersDevice = meterStore.getAllMeters(did1);
assertThat(1, is(meters.size()));
assertThat(1, is(metersDevice.size()));
MeterCellId idTwo = meterStore.allocateMeterId(did1, MeterScope.globalScope());
assertThat(mid2, is(idTwo));
Meter meterTwo = DefaultMeter.builder().forDevice(did1).fromApp(APP_ID).withId(mid2).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(b1)).build();
((DefaultMeter) meterTwo).setState(MeterState.PENDING_ADD);
meterStore.addOrUpdateMeter(meterTwo);
assertThat(1, is(meters.size()));
assertThat(1, is(metersDevice.size()));
meters = meterStore.getAllMeters();
metersDevice = meterStore.getAllMeters(did1);
assertThat(2, is(meters.size()));
assertThat(2, is(metersDevice.size()));
}
Aggregations