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