use of org.onosproject.net.behaviour.upf.UpfEntityType in project up4 by omec-project.
the class ReadUpfEntitiesCommand method doExecute.
@Override
protected void doExecute() {
Up4AdminService up4Admin = get(Up4AdminService.class);
Up4Service up4Service = get(Up4Service.class);
boolean filterCounters = false;
try {
List<UpfEntityType> printedTypes = new ArrayList<>();
if (all) {
printedTypes.add(UpfEntityType.APPLICATION);
printedTypes.add(UpfEntityType.SESSION_UPLINK);
printedTypes.add(UpfEntityType.SESSION_DOWNLINK);
printedTypes.add(UpfEntityType.TERMINATION_UPLINK);
printedTypes.add(UpfEntityType.TERMINATION_DOWNLINK);
printedTypes.add(UpfEntityType.TUNNEL_PEER);
printedTypes.add(UpfEntityType.INTERFACE);
printedTypes.add(UpfEntityType.SESSION_METER);
printedTypes.add(UpfEntityType.APPLICATION_METER);
filterCounters = true;
} else if (ue) {
printedTypes.add(UpfEntityType.APPLICATION);
printedTypes.add(UpfEntityType.SESSION_UPLINK);
printedTypes.add(UpfEntityType.SESSION_DOWNLINK);
printedTypes.add(UpfEntityType.TERMINATION_UPLINK);
printedTypes.add(UpfEntityType.TERMINATION_DOWNLINK);
printedTypes.add(UpfEntityType.TUNNEL_PEER);
printedTypes.add(UpfEntityType.SESSION_METER);
printedTypes.add(UpfEntityType.APPLICATION_METER);
filterCounters = true;
} else {
if (application) {
printedTypes.add(UpfEntityType.APPLICATION);
}
if (sessions) {
printedTypes.add(UpfEntityType.SESSION_UPLINK);
printedTypes.add(UpfEntityType.SESSION_DOWNLINK);
}
if (termination) {
printedTypes.add(UpfEntityType.TERMINATION_UPLINK);
printedTypes.add(UpfEntityType.TERMINATION_DOWNLINK);
}
if (tunnels) {
printedTypes.add(UpfEntityType.TUNNEL_PEER);
}
if (counters) {
printedTypes.add(UpfEntityType.COUNTER);
filterCounters = false;
}
if (interfaces) {
printedTypes.add(UpfEntityType.INTERFACE);
}
if (appMeters) {
printedTypes.add(UpfEntityType.APPLICATION_METER);
}
if (sessMeters) {
printedTypes.add(UpfEntityType.SESSION_METER);
}
}
for (var type : printedTypes) {
if (type.equals(UpfEntityType.TERMINATION_UPLINK)) {
Collection<? extends UpfEntity> terminations = up4Admin.adminReadAll(type);
for (var t : terminations) {
UpfTerminationUplink term = (UpfTerminationUplink) t;
print(term.toString());
if (filterCounters) {
print(up4Service.readCounter(term.counterId()).toString());
}
}
} else if (type.equals(UpfEntityType.TERMINATION_DOWNLINK)) {
Collection<? extends UpfEntity> terminations = up4Admin.adminReadAll(type);
for (var t : terminations) {
UpfTerminationDownlink term = (UpfTerminationDownlink) t;
print(term.toString());
if (filterCounters) {
print(up4Service.readCounter(term.counterId()).toString());
}
}
} else {
up4Admin.adminReadAll(type).forEach(upfEntity -> print(upfEntity.toString()));
}
}
} catch (UpfProgrammableException e) {
print("Error while reading UPF entity: " + e.getMessage());
}
}
use of org.onosproject.net.behaviour.upf.UpfEntityType in project up4 by omec-project.
the class Up4DeviceManager method deleteAll.
@Override
public void deleteAll(UpfEntityType entityType) throws UpfProgrammableException {
switch(entityType) {
case TERMINATION_DOWNLINK:
getLeaderUpfProgrammable().deleteAll(entityType);
up4Store.reset();
break;
case INTERFACE:
Collection<? extends UpfEntity> intfs = getLeaderUpfProgrammable().readAll(UpfEntityType.INTERFACE).stream().filter(t -> !((UpfInterface) t).isDbufReceiver()).collect(Collectors.toList());
for (UpfEntity i : intfs) {
getLeaderUpfProgrammable().delete(i);
}
break;
case TUNNEL_PEER:
Collection<? extends UpfEntity> tunnels = getLeaderUpfProgrammable().readAll(UpfEntityType.TUNNEL_PEER).stream().filter(t -> ((UpfGtpTunnelPeer) t).tunPeerId() != DBUF_TUNNEL_ID).collect(Collectors.toList());
for (UpfEntity tun : tunnels) {
getLeaderUpfProgrammable().delete(tun);
}
break;
default:
getLeaderUpfProgrammable().deleteAll(entityType);
}
}
use of org.onosproject.net.behaviour.upf.UpfEntityType 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