Search in sources :

Example 1 with PiMeterCellId

use of org.onosproject.net.pi.runtime.PiMeterCellId in project up4 by omec-project.

the class Up4TranslatorImpl method upfEntityToUp4MeterEntry.

@Override
public PiMeterCellConfig upfEntityToUp4MeterEntry(UpfEntity entity) throws Up4TranslationException {
    PiMeterId meterId;
    switch(entity.type()) {
        case SESSION_METER:
            meterId = PRE_QOS_PIPE_SESSION_METER;
            break;
        case APPLICATION_METER:
            meterId = PRE_QOS_PIPE_APP_METER;
            break;
        default:
            throw new Up4TranslationException("Attempting to translate an unsupported UPF entity to a meter entry! " + entity);
    }
    UpfMeter upfMeter = (UpfMeter) entity;
    PiMeterCellId piMeterCellId = PiMeterCellId.ofIndirect(meterId, upfMeter.cellId());
    if (upfMeter.isReset()) {
        return PiMeterCellConfig.reset(piMeterCellId);
    }
    Band peakBand = upfMeter.peakBand().orElse(DefaultBand.builder().withRate(ZERO_BAND_RATE).burstSize(ZERO_BAND_BURST).ofType(Band.Type.MARK_RED).build());
    Band commitedBand = upfMeter.committedBand().orElse(DefaultBand.builder().withRate(ZERO_BAND_RATE).burstSize(ZERO_BAND_BURST).ofType(Band.Type.MARK_YELLOW).build());
    return PiMeterCellConfig.builder().withMeterBand(new PiMeterBand(PiMeterBandType.PEAK, peakBand.rate(), peakBand.burst())).withMeterBand(new PiMeterBand(PiMeterBandType.COMMITTED, commitedBand.rate(), commitedBand.burst())).withMeterCellId(piMeterCellId).build();
}
Also used : PiMeterBand(org.onosproject.net.pi.runtime.PiMeterBand) PiMeterId(org.onosproject.net.pi.model.PiMeterId) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) UpfMeter(org.onosproject.net.behaviour.upf.UpfMeter) Band(org.onosproject.net.meter.Band) DefaultBand(org.onosproject.net.meter.DefaultBand) PiMeterBand(org.onosproject.net.pi.runtime.PiMeterBand)

Example 2 with PiMeterCellId

use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.

the class DirectMeterEntryCodec method decode.

@Override
protected PiMeterCellConfig decode(P4RuntimeOuterClass.DirectMeterEntry message, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException {
    PiMeterCellId cellId = PiMeterCellId.ofDirect(CODECS.tableEntry().decode(message.getTableEntry(), null, pipeconf));
    // When a field is unset, gRPC (P4RT) will return a default value
    // So, if the meter config is unset, the value of rate and burst will be 0,
    // while 0 is a meaningful value and not equals to UNSET in P4RT.
    // We cannot extract the values directly.
    P4RuntimeOuterClass.MeterConfig p4Config = message.hasConfig() ? message.getConfig() : null;
    return MeterEntryCodec.getPiMeterCellConfig(cellId, p4Config);
}
Also used : P4RuntimeOuterClass(p4.v1.P4RuntimeOuterClass) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId)

Example 3 with PiMeterCellId

use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.

the class MeterEntryCodec method decode.

@Override
protected PiMeterCellConfig decode(P4RuntimeOuterClass.MeterEntry message, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException {
    final String meterName = browser.meters().getById(message.getMeterId()).getPreamble().getName();
    PiMeterCellId cellId = PiMeterCellId.ofIndirect(PiMeterId.of(meterName), message.getIndex().getIndex());
    // When a field is unset, gRPC (P4RT) will return a default value
    // So, if the meter config is unset, the value of rate and burst will be 0,
    // while 0 is a meaningful value and not equals to UNSET in P4RT.
    // We cannot extract the values directly.
    P4RuntimeOuterClass.MeterConfig p4Config = message.hasConfig() ? message.getConfig() : null;
    return getPiMeterCellConfig(cellId, p4Config);
}
Also used : P4RuntimeOuterClass(p4.v1.P4RuntimeOuterClass) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId)

Example 4 with PiMeterCellId

use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.

the class DistributedMeterStore method freeMeterId.

protected void freeMeterId(DeviceId deviceId, MeterCellId meterCellId) {
    MeterTableKey meterTableKey;
    if (meterCellId.type() == PIPELINE_INDEPENDENT) {
        meterTableKey = MeterTableKey.key(deviceId, MeterScope.of(((PiMeterCellId) meterCellId).meterId().id()));
    } else if (meterCellId.type() == INDEX) {
        meterTableKey = MeterTableKey.key(deviceId, MeterScope.globalScope());
    } else {
        log.warn("Unable to free meter id unsupported cell type {}", meterCellId.type());
        return;
    }
    freeMeterId(meterTableKey, meterCellId);
}
Also used : MeterTableKey(org.onosproject.net.meter.MeterTableKey) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId)

Example 5 with PiMeterCellId

use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.

the class DistributedMeterStore method allocateMeterId.

@Override
public MeterCellId allocateMeterId(DeviceId deviceId, MeterScope meterScope) {
    if (userDefinedIndexMode) {
        log.warn("Unable to allocate meter id when user defined index mode is enabled");
        return null;
    }
    MeterTableKey meterTableKey = MeterTableKey.key(deviceId, meterScope);
    MeterCellId meterCellId;
    long id;
    // First, search for reusable key
    meterCellId = firstReusableMeterId(meterTableKey);
    if (meterCellId != null) {
        return meterCellId;
    }
    // If there was no reusable meter id we have to generate a new value
    // using start and end index as lower and upper bound respectively.
    long startIndex = getStartIndex(meterTableKey);
    long endIndex = getEndIndex(meterTableKey);
    // If the device does not give us MeterFeatures fallback to queryMeters
    if (startIndex == -1L || endIndex == -1L) {
        // Only meaningful for OpenFlow today
        long maxMeters = queryMaxMeters(deviceId);
        if (maxMeters == 0L) {
            return null;
        } else {
            // OpenFlow meter index starts from 1, ends with max
            startIndex = 1L;
            endIndex = maxMeters;
        }
    }
    do {
        id = meterIdGenerators.getAndIncrement(meterTableKey);
    } while (id < startIndex);
    if (id > endIndex) {
        return null;
    }
    // return a MeterId, otherwise we create a PiMeterCellId
    if (meterScope.isGlobal()) {
        return MeterId.meterId(id);
    } else {
        return PiMeterCellId.ofIndirect(PiMeterId.of(meterScope.id()), id);
    }
}
Also used : MeterTableKey(org.onosproject.net.meter.MeterTableKey) MeterCellId(org.onosproject.net.meter.MeterCellId) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId)

Aggregations

PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)11 MeterTableKey (org.onosproject.net.meter.MeterTableKey)4 PiMeterId (org.onosproject.net.pi.model.PiMeterId)4 MeterId (org.onosproject.net.meter.MeterId)2 MeterScope (org.onosproject.net.meter.MeterScope)2 PiMeterCellConfig (org.onosproject.net.pi.runtime.PiMeterCellConfig)2 PiMeterCellHandle (org.onosproject.net.pi.runtime.PiMeterCellHandle)2 WriteRequest (org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest)2 P4RuntimeOuterClass (p4.v1.P4RuntimeOuterClass)2 HashSet (java.util.HashSet)1 UpfMeter (org.onosproject.net.behaviour.upf.UpfMeter)1 Band (org.onosproject.net.meter.Band)1 DefaultBand (org.onosproject.net.meter.DefaultBand)1 DefaultMeter (org.onosproject.net.meter.DefaultMeter)1 DefaultMeterFeatures (org.onosproject.net.meter.DefaultMeterFeatures)1 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)1 Meter (org.onosproject.net.meter.Meter)1 MeterCellId (org.onosproject.net.meter.MeterCellId)1 MeterFeatures (org.onosproject.net.meter.MeterFeatures)1 MeterKey (org.onosproject.net.meter.MeterKey)1