use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class MetersWebResource method getMeters.
/**
* Returns all meters of all devices.
*
* @return 200 OK with array of all the meters in the system
* @onos.rsModel Meters
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getMeters() {
MeterService meterService = get(MeterService.class);
final Iterable<Meter> meters = meterService.getAllMeters();
if (meters != null) {
meters.forEach(meter -> metersNode.add(codec(Meter.class).encode(meter, this)));
}
return ok(root).build();
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class MetersWebResource method createMeter.
/**
* Creates new meter rule. Creates and installs a new meter rule for the
* specified device.
*
* @param deviceId device identifier
* @param stream meter rule JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel MeterPost
*/
@POST
@Path("{deviceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createMeter(@PathParam("deviceId") String deviceId, InputStream stream) {
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
if ((specifiedDeviceId != null && !specifiedDeviceId.asText().equals(deviceId)) || get(DeviceService.class).getDevice(DeviceId.deviceId(deviceId)) == null) {
throw new IllegalArgumentException(DEVICE_INVALID);
}
jsonTree.put("deviceId", deviceId);
final MeterRequest meterRequest = codec(MeterRequest.class).decode(jsonTree, this);
MeterService meterService = get(MeterService.class);
final Meter meter = meterService.submit(meterRequest);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("meters").path(deviceId).path(Long.toString(meter.id().id()));
return Response.created(locationBuilder.build()).build();
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
use of org.onosproject.net.meter.Meter 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.Meter 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.Meter in project onos by opennetworkinglab.
the class OpenFlowMeterProvider method performOperation.
private void performOperation(OpenFlowSwitch sw, MeterOperation op) {
Meter meter = op.meter();
MeterModBuilder builder = MeterModBuilder.builder(meter.id().id(), sw.factory());
if (meter.isBurst()) {
builder.burst();
}
builder.withBands(meter.bands()).withId(meter.id()).withRateUnit(meter.unit());
switch(op.type()) {
case ADD:
pendingOperations.put(op.meter().id().id(), op);
sw.sendMsg(builder.add());
break;
case REMOVE:
sw.sendMsg(builder.remove());
break;
case MODIFY:
pendingOperations.put(op.meter().id().id(), op);
sw.sendMsg(builder.modify());
break;
default:
log.warn("Unknown Meter command {}; not sending anything", op.type());
providerService.meterOperationFailed(op, MeterFailReason.UNKNOWN_COMMAND);
}
}
Aggregations