Search in sources :

Example 6 with UpfEntity

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;
}
Also used : UpfTerminationDownlink(org.onosproject.net.behaviour.upf.UpfTerminationDownlink) UpfMeter(org.onosproject.net.behaviour.upf.UpfMeter) Ip4Address(org.onlab.packet.Ip4Address) UpfSessionDownlink(org.onosproject.net.behaviour.upf.UpfSessionDownlink) UpfGtpTunnelPeer(org.onosproject.net.behaviour.upf.UpfGtpTunnelPeer) UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity)

Example 7 with UpfEntity

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

Aggregations

UpfEntity (org.onosproject.net.behaviour.upf.UpfEntity)7 UpfEntityType (org.onosproject.net.behaviour.upf.UpfEntityType)4 UpfMeter (org.onosproject.net.behaviour.upf.UpfMeter)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)3 UpfTerminationDownlink (org.onosproject.net.behaviour.upf.UpfTerminationDownlink)3 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Command (org.apache.karaf.shell.api.action.Command)2 Service (org.apache.karaf.shell.api.action.lifecycle.Service)2 Up4Service (org.omecproject.up4.Up4Service)2 Ip4Address (org.onlab.packet.Ip4Address)2 UpfGtpTunnelPeer (org.onosproject.net.behaviour.upf.UpfGtpTunnelPeer)2 UpfSessionDownlink (org.onosproject.net.behaviour.upf.UpfSessionDownlink)2 UpfTerminationUplink (org.onosproject.net.behaviour.upf.UpfTerminationUplink)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1