Search in sources :

Example 91 with HttpRequestResponseInfo

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

the class CacheAnalysisImpl method addToCache.

/**
 * Adds the request and response in cacheEntries after the analysis.
 *
 * @param cacheEntry
 * @param dupEntries
 */
private void addToCache(CacheEntry cacheEntry, Map<String, SortedSet<Range>> rangeEntries, Map<String, CacheEntry> cacheEntries, Map<String, CacheEntry> dupEntries, Session session) {
    HttpRequestResponseInfo response = cacheEntry.getResponse();
    Range range = null;
    long xferSize = calculatePartialTransfer(response, session);
    if (response.isRangeResponse()) {
        long first = response.getRangeFirst();
        long last = xferSize > 0 ? first + xferSize - 1 : response.getRangeLast();
        range = new Range(first, last + 1);
    } else if (xferSize > 0) {
        range = new Range(0, xferSize);
    }
    String objFullName = getObjFullName(cacheEntry.getRequest(), cacheEntry.getResponse());
    if (range != null) {
        SortedSet<Range> ranges = rangeEntries.get(objFullName);
        if (ranges != null) {
            ranges.add(range);
            Iterator<Range> iter = ranges.iterator();
            Range last = iter.next();
            while (iter.hasNext()) {
                Range curr = iter.next();
                if (curr.getFirstByte() >= last.getFirstByte() && curr.getFirstByte() <= last.getLastByte()) {
                    last.setLastByte(Math.max(last.getLastByte(), curr.getLastByte()));
                    iter.remove();
                }
            }
        } else {
            ranges = new TreeSet<Range>();
            ranges.add(range);
            rangeEntries.put(objFullName, ranges);
        }
    } else {
        rangeEntries.remove(objFullName);
    }
    cacheEntries.put(objFullName + cacheEntry.getContentLength(), cacheEntry);
    dupEntries.put(getObjDuplicateName(cacheEntry.getRequest(), cacheEntry.getResponse()), cacheEntry);
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) Range(com.att.aro.core.packetanalysis.pojo.Range)

Example 92 with HttpRequestResponseInfo

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

the class ImageExtractor method extractImage.

public void extractImage(HttpRequestResponseInfo request, String imageFileName) {
    HttpRequestResponseInfo response = request.getAssocReqResp();
    Session session = request.getSession();
    if (response != null) {
        byte[] content = null;
        String fullpath;
        try {
            content = httpRequestResponseHelper.getContent(response, session);
            fullpath = imagePath + imageFileName;
            fileManager.saveFile(new ByteArrayInputStream(content), fullpath);
        } catch (Exception e) {
            LOGGER.info("Failed to extract " + VideoImageAnalysisUtil.getTimeString(response) + imageFileName + " response: " + e.getMessage());
            return;
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 93 with HttpRequestResponseInfo

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

the class SessionManagerImpl method setFirstAndLastDataPacket.

/**
 * Used to set the first and last data packet for secure sessions in iOS.
 * The data isn't available from the request and response file, so this method helps with it
 * Identified the packet with the time stamp closest to the request time in iOS secure file.
 *
 * @param results
 * @param usedPackets
 * @param rrInfo
 * @param packetMap
 * @param matchKey
 */
private void setFirstAndLastDataPacket(ArrayList<HttpRequestResponseInfo> results, Map<Double, PacketInfo> usedPackets, HttpRequestResponseInfo rrInfo, TreeMap<Double, PacketInfo> packetMap, Map.Entry<Double, PacketInfo> matchKey) {
    /**
     * Identify the packet closest to the request time stamp in the iOS file
     * Assign that as the first and last data packet
     */
    if (matchKey != null) {
        do {
            if (!usedPackets.containsKey(matchKey.getKey()) && ((TCPPacket) matchKey.getValue().getPacket()).getLen() > 0) {
                rrInfo.setFirstDataPacket(matchKey.getValue());
                rrInfo.setLastDataPacket(matchKey.getValue());
                usedPackets.put(matchKey.getKey(), matchKey.getValue());
                break;
            }
        } while ((matchKey = packetMap.higherEntry(matchKey.getKey())) != null);
    }
    /**
     * If a request has a first data packet, then
     * the the previous packet with data, if it hasn't been used before,
     * is the last data packet for the previous request.
     */
    if (results.size() > 0) {
        HttpRequestResponseInfo previousRequest = results.get(results.size() - 1);
        while (matchKey != null && ((matchKey = packetMap.lowerEntry(matchKey.getKey())) != null) && ((TCPPacket) matchKey.getValue().getPacket()).getLen() > 0) {
            if (matchKey.getValue().getTimeStamp() < previousRequest.getTimeStamp()) {
                break;
            } else if (!usedPackets.containsKey(matchKey.getKey())) {
                previousRequest.setLastDataPacket(matchKey.getValue());
                break;
            }
        }
    }
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket)

Example 94 with HttpRequestResponseInfo

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

the class SessionManagerImpl method analyzeRequestResponses.

/**
 * Traverse all Sessions of all types UDP/TCP/
 *
 * @param sessions
 */
private void analyzeRequestResponses(List<Session> sessions) {
    ArrayList<HttpRequestResponseInfo> results;
    for (Session session : sessions) {
        int limit = 0;
        results = new ArrayList<>();
        PacketInfo previousPacket = null;
        if (session.isUdpOnly()) {
            // UDP
            HttpRequestResponseInfo rrInfo = null;
            HttpRequestResponseInfo recentUpRRInfo = null;
            HttpRequestResponseInfo recentDnRRInfo = null;
            for (PacketInfo udpPacketInfo : session.getUdpPackets()) {
                try {
                    switch(udpPacketInfo.getDir()) {
                        case UPLINK:
                            if (!session.isDataInaccessible()) {
                                rrInfo = extractHttpRequestResponseInfo(results, session, udpPacketInfo, udpPacketInfo.getDir(), previousPacket, limit);
                            }
                            if (rrInfo != null) {
                                recentUpRRInfo = rrInfo;
                            } else {
                                if (443 == session.getLocalPort() || 443 == session.getRemotePort() || 80 == session.getLocalPort() || 80 == session.getRemotePort()) {
                                    session.setDataInaccessible(true);
                                    results = analyzeRequestResponsesForQUICUDPSession(session);
                                    break;
                                }
                                if (recentUpRRInfo == null) {
                                    // Creating a Request Objects when no actual requests were found.
                                    session.setDataInaccessible(true);
                                    rrInfo = new HttpRequestResponseInfo(session.getRemoteHostName(), udpPacketInfo.getDir());
                                    populateRRInfo(rrInfo, udpPacketInfo, false, false, HttpDirection.REQUEST);
                                    results.add(rrInfo);
                                    recentUpRRInfo = rrInfo;
                                }
                                if (udpPacketInfo.getPayloadLen() != 0) {
                                    updateRequestResponseObject(recentUpRRInfo, udpPacketInfo);
                                }
                            }
                            rrInfo = null;
                            recentUpRRInfo.writePayload(udpPacketInfo, false, 0);
                            recentUpRRInfo.addUDPPacket(udpPacketInfo);
                            break;
                        case DOWNLINK:
                            if (!session.isDataInaccessible()) {
                                rrInfo = extractHttpRequestResponseInfo(results, session, udpPacketInfo, udpPacketInfo.getDir(), previousPacket, limit);
                            }
                            if (rrInfo != null) {
                                recentDnRRInfo = rrInfo;
                            } else {
                                if (recentDnRRInfo == null) {
                                    rrInfo = new HttpRequestResponseInfo(session.getRemoteHostName(), udpPacketInfo.getDir());
                                    populateRRInfo(rrInfo, udpPacketInfo, false, false, HttpDirection.RESPONSE);
                                    results.add(rrInfo);
                                    recentDnRRInfo = rrInfo;
                                }
                                if (udpPacketInfo.getPayloadLen() != 0) {
                                    updateRequestResponseObject(recentDnRRInfo, udpPacketInfo);
                                }
                            }
                            rrInfo = null;
                            recentDnRRInfo.writePayload(udpPacketInfo, false, 0);
                            recentDnRRInfo.addUDPPacket(udpPacketInfo);
                            break;
                        default:
                            LOGGER.warn("91 - No direction for packet");
                            continue;
                    }
                } catch (IOException e) {
                    LOGGER.error("Error Storing data to UDP Request Response Obect. Session ID: " + session.getSessionKey());
                }
            }
        } else {
            // TCP
            analyzeACK(session);
            analyzeZeroWindow(session);
            analyzeRecoverPkts(session);
            PacketInfo packetInfo = null;
            TCPPacket tcpPacket = null;
            HttpRequestResponseInfo rrInfo = null;
            HttpRequestResponseInfo tempRRInfo = null;
            try {
                long expectedUploadSeqNo = 0;
                for (long uploadSequenceNumber : session.getUplinkPacketsSortedBySequenceNumbers().keySet()) {
                    // Identify correct packet from the whole transmission stream
                    packetInfo = identifyCorrectTransmissionStream(session.getUplinkPacketsSortedBySequenceNumbers().get(uploadSequenceNumber), session.getAckNumbers(), session, PacketDirection.UPLINK);
                    tcpPacket = (TCPPacket) packetInfo.getPacket();
                    if (packetInfo.getPayloadLen() > 0) {
                        if (!session.isDataInaccessible()) {
                            rrInfo = extractHttpRequestResponseInfo(results, session, packetInfo, packetInfo.getDir(), previousPacket, limit);
                        }
                        if (rrInfo != null) {
                            tempRRInfo = rrInfo;
                            String host = rrInfo.getHostName();
                            if (host != null) {
                                URI referrer = rrInfo.getReferrer();
                                session.setRemoteHostName(host);
                                session.setDomainName(referrer != null ? referrer.getHost() : host);
                            }
                            if (isAnIOSSecureSession(session)) {
                                break;
                            }
                            expectedUploadSeqNo = uploadSequenceNumber + tcpPacket.getPayloadLen();
                        } else if (tempRRInfo != null) {
                            int headerDelta = 0;
                            boolean flag = false;
                            if (!session.isDataInaccessible() && !tempRRInfo.isHeaderParseComplete()) {
                                flag = true;
                                headerDelta = setHeaderOffset(tempRRInfo, packetInfo, tcpPacket);
                                tempRRInfo.writeHeader(packetInfo, headerDelta);
                            }
                            tempRRInfo.setLastDataPacket(packetInfo);
                            tempRRInfo.setRawSize(tempRRInfo.getRawSize() + packetInfo.getLen() - headerDelta);
                            if (tcpPacket.getSequenceNumber() == expectedUploadSeqNo) {
                                expectedUploadSeqNo = tcpPacket.getSequenceNumber() + tcpPacket.getPayloadLen();
                                tempRRInfo.writePayload(packetInfo, flag, headerDelta);
                            } else if (tcpPacket.getSequenceNumber() < expectedUploadSeqNo) {
                                tcpPacket.setRetransmission(true);
                            } else {
                                LOGGER.warn("Identified the following Request is corrupt. Session: " + session.getSessionKey() + ". Request Age: " + tempRRInfo.getAge());
                                tempRRInfo.setCorrupt(true);
                                tempRRInfo.writePayload(packetInfo, false, 0);
                            }
                        } else {
                            if (session.isDecrypted()) {
                                continue;
                            } else if (session.isSsl()) {
                                break;
                            }
                            session.setDataInaccessible(true);
                            rrInfo = new HttpRequestResponseInfo(session.getRemoteHostName(), packetInfo.getDir());
                            expectedUploadSeqNo = uploadSequenceNumber + tcpPacket.getPayloadLen();
                            populateRRInfo(rrInfo, packetInfo, false, true, HttpDirection.REQUEST);
                            results.add(rrInfo);
                            tempRRInfo = rrInfo;
                        }
                        rrInfo = null;
                        tempRRInfo.addTCPPacket(uploadSequenceNumber, packetInfo);
                    }
                }
                rrInfo = null;
                tempRRInfo = null;
                if (!(session.isIOSSecureSession() || (session.isSsl() && !session.isDecrypted()))) {
                    long expectedDownloadSeqNo = 0;
                    for (long downloadSequenceNumber : session.getDownlinkPacketsSortedBySequenceNumbers().keySet()) {
                        // Identify correct packet from the whole transmission stream
                        packetInfo = identifyCorrectTransmissionStream(session.getDownlinkPacketsSortedBySequenceNumbers().get(downloadSequenceNumber), session.getAckNumbers(), session, PacketDirection.DOWNLINK);
                        tcpPacket = (TCPPacket) packetInfo.getPacket();
                        if (packetInfo.getPayloadLen() > 0) {
                            if (!session.isDataInaccessible()) {
                                rrInfo = extractHttpRequestResponseInfo(results, session, packetInfo, packetInfo.getDir(), previousPacket, limit);
                                limit = 0;
                                if (rrInfo != null && !rrInfo.isHeaderParseComplete()) {
                                    previousPacket = packetInfo;
                                    continue;
                                } else {
                                    previousPacket = null;
                                }
                            }
                            if (rrInfo != null) {
                                tempRRInfo = rrInfo;
                                expectedDownloadSeqNo = downloadSequenceNumber + tcpPacket.getPayloadLen();
                            } else if (tempRRInfo != null) {
                                boolean flag = false;
                                int headerDelta = 0;
                                tempRRInfo.setLastDataPacket(packetInfo);
                                if (tcpPacket.getSequenceNumber() == expectedDownloadSeqNo) {
                                    expectedDownloadSeqNo = tcpPacket.getSequenceNumber() + tcpPacket.getPayloadLen();
                                    if (tempRRInfo.getContentLength() == 0 || ((tempRRInfo.getPayloadData().size() + packetInfo.getPayloadLen()) <= tempRRInfo.getContentLength())) {
                                        tempRRInfo.writePayload(packetInfo, flag, headerDelta);
                                        tempRRInfo.setRawSize(tempRRInfo.getRawSize() + packetInfo.getLen() - headerDelta);
                                    } else if (tempRRInfo.getContentLength() > 0 && (tempRRInfo.getPayloadData().size() + packetInfo.getPayloadLen()) > tempRRInfo.getContentLength()) {
                                        limit = tempRRInfo.getContentLength() - tempRRInfo.getPayloadData().size();
                                        tempRRInfo.writePayload(packetInfo, limit);
                                        previousPacket = packetInfo;
                                    // TODO: Update RAW SIZE
                                    }
                                } else if (tcpPacket.getSequenceNumber() < expectedDownloadSeqNo) {
                                    tcpPacket.setRetransmission(true);
                                } else {
                                    LOGGER.warn("Identified the following Response is corrupt. Session: " + session.getSessionKey() + ". Request Age: " + tempRRInfo.getAge());
                                    tempRRInfo.setCorrupt(true);
                                    tempRRInfo.writePayload(packetInfo, false, 0);
                                }
                            } else {
                                if (session.isDecrypted()) {
                                    continue;
                                }
                                rrInfo = new HttpRequestResponseInfo(session.getRemoteHostName(), packetInfo.getDir());
                                expectedDownloadSeqNo = downloadSequenceNumber + tcpPacket.getPayloadLen();
                                populateRRInfo(rrInfo, packetInfo, false, true, HttpDirection.RESPONSE);
                                results.add(rrInfo);
                                tempRRInfo = rrInfo;
                            }
                            rrInfo = null;
                            tempRRInfo.addTCPPacket(downloadSequenceNumber, packetInfo);
                        }
                    }
                }
            } catch (IOException e) {
                LOGGER.error("Error Storing data to TCP Request Response Obect. Session ID: " + session.getSessionKey());
            }
            if (session.isIOSSecureSession()) {
                results = analyzeRequestResponsesForIOSSecureSessions(session);
            } else if (session.isSsl() && !session.isDecrypted()) {
                results = analyzeRequestResponsesForSecureSessions(session);
            }
        }
        Collections.sort(results);
        session.setRequestResponseInfo(results);
        populateDataForRequestResponses(session);
        if (session.getDomainName() == null) {
            session.setDomainName(session.getRemoteIP().getHostName());
        }
    }
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) IOException(java.io.IOException) URI(java.net.URI) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 95 with HttpRequestResponseInfo

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

the class SessionManagerImpl method analyzeRequestResponsesForSecureSessions.

/**
 * Estimate RequestResponseObjects for Secure Sessions
 * @param session
 * @return
 */
private ArrayList<HttpRequestResponseInfo> analyzeRequestResponsesForSecureSessions(Session session) {
    session.setDataInaccessible(true);
    boolean flag = false;
    TCPPacket tcpPacket = null;
    HttpRequestResponseInfo rrInfo = null;
    HttpRequestResponseInfo downlinkRRInfo = null;
    ArrayList<HttpRequestResponseInfo> results = new ArrayList<>();
    for (PacketInfo packetInfo : session.getAllPackets()) {
        tcpPacket = (TCPPacket) packetInfo.getPacket();
        byte[] data = tcpPacket.getData();
        int packetPosition = tcpPacket.getDataOffset();
        if (packetInfo.getDir() == PacketDirection.UPLINK) {
            if ((packetPosition + 4) < tcpPacket.getLen() && data[packetPosition] == TLS_APPLICATION_DATA) {
                rrInfo = generateRequestResponseObjectsForSSLOrUDPSessions(session.getRemoteHostName(), packetInfo.getDir(), packetInfo, true);
                results.add(rrInfo);
                flag = true;
            }
            updateRequestResponseObject(rrInfo, packetInfo);
        }
        if (packetInfo.getDir() == PacketDirection.DOWNLINK) {
            if (flag && (packetPosition + 4) < tcpPacket.getLen() && data[packetPosition] == TLS_APPLICATION_DATA) {
                downlinkRRInfo = generateRequestResponseObjectsForSSLOrUDPSessions(session.getRemoteHostName(), packetInfo.getDir(), packetInfo, true);
                results.add(downlinkRRInfo);
                flag = false;
            }
            updateRequestResponseObject(downlinkRRInfo, packetInfo);
        }
    }
    if (results.isEmpty()) {
        if (!session.getUplinkPacketsSortedBySequenceNumbers().isEmpty()) {
            PacketInfo packetInfo = identifyCorrectTransmissionStream(session.getUplinkPacketsSortedBySequenceNumbers().firstEntry().getValue(), session.getAckNumbers(), session, PacketDirection.UPLINK);
            rrInfo = generateRequestResponseObjectsForSSLOrUDPSessions(session.getRemoteHostName(), PacketDirection.UPLINK, packetInfo, true);
            packetInfo = identifyCorrectTransmissionStream(session.getUplinkPacketsSortedBySequenceNumbers().lastEntry().getValue(), session.getAckNumbers(), session, PacketDirection.UPLINK);
            rrInfo.setLastDataPacket(packetInfo);
            results.add(rrInfo);
        }
        if (!session.getDownlinkPacketsSortedBySequenceNumbers().isEmpty()) {
            PacketInfo packetInfo = identifyCorrectTransmissionStream(session.getDownlinkPacketsSortedBySequenceNumbers().firstEntry().getValue(), session.getAckNumbers(), session, PacketDirection.DOWNLINK);
            downlinkRRInfo = generateRequestResponseObjectsForSSLOrUDPSessions(session.getRemoteHostName(), PacketDirection.DOWNLINK, packetInfo, true);
            packetInfo = identifyCorrectTransmissionStream(session.getDownlinkPacketsSortedBySequenceNumbers().lastEntry().getValue(), session.getAckNumbers(), session, PacketDirection.DOWNLINK);
            downlinkRRInfo.setLastDataPacket(packetInfo);
            results.add(downlinkRRInfo);
        }
    }
    return results;
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) ArrayList(java.util.ArrayList) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo)

Aggregations

HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)108 Session (com.att.aro.core.packetanalysis.pojo.Session)74 ArrayList (java.util.ArrayList)62 BaseTest (com.att.aro.core.BaseTest)40 Test (org.junit.Test)40 AbstractBestPracticeResult (com.att.aro.core.bestpractice.pojo.AbstractBestPracticeResult)29 PacketInfo (com.att.aro.core.packetanalysis.pojo.PacketInfo)14 IOException (java.io.IOException)10 HashMap (java.util.HashMap)10 TreeMap (java.util.TreeMap)10 File (java.io.File)9 IHttpRequestResponseHelper (com.att.aro.core.packetanalysis.IHttpRequestResponseHelper)5 TraceDirectoryResult (com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult)5 TCPPacket (com.att.aro.core.packetreader.pojo.TCPPacket)5 URISyntaxException (java.net.URISyntaxException)5 List (java.util.List)5 PacketAnalyzerResult (com.att.aro.core.packetanalysis.pojo.PacketAnalyzerResult)4 RequestResponseTimeline (com.att.aro.core.packetanalysis.pojo.RequestResponseTimeline)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InetAddress (java.net.InetAddress)4