Search in sources :

Example 1 with UpfProgrammable

use of org.onosproject.net.behaviour.upf.UpfProgrammable 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 UpfProgrammable

use of org.onosproject.net.behaviour.upf.UpfProgrammable 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 3 with UpfProgrammable

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

the class Up4DeviceManager method setUpfDevice.

private void setUpfDevice(DeviceId deviceId) {
    synchronized (upfInitialized) {
        UpfProgrammable upfProgrammable = upfProgrammables.get(deviceId);
        if (upfInitialized.get()) {
            log.info("UPF {} already initialized, skipping setup.", deviceId);
            // FIXME: this is merely a hotfix for interface entries disappearing when a device becomes available
            // Moreover, if the initialization is done at the very beginning, mastership could change. There could
            // be small intervals without a master and interfaces pushed could be lost. Having this call here should
            // provide more guarantee as this is also called when the pipeline is ready
            ensureInterfacesInstalled();
            // Update PSC configuration if needed
            applyPscEncap();
        } else if (!upfDevices.contains(deviceId)) {
            log.warn("UPF {} is not in the configuration!", deviceId);
        } else if (deviceService.getDevice(deviceId) == null) {
            log.warn("UPF {} currently does not exist in the device store, skip setup.", deviceId);
        } else if (!isUpfProgrammable(deviceId)) {
            log.warn("{} is not UPF physical device!", deviceId);
        } else if (upfProgrammable != null && !upfProgrammable.data().deviceId().equals(deviceId)) {
            log.warn("Change of the UPF while UPF data plane is available is not supported!");
        } else if (upfProgrammable == null) {
            log.info("Setup UPF physical device: {}", deviceId);
            upfProgrammable = deviceService.getDevice(deviceId).as(UpfProgrammable.class);
            if (!upfProgrammable.init()) {
                // error message will be printed by init()
                return;
            }
            upfProgrammables.putIfAbsent(deviceId, upfProgrammable);
            log.info("UPF physical device {} setup successful!", deviceId);
            if (upfProgrammables.keySet().containsAll(upfDevices)) {
                // Currently we don't support dynamic UPF configuration.
                // The UPF data plane is initialized when all UPF physical
                // devices have been initialized properly.
                upfInitialized.set(true);
                // Do the initial device configuration required
                installUpfEntities();
                applyPscEncap();
                // Start reconcile thread only when UPF data plane is initialized
                reconciliationTask = reconciliationExecutor.scheduleAtFixedRate(new ReconcileUpfDevices(), 0, upfReconcileInterval, TimeUnit.SECONDS);
                log.info("UPF data plane setup successful!");
            }
        }
    }
}
Also used : UpfProgrammable(org.onosproject.net.behaviour.upf.UpfProgrammable)

Example 4 with UpfProgrammable

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

the class Up4DeviceManager method ensureInterfacesInstalled.

/**
 * Ensure that all interfaces present in the UP4 config file are installed in the UPF leader device.
 */
private void ensureInterfacesInstalled() {
    log.info("Ensuring all interfaces present in app config are present on the leader device.");
    Collection<? extends UpfEntity> installedInterfaces;
    UpfProgrammable leader = getLeaderUpfProgrammable();
    try {
        installedInterfaces = leader.readAll(UpfEntityType.INTERFACE);
    } catch (UpfProgrammableException e) {
        log.warn("Failed to read interface: {}", e.getMessage());
        return;
    }
    for (UpfInterface iface : configInterfaces()) {
        if (!installedInterfaces.contains(iface)) {
            log.warn("{} is missing from leader device! Installing", iface);
            try {
                leader.apply(iface);
            } catch (UpfProgrammableException e) {
                log.warn("Failed to insert interface: {}", e.getMessage());
            }
        }
    }
}
Also used : UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) UpfInterface(org.onosproject.net.behaviour.upf.UpfInterface) UpfProgrammable(org.onosproject.net.behaviour.upf.UpfProgrammable)

Aggregations

UpfProgrammable (org.onosproject.net.behaviour.upf.UpfProgrammable)4 UpfCounter (org.onosproject.net.behaviour.upf.UpfCounter)2 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)2 UpfInterface (org.onosproject.net.behaviour.upf.UpfInterface)1