Search in sources :

Example 6 with MeterScope

use of org.onosproject.net.meter.MeterScope 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 7 with MeterScope

use of org.onosproject.net.meter.MeterScope 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

MeterScope (org.onosproject.net.meter.MeterScope)7 DeviceId (org.onosproject.net.DeviceId)5 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)5 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)4 MeterRequest (org.onosproject.net.meter.MeterRequest)4 MeterService (org.onosproject.net.meter.MeterService)4 Path (javax.ws.rs.Path)3 Meter (org.onosproject.net.meter.Meter)3 MeterCellId (org.onosproject.net.meter.MeterCellId)3 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 CoreService (org.onosproject.core.CoreService)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1 DELETE (javax.ws.rs.DELETE)1 Band (org.onosproject.net.meter.Band)1 MeterKey (org.onosproject.net.meter.MeterKey)1 MeterTableKey (org.onosproject.net.meter.MeterTableKey)1 StorageException (org.onosproject.store.service.StorageException)1