Search in sources :

Example 31 with PacketInfo

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

the class VideoNetworkComparisonImpl method getAvgThroughput.

private double getAvgThroughput(PacketAnalyzerResult tracedata) {
    double avgKbps;
    int curMaxLength = 0;
    for (Session session : tracedata.getSessionlist()) {
        double startTime = 0;
        int tempLength = 0;
        for (PacketInfo packetInfo : session.getTcpPackets()) {
            if (startTime == 0) {
                // give the initial value
                startTime = packetInfo.getTimeStamp();
            }
            if (startTime + 1 > packetInfo.getTimeStamp()) {
                tempLength += packetInfo.getPayloadLen();
            } else {
                if (curMaxLength < tempLength) {
                    curMaxLength = tempLength;
                    LOGGER.debug("packetInfo: " + packetInfo.getPacketId() + " packet Time: " + packetInfo.getTimeStamp() + " find the bigger max: " + curMaxLength);
                }
                // reset value
                tempLength = packetInfo.getPayloadLen();
                startTime = packetInfo.getTimeStamp();
            }
        }
    }
    // kbps
    avgKbps = (double) curMaxLength * 8 / 1024;
    return avgKbps;
}
Also used : PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 32 with PacketInfo

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

the class PacketAnalyzerImpl method filterPackets.

/**
 * Runs the filtering process on the specified packets/PacketInfos.
 *
 * @return packets/PacketInfos filtered
 */
public List<PacketInfo> filterPackets(AnalysisFilter filter, List<PacketInfo> packetsInfo) {
    // create new packets according to the filter setting
    List<PacketInfo> filteredPackets = new ArrayList<PacketInfo>();
    TimeRange timeRange = filter.getTimeRange();
    int packetIdx = 0;
    // Ff you select the check box, you want to include it.
    // All of of the skip-flags are false at first.
    boolean ipv4Skip = !filter.isIpv4Sel();
    boolean ipv6Skip = !filter.isIpv6Sel();
    boolean tcpSkip = !filter.isTcpSel();
    boolean udpSkip = !filter.isUdpSel();
    boolean dnsSkip = !filter.isDnsSelection();
    for (PacketInfo packetInfo : packetsInfo) {
        if (packetInfo.getRemoteIPAddress() != null) {
            if (ipv4Skip && packetInfo.getRemoteIPAddress() instanceof Inet4Address) {
                continue;
            }
            if (ipv6Skip && packetInfo.getRemoteIPAddress() instanceof Inet6Address) {
                continue;
            }
        } else {
            IPPacket ipPacket = (IPPacket) packetInfo.getPacket();
            if (ipPacket != null) {
                if (ipv4Skip && ipPacket.getIPVersion() == 4) {
                    continue;
                }
                if (ipv6Skip && ipPacket.getIPVersion() == 6) {
                    continue;
                }
            }
        }
        if (tcpSkip && packetInfo.getPacket() instanceof TCPPacket) {
            continue;
        }
        if (udpSkip && packetInfo.getPacket() instanceof UDPPacket) {
            UDPPacket udpPacket = (UDPPacket) packetInfo.getPacket();
            if (!(DNS_PORT == udpPacket.getDestinationPort() || DNS_PORT == udpPacket.getSourcePort())) {
                continue;
            }
        }
        if (dnsSkip && packetInfo.getPacket() instanceof UDPPacket) {
            UDPPacket udpPacket = (UDPPacket) packetInfo.getPacket();
            if (DNS_PORT == udpPacket.getDestinationPort() || DNS_PORT == udpPacket.getSourcePort()) {
                continue;
            }
        }
        // Check time range
        double timestamp = packetInfo.getTimeStamp();
        if (timeRange != null && (timeRange.getBeginTime() > timestamp || timeRange.getEndTime() < timestamp)) {
            // Not in time range
            continue;
        }
        // Check to see if application is selected
        if (filter.getPacketColor(packetInfo) == null) {
            // App unknown by filter
            continue;
        }
        packetInfo.setPacketId(++packetIdx);
        filteredPackets.add(packetInfo);
    }
    return filteredPackets;
}
Also used : TimeRange(com.att.aro.core.packetanalysis.pojo.TimeRange) Inet4Address(java.net.Inet4Address) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) ArrayList(java.util.ArrayList) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) Inet6Address(java.net.Inet6Address) UDPPacket(com.att.aro.core.packetreader.pojo.UDPPacket) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket)

Example 33 with PacketInfo

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

the class PacketAnalyzerImpl method generateGetRequestMapAndPopulateLatencyStat.

/*
	 * Create a TreeMap of all pertinent Requests keyed by timestamp plus tie-breaker.
	 * Populates min/max/avg latency statistics.
	 *
	 * @param sessionlist
	 * 
	 * @return Map of Requests
	 */
private void generateGetRequestMapAndPopulateLatencyStat(List<Session> sessionList, Statistic stat) {
    int counter = 0;
    double minLatency = Double.MAX_VALUE;
    double maxLatency = Double.MIN_VALUE;
    double totalLatency = 0.0d;
    int totalSessions = 0;
    requestMap.clear();
    for (Session session : sessionList) {
        // Calculate latency data by session
        if (session.getLatency() > 0) {
            minLatency = Math.min(minLatency, session.getLatency());
            maxLatency = Math.max(maxLatency, session.getLatency());
            totalLatency += session.getLatency();
            ++totalSessions;
        }
        List<HttpRequestResponseInfo> rri = session.getRequestResponseInfo();
        for (HttpRequestResponseInfo rrInfo : rri) {
            if (HttpDirection.REQUEST.equals(rrInfo.getDirection()) && HttpRequestResponseInfo.HTTP_GET.equals(rrInfo.getRequestType()) && rrInfo.getObjNameWithoutParams().contains(".")) {
                double key = getReqInfoKey(rrInfo, 0);
                if (requestMap.containsKey(key)) {
                    do {
                        key = getReqInfoKey(rrInfo, ++counter);
                    } while (requestMap.containsKey(key));
                    counter = 0;
                }
                requestMap.put(key, rrInfo);
            }
        }
        // Set a forward link for all packets in session to the next packet (within the session).
        List<PacketInfo> packets = session.getTcpPackets();
        for (int i = 0; i < packets.size() - 1; i++) {
            packets.get(i).getPacket().setNextPacketInSession(packets.get(i + 1).getPacket());
        }
    }
    stat.setMinLatency(Double.MAX_VALUE == minLatency ? 0.0d : minLatency);
    stat.setMaxLatency(Double.MIN_VALUE == maxLatency ? 0.0d : maxLatency);
    stat.setAverageLatency(totalSessions != 0 ? totalLatency / totalSessions : 0.0);
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 34 with PacketInfo

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

the class PacketAnalyzerImpl method finalResult.

protected PacketAnalyzerResult finalResult(AbstractTraceResult result, Profile profile, AnalysisFilter filter) {
    PacketAnalyzerResult data = new PacketAnalyzerResult();
    if (filter == null) {
        double endTime = result.getAllpackets().size() > 0 ? Math.max(result.getAllpackets().get(result.getAllpackets().size() - 1).getTimeStamp(), result.getTraceDuration()) : 0.0;
        result.setTimeRange(new TimeRange("Full", TimeRange.TimeRangeType.FULL, 0.0, endTime));
    } else {
        result.setTimeRange(filter.getTimeRange());
    }
    // List of packets included in analysis (application filtered)
    List<PacketInfo> filteredPackets;
    Profile aProfile = profile;
    if (aProfile == null) {
        // if the user doesn't load any profile.....
        aProfile = profilefactory.createLTEdefault();
        aProfile.setName("AT&T LTE");
    }
    // for the situation, filter out all no-ip packets and caused the allpackets is empty, need to refactor
    if (result != null && result.getAllpackets() != null && result.getAllpackets().size() == 0) {
        data.setTraceresult(result);
        return data;
    }
    /* Purpose of this code block is to finish building out the filter, if needed, for TimeRange analysis
		 * 
		 * This code block is excuted when:
		 *  1: time-range.json exists in trace folder
		 *  	a: and the json contains an entry with RangeType.AUTO
		 *  2: A TimeRange object was created and launched in TimeRangeEditorDialog
		 *  
		 *  AroController will have created an AnalysisFilter and so filter will not be null
		 *  
		 */
    try {
        if ((filter != null && filter.getTimeRange() != null && filter.getTimeRange().getPath() != null) || result.getAllAppNames().size() == 1) {
            String app = TraceDataReaderImpl.UNKNOWN_APPNAME;
            if (filter != null && filter.getAppSelections() != null && filter.getAppSelections().containsKey(app) && filter.getAppSelections().get(app).getIPAddressSelections().isEmpty()) {
                LOGGER.debug("AUTO Time Range analysis: add all found appIps to " + app + ", then store in the filter");
                ApplicationSelection appSelection = new ApplicationSelection(app, result.getAppIps().get(app));
                filter.getAppSelections().put(app, appSelection);
            }
        }
    } catch (Exception e) {
        LOGGER.error("Error handling TimeRange JSON data", e);
    }
    TimeRange timeRange = null;
    boolean isCSI = false;
    filteredPackets = new ArrayList<PacketInfo>();
    if (filter == null) {
        if (result != null) {
            filteredPackets = result.getAllpackets();
        }
    } else {
        // do the filter
        if (filter.isCSI() && filter.getManifestFilePath() != null) {
            isCSI = true;
        }
        timeRange = filter.getTimeRange();
        if (result != null) {
            filteredPackets = filterPackets(filter, result.getAllpackets());
        }
    }
    // Fix for Sev 2 Time Range Analysis Issue - DE187848
    if (result != null) {
        result.setAllpackets(filteredPackets);
        SessionManagerImpl sessionMangerImpl = (SessionManagerImpl) sessionmanager;
        sessionMangerImpl.setPcapTimeOffset(result.getPcapTimeOffset());
        // for iOS trace
        sessionmanager.setiOSSecureTracePath(result.getTraceDirectory());
        // Check if secure trace path exists
        if (result instanceof TraceDirectoryResult) {
            File file = new File(((SessionManagerImpl) sessionmanager).getTracePath());
            if (file.exists()) {
                ((TraceDirectoryResult) result).setSecureTrace(true);
            }
        }
    }
    Statistic stat = this.getStatistic(filteredPackets);
    List<Session> sessionList = sessionmanager.processPacketsAndAssembleSessions(filteredPackets);
    generateGetRequestMapAndPopulateLatencyStat(sessionList, stat);
    if (result != null && stat.getAppName() != null && stat.getAppName().size() == 1 && stat.getAppName().contains(TraceDataReaderImpl.UNKNOWN_APPNAME)) {
        stat.setAppName(new HashSet<String>(result.getAppInfos()));
    }
    // get Unanalyzed HTTPS bytes
    boolean isSecureTrace = result instanceof TraceDirectoryResult ? ((TraceDirectoryResult) result).isSecureTrace() : false;
    if (isSecureTrace) {
        stat.setTotalHTTPSBytesNotAnalyzed(getHttpsBytesNotAnalyzed(sessionList));
    } else {
        stat.setTotalHTTPSBytesNotAnalyzed(stat.getTotalHTTPSByte());
    }
    // stat is used to get some info for RrcStateMachine etc
    if (result != null) {
        LOGGER.debug("Starting pre processing in PAI");
        AbstractRrcStateMachine statemachine = statemachinefactory.create(filteredPackets, aProfile, stat.getPacketDuration(), result.getTraceDuration(), stat.getTotalByte(), timeRange);
        EnergyModel energymodel = energymodelfactory.create(aProfile, statemachine.getTotalRRCEnergy(), result.getGpsInfos(), result.getCameraInfos(), result.getBluetoothInfos(), result.getScreenStateInfos());
        BurstCollectionAnalysisData burstcollectiondata = burstcollectionanalyzer.analyze(filteredPackets, aProfile, stat.getPacketSizeToCountMap(), statemachine.getStaterangelist(), result.getUserEvents(), result.getCpuActivityList().getCpuActivities(), sessionList);
        data.clearBPResults();
        try {
            List<BestPracticeType> videoBPList = BestPracticeType.getByCategory(BestPracticeType.Category.VIDEO);
            data.setStreamingVideoData(videoTrafficCollector.clearData());
            if (CollectionUtils.containsAny(SettingsUtil.retrieveBestPractices(), videoBPList)) {
                if (isCSI || csiDataHelper.doesCSIFileExist(result.getTraceDirectory())) {
                    data.setStreamingVideoData(videoTrafficInferencer.inferVideoData(result, sessionList, (filter != null && filter.getManifestFilePath() != null) ? filter.getManifestFilePath() : result.getTraceDirectory()));
                } else {
                    data.setStreamingVideoData(videoTrafficCollector.collect(result, sessionList, requestMap));
                }
            }
        } catch (Exception ex) {
            LOGGER.error("Error in Video usage analysis :", ex);
            // Guarantee that StreamingVideoData is empty
            data.setStreamingVideoData(videoTrafficCollector.clearData());
            data.getStreamingVideoData().setFinished(true);
        }
        try {
            List<BestPracticeType> imageBPList = new ArrayList<>();
            imageBPList.add(BestPracticeType.IMAGE_MDATA);
            imageBPList.add(BestPracticeType.IMAGE_CMPRS);
            imageBPList.add(BestPracticeType.IMAGE_FORMAT);
            imageBPList.add(BestPracticeType.IMAGE_COMPARE);
            if (CollectionUtils.containsAny(SettingsUtil.retrieveBestPractices(), imageBPList)) {
                imageExtractor.execute(result, sessionList, requestMap);
            }
        } catch (Exception ex) {
            LOGGER.error("Error in Image extraction:" + ex.getMessage(), ex);
        }
        htmlExtractor.execute(result, sessionList, requestMap);
        // Calculate time range analysis
        double beginTime = 0.0d;
        double endTime = 0.0d;
        if (filter != null && filter.getTimeRange() != null) {
            beginTime = filter.getTimeRange().getBeginTime();
            endTime = filter.getTimeRange().getEndTime();
        } else {
            endTime = result.getTraceDuration();
        }
        data.setBurstCollectionAnalysisData(burstcollectiondata);
        data.setEnergyModel(energymodel);
        data.setSessionlist(sessionList);
        data.setStatemachine(statemachine);
        data.setStatistic(stat);
        data.setTraceresult(result);
        data.setProfile(aProfile);
        data.setFilter(filter);
        data.setDeviceKeywords(result.getDeviceKeywordInfos());
        data.setTimeRangeAnalysis(new TimeRangeAnalysis(beginTime, endTime, data));
    }
    return data;
}
Also used : ApplicationSelection(com.att.aro.core.packetanalysis.pojo.ApplicationSelection) ArrayList(java.util.ArrayList) BestPracticeType(com.att.aro.core.bestpractice.pojo.BestPracticeType) Profile(com.att.aro.core.configuration.pojo.Profile) Statistic(com.att.aro.core.packetanalysis.pojo.Statistic) TraceDirectoryResult(com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult) AbstractRrcStateMachine(com.att.aro.core.packetanalysis.pojo.AbstractRrcStateMachine) EnergyModel(com.att.aro.core.packetanalysis.pojo.EnergyModel) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) TimeRange(com.att.aro.core.packetanalysis.pojo.TimeRange) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) BurstCollectionAnalysisData(com.att.aro.core.packetanalysis.pojo.BurstCollectionAnalysisData) PacketAnalyzerResult(com.att.aro.core.packetanalysis.pojo.PacketAnalyzerResult) File(java.io.File) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 35 with PacketInfo

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

the class SessionManagerImpl method associatePacketToTCPSessionAndPopulateCollections.

private Session associatePacketToTCPSessionAndPopulateCollections(List<Session> sessions, Map<String, List<Session>> tcpSessions, PacketInfo packetInfo, TCPPacket tcpPacket) {
    int localPort;
    int remotePort;
    Session session;
    InetAddress localIP;
    InetAddress remoteIP;
    switch(packetInfo.getDir()) {
        case UPLINK:
            localIP = tcpPacket.getSourceIPAddress();
            localPort = tcpPacket.getSourcePort();
            remoteIP = tcpPacket.getDestinationIPAddress();
            remotePort = tcpPacket.getDestinationPort();
            break;
        case DOWNLINK:
            localIP = tcpPacket.getDestinationIPAddress();
            localPort = tcpPacket.getDestinationPort();
            remoteIP = tcpPacket.getSourceIPAddress();
            remotePort = tcpPacket.getSourcePort();
            break;
        default:
            localIP = tcpPacket.getSourceIPAddress();
            localPort = tcpPacket.getSourcePort();
            remoteIP = tcpPacket.getDestinationIPAddress();
            remotePort = tcpPacket.getDestinationPort();
            LOGGER.warn("29 - Unable to determine packet direction. Assuming Uplink");
            break;
    }
    String sessionKey = localIP.getHostAddress() + " " + localPort + " " + remotePort + " " + remoteIP.getHostAddress();
    if (!tcpSessions.containsKey(sessionKey)) {
        session = new Session(localIP, remoteIP, remotePort, localPort, sessionKey);
        sessions.add(session);
        List<Session> tcpSessionList = new ArrayList<>();
        tcpSessionList.add(session);
        tcpSessions.put(sessionKey, tcpSessionList);
    } else {
        session = (tcpSessions.get(sessionKey)).get(tcpSessions.get(sessionKey).size() - 1);
        if (tcpPacket.isSYN() && packetInfo.getDir().equals(PacketDirection.UPLINK)) {
            if (!session.getUplinkPacketsSortedBySequenceNumbers().containsKey(tcpPacket.getSequenceNumber())) {
                session = new Session(localIP, remoteIP, remotePort, localPort, sessionKey);
                sessions.add(session);
                tcpSessions.get(sessionKey).add(session);
            } else {
                tcpPacket.setRetransmission(true);
            }
        }
    }
    if (session.getBaseUplinkSequenceNumber() == 0 && packetInfo.getDir().equals(PacketDirection.UPLINK)) {
        session.setBaseUplinkSequenceNumber(tcpPacket.getSequenceNumber());
    }
    if (session.getBaseDownlinkSequenceNumber() == 0 && packetInfo.getDir().equals(PacketDirection.DOWNLINK)) {
        session.setBaseDownlinkSequenceNumber(tcpPacket.getSequenceNumber());
    }
    if (!session.getTcpPackets().isEmpty() && (tcpPacket.isFIN() || tcpPacket.isRST())) {
        PacketInfo previousPacket = session.getTcpPackets().get(session.getTcpPackets().size() - 1);
        double delay = packetInfo.getTimeStamp() - previousPacket.getTimeStamp();
        session.setSessionTermination(new Termination(packetInfo, delay));
    }
    boolean packetAdditionComplete = session.addTcpPacket(packetInfo, tcpPacket.getSequenceNumber());
    if (tcpPacket.isSYN()) {
        if (packetInfo.getDir() == PacketDirection.UPLINK) {
            session.addSynPackets(packetInfo);
        } else if (packetInfo.getDir() == PacketDirection.DOWNLINK) {
            session.addSynAckPackets(packetInfo);
        }
    }
    session.setBytesTransferred(session.getBytesTransferred() + packetInfo.getPayloadLen());
    if (!packetAdditionComplete) {
        packetInfo.setTcpInfo(TcpInfo.TCP_DATA_DUP);
    }
    return session;
}
Also used : ArrayList(java.util.ArrayList) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) Termination(com.att.aro.core.packetanalysis.pojo.Termination) InetAddress(java.net.InetAddress) Session(com.att.aro.core.packetanalysis.pojo.Session)

Aggregations

PacketInfo (com.att.aro.core.packetanalysis.pojo.PacketInfo)119 ArrayList (java.util.ArrayList)92 BaseTest (com.att.aro.core.BaseTest)63 Test (org.junit.Test)63 RrcStateRange (com.att.aro.core.packetanalysis.pojo.RrcStateRange)48 Session (com.att.aro.core.packetanalysis.pojo.Session)33 TCPPacket (com.att.aro.core.packetreader.pojo.TCPPacket)30 Profile3G (com.att.aro.core.configuration.pojo.Profile3G)26 Profile (com.att.aro.core.configuration.pojo.Profile)25 InetAddress (java.net.InetAddress)25 RRCState (com.att.aro.core.packetanalysis.pojo.RRCState)21 ProfileLTE (com.att.aro.core.configuration.pojo.ProfileLTE)18 HashSet (java.util.HashSet)16 HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)14 UDPPacket (com.att.aro.core.packetreader.pojo.UDPPacket)14 Packet (com.att.aro.core.packetreader.pojo.Packet)11 HashMap (java.util.HashMap)11 BurstCollectionAnalysisData (com.att.aro.core.packetanalysis.pojo.BurstCollectionAnalysisData)9 DomainNameSystem (com.att.aro.core.packetreader.pojo.DomainNameSystem)9 IPPacket (com.att.aro.core.packetreader.pojo.IPPacket)9