Search in sources :

Example 1 with UpfEntityType

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

the class ReadUpfEntitiesCommand method doExecute.

@Override
protected void doExecute() {
    Up4AdminService up4Admin = get(Up4AdminService.class);
    Up4Service up4Service = get(Up4Service.class);
    boolean filterCounters = false;
    try {
        List<UpfEntityType> printedTypes = new ArrayList<>();
        if (all) {
            printedTypes.add(UpfEntityType.APPLICATION);
            printedTypes.add(UpfEntityType.SESSION_UPLINK);
            printedTypes.add(UpfEntityType.SESSION_DOWNLINK);
            printedTypes.add(UpfEntityType.TERMINATION_UPLINK);
            printedTypes.add(UpfEntityType.TERMINATION_DOWNLINK);
            printedTypes.add(UpfEntityType.TUNNEL_PEER);
            printedTypes.add(UpfEntityType.INTERFACE);
            printedTypes.add(UpfEntityType.SESSION_METER);
            printedTypes.add(UpfEntityType.APPLICATION_METER);
            filterCounters = true;
        } else if (ue) {
            printedTypes.add(UpfEntityType.APPLICATION);
            printedTypes.add(UpfEntityType.SESSION_UPLINK);
            printedTypes.add(UpfEntityType.SESSION_DOWNLINK);
            printedTypes.add(UpfEntityType.TERMINATION_UPLINK);
            printedTypes.add(UpfEntityType.TERMINATION_DOWNLINK);
            printedTypes.add(UpfEntityType.TUNNEL_PEER);
            printedTypes.add(UpfEntityType.SESSION_METER);
            printedTypes.add(UpfEntityType.APPLICATION_METER);
            filterCounters = true;
        } else {
            if (application) {
                printedTypes.add(UpfEntityType.APPLICATION);
            }
            if (sessions) {
                printedTypes.add(UpfEntityType.SESSION_UPLINK);
                printedTypes.add(UpfEntityType.SESSION_DOWNLINK);
            }
            if (termination) {
                printedTypes.add(UpfEntityType.TERMINATION_UPLINK);
                printedTypes.add(UpfEntityType.TERMINATION_DOWNLINK);
            }
            if (tunnels) {
                printedTypes.add(UpfEntityType.TUNNEL_PEER);
            }
            if (counters) {
                printedTypes.add(UpfEntityType.COUNTER);
                filterCounters = false;
            }
            if (interfaces) {
                printedTypes.add(UpfEntityType.INTERFACE);
            }
            if (appMeters) {
                printedTypes.add(UpfEntityType.APPLICATION_METER);
            }
            if (sessMeters) {
                printedTypes.add(UpfEntityType.SESSION_METER);
            }
        }
        for (var type : printedTypes) {
            if (type.equals(UpfEntityType.TERMINATION_UPLINK)) {
                Collection<? extends UpfEntity> terminations = up4Admin.adminReadAll(type);
                for (var t : terminations) {
                    UpfTerminationUplink term = (UpfTerminationUplink) t;
                    print(term.toString());
                    if (filterCounters) {
                        print(up4Service.readCounter(term.counterId()).toString());
                    }
                }
            } else if (type.equals(UpfEntityType.TERMINATION_DOWNLINK)) {
                Collection<? extends UpfEntity> terminations = up4Admin.adminReadAll(type);
                for (var t : terminations) {
                    UpfTerminationDownlink term = (UpfTerminationDownlink) t;
                    print(term.toString());
                    if (filterCounters) {
                        print(up4Service.readCounter(term.counterId()).toString());
                    }
                }
            } else {
                up4Admin.adminReadAll(type).forEach(upfEntity -> print(upfEntity.toString()));
            }
        }
    } catch (UpfProgrammableException e) {
        print("Error while reading UPF entity: " + e.getMessage());
    }
}
Also used : UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) UpfTerminationDownlink(org.onosproject.net.behaviour.upf.UpfTerminationDownlink) Collection(java.util.Collection) Command(org.apache.karaf.shell.api.action.Command) ArrayList(java.util.ArrayList) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Up4Service(org.omecproject.up4.Up4Service) UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) Service(org.apache.karaf.shell.api.action.lifecycle.Service) UpfEntityType(org.onosproject.net.behaviour.upf.UpfEntityType) Option(org.apache.karaf.shell.api.action.Option) UpfTerminationUplink(org.onosproject.net.behaviour.upf.UpfTerminationUplink) Up4AdminService(org.omecproject.up4.impl.Up4AdminService) UpfTerminationDownlink(org.onosproject.net.behaviour.upf.UpfTerminationDownlink) ArrayList(java.util.ArrayList) UpfEntityType(org.onosproject.net.behaviour.upf.UpfEntityType) UpfTerminationUplink(org.onosproject.net.behaviour.upf.UpfTerminationUplink) Up4Service(org.omecproject.up4.Up4Service) UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) Collection(java.util.Collection) Up4AdminService(org.omecproject.up4.impl.Up4AdminService)

Example 2 with UpfEntityType

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

the class Up4DeviceManager method deleteAll.

@Override
public void deleteAll(UpfEntityType entityType) throws UpfProgrammableException {
    switch(entityType) {
        case TERMINATION_DOWNLINK:
            getLeaderUpfProgrammable().deleteAll(entityType);
            up4Store.reset();
            break;
        case INTERFACE:
            Collection<? extends UpfEntity> intfs = getLeaderUpfProgrammable().readAll(UpfEntityType.INTERFACE).stream().filter(t -> !((UpfInterface) t).isDbufReceiver()).collect(Collectors.toList());
            for (UpfEntity i : intfs) {
                getLeaderUpfProgrammable().delete(i);
            }
            break;
        case TUNNEL_PEER:
            Collection<? extends UpfEntity> tunnels = getLeaderUpfProgrammable().readAll(UpfEntityType.TUNNEL_PEER).stream().filter(t -> ((UpfGtpTunnelPeer) t).tunPeerId() != DBUF_TUNNEL_ID).collect(Collectors.toList());
            for (UpfEntity tun : tunnels) {
                getLeaderUpfProgrammable().delete(tun);
            }
            break;
        default:
            getLeaderUpfProgrammable().deleteAll(entityType);
    }
}
Also used : Up4Config(org.omecproject.up4.config.Up4Config) UpfMeter(org.onosproject.net.behaviour.upf.UpfMeter) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) DeviceService(org.onosproject.net.device.DeviceService) APP_SUBJECT_FACTORY(org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY) Future(java.util.concurrent.Future) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Pair(org.apache.commons.lang3.tuple.Pair) MeterCellId(org.onosproject.net.meter.MeterCellId) MeterService(org.onosproject.net.meter.MeterService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) MastershipService(org.onosproject.mastership.MastershipService) APPLICATION_METER(org.onosproject.net.behaviour.upf.UpfEntityType.APPLICATION_METER) Up4DbufConfig(org.omecproject.up4.config.Up4DbufConfig) Ip4Address(org.onlab.packet.Ip4Address) UpfDevice(org.onosproject.net.behaviour.upf.UpfDevice) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) UpfInterface(org.onosproject.net.behaviour.upf.UpfInterface) ConfigFactory(org.onosproject.net.config.ConfigFactory) DeviceEvent(org.onosproject.net.device.DeviceEvent) SESSION_DOWNLINK(org.onosproject.net.behaviour.upf.UpfEntityType.SESSION_DOWNLINK) TERMINATION_UPLINK(org.onosproject.net.behaviour.upf.UpfEntityType.TERMINATION_UPLINK) Tools.getLongProperty(org.onlab.util.Tools.getLongProperty) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) DbufClient(org.omecproject.dbuf.client.DbufClient) MeterRequest(org.onosproject.net.meter.MeterRequest) TUNNEL_PEER(org.onosproject.net.behaviour.upf.UpfEntityType.TUNNEL_PEER) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent) ComponentContext(org.osgi.service.component.ComponentContext) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) Up4Service(org.omecproject.up4.Up4Service) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) UpfCounter(org.onosproject.net.behaviour.upf.UpfCounter) StreamSupport(java.util.stream.StreamSupport) UpfEntityType(org.onosproject.net.behaviour.upf.UpfEntityType) FlowRuleListener(org.onosproject.net.flow.FlowRuleListener) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) UPF_RECONCILE_INTERVAL(org.omecproject.up4.impl.OsgiPropertyConstants.UPF_RECONCILE_INTERVAL) DeviceListener(org.onosproject.net.device.DeviceListener) Meter(org.onosproject.net.meter.Meter) Properties(java.util.Properties) TERMINATION_DOWNLINK(org.onosproject.net.behaviour.upf.UpfEntityType.TERMINATION_DOWNLINK) UpfTerminationUplink(org.onosproject.net.behaviour.upf.UpfTerminationUplink) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) UpfProgrammable(org.onosproject.net.behaviour.upf.UpfProgrammable) DefaultMeter(org.onosproject.net.meter.DefaultMeter) Context(io.grpc.Context) UpfTerminationDownlink(org.onosproject.net.behaviour.upf.UpfTerminationDownlink) CoreService(org.onosproject.core.CoreService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Up4EventListener(org.omecproject.up4.Up4EventListener) ByteBuffer(java.nio.ByteBuffer) PiPipeconfEvent(org.onosproject.net.pi.service.PiPipeconfEvent) UpfGtpTunnelPeer(org.onosproject.net.behaviour.upf.UpfGtpTunnelPeer) UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) DEFAULT_SLICE_ID(org.omecproject.up4.impl.AppConstants.DEFAULT_SLICE_ID) DefaultDbufClient(org.omecproject.dbuf.client.DefaultDbufClient) Ip4Prefix(org.onlab.packet.Ip4Prefix) MeterEvent(org.onosproject.net.meter.MeterEvent) MeterScope(org.onosproject.net.meter.MeterScope) AbstractListenerManager(org.onosproject.event.AbstractListenerManager) Device(org.onosproject.net.Device) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) PiPipeconfListener(org.onosproject.net.pi.service.PiPipeconfListener) UPF_RECONCILE_INTERVAL_DEFAULT(org.omecproject.up4.impl.OsgiPropertyConstants.UPF_RECONCILE_INTERVAL_DEFAULT) SESSION_METER(org.onosproject.net.behaviour.upf.UpfEntityType.SESSION_METER) PiPipeconfService(org.onosproject.net.pi.service.PiPipeconfService) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MeterListener(org.onosproject.net.meter.MeterListener) Activate(org.osgi.service.component.annotations.Activate) ExecutorService(java.util.concurrent.ExecutorService) UpfSessionDownlink(org.onosproject.net.behaviour.upf.UpfSessionDownlink) UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) Logger(org.slf4j.Logger) Up4Event(org.omecproject.up4.Up4Event) Maps(com.google.common.collect.Maps) MeterState(org.onosproject.net.meter.MeterState) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest) Modified(org.osgi.service.component.annotations.Modified) Reference(org.osgi.service.component.annotations.Reference) COUNTER(org.onosproject.net.behaviour.upf.UpfEntityType.COUNTER) UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity)

Example 3 with UpfEntityType

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

ArrayList (java.util.ArrayList)3 UpfEntity (org.onosproject.net.behaviour.upf.UpfEntity)3 UpfEntityType (org.onosproject.net.behaviour.upf.UpfEntityType)3 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)3 Collection (java.util.Collection)2 List (java.util.List)2 Up4Service (org.omecproject.up4.Up4Service)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Context (io.grpc.Context)1 ByteBuffer (java.nio.ByteBuffer)1 Dictionary (java.util.Dictionary)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)1 Future (java.util.concurrent.Future)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1