Search in sources :

Example 21 with Statistic

use of com.att.aro.core.packetanalysis.pojo.Statistic in project VideoOptimzer by attdevsupport.

the class PacketAnalyzerImpl method getStatistic.

@Override
public Statistic getStatistic(List<PacketInfo> packetInfos) {
    Statistic stat = new Statistic();
    Set<String> appNames = new HashSet<String>();
    if (!packetInfos.isEmpty() && packetInfos.size() > 0) {
        long totalHTTPSBytes = 0;
        long totalBytes = 0;
        long totalTCPBytes = 0;
        long totalPayloadBytes = 0;
        long totalTCPPayloadBytes = 0;
        int totalTCPPackets = 0;
        double minTCPPacketTimestamp = Double.MAX_VALUE;
        double maxTCPPacketTimestamp = Double.MIN_VALUE;
        List<IPPacketSummary> ipPacketSummary = new ArrayList<>();
        List<ApplicationPacketSummary> applicationPacketSummary = new ArrayList<>();
        Map<Integer, Integer> packetSizeToCountMap = new HashMap<>();
        Map<String, PacketCounter> appPackets = new HashMap<>();
        Map<InetAddress, PacketCounter> ipPackets = new HashMap<>();
        for (PacketInfo packetInfo : packetInfos) {
            if (packetInfo != null) {
                totalBytes += packetInfo.getLen();
                totalPayloadBytes += packetInfo.getPacket().getPayloadLen();
                PacketCounter pCounter;
                if (packetInfo.getPacket() instanceof TCPPacket) {
                    ++totalTCPPackets;
                    minTCPPacketTimestamp = Math.min(minTCPPacketTimestamp, packetInfo.getTimeStamp());
                    maxTCPPacketTimestamp = Math.max(maxTCPPacketTimestamp, packetInfo.getTimeStamp());
                    TCPPacket tcp = (TCPPacket) packetInfo.getPacket();
                    totalTCPBytes += tcp.getPacketLength();
                    totalTCPPayloadBytes += tcp.getPayloadLen();
                    if (tcp.isSsl() || tcp.getDestinationPort() == 443 || tcp.getSourcePort() == 443) {
                        totalHTTPSBytes += tcp.getPayloadLen();
                    }
                }
                if (packetInfo.getPacket() instanceof IPPacket) {
                    // Count packets by packet size
                    Integer packetSize = packetInfo.getPacket().getPayloadLen();
                    Integer iValue = packetSizeToCountMap.get(packetSize);
                    if (iValue == null) {
                        iValue = 1;
                    } else {
                        iValue++;
                    }
                    packetSizeToCountMap.put(packetSize, iValue);
                    // Get IP address summary
                    InetAddress ipAddress = packetInfo.getRemoteIPAddress();
                    pCounter = ipPackets.get(ipAddress);
                    if (pCounter == null) {
                        pCounter = new PacketCounter();
                        ipPackets.put(ipAddress, pCounter);
                    }
                    pCounter.add(packetInfo);
                }
                String appName = packetInfo.getAppName();
                appNames.add(appName);
                pCounter = appPackets.get(appName);
                if (pCounter == null) {
                    pCounter = new PacketCounter();
                    appPackets.put(appName, pCounter);
                }
                pCounter.add(packetInfo);
            }
        }
        for (Map.Entry<InetAddress, PacketCounter> ipPacketMap : ipPackets.entrySet()) {
            ipPacketSummary.add(new IPPacketSummary(ipPacketMap.getKey(), ipPacketMap.getValue().getPacketCount(), ipPacketMap.getValue().getTotalBytes(), ipPacketMap.getValue().getTotalPayloadBytes()));
        }
        for (Map.Entry<String, PacketCounter> appPacketMap : appPackets.entrySet()) {
            applicationPacketSummary.add(new ApplicationPacketSummary(appPacketMap.getKey(), appPacketMap.getValue().getPacketCount(), appPacketMap.getValue().getTotalBytes(), appPacketMap.getValue().getTotalPayloadBytes()));
        }
        double packetsDuration = packetInfos.get(packetInfos.size() - 1).getTimeStamp() - packetInfos.get(0).getTimeStamp();
        double tcpPacketDuration = (maxTCPPacketTimestamp > minTCPPacketTimestamp) ? (maxTCPPacketTimestamp - minTCPPacketTimestamp) : 0.0d;
        double avgKbps = packetsDuration != 0 ? totalBytes * 8.0 / 1000.0 / packetsDuration : 0.0d;
        double avgTCPKbps = tcpPacketDuration != 0 ? totalTCPBytes * 8.0 / 1000.0 / tcpPacketDuration : 0.0d;
        stat.setApplicationPacketSummary(applicationPacketSummary);
        stat.setAverageKbps(avgKbps);
        stat.setAverageTCPKbps(avgTCPKbps);
        stat.setIpPacketSummary(ipPacketSummary);
        stat.setPacketDuration(packetsDuration);
        stat.setTcpPacketDuration(tcpPacketDuration);
        stat.setTotalByte(totalBytes);
        stat.setTotalPayloadBytes(totalPayloadBytes);
        stat.setTotalTCPBytes(totalTCPBytes);
        stat.setTotalTCPPayloadBytes(totalTCPPayloadBytes);
        stat.setTotalHTTPSByte(totalHTTPSBytes);
        stat.setTotalPackets(packetInfos.size());
        stat.setTotalTCPPackets(totalTCPPackets);
        stat.setPacketSizeToCountMap(packetSizeToCountMap);
    }
    stat.setAppName(appNames);
    return stat;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PacketCounter(com.att.aro.core.packetanalysis.pojo.PacketCounter) Statistic(com.att.aro.core.packetanalysis.pojo.Statistic) IPPacketSummary(com.att.aro.core.packetanalysis.pojo.IPPacketSummary) HashSet(java.util.HashSet) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) ApplicationPacketSummary(com.att.aro.core.packetanalysis.pojo.ApplicationPacketSummary) InetAddress(java.net.InetAddress) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket)

Example 22 with Statistic

use of com.att.aro.core.packetanalysis.pojo.Statistic in project VideoOptimzer by attdevsupport.

the class HttpsUsageImpl method runTest.

@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
    /*
		 * Reset these total numbers before each test-run due to bean being
		 * singleton.
		 */
    totalNumConnectionsCurrentTrace = 0;
    totalNumHttpConnectionsCurrentTrace = 0;
    List<Session> sessions = tracedata.getSessionlist();
    Map<InetAddress, List<Session>> ipSessionsMap = buildIpSessionsMap(sessions);
    List<HttpsUsageEntry> httpsUsageEntries = buildHttpsUsageEntry(ipSessionsMap);
    int httpConnectionsPercentageCurrentTrace = getHttpConnectionsPercentage(totalNumHttpConnectionsCurrentTrace, totalNumConnectionsCurrentTrace);
    HttpsUsageResult result = new HttpsUsageResult();
    String testResultText = "";
    Statistic stat = tracedata.getStatistic();
    if (passTest()) {
        result.setResultType(BPResultType.PASS);
        testResultText = MessageFormat.format(testResultPassText, ApplicationConfig.getInstance().getAppShortName(), totalNumHttpConnectionsCurrentTrace, formatDoubleToString(stat.getTotalHTTPSByte() / 1000.0, 2), formatDoubleToString(stat.getTotalHTTPSByte() * 100.0 / stat.getTotalByte(), 2), formatDoubleToString(stat.getTotalHTTPSBytesNotAnalyzed() / 1000.0, 2));
        result.setResultExcelText(BPResultType.PASS.getDescription());
    } else if (failTest(httpsUsageEntries, httpConnectionsPercentageCurrentTrace)) {
        result.setResultType(BPResultType.FAIL);
        testResultText = MessageFormat.format(testResultAnyText, ApplicationConfig.getInstance().getAppShortName(), totalNumHttpConnectionsCurrentTrace, httpConnectionsPercentageCurrentTrace, formatDoubleToString(stat.getTotalHTTPSByte() / 1000.0, 2), formatDoubleToString(stat.getTotalHTTPSByte() * 100.0 / stat.getTotalByte(), 2), formatDoubleToString(stat.getTotalHTTPSBytesNotAnalyzed() / 1000.0, 2));
        result.setResultExcelText(MessageFormat.format(textExcelResults, BPResultType.FAIL.getDescription(), totalNumHttpConnectionsCurrentTrace, httpConnectionsPercentageCurrentTrace));
    } else {
        result.setResultType(BPResultType.WARNING);
        testResultText = MessageFormat.format(testResultAnyText, ApplicationConfig.getInstance().getAppShortName(), totalNumHttpConnectionsCurrentTrace, httpConnectionsPercentageCurrentTrace, formatDoubleToString(stat.getTotalHTTPSByte() / 1000.0, 2), formatDoubleToString(stat.getTotalHTTPSByte() * 100.0 / stat.getTotalByte(), 2), formatDoubleToString(stat.getTotalHTTPSBytesNotAnalyzed() / 1000.0, 2));
        result.setResultExcelText(MessageFormat.format(textExcelResults, BPResultType.WARNING.getDescription(), totalNumHttpConnectionsCurrentTrace, httpConnectionsPercentageCurrentTrace));
    }
    result.setOverviewTitle(overviewTitle);
    result.setDetailTitle(detailedTitle);
    result.setLearnMoreUrl(learnMoreUrl);
    result.setAboutText(aboutText);
    result.setResults(httpsUsageEntries);
    result.setResultText(testResultText);
    result.setExportAll(exportAll);
    return result;
}
Also used : Statistic(com.att.aro.core.packetanalysis.pojo.Statistic) ArrayList(java.util.ArrayList) List(java.util.List) HttpsUsageEntry(com.att.aro.core.bestpractice.pojo.HttpsUsageEntry) InetAddress(java.net.InetAddress) HttpsUsageResult(com.att.aro.core.bestpractice.pojo.HttpsUsageResult) Session(com.att.aro.core.packetanalysis.pojo.Session)

Aggregations

Statistic (com.att.aro.core.packetanalysis.pojo.Statistic)22 BaseTest (com.att.aro.core.BaseTest)11 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 PacketInfo (com.att.aro.core.packetanalysis.pojo.PacketInfo)9 Session (com.att.aro.core.packetanalysis.pojo.Session)9 InetAddress (java.net.InetAddress)8 TCPPacket (com.att.aro.core.packetreader.pojo.TCPPacket)7 PacketAnalyzerResult (com.att.aro.core.packetanalysis.pojo.PacketAnalyzerResult)4 AbstractRrcStateMachine (com.att.aro.core.packetanalysis.pojo.AbstractRrcStateMachine)3 AnalysisFilter (com.att.aro.core.packetanalysis.pojo.AnalysisFilter)3 EnergyModel (com.att.aro.core.packetanalysis.pojo.EnergyModel)3 AbstractBestPracticeResult (com.att.aro.core.bestpractice.pojo.AbstractBestPracticeResult)2 CacheControlResult (com.att.aro.core.bestpractice.pojo.CacheControlResult)2 TimeRangeAnalysis (com.att.aro.core.packetanalysis.impl.TimeRangeAnalysis)2 BurstCollectionAnalysisData (com.att.aro.core.packetanalysis.pojo.BurstCollectionAnalysisData)2 TimeRange (com.att.aro.core.packetanalysis.pojo.TimeRange)2 TraceDirectoryResult (com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult)2 AROTraceData (com.att.aro.core.pojo.AROTraceData)2 File (java.io.File)2