use of org.onosproject.net.meter.MeterRequest in project onos by opennetworkinglab.
the class MeterRequestCodecTest method testMeterRequestDecode.
/**
* Test decoding of a MeterRequest object.
*/
@Test
public void testMeterRequestDecode() throws IOException {
MeterRequest meterRequest = getMeterRequest("simple-meter-request.json");
checkCommonData(meterRequest);
assertThat(meterRequest.bands().size(), is(1));
Band band = meterRequest.bands().iterator().next();
assertThat(band.type().toString(), is("REMARK"));
assertThat(band.rate(), is(10L));
assertThat(band.dropPrecedence(), is((short) 20));
assertThat(band.burst(), is(30L));
}
use of org.onosproject.net.meter.MeterRequest in project onos by opennetworkinglab.
the class MeterAddCommand method doExecute.
@Override
protected void doExecute() {
MeterService service = get(MeterService.class);
CoreService coreService = get(CoreService.class);
DeviceId deviceId = DeviceId.deviceId(uri);
checkOptions();
MeterRequest.Builder builder = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(coreService.registerApplication(appId)).withUnit(unit).withBands(bands);
if (isBurst) {
builder = builder.burst();
}
// the user defined mode being active.
if (scope != null) {
builder = builder.withScope(scope);
}
if (index != null) {
builder = builder.withIndex(index);
}
MeterRequest request = builder.add();
Meter m = service.submit(request);
log.info("Requested meter with cellId {}: {}", m.meterCellId().toString(), m.toString());
print("Requested meter with cellId %s: %s", m.meterCellId().toString(), m.toString());
}
use of org.onosproject.net.meter.MeterRequest 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();
}
use of org.onosproject.net.meter.MeterRequest in project onos by opennetworkinglab.
the class MeterRemoveCommand method doExecute.
@Override
protected void doExecute() {
MeterService service = get(MeterService.class);
CoreService coreService = get(CoreService.class);
DeviceId deviceId = DeviceId.deviceId(uri);
MeterScope scope = MeterScope.globalScope();
if (!isNullOrEmpty(scopeString)) {
scope = MeterScope.of(scopeString);
}
MeterCellId meterCellId;
long index = Long.parseLong(indexString);
if (scope.equals(MeterScope.globalScope())) {
meterCellId = MeterId.meterId(index);
} else {
meterCellId = PiMeterCellId.ofIndirect(PiMeterId.of(scope.id()), index);
}
MeterRequest.Builder builder = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(coreService.registerApplication(appId));
MeterRequest meterRequest = builder.remove();
service.withdraw(builder.remove(), meterCellId);
log.info("Requested meter {} removal: {}", meterCellId.toString(), meterRequest.toString());
print("Requested meter %s removal: %s", meterCellId.toString(), meterRequest.toString());
}
use of org.onosproject.net.meter.MeterRequest in project onos by opennetworkinglab.
the class DefaultOFSwitch method processMeterMod.
private void processMeterMod(OFMeterMod meterMod, Channel channel) {
log.debug("processing METER_MOD {} message", meterMod.getCommand());
long meterModId = meterMod.getMeterId();
Meter existingMeter = meterService.getMeter(deviceId, MeterId.meterId(meterModId));
MeterRequest meterRequest = null;
switch(meterMod.getCommand()) {
case ADD:
if (existingMeter != null) {
meterModError(meterMod, OFMeterModFailedCode.METER_EXISTS, channel);
return;
}
meterRequest = meterRequestBuilder(meterMod).add();
break;
case MODIFY:
if (existingMeter == null) {
meterModError(meterMod, OFMeterModFailedCode.UNKNOWN_METER, channel);
return;
}
meterRequest = meterRequestBuilder(meterMod).add();
break;
case DELETE:
// non-existing meter id will not result in OFMeterModFailedErrorMsg
// being sent to the controller
meterRequest = meterRequestBuilder(meterMod).remove();
break;
default:
log.warn("Unexpected message {} received for switch {}", meterMod.getCommand(), this);
return;
}
meterService.submit(meterRequest);
}
Aggregations