Search in sources :

Example 31 with Session

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

the class SimultnsUtil method getDistinctMap.

public Map<String, ArrayList<Session>> getDistinctMap(List<Session> sessions) {
    Map<String, ArrayList<Session>> distinctMap = new HashMap<String, ArrayList<Session>>();
    for (Session session : sessions) {
        if (session != null && !session.isUdpOnly()) {
            String domainName = session.getRemoteIP().toString();
            ArrayList<Session> tempList = distinctMap.get(domainName);
            if (tempList == null) {
                tempList = new ArrayList<Session>();
            }
            tempList.add(session);
            distinctMap.put(domainName, tempList);
        }
    }
    return distinctMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 32 with Session

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

the class SimultnsUtil method createDomainsTCPSessions.

public List<SessionValues> createDomainsTCPSessions(Collection<Session> allTCPSessions) {
    List<SessionValues> sessionValues = new ArrayList<SessionValues>();
    Session lastSession = null;
    for (Session aSession : allTCPSessions) {
        if (aSession != null) {
            if (!aSession.getRequestResponseInfo().isEmpty()) {
                for (HttpRequestResponseInfo req : aSession.getRequestResponseInfo()) {
                    sessionValues = addSessionValues(sessionValues, lastSession, aSession, req);
                    lastSession = aSession;
                }
            } else {
                HttpRequestResponseInfo reqResp = new HttpRequestResponseInfo();
                if (aSession.getRemoteHostName() != null) {
                    reqResp.setHostName(aSession.getRemoteHostName());
                    reqResp.setFirstDataPacket(aSession.getTcpPackets().get(0));
                }
                sessionValues = addSessionValues(sessionValues, lastSession, aSession, reqResp);
            }
        }
    }
    return sessionValues;
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) ArrayList(java.util.ArrayList) SessionValues(com.att.aro.core.packetanalysis.pojo.SessionValues) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 33 with Session

use of com.att.aro.core.packetanalysis.pojo.Session 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 Session

use of com.att.aro.core.packetanalysis.pojo.Session 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 Session

use of com.att.aro.core.packetanalysis.pojo.Session 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

Session (com.att.aro.core.packetanalysis.pojo.Session)130 ArrayList (java.util.ArrayList)86 HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)74 BaseTest (com.att.aro.core.BaseTest)49 Test (org.junit.Test)49 PacketInfo (com.att.aro.core.packetanalysis.pojo.PacketInfo)32 AbstractBestPracticeResult (com.att.aro.core.bestpractice.pojo.AbstractBestPracticeResult)31 InetAddress (java.net.InetAddress)26 HashMap (java.util.HashMap)19 TCPPacket (com.att.aro.core.packetreader.pojo.TCPPacket)17 HashSet (java.util.HashSet)11 TreeMap (java.util.TreeMap)11 List (java.util.List)10 Statistic (com.att.aro.core.packetanalysis.pojo.Statistic)9 File (java.io.File)9 TraceDirectoryResult (com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult)8 DomainNameSystem (com.att.aro.core.packetreader.pojo.DomainNameSystem)8 BurstCollectionAnalysisData (com.att.aro.core.packetanalysis.pojo.BurstCollectionAnalysisData)7 HttpRequestResponseInfoWithSession (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfoWithSession)7 UDPPacket (com.att.aro.core.packetreader.pojo.UDPPacket)7