use of org.onosproject.net.pi.runtime.PiMeterBand 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.PiMeterBand in project onos by opennetworkinglab.
the class TofinoMeterProgrammableTest method testWrongIsRateSimilar.
/**
* Test wrong isRateSimilar of the tofino behavior.
*/
@Test
public void testWrongIsRateSimilar() {
PiMeterBand onosMeterBand;
PiMeterBand deviceMeterBand;
PiMeterCellConfig onosMeter;
PiMeterCellConfig deviceMeter;
for (Map.Entry<Long, Long> entry : WRONG_RATES.entrySet()) {
onosMeterBand = new PiMeterBand(PiMeterBandType.COMMITTED, entry.getKey(), 0);
deviceMeterBand = new PiMeterBand(PiMeterBandType.COMMITTED, entry.getValue(), 0);
onosMeter = PiMeterCellConfig.builder().withMeterCellId(meterCellId).withMeterBand(onosMeterBand).withMeterBand(new PiMeterBand(PiMeterBandType.PEAK, 0, 0)).build();
deviceMeter = PiMeterCellConfig.builder().withMeterCellId(meterCellId).withMeterBand(deviceMeterBand).withMeterBand(new PiMeterBand(PiMeterBandType.PEAK, 0, 0)).build();
assertFalse(meterProgrammable.isSimilar(onosMeter, deviceMeter));
}
}
use of org.onosproject.net.pi.runtime.PiMeterBand in project onos by opennetworkinglab.
the class TofinoMeterProgrammable method isSimilar.
@Override
public boolean isSimilar(PiMeterCellConfig onosMeter, PiMeterCellConfig deviceMeter) {
final PiMeterBand onosCommittedBand = onosMeter.committedBand();
final PiMeterBand onosPeakBand = onosMeter.peakBand();
final PiMeterBand deviceCommittedBand = deviceMeter.committedBand();
final PiMeterBand devicePeakBand = deviceMeter.peakBand();
// close to a read, read can still return the default config
if (deviceCommittedBand == null || devicePeakBand == null) {
return false;
}
final long onosCir = onosCommittedBand.rate();
final long onosCburst = onosCommittedBand.burst();
final long onosPir = onosPeakBand.rate();
final long onosPburst = onosPeakBand.burst();
final long deviceCir = deviceCommittedBand.rate();
final long deviceCburst = deviceCommittedBand.burst();
final long devicePir = devicePeakBand.rate();
final long devicePburst = devicePeakBand.burst();
return isRateSimilar(onosCir, deviceCir) && isRateSimilar(onosPir, devicePir) && isBurstSimilar(onosCburst, deviceCburst) && isBurstSimilar(onosPburst, devicePburst);
}
use of org.onosproject.net.pi.runtime.PiMeterBand in project onos by opennetworkinglab.
the class MeterEntryCodec method getP4Config.
static P4RuntimeOuterClass.MeterConfig getP4Config(PiMeterCellConfig piConfig) {
// The config has no band, we don't have to create a P4RT meter config
if (piConfig.isDefaultConfig()) {
return null;
}
final PiMeterBand committedBand = piConfig.committedBand();
final PiMeterBand peakBand = piConfig.peakBand();
return P4RuntimeOuterClass.MeterConfig.newBuilder().setCir(committedBand.rate()).setCburst(committedBand.burst()).setPir(peakBand.rate()).setPburst(peakBand.burst()).build();
}
use of org.onosproject.net.pi.runtime.PiMeterBand in project onos by opennetworkinglab.
the class TofinoMeterProgrammableTest method testIsRateSimilar.
/**
* Test isRateSimilar check of the tofino behavior.
*/
@Test
public void testIsRateSimilar() {
PiMeterBand onosMeterBand;
PiMeterBand deviceMeterBand;
PiMeterCellConfig onosMeter;
PiMeterCellConfig deviceMeter;
for (Map.Entry<Long, Long> entry : RATES.entrySet()) {
onosMeterBand = new PiMeterBand(PiMeterBandType.COMMITTED, entry.getKey(), 0);
deviceMeterBand = new PiMeterBand(PiMeterBandType.COMMITTED, entry.getValue(), 0);
onosMeter = PiMeterCellConfig.builder().withMeterCellId(meterCellId).withMeterBand(onosMeterBand).withMeterBand(new PiMeterBand(PiMeterBandType.PEAK, 0, 0)).build();
deviceMeter = PiMeterCellConfig.builder().withMeterCellId(meterCellId).withMeterBand(deviceMeterBand).withMeterBand(new PiMeterBand(PiMeterBandType.PEAK, 0, 0)).build();
assertTrue(meterProgrammable.isSimilar(onosMeter, deviceMeter));
}
}
Aggregations