Search in sources :

Example 1 with FlowEntryWithLoad

use of org.onosproject.net.statistic.FlowEntryWithLoad in project onos by opennetworkinglab.

the class GetFlowStatisticsCommand method doExecute.

@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    FlowStatisticService flowStatsService = get(FlowStatisticService.class);
    String deviceUri = getDeviceId(devicePort);
    String portUri = getPortNumber(devicePort);
    DeviceId ingressDeviceId = deviceId(deviceUri);
    PortNumber ingressPortNumber;
    if (portUri.length() == 0) {
        ingressPortNumber = null;
    } else {
        ingressPortNumber = portNumber(portUri);
    }
    Device device = deviceService.getDevice(ingressDeviceId);
    if (device == null) {
        error("No such device %s", ingressDeviceId.uri());
        return;
    }
    if (ingressPortNumber != null) {
        Port port = deviceService.getPort(ingressDeviceId, ingressPortNumber);
        if (port == null) {
            error("No such port %s on device %s", portUri, ingressDeviceId.uri());
            return;
        }
    }
    if (flowLiveType != null) {
        flowLiveType = flowLiveType.toUpperCase();
    }
    if (instructionType != null) {
        instructionType = instructionType.toUpperCase();
    }
    // convert String to FlowLiveType and check validity
    FlowEntry.FlowLiveType inLiveType;
    if (flowLiveType == null) {
        inLiveType = null;
    } else {
        inLiveType = getFlowLiveType(flowLiveType);
        if (inLiveType == null) {
            error("Invalid flow live type [%s] error", flowLiveType);
            return;
        }
    }
    // convert String to InstructionType and check validity
    Instruction.Type inInstructionType;
    if (instructionType == null) {
        inInstructionType = null;
    } else {
        inInstructionType = getInstructionType(instructionType);
        if (inInstructionType == null) {
            error("Invalid instruction type [%s] error", instructionType);
            return;
        }
    }
    if (showTopn != null) {
        int topn = Integer.parseInt(showTopn);
        if (topn <= 0) {
            // default value
            topn = 100;
        } else if (topn > 1000) {
            // max value
            topn = 1000;
        }
        // print show topn head line with type
        print("deviceId=%s, show TOPN=%s flows, liveType=%s, instruction type=%s", deviceUri, Integer.toString(topn), flowLiveType == null ? "ALL" : flowLiveType, instructionType == null ? "ALL" : instructionType);
        if (ingressPortNumber == null) {
            Map<ConnectPoint, List<FlowEntryWithLoad>> typedFlowLoadMap = flowStatsService.loadTopnByType(device, inLiveType, inInstructionType, topn);
            // print all ports topn flows load for a given device
            for (ConnectPoint cp : typedFlowLoadMap.keySet()) {
                printPortFlowsLoad(cp, typedFlowLoadMap.get(cp));
            }
        } else {
            List<FlowEntryWithLoad> typedFlowLoad = flowStatsService.loadTopnByType(device, ingressPortNumber, inLiveType, inInstructionType, topn);
            // print device/port topn flows load
            ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
            printPortFlowsLoad(cp, typedFlowLoad);
        }
    } else if (showAll) {
        // is true?
        // print show all head line with type
        print("deviceId=%s, show ALL flows, liveType=%s, instruction type=%s", deviceUri, flowLiveType == null ? "ALL" : flowLiveType, instructionType == null ? "ALL" : instructionType);
        if (ingressPortNumber == null) {
            Map<ConnectPoint, List<FlowEntryWithLoad>> typedFlowLoadMap = flowStatsService.loadAllByType(device, inLiveType, inInstructionType);
            // print all ports all flows load for a given device
            for (ConnectPoint cp : typedFlowLoadMap.keySet()) {
                printPortFlowsLoad(cp, typedFlowLoadMap.get(cp));
            }
        } else {
            List<FlowEntryWithLoad> typedFlowLoad = flowStatsService.loadAllByType(device, ingressPortNumber, inLiveType, inInstructionType);
            // print device/port all flows load
            ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
            printPortFlowsLoad(cp, typedFlowLoad);
        }
    } else {
        // if (showSummary == true) //always is true
        // print show summary head line
        print("deviceId=%s, show SUMMARY flows", deviceUri);
        if (ingressPortNumber == null) {
            Map<ConnectPoint, SummaryFlowEntryWithLoad> summaryFlowLoadMap = flowStatsService.loadSummary(device);
            // print all ports flow load summary for a given device
            for (ConnectPoint cp : summaryFlowLoadMap.keySet()) {
                printPortSummaryLoad(cp, summaryFlowLoadMap.get(cp));
            }
        } else {
            SummaryFlowEntryWithLoad summaryFlowLoad = flowStatsService.loadSummary(device, ingressPortNumber);
            // print device/port flow load summary
            ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
            printPortSummaryLoad(cp, summaryFlowLoad);
        }
    }
}
Also used : FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) FlowStatisticService(org.onosproject.net.statistic.FlowStatisticService) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) List(java.util.List) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) Map(java.util.Map)

Example 2 with FlowEntryWithLoad

use of org.onosproject.net.statistic.FlowEntryWithLoad in project onos by opennetworkinglab.

the class GetFlowStatisticsCommand method printPortFlowsLoad.

private void printPortFlowsLoad(ConnectPoint cp, List<FlowEntryWithLoad> typedFlowLoad) {
    print("  deviceId/Port=%s/%s, %s flows", cp.elementId(), cp.port(), typedFlowLoad.size());
    for (FlowEntryWithLoad fel : typedFlowLoad) {
        StoredFlowEntry sfe = fel.storedFlowEntry();
        print("    flowId=%s, state=%s, liveType=%s, life=%s -> %s", Long.toHexString(sfe.id().value()), sfe.state(), sfe.liveType(), sfe.life(), fel.load().isValid() ? fel.load() : "Load{rate=0, NOT VALID}");
    }
}
Also used : FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry)

Example 3 with FlowEntryWithLoad

use of org.onosproject.net.statistic.FlowEntryWithLoad in project onos by opennetworkinglab.

the class FlowStatisticManager method typedFlowEntryLoadByInstInternal.

private List<FlowEntryWithLoad> typedFlowEntryLoadByInstInternal(ConnectPoint cp, Map<FlowRule, FlowEntry> currentMap, Map<FlowRule, FlowEntry> previousMap, boolean isAllInstType, Instruction.Type instType) {
    List<FlowEntryWithLoad> fel = new ArrayList<>();
    currentMap.values().forEach(fe -> {
        if (isAllInstType || fe.treatment().allInstructions().stream().filter(i -> i.type() == instType).findAny().isPresent()) {
            long currentBytes = fe.bytes();
            long previousBytes = previousMap.getOrDefault(fe, new DefaultFlowEntry(fe)).bytes();
            long liveTypePollInterval = getLiveTypePollInterval(fe.liveType());
            Load fLoad = new DefaultLoad(currentBytes, previousBytes, liveTypePollInterval);
            fel.add(new FlowEntryWithLoad(cp, fe, fLoad));
        }
    });
    return fel;
}
Also used : SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) Comparators(org.onosproject.utils.Comparators) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) PollInterval(org.onosproject.net.statistic.PollInterval) DefaultTypedFlowEntry(org.onosproject.net.flow.DefaultTypedFlowEntry) HashMap(java.util.HashMap) ConnectPoint(org.onosproject.net.ConnectPoint) Load(org.onosproject.net.statistic.Load) ArrayList(java.util.ArrayList) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) Component(org.osgi.service.component.annotations.Component) Port(org.onosproject.net.Port) Map(java.util.Map) Activate(org.osgi.service.component.annotations.Activate) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Instruction(org.onosproject.net.flow.instructions.Instruction) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) MoreObjects(com.google.common.base.MoreObjects) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) Set(java.util.Set) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) Collectors(java.util.stream.Collectors) FlowStatisticService(org.onosproject.net.statistic.FlowStatisticService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) List(java.util.List) StatisticStore(org.onosproject.net.statistic.StatisticStore) TreeMap(java.util.TreeMap) Predicate(com.google.common.base.Predicate) FlowRule(org.onosproject.net.flow.FlowRule) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) TypedStoredFlowEntry(org.onosproject.net.flow.TypedStoredFlowEntry) STATISTIC_READ(org.onosproject.security.AppPermission.Type.STATISTIC_READ) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) Reference(org.osgi.service.component.annotations.Reference) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Load(org.onosproject.net.statistic.Load) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ArrayList(java.util.ArrayList) DefaultLoad(org.onosproject.net.statistic.DefaultLoad)

Example 4 with FlowEntryWithLoad

use of org.onosproject.net.statistic.FlowEntryWithLoad in project onos by opennetworkinglab.

the class FlowStatisticManager method loadTopnByType.

@Override
public Map<ConnectPoint, List<FlowEntryWithLoad>> loadTopnByType(Device device, FlowEntry.FlowLiveType liveType, Instruction.Type instType, int topn) {
    checkPermission(STATISTIC_READ);
    Map<ConnectPoint, List<FlowEntryWithLoad>> allLoad = new TreeMap<>(Comparators.CONNECT_POINT_COMPARATOR);
    if (device == null) {
        return allLoad;
    }
    List<Port> ports = new ArrayList<>(deviceService.getPorts(device.id()));
    for (Port port : ports) {
        ConnectPoint cp = new ConnectPoint(device.id(), port.number());
        List<FlowEntryWithLoad> fel = loadTopnPortInternal(cp, liveType, instType, topn);
        allLoad.put(cp, fel);
    }
    return allLoad;
}
Also used : SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) Port(org.onosproject.net.Port) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 5 with FlowEntryWithLoad

use of org.onosproject.net.statistic.FlowEntryWithLoad in project onos by opennetworkinglab.

the class FlowStatisticManager method loadAllByType.

@Override
public Map<ConnectPoint, List<FlowEntryWithLoad>> loadAllByType(Device device, FlowEntry.FlowLiveType liveType, Instruction.Type instType) {
    checkPermission(STATISTIC_READ);
    Map<ConnectPoint, List<FlowEntryWithLoad>> allLoad = new TreeMap<>(Comparators.CONNECT_POINT_COMPARATOR);
    if (device == null) {
        return allLoad;
    }
    List<Port> ports = new ArrayList<>(deviceService.getPorts(device.id()));
    for (Port port : ports) {
        ConnectPoint cp = new ConnectPoint(device.id(), port.number());
        List<FlowEntryWithLoad> fel = loadAllPortInternal(cp, liveType, instType);
        allLoad.put(cp, fel);
    }
    return allLoad;
}
Also used : SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) Port(org.onosproject.net.Port) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

FlowEntryWithLoad (org.onosproject.net.statistic.FlowEntryWithLoad)5 SummaryFlowEntryWithLoad (org.onosproject.net.statistic.SummaryFlowEntryWithLoad)5 List (java.util.List)4 ConnectPoint (org.onosproject.net.ConnectPoint)4 Port (org.onosproject.net.Port)4 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)3 TypedFlowEntryWithLoad (org.onosproject.net.statistic.TypedFlowEntryWithLoad)3 Map (java.util.Map)2 Device (org.onosproject.net.Device)2 PortNumber (org.onosproject.net.PortNumber)2 DeviceService (org.onosproject.net.device.DeviceService)2 FlowEntry (org.onosproject.net.flow.FlowEntry)2 Instruction (org.onosproject.net.flow.instructions.Instruction)2 FlowStatisticService (org.onosproject.net.statistic.FlowStatisticService)2 MoreObjects (com.google.common.base.MoreObjects)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Predicate (com.google.common.base.Predicate)1 ImmutableSet (com.google.common.collect.ImmutableSet)1