Search in sources :

Example 11 with MeterRequest

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

the class FabricUpfTranslator method upfMeterToFabricMeter.

public MeterRequest upfMeterToFabricMeter(UpfMeter upfMeter, DeviceId deviceId, ApplicationId appId) throws UpfProgrammableException {
    final PiMeterId meterId;
    if (upfMeter.type().equals(UpfEntityType.SESSION_METER)) {
        meterId = FABRIC_INGRESS_UPF_SESSION_METER;
    } else if (upfMeter.type().equals(UpfEntityType.APPLICATION_METER)) {
        meterId = FABRIC_INGRESS_UPF_APP_METER;
    } else if (upfMeter.type().equals(UpfEntityType.SLICE_METER)) {
        meterId = FABRIC_INGRESS_QOS_SLICE_TC_METER;
    } else {
        // I should never reach this point.
        throw new UpfProgrammableException("Unknown UPF meter type. I should never reach this point! " + upfMeter);
    }
    MeterRequest.Builder meterRequest = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(appId).withScope(MeterScope.of(meterId.id())).withUnit(Meter.Unit.BYTES_PER_SEC).withIndex((long) upfMeter.cellId());
    if (upfMeter.isReset()) {
        return meterRequest.remove();
    } else {
        Collection<Band> bands = Lists.newArrayList();
        if (upfMeter.committedBand().isPresent()) {
            bands.add(upfMeter.committedBand().get());
        } else {
            bands.add(DefaultBand.builder().ofType(Band.Type.MARK_YELLOW).withRate(0).burstSize(0).build());
        }
        if (upfMeter.peakBand().isPresent()) {
            bands.add(upfMeter.peakBand().get());
        } else {
            bands.add(DefaultBand.builder().ofType(Band.Type.MARK_RED).withRate(0).burstSize(0).build());
        }
        meterRequest.withBands(bands);
        return meterRequest.add();
    }
}
Also used : PiMeterId(org.onosproject.net.pi.model.PiMeterId) UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) Band(org.onosproject.net.meter.Band) DefaultBand(org.onosproject.net.meter.DefaultBand) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest)

Example 12 with MeterRequest

use of org.onosproject.net.meter.MeterRequest in project up4 by omec-project.

the class Up4DeviceManager method meterToMeterRequestForDevice.

private MeterRequest meterToMeterRequestForDevice(Meter meter, DeviceId deviceId, boolean add) {
    assert meter.meterCellId().type().equals(MeterCellId.MeterCellType.PIPELINE_INDEPENDENT);
    PiMeterCellId piMeterCellId = (PiMeterCellId) meter.meterCellId();
    MeterScope meterScope = MeterScope.of(piMeterCellId.meterId().id());
    MeterRequest.Builder mRequestBuilder = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(meter.appId()).withUnit(meter.unit()).withScope(meterScope).withBands(meter.bands()).withIndex(piMeterCellId.index());
    if (add) {
        return mRequestBuilder.add();
    }
    return mRequestBuilder.remove();
}
Also used : PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterScope(org.onosproject.net.meter.MeterScope) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest)

Example 13 with MeterRequest

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

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

Example 15 with MeterRequest

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

the class DefaultOFSwitch method processMeterMod.

private void processMeterMod(OFMeterMod meterMod, Channel channel) {
    log.debug("processing METER_MOD {} message", meterMod.getCommand());
    long meterModId = meterMod.getMeterId();
    Meter existingMeter = meterService.getMeter(deviceId, MeterId.meterId(meterModId));
    MeterRequest meterRequest = null;
    switch(meterMod.getCommand()) {
        case ADD:
            if (existingMeter != null) {
                meterModError(meterMod, OFMeterModFailedCode.METER_EXISTS, channel);
                return;
            }
            meterRequest = meterRequestBuilder(meterMod).add();
            break;
        case MODIFY:
            if (existingMeter == null) {
                meterModError(meterMod, OFMeterModFailedCode.UNKNOWN_METER, channel);
                return;
            }
            meterRequest = meterRequestBuilder(meterMod).add();
            break;
        case DELETE:
            // non-existing meter id will not result in OFMeterModFailedErrorMsg
            // being sent to the controller
            meterRequest = meterRequestBuilder(meterMod).remove();
            break;
        default:
            log.warn("Unexpected message {} received for switch {}", meterMod.getCommand(), this);
            return;
    }
    meterService.submit(meterRequest);
}
Also used : Meter(org.onosproject.net.meter.Meter) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest)

Aggregations

MeterRequest (org.onosproject.net.meter.MeterRequest)19 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)10 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)8 Test (org.junit.Test)7 DeviceId (org.onosproject.net.DeviceId)6 Meter (org.onosproject.net.meter.Meter)5 MeterService (org.onosproject.net.meter.MeterService)5 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)5 Band (org.onosproject.net.meter.Band)4 MeterCellId (org.onosproject.net.meter.MeterCellId)4 MeterScope (org.onosproject.net.meter.MeterScope)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Path (javax.ws.rs.Path)3 CoreService (org.onosproject.core.CoreService)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DELETE (javax.ws.rs.DELETE)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1