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();
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations