Search in sources :

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

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