use of org.onosproject.net.behaviour.upf.UpfEntity in project up4 by omec-project.
the class Up4DeviceManager method getDownlinkFlows.
@Override
public Collection<DownlinkUpfFlow> getDownlinkFlows() throws UpfProgrammableException {
Collection<DownlinkUpfFlow> downlinkFlows = Lists.newArrayList();
Map<Ip4Address, UpfSessionDownlink> ueToSess = Maps.newHashMap();
Map<Byte, UpfGtpTunnelPeer> idToTunn = Maps.newHashMap();
Map<Integer, UpfMeter> sessMeters = Maps.newHashMap();
Map<Integer, UpfMeter> appMeters = Maps.newHashMap();
Collection<? extends UpfEntity> downlinkTerm = this.adminReadAll(TERMINATION_DOWNLINK);
this.adminReadAll(SESSION_DOWNLINK).forEach(s -> ueToSess.put(((UpfSessionDownlink) s).ueAddress(), (UpfSessionDownlink) s));
this.adminReadAll(TUNNEL_PEER).forEach(t -> idToTunn.put(((UpfGtpTunnelPeer) t).tunPeerId(), (UpfGtpTunnelPeer) t));
this.adminReadAll(SESSION_METER).forEach(sm -> sessMeters.put(((UpfMeter) sm).cellId(), (UpfMeter) sm));
this.adminReadAll(APPLICATION_METER).forEach(am -> appMeters.put(((UpfMeter) am).cellId(), (UpfMeter) am));
for (UpfEntity t : downlinkTerm) {
UpfTerminationDownlink term = (UpfTerminationDownlink) t;
UpfSessionDownlink sess = ueToSess.getOrDefault(term.ueSessionId(), null);
UpfGtpTunnelPeer tunn = null;
UpfMeter sMeter = null;
UpfMeter aMeter = null;
if (sess != null) {
tunn = idToTunn.getOrDefault(sess.tunPeerId(), null);
sMeter = sessMeters.getOrDefault(sess.sessionMeterIdx(), null);
}
aMeter = appMeters.getOrDefault(term.appMeterIdx(), null);
downlinkFlows.add(DownlinkUpfFlow.builder().withTerminationDownlink(term).withSessionDownlink(sess).withTunnelPeer(tunn).withCounter(this.readCounter(term.counterId())).withAppMeter(aMeter).withSessionMeter(sMeter).build());
}
return downlinkFlows;
}
use of org.onosproject.net.behaviour.upf.UpfEntity 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