package org.kne.cloud.network.monitor;

import org.kne.math.Long128;

/**
     * 流量统计信息类
     */
    public class TrafficStats {
        public long packetCount;
        public long totalBytes;
        public Long128 earliestTimestamp;
        public Long128 latestTimestamp;
        public long timeWindowNs;
        public Long128 currentTime;
        
        public TrafficStats() {
            this.packetCount = 0;
            this.totalBytes = 0;
            this.earliestTimestamp =Long128.ZERO;
            this.latestTimestamp = Long128.ZERO;
            this.timeWindowNs = 0;
            this.currentTime = Long128.ZERO;
        }
        
        public long getPacketsPerSecond() {
            return (long) (timeWindowNs > 0 ? (packetCount * 1e9) / timeWindowNs : 0.0);
        }
        
        public long getAveragePacketSize() {
            return (long) (packetCount > 0 ? (double) totalBytes / packetCount : 0.0);
        }
        
        public long getBandwidth() {
            return (long) (timeWindowNs > 0 ? (totalBytes* 1e9) / timeWindowNs : 0.0);
        }

		@Override
		public String toString() {
			return "TrafficStats [packetCount=" + packetCount + ", totalBytes=" + totalBytes + ", timeWindowNs="
					+ timeWindowNs + ", getPacketsPerSecond()=" + getPacketsPerSecond() + ", getAveragePacketSize()="
					+ getAveragePacketSize() + ", getBandwidth()=" + getBandwidth() + "]";
		}
        
        
    }
    