Search in sources :

Example 1 with PiMeterBand

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

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));
    }
}
Also used : PiMeterBand(org.onosproject.net.pi.runtime.PiMeterBand) PiMeterCellConfig(org.onosproject.net.pi.runtime.PiMeterCellConfig) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with PiMeterBand

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);
}
Also used : PiMeterBand(org.onosproject.net.pi.runtime.PiMeterBand)

Example 4 with PiMeterBand

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();
}
Also used : PiMeterBand(org.onosproject.net.pi.runtime.PiMeterBand)

Example 5 with PiMeterBand

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));
    }
}
Also used : PiMeterBand(org.onosproject.net.pi.runtime.PiMeterBand) PiMeterCellConfig(org.onosproject.net.pi.runtime.PiMeterCellConfig) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

PiMeterBand (org.onosproject.net.pi.runtime.PiMeterBand)7 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 Test (org.junit.Test)4 PiMeterCellConfig (org.onosproject.net.pi.runtime.PiMeterCellConfig)4 UpfMeter (org.onosproject.net.behaviour.upf.UpfMeter)1 Band (org.onosproject.net.meter.Band)1 DefaultBand (org.onosproject.net.meter.DefaultBand)1 PiMeterId (org.onosproject.net.pi.model.PiMeterId)1 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)1