Search in sources :

Example 1 with UpfCounter

use of org.onosproject.net.behaviour.upf.UpfCounter in project up4 by omec-project.

the class Up4DeviceManager method readCounter.

@Override
public UpfCounter readCounter(int counterIdx) throws UpfProgrammableException {
    if (isMaxUeSet() && counterIdx >= getMaxUe() * 2) {
        throw new UpfProgrammableException("Requested PDR counter cell index above max supported UE value.", UpfProgrammableException.Type.ENTITY_OUT_OF_RANGE, UpfEntityType.COUNTER);
    }
    // When reading counters we need to explicitly read on all UPF physical
    // devices and aggregate counter values.
    assertUpfIsReady();
    // TODO: add get on builder can simply this, by removing the need for building the PdrStat every time.
    UpfCounter.Builder builder = UpfCounter.builder();
    builder.withCellId(counterIdx);
    UpfCounter prevStats = builder.build();
    for (UpfProgrammable upfProg : upfProgrammables.values()) {
        UpfCounter pdrStat = upfProg.readCounter(counterIdx);
        builder.setIngress(pdrStat.getIngressPkts() + prevStats.getIngressPkts(), pdrStat.getIngressBytes() + prevStats.getIngressBytes());
        builder.setEgress(pdrStat.getEgressPkts() + prevStats.getEgressPkts(), pdrStat.getEgressBytes() + prevStats.getEgressBytes());
        prevStats = builder.build();
    }
    builder.withCellId(counterIdx);
    return builder.build();
}
Also used : UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) UpfCounter(org.onosproject.net.behaviour.upf.UpfCounter) UpfProgrammable(org.onosproject.net.behaviour.upf.UpfProgrammable)

Example 2 with UpfCounter

use of org.onosproject.net.behaviour.upf.UpfCounter in project up4 by omec-project.

the class CounterReadCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    UpfCounter stats;
    if (deviceId != null) {
        Up4AdminService app = get(Up4AdminService.class);
        stats = app.readCounter(ctrIndex, DeviceId.deviceId(deviceId));
    } else {
        Up4Service app = get(Up4Service.class);
        stats = app.readCounter(ctrIndex);
    }
    print(stats.toString());
}
Also used : Up4Service(org.omecproject.up4.Up4Service) UpfCounter(org.onosproject.net.behaviour.upf.UpfCounter) Up4AdminService(org.omecproject.up4.impl.Up4AdminService)

Example 3 with UpfCounter

use of org.onosproject.net.behaviour.upf.UpfCounter in project up4 by omec-project.

the class Up4DeviceManager method readCounters.

@Override
public Collection<UpfCounter> readCounters(long maxCounterId) throws UpfProgrammableException {
    if (isMaxUeSet()) {
        if (maxCounterId == -1) {
            maxCounterId = getMaxUe() * 2;
        } else {
            maxCounterId = Math.min(maxCounterId, getMaxUe() * 2);
        }
    }
    // When reading counters we need to explicitly read on all UPF physical
    // devices and aggregate counter values.
    assertUpfIsReady();
    // TODO: add get on builder can simply this, by removing the need for building the PdrStat every time.
    UpfCounter.Builder builder = UpfCounter.builder();
    Map<Integer, UpfCounter> mapCounterIdStats = Maps.newHashMap();
    for (UpfProgrammable upfProg : upfProgrammables.values()) {
        Collection<UpfCounter> pdrStats = upfProg.readCounters(maxCounterId);
        pdrStats.forEach(currStat -> {
            mapCounterIdStats.compute(currStat.getCellId(), (counterId, prevStats) -> {
                if (prevStats == null) {
                    return currStat;
                }
                builder.setIngress(currStat.getIngressPkts() + prevStats.getIngressPkts(), currStat.getIngressBytes() + prevStats.getIngressBytes());
                builder.setEgress(currStat.getEgressPkts() + prevStats.getEgressPkts(), currStat.getEgressBytes() + prevStats.getEgressBytes());
                builder.withCellId(counterId);
                return builder.build();
            });
        });
    }
    return mapCounterIdStats.values();
}
Also used : UpfCounter(org.onosproject.net.behaviour.upf.UpfCounter) UpfProgrammable(org.onosproject.net.behaviour.upf.UpfProgrammable)

Example 4 with UpfCounter

use of org.onosproject.net.behaviour.upf.UpfCounter in project up4 by omec-project.

the class Up4NorthComponent method readCountersAndTranslate.

/**
 * Read the all p4 counter cell requested by the message, and translate them to p4runtime
 * entities for crafting a p4runtime read response.
 *
 * @param message a p4runtime CounterEntry message from a read request
 * @return the requested counter cells' contents, as a list of p4runtime entities
 * @throws StatusException if the counter index is out of range
 */
private List<P4RuntimeOuterClass.Entity> readCountersAndTranslate(P4RuntimeOuterClass.CounterEntry message) throws StatusException {
    ArrayList<PiCounterCell> responseCells = new ArrayList<>();
    Integer index = null;
    // FYI a counter read message with no index corresponds to a wildcard read of all indices
    if (message.hasIndex()) {
        index = (int) message.getIndex().getIndex();
    }
    String counterName = null;
    PiCounterId piCounterId = null;
    int counterId = message.getCounterId();
    // FYI a counterId of 0 corresponds to a wildcard read of all counters
    if (counterId != 0) {
        try {
            counterName = PipeconfHelper.getP4InfoBrowser(pipeconf).counters().getById(message.getCounterId()).getPreamble().getName();
            piCounterId = PiCounterId.of(counterName);
        } catch (P4InfoBrowser.NotFoundException e) {
            log.warn("Unable to find UP4 counter with ID {}", counterId);
            throw INVALID_ARGUMENT.withDescription("Invalid UP4 counter identifier.").asException();
        }
    }
    // cell was requested.
    if (counterName != null && index != null) {
        // A single counter cell was requested
        UpfCounter ctrValues;
        try {
            ctrValues = up4Service.readCounter(index);
        } catch (UpfProgrammableException e) {
            throw INVALID_ARGUMENT.withDescription(e.getMessage()).asException();
        }
        long pkts;
        long bytes;
        if (piCounterId.equals(PRE_QOS_PIPE_PRE_QOS_COUNTER)) {
            pkts = ctrValues.getIngressPkts();
            bytes = ctrValues.getIngressBytes();
        } else if (piCounterId.equals(POST_QOS_PIPE_POST_QOS_COUNTER)) {
            pkts = ctrValues.getEgressPkts();
            bytes = ctrValues.getEgressBytes();
        } else {
            log.warn("Received read request for unknown counter {}", piCounterId);
            throw INVALID_ARGUMENT.withDescription("Invalid UP4 counter identifier.").asException();
        }
        responseCells.add(new PiCounterCell(PiCounterCellId.ofIndirect(piCounterId, index), pkts, bytes));
    } else {
        // All cells were requested, either for a specific counter or all counters
        // FIXME: only read the counter that was requested, instead of both ingress and egress unconditionally
        Collection<UpfCounter> allStats;
        try {
            allStats = up4Service.readCounters(-1);
        } catch (UpfProgrammableException e) {
            throw io.grpc.Status.UNKNOWN.withDescription(e.getMessage()).asException();
        }
        for (UpfCounter stat : allStats) {
            if (piCounterId == null || piCounterId.equals(PRE_QOS_PIPE_PRE_QOS_COUNTER)) {
                // If all counters were requested, or just the ingress one
                responseCells.add(new PiCounterCell(PiCounterCellId.ofIndirect(PRE_QOS_PIPE_PRE_QOS_COUNTER, stat.getCellId()), stat.getIngressPkts(), stat.getIngressBytes()));
            }
            if (piCounterId == null || piCounterId.equals(POST_QOS_PIPE_POST_QOS_COUNTER)) {
                // If all counters were requested, or just the egress one
                responseCells.add(new PiCounterCell(PiCounterCellId.ofIndirect(POST_QOS_PIPE_POST_QOS_COUNTER, stat.getCellId()), stat.getEgressPkts(), stat.getEgressBytes()));
            }
        }
    }
    List<P4RuntimeOuterClass.Entity> responseEntities = new ArrayList<>();
    for (PiCounterCell cell : responseCells) {
        try {
            responseEntities.add(Codecs.CODECS.entity().encode(cell, null, pipeconf));
            log.trace("Encoded response to counter read request for counter {} and index {}", cell.cellId().counterId(), cell.cellId().index());
        } catch (CodecException e) {
            log.error("Unable to encode counter cell into a p4runtime entity: {}", e.getMessage());
            throw io.grpc.Status.INTERNAL.withDescription("Unable to encode counter cell into a p4runtime entity.").asException();
        }
    }
    log.debug("Encoded response to counter read request for {} cells", responseEntities.size());
    return responseEntities;
}
Also used : UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) PiEntity(org.onosproject.net.pi.runtime.PiEntity) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) HexString(org.onlab.util.HexString) UpfCounter(org.onosproject.net.behaviour.upf.UpfCounter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) PiCounterCell(org.onosproject.net.pi.runtime.PiCounterCell) CodecException(org.onosproject.p4runtime.ctl.codec.CodecException) PiCounterId(org.onosproject.net.pi.model.PiCounterId) P4InfoBrowser(org.onosproject.p4runtime.ctl.utils.P4InfoBrowser)

Aggregations

UpfCounter (org.onosproject.net.behaviour.upf.UpfCounter)4 UpfProgrammable (org.onosproject.net.behaviour.upf.UpfProgrammable)2 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)2 ByteString (com.google.protobuf.ByteString)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Up4Service (org.omecproject.up4.Up4Service)1 Up4AdminService (org.omecproject.up4.impl.Up4AdminService)1 HexString (org.onlab.util.HexString)1 UpfEntity (org.onosproject.net.behaviour.upf.UpfEntity)1 PiCounterId (org.onosproject.net.pi.model.PiCounterId)1 PiCounterCell (org.onosproject.net.pi.runtime.PiCounterCell)1 PiEntity (org.onosproject.net.pi.runtime.PiEntity)1 CodecException (org.onosproject.p4runtime.ctl.codec.CodecException)1 P4InfoBrowser (org.onosproject.p4runtime.ctl.utils.P4InfoBrowser)1