use of org.onosproject.net.meter.MeterRequest in project fabric-tna by stratum.
the class FabricUpfTranslator method upfMeterToFabricMeter.
public MeterRequest upfMeterToFabricMeter(UpfMeter upfMeter, DeviceId deviceId, ApplicationId appId) throws UpfProgrammableException {
final PiMeterId meterId;
if (upfMeter.type().equals(UpfEntityType.SESSION_METER)) {
meterId = FABRIC_INGRESS_UPF_SESSION_METER;
} else if (upfMeter.type().equals(UpfEntityType.APPLICATION_METER)) {
meterId = FABRIC_INGRESS_UPF_APP_METER;
} else if (upfMeter.type().equals(UpfEntityType.SLICE_METER)) {
meterId = FABRIC_INGRESS_QOS_SLICE_TC_METER;
} else {
// I should never reach this point.
throw new UpfProgrammableException("Unknown UPF meter type. I should never reach this point! " + upfMeter);
}
MeterRequest.Builder meterRequest = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(appId).withScope(MeterScope.of(meterId.id())).withUnit(Meter.Unit.BYTES_PER_SEC).withIndex((long) upfMeter.cellId());
if (upfMeter.isReset()) {
return meterRequest.remove();
} else {
Collection<Band> bands = Lists.newArrayList();
if (upfMeter.committedBand().isPresent()) {
bands.add(upfMeter.committedBand().get());
} else {
bands.add(DefaultBand.builder().ofType(Band.Type.MARK_YELLOW).withRate(0).burstSize(0).build());
}
if (upfMeter.peakBand().isPresent()) {
bands.add(upfMeter.peakBand().get());
} else {
bands.add(DefaultBand.builder().ofType(Band.Type.MARK_RED).withRate(0).burstSize(0).build());
}
meterRequest.withBands(bands);
return meterRequest.add();
}
}
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 MetersWebResource method deleteMeterByDeviceIdAndMeterId.
/**
* Removes the meter by device id and meter id.
*
* @param deviceId device identifier
* @param meterId meter identifier
* @return 204 NO CONTENT
*/
@DELETE
@Path("{deviceId}/{meterId}")
public Response deleteMeterByDeviceIdAndMeterId(@PathParam("deviceId") String deviceId, @PathParam("meterId") String meterId) {
DeviceId did = DeviceId.deviceId(deviceId);
MeterCellId mid = MeterId.meterId(Long.valueOf(meterId));
MeterRequest meterRequest = deleteRequest(did);
MeterService meterService = get(MeterService.class);
meterService.withdraw(meterRequest, mid);
return Response.noContent().build();
}
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