Search in sources :

Example 1 with MeterService

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());
}
Also used : Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) CoreService(org.onosproject.core.CoreService) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest) MeterService(org.onosproject.net.meter.MeterService)

Example 2 with MeterService

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);
        }
    }
}
Also used : Meter(org.onosproject.net.meter.Meter) MeterService(org.onosproject.net.meter.MeterService)

Example 3 with MeterService

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);
}
Also used : DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MeterService(org.onosproject.net.meter.MeterService) MeterId(org.onosproject.net.meter.MeterId)

Example 4 with MeterService

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);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Meter(org.onosproject.net.meter.Meter) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) MeterService(org.onosproject.net.meter.MeterService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with MeterService

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();
}
Also used : Meter(org.onosproject.net.meter.Meter) MeterService(org.onosproject.net.meter.MeterService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

MeterService (org.onosproject.net.meter.MeterService)14 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 DELETE (javax.ws.rs.DELETE)2 CoreService (org.onosproject.core.CoreService)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