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