Search in sources :

Example 21 with PiTableEntry

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

Aggregations

PiTableEntry (org.onosproject.net.pi.runtime.PiTableEntry)21 Test (org.junit.Test)13 EqualsTester (com.google.common.testing.EqualsTester)6 TableEntry (p4.v1.P4RuntimeOuterClass.TableEntry)5 PiAction (org.onosproject.net.pi.runtime.PiAction)4 PiTernaryFieldMatch (org.onosproject.net.pi.runtime.PiTernaryFieldMatch)4 FlowRule (org.onosproject.net.flow.FlowRule)3 PiCounterCellData (org.onosproject.net.pi.runtime.PiCounterCellData)3 PiExactFieldMatch (org.onosproject.net.pi.runtime.PiExactFieldMatch)3 PiTableEntryHandle (org.onosproject.net.pi.runtime.PiTableEntryHandle)3 Up4Translator (org.omecproject.up4.Up4Translator)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 PiOptionalFieldMatch (org.onosproject.net.pi.runtime.PiOptionalFieldMatch)2 ImmutableList (com.google.common.collect.ImmutableList)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 Map (java.util.Map)1