Search in sources :

Example 1 with UpfEntity

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

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

the class Up4DeviceManager method getUplinkFlows.

@Override
public Collection<UplinkUpfFlow> getUplinkFlows() throws UpfProgrammableException {
    Collection<UplinkUpfFlow> uplinkFlows = Lists.newArrayList();
    Collection<? extends UpfEntity> uplinkTerm = this.adminReadAll(TERMINATION_UPLINK);
    Map<Integer, UpfMeter> appMeters = Maps.newHashMap();
    this.adminReadAll(APPLICATION_METER).forEach(am -> appMeters.put(((UpfMeter) am).cellId(), (UpfMeter) am));
    for (UpfEntity t : uplinkTerm) {
        UpfTerminationUplink term = (UpfTerminationUplink) t;
        uplinkFlows.add(UplinkUpfFlow.builder().withTerminationUplink(term).withCounter(this.readCounter(term.counterId())).withAppMeter(appMeters.getOrDefault(term.appMeterIdx(), null)).build());
    }
    return uplinkFlows;
}
Also used : UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) UpfMeter(org.onosproject.net.behaviour.upf.UpfMeter) UpfTerminationUplink(org.onosproject.net.behaviour.upf.UpfTerminationUplink)

Example 3 with UpfEntity

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

the class Up4TranslatorImplTest method up4ToUpfEntity.

public UpfEntity up4ToUpfEntity(UpfEntity expected, PiEntity up4Entry) {
    UpfEntity translatedEntity;
    try {
        switch(up4Entry.piEntityType()) {
            case TABLE_ENTRY:
                translatedEntity = up4Translator.up4TableEntryToUpfEntity((PiTableEntry) up4Entry);
                break;
            case METER_CELL_CONFIG:
                translatedEntity = up4Translator.up4MeterEntryToUpfEntity((PiMeterCellConfig) up4Entry);
                break;
            default:
                assertThat("Unsupported PI entity!", false);
                return null;
        }
    } catch (Up4Translator.Up4TranslationException e) {
        assertThat("UP4 table entry should translate to UPF entity without error.", false);
        return null;
    }
    assertThat(translatedEntity, equalTo(expected));
    return translatedEntity;
}
Also used : UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) PiMeterCellConfig(org.onosproject.net.pi.runtime.PiMeterCellConfig) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) Up4Translator(org.omecproject.up4.Up4Translator)

Example 4 with UpfEntity

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

the class ReadFlowsCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    Up4AdminService adminService = get(Up4AdminService.class);
    Collection<DownlinkUpfFlow> dlUpfFlow = adminService.getDownlinkFlows();
    Collection<UplinkUpfFlow> ulUpfFlow = adminService.getUplinkFlows();
    Collection<? extends UpfEntity> ulSess = adminService.adminReadAll(UpfEntityType.SESSION_UPLINK);
    Collection<? extends UpfEntity> appFilters = adminService.adminReadAll(UpfEntityType.APPLICATION);
    // Get session and app meter only to show the number of meters
    Collection<? extends UpfEntity> sessMeters = adminService.adminReadAll(UpfEntityType.SESSION_METER);
    Map<Integer, UpfMeter> sessMeterMap = sessMeters.stream().map(m -> (UpfMeter) m).collect(Collectors.toMap(UpfMeter::cellId, m -> m));
    Collection<? extends UpfEntity> appMeters = adminService.adminReadAll(UpfEntityType.APPLICATION_METER);
    print(SEPARATOR);
    print(appFilters.size() + " Applications");
    for (UpfEntity a : appFilters) {
        if (!a.type().equals(UpfEntityType.APPLICATION)) {
            print("ERROR: Wrong application filter: " + a);
            continue;
        }
        UpfApplication app = (UpfApplication) a;
        print("app_id=" + app.appId() + ", ipv4_prefix=" + app.ip4Prefix() + ", l4_range=" + app.l4PortRange() + ", ip_proto=" + app.ipProto());
    }
    print(SEPARATOR);
    print(ulSess.size() + " Uplink Sessions");
    for (UpfEntity s : ulSess) {
        if (!s.type().equals(UpfEntityType.SESSION_UPLINK)) {
            print("ERROR: Wrong uplink session: " + s);
            continue;
        }
        UpfSessionUplink sess = (UpfSessionUplink) s;
        print("n3_addr=" + sess.tunDstAddr() + ", teid=" + sess.teid() + (sess.needsDropping() ? ", drop()" : ", fwd(" + "sess_meter_idx=" + sess.sessionMeterIdx() + ")"));
        UpfMeter sessMeter = sessMeterMap.getOrDefault(sess.sessionMeterIdx(), null);
        if (sessMeter == null) {
            print("    NO SESSION METER (sess_meter_idx=" + sess.sessionMeterIdx() + ")");
        } else {
            print("    Session meter: " + ppUpfMeter(sessMeter));
        }
    }
    print(SEPARATOR);
    print(ulUpfFlow.size() + " Uplink Flows");
    for (UplinkUpfFlow f : ulUpfFlow) {
        print(f.toString());
    }
    print(SEPARATOR);
    print(dlUpfFlow.size() + " Downlink Flows");
    for (DownlinkUpfFlow f : dlUpfFlow) {
        print(f.toString());
    }
    print(SEPARATOR);
    print("Apps=%d, UL sess=%d, UL flows=%d, DL flows=%s", appFilters.size(), ulSess.size(), ulUpfFlow.size(), dlUpfFlow.size());
    print("App meters=%d, Sess meters=%d", appMeters.size(), sessMeters.size());
}
Also used : UpfMeter(org.onosproject.net.behaviour.upf.UpfMeter) Collection(java.util.Collection) DownlinkUpfFlow(org.omecproject.up4.impl.DownlinkUpfFlow) UpfSessionUplink(org.onosproject.net.behaviour.upf.UpfSessionUplink) Collectors(java.util.stream.Collectors) Command(org.apache.karaf.shell.api.action.Command) Up4Utils.ppUpfMeter(org.omecproject.up4.impl.Up4Utils.ppUpfMeter) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) UplinkUpfFlow(org.omecproject.up4.impl.UplinkUpfFlow) UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) Map(java.util.Map) Service(org.apache.karaf.shell.api.action.lifecycle.Service) UpfEntityType(org.onosproject.net.behaviour.upf.UpfEntityType) UpfApplication(org.onosproject.net.behaviour.upf.UpfApplication) Up4AdminService(org.omecproject.up4.impl.Up4AdminService) UpfSessionUplink(org.onosproject.net.behaviour.upf.UpfSessionUplink) DownlinkUpfFlow(org.omecproject.up4.impl.DownlinkUpfFlow) UpfMeter(org.onosproject.net.behaviour.upf.UpfMeter) Up4Utils.ppUpfMeter(org.omecproject.up4.impl.Up4Utils.ppUpfMeter) UpfApplication(org.onosproject.net.behaviour.upf.UpfApplication) UplinkUpfFlow(org.omecproject.up4.impl.UplinkUpfFlow) UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) Up4AdminService(org.omecproject.up4.impl.Up4AdminService)

Example 5 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)

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