Search in sources :

Example 1 with SummaryFlowEntryWithLoad

use of org.onosproject.net.statistic.SummaryFlowEntryWithLoad 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 SummaryFlowEntryWithLoad

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

the class FlowStatisticManager method loadSummaryPortInternal.

private SummaryFlowEntryWithLoad loadSummaryPortInternal(ConnectPoint cp) {
    checkPermission(STATISTIC_READ);
    Set<FlowEntry> currentStats;
    Set<FlowEntry> previousStats;
    TypedStatistics typedStatistics;
    synchronized (statisticStore) {
        currentStats = statisticStore.getCurrentStatistic(cp);
        if (currentStats == null) {
            return new SummaryFlowEntryWithLoad(cp, new DefaultLoad());
        }
        previousStats = statisticStore.getPreviousStatistic(cp);
        if (previousStats == null) {
            return new SummaryFlowEntryWithLoad(cp, new DefaultLoad());
        }
        // copy to local flow entry
        typedStatistics = new TypedStatistics(currentStats, previousStats);
        // Check for validity of this stats data
        checkLoadValidity(currentStats, previousStats);
    }
    // current and previous set is not empty!
    Set<FlowEntry> currentSet = typedStatistics.current();
    Set<FlowEntry> previousSet = typedStatistics.previous();
    PollInterval pollIntervalInstance = PollInterval.getInstance();
    // We assume that default pollInterval is flowPollFrequency in case adaptiveFlowSampling is true or false
    Load totalLoad = new DefaultLoad(aggregateBytesSet(currentSet), aggregateBytesSet(previousSet), pollIntervalInstance.getPollInterval());
    Map<FlowRule, FlowEntry> currentMap;
    Map<FlowRule, FlowEntry> previousMap;
    currentMap = typedStatistics.currentImmediate();
    previousMap = typedStatistics.previousImmediate();
    Load immediateLoad = new DefaultLoad(aggregateBytesMap(currentMap), aggregateBytesMap(previousMap), pollIntervalInstance.getPollInterval());
    currentMap = typedStatistics.currentShort();
    previousMap = typedStatistics.previousShort();
    Load shortLoad = new DefaultLoad(aggregateBytesMap(currentMap), aggregateBytesMap(previousMap), pollIntervalInstance.getPollInterval());
    currentMap = typedStatistics.currentMid();
    previousMap = typedStatistics.previousMid();
    Load midLoad = new DefaultLoad(aggregateBytesMap(currentMap), aggregateBytesMap(previousMap), pollIntervalInstance.getMidPollInterval());
    currentMap = typedStatistics.currentLong();
    previousMap = typedStatistics.previousLong();
    Load longLoad = new DefaultLoad(aggregateBytesMap(currentMap), aggregateBytesMap(previousMap), pollIntervalInstance.getLongPollInterval());
    currentMap = typedStatistics.currentUnknown();
    previousMap = typedStatistics.previousUnknown();
    Load unknownLoad = new DefaultLoad(aggregateBytesMap(currentMap), aggregateBytesMap(previousMap), pollIntervalInstance.getPollInterval());
    return new SummaryFlowEntryWithLoad(cp, totalLoad, immediateLoad, shortLoad, midLoad, longLoad, unknownLoad);
}
Also used : 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) PollInterval(org.onosproject.net.statistic.PollInterval) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultTypedFlowEntry(org.onosproject.net.flow.DefaultTypedFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) TypedStoredFlowEntry(org.onosproject.net.flow.TypedStoredFlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultLoad(org.onosproject.net.statistic.DefaultLoad)

Example 3 with SummaryFlowEntryWithLoad

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

the class FlowStatisticManager method loadSummary.

@Override
public Map<ConnectPoint, SummaryFlowEntryWithLoad> loadSummary(Device device) {
    checkPermission(STATISTIC_READ);
    Map<ConnectPoint, SummaryFlowEntryWithLoad> summaryLoad = new TreeMap<>(Comparators.CONNECT_POINT_COMPARATOR);
    if (device == null) {
        return summaryLoad;
    }
    List<Port> ports = new ArrayList<>(deviceService.getPorts(device.id()));
    for (Port port : ports) {
        ConnectPoint cp = new ConnectPoint(device.id(), port.number());
        SummaryFlowEntryWithLoad sfe = loadSummaryPortInternal(cp);
        summaryLoad.put(cp, sfe);
    }
    return summaryLoad;
}
Also used : Port(org.onosproject.net.Port) ArrayList(java.util.ArrayList) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) TreeMap(java.util.TreeMap) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

SummaryFlowEntryWithLoad (org.onosproject.net.statistic.SummaryFlowEntryWithLoad)3 ConnectPoint (org.onosproject.net.ConnectPoint)2 Port (org.onosproject.net.Port)2 FlowEntry (org.onosproject.net.flow.FlowEntry)2 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)2 FlowEntryWithLoad (org.onosproject.net.statistic.FlowEntryWithLoad)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Device (org.onosproject.net.Device)1 DeviceId (org.onosproject.net.DeviceId)1 PortNumber (org.onosproject.net.PortNumber)1 DeviceService (org.onosproject.net.device.DeviceService)1 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)1 DefaultTypedFlowEntry (org.onosproject.net.flow.DefaultTypedFlowEntry)1 FlowRule (org.onosproject.net.flow.FlowRule)1 TypedStoredFlowEntry (org.onosproject.net.flow.TypedStoredFlowEntry)1 Instruction (org.onosproject.net.flow.instructions.Instruction)1 DefaultLoad (org.onosproject.net.statistic.DefaultLoad)1