Search in sources :

Example 6 with CodecException

use of org.onosproject.p4runtime.ctl.codec.CodecException 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)

Example 7 with CodecException

use of org.onosproject.p4runtime.ctl.codec.CodecException in project onos by opennetworkinglab.

the class StreamClientImpl method handlePacketIn.

private void handlePacketIn(P4RuntimeOuterClass.PacketIn packetInMsg) {
    if (log.isTraceEnabled()) {
        log.trace("Received packet-in from {}: {}", deviceId, packetInMsg);
    }
    if (!pipeconfService.getPipeconf(deviceId).isPresent()) {
        log.warn("Unable to handle packet-in from {}, missing pipeconf: {}", deviceId, TextFormat.shortDebugString(packetInMsg));
        return;
    }
    // Decode packet message and post event.
    // TODO: consider implementing a cache to speed up
    // encoding/deconding of packet-in/out (e.g. LLDP, ARP)
    final PiPipeconf pipeconf = pipeconfService.getPipeconf(deviceId).get();
    final PiPacketOperation pktOperation;
    try {
        pktOperation = CODECS.packetIn().decode(packetInMsg, null, pipeconf);
    } catch (CodecException e) {
        log.warn("Unable to process packet-int: {}", e.getMessage());
        return;
    }
    controller.postEvent(new P4RuntimeEvent(P4RuntimeEvent.Type.PACKET_IN, new PacketInEvent(deviceId, pktOperation)));
}
Also used : PacketInEvent(org.onosproject.p4runtime.ctl.controller.PacketInEvent) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) CodecException(org.onosproject.p4runtime.ctl.codec.CodecException) P4RuntimeEvent(org.onosproject.p4runtime.api.P4RuntimeEvent)

Aggregations

CodecException (org.onosproject.p4runtime.ctl.codec.CodecException)7 PiCounterCell (org.onosproject.net.pi.runtime.PiCounterCell)4 P4RuntimeOuterClass (p4.v1.P4RuntimeOuterClass)4 PiEntity (org.onosproject.net.pi.runtime.PiEntity)3 ArrayList (java.util.ArrayList)2 UpfEntity (org.onosproject.net.behaviour.upf.UpfEntity)2 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)2 ByteString (com.google.protobuf.ByteString)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 HexString (org.onlab.util.HexString)1 UpfCounter (org.onosproject.net.behaviour.upf.UpfCounter)1 UpfEntityType (org.onosproject.net.behaviour.upf.UpfEntityType)1 PiCounterId (org.onosproject.net.pi.model.PiCounterId)1 PiPipeconf (org.onosproject.net.pi.model.PiPipeconf)1 PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)1 P4RuntimeEvent (org.onosproject.p4runtime.api.P4RuntimeEvent)1 PacketInEvent (org.onosproject.p4runtime.ctl.controller.PacketInEvent)1 P4InfoBrowser (org.onosproject.p4runtime.ctl.utils.P4InfoBrowser)1 StreamMessageRequest (p4.v1.P4RuntimeOuterClass.StreamMessageRequest)1