use of org.onosproject.net.meter.MeterService in project onos by opennetworkinglab.
the class MetersWebResource method getMetersByDeviceIdAndScope.
/**
* Returns a collection of meters by the device id and meter scope.
*
* @param deviceId device identifier
* @param scope scope identifier
* @return 200 OK with array of meters which belongs to specified device
* @onos.rsModel Meters
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("scope/{deviceId}/{scope}")
public Response getMetersByDeviceIdAndScope(@PathParam("deviceId") String deviceId, @PathParam("scope") String scope) {
DeviceId did = DeviceId.deviceId(deviceId);
MeterScope meterScope = MeterScope.of(scope);
MeterService meterService = get(MeterService.class);
final Iterable<Meter> meters = meterService.getMeters(did, meterScope);
if (meters != null) {
meters.forEach(meter -> metersNode.add(codec(Meter.class).encode(meter, this)));
}
return ok(root).build();
}
use of org.onosproject.net.meter.MeterService in project onos by opennetworkinglab.
the class MetersWebResource method deleteMeterByDeviceIdAndMeterCellId.
/**
* Removes the meter by the device id and meter cell id.
*
* @param deviceId device identifier
* @param scope scope identifier
* @param index index
* @return 204 NO CONTENT
*/
@DELETE
@Path("{deviceId}/{scope}/{index}")
public Response deleteMeterByDeviceIdAndMeterCellId(@PathParam("deviceId") String deviceId, @PathParam("scope") String scope, @PathParam("index") String index) {
DeviceId did = DeviceId.deviceId(deviceId);
MeterScope meterScope = MeterScope.of(scope);
long meterIndex = Long.parseLong(index);
MeterCellId meterCellId;
if (meterScope.equals(MeterScope.globalScope())) {
meterCellId = MeterId.meterId(meterIndex);
} else {
meterCellId = PiMeterCellId.ofIndirect(PiMeterId.of(meterScope.id()), meterIndex);
}
MeterRequest meterRequest = deleteRequest(did);
MeterService meterService = get(MeterService.class);
meterService.withdraw(meterRequest, meterCellId);
return Response.noContent().build();
}
use of org.onosproject.net.meter.MeterService in project onos by opennetworkinglab.
the class MetersWebResource method getMetersByDeviceId.
/**
* Returns a collection of meters by the device id.
*
* @param deviceId device identifier
* @return 200 OK with array of meters which belongs to specified device
* @onos.rsModel Meters
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}")
public Response getMetersByDeviceId(@PathParam("deviceId") String deviceId) {
DeviceId did = DeviceId.deviceId(deviceId);
MeterService meterService = get(MeterService.class);
final Iterable<Meter> meters = meterService.getMeters(did);
if (meters != null) {
meters.forEach(meter -> metersNode.add(codec(Meter.class).encode(meter, this)));
}
return ok(root).build();
}
use of org.onosproject.net.meter.MeterService in project fabric-tna by stratum.
the class FabricUpfProgrammable method setupBehaviour.
@Override
protected boolean setupBehaviour(String opName) {
/* Always setup internally the behavior to refresh
the internal references: client, controller, etc*/
if (!super.setupBehaviour(opName)) {
return false;
}
// Already initialized.
if (appId != null) {
return true;
}
if (!computeHardwareResourceSizes()) {
// error message will be printed by computeHardwareResourceSizes()
return false;
}
flowRuleService = handler().get(FlowRuleService.class);
meterService = handler().get(MeterService.class);
packetService = handler().get(PacketService.class);
slicingService = handler().get(SlicingService.class);
upfTranslator = new FabricUpfTranslator();
final CoreService coreService = handler().get(CoreService.class);
appId = coreService.getAppId(Constants.APP_NAME_UPF);
if (appId == null) {
log.warn("Application ID is null. Cannot initialize behaviour.");
return false;
}
var capabilities = new FabricCapabilities(pipeconf);
if (!capabilities.supportUpf()) {
log.warn("Pipeconf {} on {} does not support UPF capabilities, " + "cannot perform {}", pipeconf.id(), deviceId, opName);
return false;
}
return true;
}
use of org.onosproject.net.meter.MeterService in project onos by opennetworkinglab.
the class OpenFlowPolicerConfigurable method allocatePolicerId.
@Override
public PolicerId allocatePolicerId() {
// Init step
DriverHandler handler = handler();
// First step is to get MeterService
MeterService meterService = handler.get(MeterService.class);
// There was a problem, return none
if (meterService == null) {
log.warn("MeterService is null");
return PolicerId.NONE;
}
// Let's get the device id
DeviceId deviceId = handler.data().deviceId();
// Double check correspondence between schemas
if (!deviceId.uri().getScheme().equals(OF_SCHEME)) {
log.warn("The device {} does not seem to be managed by OpenFlow", deviceId);
return PolicerId.NONE;
}
// Get a new meter id
MeterId meterId = meterService.allocateMeterId(deviceId);
// There was a problem
if (meterId == null) {
log.warn("MeterService does not provide valid ids");
return PolicerId.NONE;
}
// Create a policer id from the meter id
return getPolicerIdFromMeterId(meterId);
}
Aggregations