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;
}
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)));
}
Aggregations