Search in sources :

Example 11 with MeterService

use of org.onosproject.net.meter.MeterService in project onos by opennetworkinglab.

the class WipeOutCommand method wipeOutMeters.

private void wipeOutMeters() {
    print("Wiping meters");
    MeterService meterService = get(MeterService.class);
    DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
    for (Device device : deviceAdminService.getDevices()) {
        meterService.purgeMeters(device.id());
    }
}
Also used : Device(org.onosproject.net.Device) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) MeterService(org.onosproject.net.meter.MeterService)

Example 12 with MeterService

use of org.onosproject.net.meter.MeterService 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();
}
Also used : DeviceId(org.onosproject.net.DeviceId) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest) MeterService(org.onosproject.net.meter.MeterService) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterCellId(org.onosproject.net.meter.MeterCellId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 13 with MeterService

use of org.onosproject.net.meter.MeterService in project onos by opennetworkinglab.

the class MetersWebResource method getMeterByDeviceIdAndMeterId.

/**
 * Returns a meter by the meter id.
 *
 * @param deviceId device identifier
 * @param meterId meter identifier
 * @return 200 OK with a meter, return 404 if no entry has been found
 * @onos.rsModel Meter
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{meterId}")
public Response getMeterByDeviceIdAndMeterId(@PathParam("deviceId") String deviceId, @PathParam("meterId") String meterId) {
    DeviceId did = DeviceId.deviceId(deviceId);
    MeterCellId mid = MeterId.meterId(Long.valueOf(meterId));
    MeterService meterService = get(MeterService.class);
    final Meter meter = nullIsNotFound(meterService.getMeter(did, mid), METER_NOT_FOUND + mid);
    metersNode.add(codec(Meter.class).encode(meter, this));
    return ok(root).build();
}
Also used : Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) MeterService(org.onosproject.net.meter.MeterService) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterCellId(org.onosproject.net.meter.MeterCellId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with MeterService

use of org.onosproject.net.meter.MeterService in project onos by opennetworkinglab.

the class MetersWebResource method getMeterByDeviceIdAndMeterCellId.

/**
 * Returns a meter by the meter cell id.
 *
 * @param deviceId device identifier
 * @param scope scope identifier
 * @param index index
 * @return 200 OK with a meter, return 404 if no entry has been found
 * @onos.rsModel Meter
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{scope}/{index}")
public Response getMeterByDeviceIdAndMeterCellId(@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);
    }
    MeterService meterService = get(MeterService.class);
    final Meter meter = nullIsNotFound(meterService.getMeter(did, meterCellId), METER_NOT_FOUND + meterCellId);
    metersNode.add(codec(Meter.class).encode(meter, this));
    return ok(root).build();
}
Also used : Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) MeterScope(org.onosproject.net.meter.MeterScope) MeterService(org.onosproject.net.meter.MeterService) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterCellId(org.onosproject.net.meter.MeterCellId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 15 with MeterService

use of org.onosproject.net.meter.MeterService 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());
}
Also used : DeviceId(org.onosproject.net.DeviceId) MeterScope(org.onosproject.net.meter.MeterScope) CoreService(org.onosproject.core.CoreService) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest) MeterService(org.onosproject.net.meter.MeterService) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterCellId(org.onosproject.net.meter.MeterCellId)

Aggregations

MeterService (org.onosproject.net.meter.MeterService)15 DeviceId (org.onosproject.net.DeviceId)10 Meter (org.onosproject.net.meter.Meter)8 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)6 GET (javax.ws.rs.GET)5 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)5 MeterCellId (org.onosproject.net.meter.MeterCellId)5 MeterRequest (org.onosproject.net.meter.MeterRequest)5 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)5 MeterScope (org.onosproject.net.meter.MeterScope)4 CoreService (org.onosproject.core.CoreService)3 DELETE (javax.ws.rs.DELETE)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2 MeterId (org.onosproject.net.meter.MeterId)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1