use of org.onosproject.net.meter.MeterService 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.MeterService in project onos by opennetworkinglab.
the class MetersListCommand method doExecute.
@Override
protected void doExecute() {
if (!isNullOrEmpty(scopeString)) {
meterScope = MeterScope.of(scopeString);
}
if (!isNullOrEmpty(indexString)) {
index = Long.parseLong(indexString);
if (meterScope == null) {
meterScope = MeterScope.globalScope();
}
}
if (index != null) {
if (meterScope != null && meterScope.equals(MeterScope.globalScope())) {
meterCellId = MeterId.meterId(index);
} else if (meterScope != null) {
meterCellId = PiMeterCellId.ofIndirect(PiMeterId.of(meterScope.id()), index);
}
}
MeterService service = get(MeterService.class);
Collection<Meter> meters;
if (isNullOrEmpty(uri)) {
meters = service.getAllMeters();
printMeters(meters);
} else {
if (meterCellId != null) {
Meter m = service.getMeter(DeviceId.deviceId(uri), meterCellId);
if (m != null) {
print("%s", m);
} else {
error("Meter %s not found for device %s", meterCellId, uri);
}
} else if (meterScope != null) {
meters = service.getMeters(DeviceId.deviceId(uri), meterScope);
printMeters(meters);
} else {
meters = service.getMeters(DeviceId.deviceId(uri));
printMeters(meters);
}
}
}
use of org.onosproject.net.meter.MeterService in project onos by opennetworkinglab.
the class OpenFlowPolicerConfigurable method freePolicerId.
@Override
public void freePolicerId(PolicerId id) {
// 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;
}
// Let's get the device id
DeviceId deviceId = handler.data().deviceId();
// Double check correspondence with device schema
if (!deviceId.uri().getScheme().equals(OF_SCHEME)) {
log.warn("The device {} does not seem to be managed by OpenFlow", deviceId);
return;
}
// Double check correspondence with pid schema
if (!id.uri().getScheme().equals(OF_SCHEME)) {
log.warn("The id {} does not seem to be OpenFlow", id);
return;
}
// Get the meter id
MeterId meterId = getMeterIdFromPolicerId(id);
// Free the meter id
meterService.freeMeterId(deviceId, meterId);
}
use of org.onosproject.net.meter.MeterService 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.MeterService 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();
}
Aggregations