Search in sources :

Example 1 with PiEntity

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

the class DistributedPiTranslationStoreTest method setUp.

/**
 * Sets up the store and the storage service test harness.
 */
@Before
public void setUp() {
    store = new AbstractDistributedPiTranslationStore<PiTranslatable, PiEntity>() {

        @Override
        protected String mapSimpleName() {
            return "test";
        }
    };
    store.storageService = new TestStorageService();
    store.setDelegate(event -> {
    });
    store.activate();
}
Also used : PiTranslatable(org.onosproject.net.pi.service.PiTranslatable) PiEntity(org.onosproject.net.pi.runtime.PiEntity) TestStorageService(org.onosproject.store.service.TestStorageService) Before(org.junit.Before)

Example 2 with PiEntity

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

the class Up4NorthComponentTest method entityToCounterCell.

private PiCounterCell entityToCounterCell(P4RuntimeOuterClass.Entity entity) {
    PiEntity responsePiEntity;
    try {
        responsePiEntity = Codecs.CODECS.entity().decode(entity, null, pipeconf);
    } catch (CodecException e) {
        fail("Unable to decode p4runtime entity from read response.");
        return null;
    }
    assertThat(responsePiEntity.piEntityType(), equalTo(PiEntityType.COUNTER_CELL));
    return (PiCounterCell) responsePiEntity;
}
Also used : PiEntity(org.onosproject.net.pi.runtime.PiEntity) PiCounterCell(org.onosproject.net.pi.runtime.PiCounterCell) CodecException(org.onosproject.p4runtime.ctl.codec.CodecException)

Example 3 with PiEntity

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

the class Up4TranslatorImplTest method upfEntityToUp4.

public PiEntity upfEntityToUp4(PiEntity expected, UpfEntity up4Entry) {
    PiEntity translatedEntity;
    try {
        switch(up4Entry.type()) {
            case INTERFACE:
            case TERMINATION_DOWNLINK:
            case TERMINATION_UPLINK:
            case SESSION_DOWNLINK:
            case SESSION_UPLINK:
            case TUNNEL_PEER:
            case COUNTER:
            case APPLICATION:
                translatedEntity = up4Translator.upfEntityToUp4TableEntry(up4Entry);
                break;
            case SESSION_METER:
            case APPLICATION_METER:
                translatedEntity = up4Translator.upfEntityToUp4MeterEntry(up4Entry);
                break;
            default:
                assertThat("Unsupported UPF entity!", false);
                return null;
        }
    } catch (Up4Translator.Up4TranslationException e) {
        assertThat("UPF entity should correctly translate to UP4 table " + "entry or meter entry without error.\n" + e.getMessage(), false);
        return null;
    }
    assertThat(translatedEntity, equalTo(expected));
    return translatedEntity;
}
Also used : PiEntity(org.onosproject.net.pi.runtime.PiEntity) Up4Translator(org.omecproject.up4.Up4Translator)

Example 4 with PiEntity

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

the class Up4NorthComponent method readEntriesAndTranslate.

/**
 * Find all table entries or meter entries that match the requested entry,
 * and translate them to p4runtime entities for responding to a read request.
 *
 * @param requestedEntry the entry from a p4runtime read request
 * @return all entries that match the request, translated to p4runtime entities
 * @throws StatusException if the requested entry fails translation
 */
private List<P4RuntimeOuterClass.Entity> readEntriesAndTranslate(PiEntity requestedEntry) throws StatusException {
    List<P4RuntimeOuterClass.Entity> translatedEntries = new ArrayList<>();
    // TODO: return more specific responses matching the requested entry
    try {
        UpfEntityType entityType = up4Translator.getEntityType(requestedEntry);
        boolean isMeter = entityType.equals(UpfEntityType.SESSION_METER) || entityType.equals(UpfEntityType.APPLICATION_METER);
        Collection<? extends UpfEntity> entities = up4Service.readAll(entityType);
        for (UpfEntity entity : entities) {
            log.debug("Translating a {} entity for a read request: {}", entity.type(), entity);
            P4RuntimeOuterClass.Entity responseEntity;
            if (isMeter) {
                responseEntity = Codecs.CODECS.entity().encode(up4Translator.upfEntityToUp4MeterEntry(entity), null, pipeconf);
            } else {
                responseEntity = Codecs.CODECS.entity().encode(up4Translator.upfEntityToUp4TableEntry(entity), null, pipeconf);
            }
            translatedEntries.add(responseEntity);
        }
    } catch (Up4Translator.Up4TranslationException | UpfProgrammableException | CodecException e) {
        log.warn("Unable to encode/translate a read entry to a UP4 read response: {}", e.getMessage());
        throw INVALID_ARGUMENT.withDescription("Unable to translate a read table entry to a p4runtime entity.").asException();
    }
    return translatedEntries;
}
Also used : UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) PiEntity(org.onosproject.net.pi.runtime.PiEntity) P4RuntimeOuterClass(p4.v1.P4RuntimeOuterClass) ArrayList(java.util.ArrayList) UpfEntityType(org.onosproject.net.behaviour.upf.UpfEntityType) UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) CodecException(org.onosproject.p4runtime.ctl.codec.CodecException)

Aggregations

PiEntity (org.onosproject.net.pi.runtime.PiEntity)4 CodecException (org.onosproject.p4runtime.ctl.codec.CodecException)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Up4Translator (org.omecproject.up4.Up4Translator)1 UpfEntity (org.onosproject.net.behaviour.upf.UpfEntity)1 UpfEntityType (org.onosproject.net.behaviour.upf.UpfEntityType)1 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)1 PiCounterCell (org.onosproject.net.pi.runtime.PiCounterCell)1 PiTranslatable (org.onosproject.net.pi.service.PiTranslatable)1 TestStorageService (org.onosproject.store.service.TestStorageService)1 P4RuntimeOuterClass (p4.v1.P4RuntimeOuterClass)1