Search in sources :

Example 1 with DefaultPortStatistics

use of org.onosproject.net.device.DefaultPortStatistics in project onos by opennetworkinglab.

the class ECDeviceStore method calcDeltaStats.

/**
 * Calculate delta statistics by subtracting previous from new statistics.
 *
 * @param deviceId device indentifier
 * @param prvStats previous port statistics
 * @param newStats new port statistics
 * @return PortStatistics
 */
public PortStatistics calcDeltaStats(DeviceId deviceId, PortStatistics prvStats, PortStatistics newStats) {
    // calculate time difference
    long deltaStatsSec, deltaStatsNano;
    if (newStats.durationNano() < prvStats.durationNano()) {
        deltaStatsNano = newStats.durationNano() - prvStats.durationNano() + TimeUnit.SECONDS.toNanos(1);
        deltaStatsSec = newStats.durationSec() - prvStats.durationSec() - 1L;
    } else {
        deltaStatsNano = newStats.durationNano() - prvStats.durationNano();
        deltaStatsSec = newStats.durationSec() - prvStats.durationSec();
    }
    DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
    DefaultPortStatistics deltaStats = builder.setDeviceId(deviceId).setPort(newStats.portNumber()).setPacketsReceived(newStats.packetsReceived() - prvStats.packetsReceived()).setPacketsSent(newStats.packetsSent() - prvStats.packetsSent()).setBytesReceived(newStats.bytesReceived() - prvStats.bytesReceived()).setBytesSent(newStats.bytesSent() - prvStats.bytesSent()).setPacketsRxDropped(newStats.packetsRxDropped() - prvStats.packetsRxDropped()).setPacketsTxDropped(newStats.packetsTxDropped() - prvStats.packetsTxDropped()).setPacketsRxErrors(newStats.packetsRxErrors() - prvStats.packetsRxErrors()).setPacketsTxErrors(newStats.packetsTxErrors() - prvStats.packetsTxErrors()).setDurationSec(deltaStatsSec).setDurationNano(deltaStatsNano).build();
    return deltaStats;
}
Also used : DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics)

Example 2 with DefaultPortStatistics

use of org.onosproject.net.device.DefaultPortStatistics in project onos by opennetworkinglab.

the class OpenFlowDeviceProvider method buildPortStatistics.

private Collection<PortStatistics> buildPortStatistics(DeviceId deviceId, List<OFPortStatsEntry> entries) {
    HashSet<PortStatistics> stats = Sets.newHashSet();
    final Dpid dpid = dpid(deviceId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    for (OFPortStatsEntry entry : entries) {
        try {
            if (entry == null || entry.getPortNo() == null || entry.getPortNo().getPortNumber() < 0) {
                continue;
            }
            DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
            boolean propSupported = entry.getVersion().getWireVersion() >= OFVersion.OF_14.getWireVersion();
            Optional<OFPortStatsPropOptical> optical = propSupported ? entry.getProperties().stream().filter(OFPortStatsPropOptical.class::isInstance).map(OFPortStatsPropOptical.class::cast).findAny() : Optional.empty();
            if (optical.isPresent()) {
                long flags = optical.get().getFlags();
                boolean useFreq = false;
                for (OFPortDesc pd : sw.getPorts()) {
                    if (pd.getPortNo().equals(entry.getPortNo())) {
                        for (OFPortDescProp prop : pd.getProperties()) {
                            if (prop instanceof OFPortDescPropOptical) {
                                OFPortDescPropOptical oprop = (OFPortDescPropOptical) prop;
                                long supported = oprop.getSupported();
                                int useFreqVal = OFOpticalPortFeaturesSerializerVer14.USE_FREQ_VAL;
                                if ((supported & useFreqVal) != 0) {
                                    useFreq = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                int txTune = OFPortStatsOpticalFlagsSerializerVer14.TX_TUNE_VAL;
                long txFreq = optical.get().getTxFreqLmda();
                long txOffset = optical.get().getTxOffset();
                long txGridSpan = optical.get().getTxGridSpan();
                annotations.set(AK_TX_TUNE_FEATURE, ((flags & txTune) != 0) ? "enabled" : "disabled");
                annotations.set(propertyFrequency ? AK_TX_FREQ_HZ : AK_TX_LMDA_NM, freqLmdaToAnnotation(txFreq, useFreq));
                annotations.set(propertyFrequency ? AK_TX_OFFSET_HZ : AK_TX_OFFSET_LMDA_NM, freqLmdaToAnnotation(txOffset, useFreq));
                annotations.set(propertyFrequency ? AK_TX_GRID_SPAN_HZ : AK_TX_GRID_SPAN_LMDA_NM, freqLmdaToAnnotation(txGridSpan, useFreq));
                int rxTune = OFPortStatsOpticalFlagsSerializerVer14.RX_TUNE_VAL;
                long rxFreq = optical.get().getRxFreqLmda();
                long rxOffset = optical.get().getRxOffset();
                long rxGridSpan = optical.get().getRxGridSpan();
                annotations.set(AK_RX_TUNE_FEATURE, ((flags & rxTune) != 0) ? "enabled" : "disabled");
                annotations.set(propertyFrequency ? AK_RX_FREQ_HZ : AK_RX_LMDA_NM, freqLmdaToAnnotation(rxFreq, useFreq));
                annotations.set(propertyFrequency ? AK_RX_OFFSET_HZ : AK_RX_OFFSET_LMDA_NM, freqLmdaToAnnotation(rxOffset, useFreq));
                annotations.set(propertyFrequency ? AK_RX_GRID_SPAN_HZ : AK_RX_GRID_SPAN_LMDA_NM, freqLmdaToAnnotation(rxGridSpan, useFreq));
                int txPwrVal = OFPortStatsOpticalFlagsSerializerVer14.TX_PWR_VAL;
                int txPwr = optical.get().getTxPwr();
                annotations.set(AK_TX_PWR_FEATURE, ((flags & txPwrVal) != 0) ? "enabled" : "disabled");
                annotations.set(AK_TX_PWR, Integer.toString(txPwr));
                int rxPwrVal = OFPortStatsOpticalFlagsSerializerVer14.RX_PWR_VAL;
                int rxPwr = optical.get().getRxPwr();
                annotations.set(AK_RX_PWR_FEATURE, ((flags & rxPwrVal) != 0) ? "enabled" : "disabled");
                annotations.set(AK_RX_PWR, Integer.toString(rxPwr));
                int txBias = OFPortStatsOpticalFlagsSerializerVer14.TX_BIAS_VAL;
                int biasCurrent = optical.get().getBiasCurrent();
                annotations.set(AK_TX_BIAS_FEATURE, ((flags & txBias) != 0) ? "enabled" : "disabled");
                annotations.set(AK_BIAS_CURRENT, Integer.toString(biasCurrent));
                int txTemp = OFPortStatsOpticalFlagsSerializerVer14.TX_TEMP_VAL;
                int temperature = optical.get().getTemperature();
                annotations.set(AK_TX_TEMP_FEATURE, ((flags & txTemp) != 0) ? "enabled" : "disabled");
                annotations.set(AK_TEMPERATURE, Integer.toString(temperature));
            }
            DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
            DefaultPortStatistics stat = builder.setDeviceId(deviceId).setPort(PortNumber.portNumber(entry.getPortNo().getPortNumber())).setPacketsReceived(entry.getRxPackets().getValue()).setPacketsSent(entry.getTxPackets().getValue()).setBytesReceived(entry.getRxBytes().getValue()).setBytesSent(entry.getTxBytes().getValue()).setPacketsRxDropped(entry.getRxDropped().getValue()).setPacketsTxDropped(entry.getTxDropped().getValue()).setPacketsRxErrors(entry.getRxErrors().getValue()).setPacketsTxErrors(entry.getTxErrors().getValue()).setDurationSec(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationSec()).setDurationNano(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationNsec()).setAnnotations(annotations.build()).build();
            stats.add(stat);
        } catch (Exception e) {
            LOG.warn("Unable to process port stats", e);
        }
    }
    return Collections.unmodifiableSet(stats);
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) Builder(org.onosproject.net.DefaultAnnotations.Builder) Dpid(org.onosproject.openflow.controller.Dpid) OFPortDescProp(org.projectfloodlight.openflow.protocol.OFPortDescProp) OFPortStatsPropOptical(org.projectfloodlight.openflow.protocol.OFPortStatsPropOptical) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics) OFPortDescPropOptical(org.projectfloodlight.openflow.protocol.OFPortDescPropOptical) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFPortStatsEntry(org.projectfloodlight.openflow.protocol.OFPortStatsEntry)

Example 3 with DefaultPortStatistics

use of org.onosproject.net.device.DefaultPortStatistics in project onos by opennetworkinglab.

the class SimpleDeviceStore method calcDeltaStats.

public PortStatistics calcDeltaStats(DeviceId deviceId, PortStatistics prvStats, PortStatistics newStats) {
    // calculate time difference
    long deltaStatsSec, deltaStatsNano;
    if (newStats.durationNano() < prvStats.durationNano()) {
        deltaStatsNano = newStats.durationNano() - prvStats.durationNano() + TimeUnit.SECONDS.toNanos(1);
        deltaStatsSec = newStats.durationSec() - prvStats.durationSec() - 1L;
    } else {
        deltaStatsNano = newStats.durationNano() - prvStats.durationNano();
        deltaStatsSec = newStats.durationSec() - prvStats.durationSec();
    }
    DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
    DefaultPortStatistics deltaStats = builder.setDeviceId(deviceId).setPort(newStats.portNumber()).setPacketsReceived(newStats.packetsReceived() - prvStats.packetsReceived()).setPacketsSent(newStats.packetsSent() - prvStats.packetsSent()).setBytesReceived(newStats.bytesReceived() - prvStats.bytesReceived()).setBytesSent(newStats.bytesSent() - prvStats.bytesSent()).setPacketsRxDropped(newStats.packetsRxDropped() - prvStats.packetsRxDropped()).setPacketsTxDropped(newStats.packetsTxDropped() - prvStats.packetsTxDropped()).setPacketsRxErrors(newStats.packetsRxErrors() - prvStats.packetsRxErrors()).setPacketsTxErrors(newStats.packetsTxErrors() - prvStats.packetsTxErrors()).setDurationSec(deltaStatsSec).setDurationNano(deltaStatsNano).build();
    return deltaStats;
}
Also used : DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics)

Example 4 with DefaultPortStatistics

use of org.onosproject.net.device.DefaultPortStatistics in project onos by opennetworkinglab.

the class GossipDeviceStore method calcDeltaStats.

/**
 * Calculate delta statistics by subtracting previous from new statistics.
 *
 * @param deviceId device identifier
 * @param prvStats previous port statistics
 * @param newStats new port statistics
 * @return PortStatistics
 */
public PortStatistics calcDeltaStats(DeviceId deviceId, PortStatistics prvStats, PortStatistics newStats) {
    // calculate time difference
    long deltaStatsSec, deltaStatsNano;
    if (newStats.durationNano() < prvStats.durationNano()) {
        deltaStatsNano = newStats.durationNano() - prvStats.durationNano() + TimeUnit.SECONDS.toNanos(1);
        deltaStatsSec = newStats.durationSec() - prvStats.durationSec() - 1L;
    } else {
        deltaStatsNano = newStats.durationNano() - prvStats.durationNano();
        deltaStatsSec = newStats.durationSec() - prvStats.durationSec();
    }
    DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
    DefaultPortStatistics deltaStats = builder.setDeviceId(deviceId).setPort(newStats.portNumber()).setPacketsReceived(newStats.packetsReceived() - prvStats.packetsReceived()).setPacketsSent(newStats.packetsSent() - prvStats.packetsSent()).setBytesReceived(newStats.bytesReceived() - prvStats.bytesReceived()).setBytesSent(newStats.bytesSent() - prvStats.bytesSent()).setPacketsRxDropped(newStats.packetsRxDropped() - prvStats.packetsRxDropped()).setPacketsTxDropped(newStats.packetsTxDropped() - prvStats.packetsTxDropped()).setPacketsRxErrors(newStats.packetsRxErrors() - prvStats.packetsRxErrors()).setPacketsTxErrors(newStats.packetsTxErrors() - prvStats.packetsTxErrors()).setDurationSec(deltaStatsSec).setDurationNano(deltaStatsNano).build();
    return deltaStats;
}
Also used : DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics)

Example 5 with DefaultPortStatistics

use of org.onosproject.net.device.DefaultPortStatistics in project onos by opennetworkinglab.

the class PortStatisticsImpl method buildStatisticsForPort.

private DefaultPortStatistics buildStatisticsForPort(JsonNode portResponse, PortNumber portNumber, DeviceId deviceId) {
    DefaultPortStatistics defaultPortStatistics = null;
    try {
        long packetsReceivedUcast = portResponse.get(IN_UCASTPKTS).asLong();
        long packetsReceivedMcast = portResponse.get(IN_MULICASTPKTS).asLong();
        long packetsReceivedBcast = portResponse.get(IN_BRODCASTPKTS).asLong();
        long packetsSentUcast = portResponse.get(OUT_UCASTPKTS).asLong();
        long packetsSentMcast = portResponse.get(OUT_MULICASTPKTS).asLong();
        long packetsSentBcast = portResponse.get(OUT_BRODCASTPKTS).asLong();
        long bytesReceived = portResponse.get(IN_OCTETS).asLong();
        long bytesSent = portResponse.get(OUT_OCTETS).asLong();
        long packetsRxDropped = portResponse.get(IN_DISCARDS).asLong();
        long packetsTxDropped = portResponse.get(OUT_DISCARDS).asLong();
        long packetsRxErrors = portResponse.get(IN_TOTALERRORS).asLong();
        long packetsTxErrors = portResponse.get(OUT_TOTALERRORS).asLong();
        double counter = portResponse.get(COUNTER).asDouble();
        long packetsSent = packetsSentUcast + packetsSentMcast + packetsSentBcast;
        long packetsReceived = packetsReceivedUcast + packetsReceivedMcast + packetsReceivedBcast;
        long counterSec = (long) counter;
        long counterNano = (long) (counter * SEC_TO_NSEC);
        DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
        defaultPortStatistics = builder.setPort(portNumber).setPacketsReceived(packetsReceived).setPacketsSent(packetsSent).setBytesReceived(bytesReceived).setBytesSent(bytesSent).setPacketsRxDropped(packetsRxDropped).setPacketsTxDropped(packetsTxDropped).setPacketsRxErrors(packetsRxErrors).setPacketsTxErrors(packetsTxErrors).setDeviceId(deviceId).setDurationSec(counterSec).setDurationNano(counterNano).setAnnotations(DefaultAnnotations.builder().build()).build();
    } catch (Exception e) {
        log.error("Cannot process port statistics calculation: {}", e.toString());
    }
    log.debug("Port statistics: {}", defaultPortStatistics);
    return defaultPortStatistics;
}
Also used : DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics)

Aggregations

DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)1 Builder (org.onosproject.net.DefaultAnnotations.Builder)1 PortStatistics (org.onosproject.net.device.PortStatistics)1 Dpid (org.onosproject.openflow.controller.Dpid)1 OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)1 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)1 OFPortDescProp (org.projectfloodlight.openflow.protocol.OFPortDescProp)1 OFPortDescPropOptical (org.projectfloodlight.openflow.protocol.OFPortDescPropOptical)1 OFPortStatsEntry (org.projectfloodlight.openflow.protocol.OFPortStatsEntry)1 OFPortStatsPropOptical (org.projectfloodlight.openflow.protocol.OFPortStatsPropOptical)1