Search in sources :

Example 6 with MeterService

use of org.onosproject.net.meter.MeterService 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();
}
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) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with MeterService

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

the class MetersWebResource method deleteMeterByDeviceIdAndMeterCellId.

/**
 * Removes the meter by the device id and meter cell id.
 *
 * @param deviceId device identifier
 * @param scope scope identifier
 * @param index index
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{deviceId}/{scope}/{index}")
public Response deleteMeterByDeviceIdAndMeterCellId(@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);
    }
    MeterRequest meterRequest = deleteRequest(did);
    MeterService meterService = get(MeterService.class);
    meterService.withdraw(meterRequest, meterCellId);
    return Response.noContent().build();
}
Also used : DeviceId(org.onosproject.net.DeviceId) MeterScope(org.onosproject.net.meter.MeterScope) 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 8 with MeterService

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

Example 9 with MeterService

use of org.onosproject.net.meter.MeterService in project fabric-tna by stratum.

the class FabricUpfProgrammable method setupBehaviour.

@Override
protected boolean setupBehaviour(String opName) {
    /* Always setup internally the behavior to refresh
           the internal references: client, controller, etc*/
    if (!super.setupBehaviour(opName)) {
        return false;
    }
    // Already initialized.
    if (appId != null) {
        return true;
    }
    if (!computeHardwareResourceSizes()) {
        // error message will be printed by computeHardwareResourceSizes()
        return false;
    }
    flowRuleService = handler().get(FlowRuleService.class);
    meterService = handler().get(MeterService.class);
    packetService = handler().get(PacketService.class);
    slicingService = handler().get(SlicingService.class);
    upfTranslator = new FabricUpfTranslator();
    final CoreService coreService = handler().get(CoreService.class);
    appId = coreService.getAppId(Constants.APP_NAME_UPF);
    if (appId == null) {
        log.warn("Application ID is null. Cannot initialize behaviour.");
        return false;
    }
    var capabilities = new FabricCapabilities(pipeconf);
    if (!capabilities.supportUpf()) {
        log.warn("Pipeconf {} on {} does not support UPF capabilities, " + "cannot perform {}", pipeconf.id(), deviceId, opName);
        return false;
    }
    return true;
}
Also used : PacketService(org.onosproject.net.packet.PacketService) CoreService(org.onosproject.core.CoreService) FabricCapabilities(org.stratumproject.fabric.tna.behaviour.FabricCapabilities) FlowRuleService(org.onosproject.net.flow.FlowRuleService) MeterService(org.onosproject.net.meter.MeterService) SlicingService(org.stratumproject.fabric.tna.slicing.api.SlicingService)

Example 10 with MeterService

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

the class OpenFlowPolicerConfigurable method allocatePolicerId.

@Override
public PolicerId allocatePolicerId() {
    // 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 PolicerId.NONE;
    }
    // Let's get the device id
    DeviceId deviceId = handler.data().deviceId();
    // Double check correspondence between schemas
    if (!deviceId.uri().getScheme().equals(OF_SCHEME)) {
        log.warn("The device {} does not seem to be managed by OpenFlow", deviceId);
        return PolicerId.NONE;
    }
    // Get a new meter id
    MeterId meterId = meterService.allocateMeterId(deviceId);
    // There was a problem
    if (meterId == null) {
        log.warn("MeterService does not provide valid ids");
        return PolicerId.NONE;
    }
    // Create a policer id from the meter id
    return getPolicerIdFromMeterId(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)

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