Search in sources :

Example 11 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 12 with PiMeterCellConfig

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

the class P4RuntimeMeterProgrammable method processMeterOp.

private boolean processMeterOp(MeterOperation meterOp) {
    PiMeterCellConfig piMeterCellConfig;
    final PiMeterCellHandle handle = PiMeterCellHandle.of(deviceId, (PiMeterCellId) meterOp.meter().meterCellId());
    boolean result = true;
    WRITE_LOCKS.get(deviceId).lock();
    try {
        switch(meterOp.type()) {
            case ADD:
            case MODIFY:
                // Create a config for modify operation
                try {
                    piMeterCellConfig = translator.translate(meterOp.meter(), pipeconf);
                } catch (PiTranslationException e) {
                    log.warn("Unable translate meter, aborting meter operation {}: {}", meterOp.type(), e.getMessage());
                    log.debug("exception", e);
                    return false;
                }
                translator.learn(handle, new PiTranslatedEntity<>(meterOp.meter(), piMeterCellConfig, handle));
                break;
            case REMOVE:
                // Create a empty config for reset operation
                PiMeterCellId piMeterCellId = (PiMeterCellId) meterOp.meter().meterCellId();
                piMeterCellConfig = PiMeterCellConfig.reset(piMeterCellId);
                translator.forget(handle);
                break;
            default:
                log.warn("Meter Operation type {} not supported", meterOp.type());
                return false;
        }
        WriteRequest request = client.write(p4DeviceId, pipeconf).entity(piMeterCellConfig, UpdateType.MODIFY);
        if (!request.pendingUpdates().isEmpty()) {
            result = request.submitSync().isSuccess();
        }
    } finally {
        WRITE_LOCKS.get(deviceId).unlock();
    }
    return result;
}
Also used : PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) PiMeterCellConfig(org.onosproject.net.pi.runtime.PiMeterCellConfig) WriteRequest(org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest) PiTranslationException(org.onosproject.net.pi.service.PiTranslationException) PiMeterCellHandle(org.onosproject.net.pi.runtime.PiMeterCellHandle)

Aggregations

PiMeterCellConfig (org.onosproject.net.pi.runtime.PiMeterCellConfig)12 Test (org.junit.Test)8 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 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 DefaultMeter (org.onosproject.net.meter.DefaultMeter)1 Meter (org.onosproject.net.meter.Meter)1 PiMeterId (org.onosproject.net.pi.model.PiMeterId)1 PiMeterModel (org.onosproject.net.pi.model.PiMeterModel)1 PiCounterCell (org.onosproject.net.pi.runtime.PiCounterCell)1 PiTranslationException (org.onosproject.net.pi.service.PiTranslationException)1