Search in sources :

Example 6 with PiMeterCellConfig

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

the class P4RuntimeMeterProgrammable method getMeters.

@Override
public CompletableFuture<Collection<Meter>> getMeters() {
    if (!setupBehaviour("getMeters()")) {
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    Collection<PiMeterCellConfig> piMeterCellConfigs;
    Set<PiMeterId> meterIds = new HashSet<>();
    for (PiMeterModel mode : pipelineModel.meters()) {
        meterIds.add(mode.id());
    }
    piMeterCellConfigs = client.read(p4DeviceId, pipeconf).meterCells(meterIds).submitSync().all(PiMeterCellConfig.class).stream().filter(piMeterCellConfig -> !piMeterCellConfig.isDefaultConfig()).collect(Collectors.toList());
    meterMirror.sync(deviceId, piMeterCellConfigs);
    if (piMeterCellConfigs.isEmpty()) {
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    List<PiMeterCellId> inconsistentOrDefaultCells = Lists.newArrayList();
    List<Meter> meters = Lists.newArrayList();
    // Check the consistency of meter config
    for (PiMeterCellConfig config : piMeterCellConfigs) {
        PiMeterCellHandle handle = PiMeterCellHandle.of(deviceId, config);
        DefaultMeter meter = (DefaultMeter) forgeMeter(config, handle);
        if (meter == null) {
            // A default config cannot be used to forge meter
            // because meter has at least 1 band while default config has no band
            inconsistentOrDefaultCells.add(config.cellId());
        } else {
            meters.add(meter);
        }
    }
    // Reset all inconsistent meter cells to the default config
    if (!inconsistentOrDefaultCells.isEmpty()) {
        WriteRequest request = client.write(p4DeviceId, pipeconf);
        for (PiMeterCellId cellId : inconsistentOrDefaultCells) {
            PiMeterCellHandle handle = PiMeterCellHandle.of(deviceId, cellId);
            appendEntryToWriteRequestOrSkip(request, handle, PiMeterCellConfig.reset(cellId));
        }
        request.submit().whenComplete((response, ex) -> {
            if (ex != null) {
                log.error("Exception resetting inconsistent meter entries", ex);
            } else {
                log.debug("Successfully removed {} out of {} inconsistent meter entries", response.success().size(), response.all().size());
            }
            response.success().forEach(entity -> meterMirror.remove((PiMeterCellHandle) entity.handle()));
        });
    }
    return CompletableFuture.completedFuture(meters);
}
Also used : PiMeterId(org.onosproject.net.pi.model.PiMeterId) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) PiMeterCellConfig(org.onosproject.net.pi.runtime.PiMeterCellConfig) PiMeterModel(org.onosproject.net.pi.model.PiMeterModel) WriteRequest(org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest) DefaultMeter(org.onosproject.net.meter.DefaultMeter) PiMeterCellHandle(org.onosproject.net.pi.runtime.PiMeterCellHandle) HashSet(java.util.HashSet)

Example 7 with PiMeterCellConfig

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

the class Up4NorthComponentTest method sessionMeterInsertionTestFail.

@Test(expected = AssertionFailedError.class)
public void sessionMeterInsertionTestFail() throws Exception {
    // Meter cannot be inserted!
    PiMeterCellConfig meterEntry = TestImplConstants.UP4_SESSION_METER;
    insertionTest(meterEntry);
    assertThat(mockUp4Service.readAll(UpfEntityType.SESSION_METER).size(), equalTo(1));
}
Also used : PiMeterCellConfig(org.onosproject.net.pi.runtime.PiMeterCellConfig) Test(org.junit.Test)

Example 8 with PiMeterCellConfig

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

the class Up4NorthComponent method translateEntryAndApply.

/**
 * Translate the given logical pipeline table entry or meter cell config
 * to a Up4Service entry apply call.
 *
 * @param entry The logical table entry or meter cell config to be applied
 * @throws StatusException if the entry fails translation or cannot be applied
 */
private void translateEntryAndApply(PiEntity entry) throws StatusException {
    log.debug("Translating UP4 write request to fabric entry.");
    try {
        switch(entry.piEntityType()) {
            case TABLE_ENTRY:
                PiTableEntry tableEntry = (PiTableEntry) entry;
                if (tableEntry.action().type() != PiTableAction.Type.ACTION) {
                    log.warn("Action profile entry insertion not supported.");
                    throw UNIMPLEMENTED.withDescription("Action profile entries not supported by UP4.").asException();
                }
                up4Service.apply(up4Translator.up4TableEntryToUpfEntity(tableEntry));
                break;
            case METER_CELL_CONFIG:
                up4Service.apply(up4Translator.up4MeterEntryToUpfEntity((PiMeterCellConfig) entry));
                break;
            default:
                throw UNIMPLEMENTED.withDescription("Unsupported entity type: " + entry.piEntityType()).asException();
        }
    } catch (Up4Translator.Up4TranslationException e) {
        log.warn("Failed to parse entry from a write request: {}", e.getMessage());
        throw INVALID_ARGUMENT.withDescription("Translation error: " + e.getMessage()).asException();
    } catch (UpfProgrammableException e) {
        log.warn("Failed to complete table entry insertion request: {}", e.getMessage());
        switch(e.getType()) {
            case ENTITY_EXHAUSTED:
                throw io.grpc.Status.RESOURCE_EXHAUSTED.withDescription(e.getMessage()).asException();
            case ENTITY_OUT_OF_RANGE:
                throw INVALID_ARGUMENT.withDescription(e.getMessage()).asException();
            case UNKNOWN:
            default:
                throw io.grpc.Status.UNAVAILABLE.withDescription(e.getMessage()).asException();
        }
    }
}
Also used : UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) PiMeterCellConfig(org.onosproject.net.pi.runtime.PiMeterCellConfig) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) Up4Translator(org.omecproject.up4.Up4Translator)

Example 9 with PiMeterCellConfig

use of org.onosproject.net.pi.runtime.PiMeterCellConfig 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)

Example 10 with PiMeterCellConfig

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

the class TofinoMeterProgrammableTest method testWrongIsBurstSimilar.

/**
 * Test wrong isBurstSimilar of the tofino behavior.
 */
@Test
public void testWrongIsBurstSimilar() {
    PiMeterBand onosMeterBand;
    PiMeterBand deviceMeterBand;
    PiMeterCellConfig onosMeter;
    PiMeterCellConfig deviceMeter;
    for (Map.Entry<Long, Long> entry : WRONG_BURSTS.entrySet()) {
        onosMeterBand = new PiMeterBand(PiMeterBandType.COMMITTED, 0, entry.getKey());
        deviceMeterBand = new PiMeterBand(PiMeterBandType.COMMITTED, 0, entry.getValue());
        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)

Aggregations

PiMeterCellConfig (org.onosproject.net.pi.runtime.PiMeterCellConfig)12 Test (org.junit.Test)7 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 PiMeterBand (org.onosproject.net.pi.runtime.PiMeterBand)4 Up4Translator (org.omecproject.up4.Up4Translator)2 DefaultMeter (org.onosproject.net.meter.DefaultMeter)2 Meter (org.onosproject.net.meter.Meter)2 PiMeterCellHandle (org.onosproject.net.pi.runtime.PiMeterCellHandle)2 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)2 PiTableEntry (org.onosproject.net.pi.runtime.PiTableEntry)2 WriteRequest (org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest)2 HashSet (java.util.HashSet)1 UpfEntity (org.onosproject.net.behaviour.upf.UpfEntity)1 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)1 PiMeterId (org.onosproject.net.pi.model.PiMeterId)1 PiMeterModel (org.onosproject.net.pi.model.PiMeterModel)1 PiTranslatedEntity (org.onosproject.net.pi.service.PiTranslatedEntity)1 PiTranslationException (org.onosproject.net.pi.service.PiTranslationException)1