Search in sources :

Example 31 with HttpRequestResponseInfo

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

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

the class SessionManagerImpl method getLastRRInfo.

private HttpRequestResponseInfo getLastRRInfo(byte[] streamArray, PacketInfo packetInfo, TCPPacket tcpPacket, PacketInfo previousPacket, int carryoverPayloadLength, Session session, List<HttpRequestResponseInfo> results, PacketDirection packetDirection) {
    HttpRequestResponseInfo rrInfo = null;
    String line = null;
    int readerIndex = -1;
    boolean carryoverPayloadForNewRRInfo = false;
    int remainingLength = 0;
    try {
        do {
            while (true) {
                readerIndex = storageReader.getIndex();
                line = storageReader.readLine();
                if (line == null) {
                    return rrInfo;
                }
                if (line.length() != 0) {
                    break;
                }
            }
            rrInfo = initializeRequestResponseObject(line, session, packetDirection);
            if (rrInfo == null || tcpPacket == null) {
                break;
            }
            carryoverPayloadForNewRRInfo = false;
            rrInfo.setTCP(true);
            rrInfo = populateRRInfo(session, tcpPacket, rrInfo);
            boolean isExtractable, isTCP;
            isExtractable = isTCP = session.isUdpOnly() ? false : true;
            HttpDirection direction = PacketDirection.DOWNLINK.equals(packetDirection) ? HttpDirection.RESPONSE : HttpDirection.REQUEST;
            // Set first and last packet info data to rrInfo
            if (previousPacket == null || readerIndex >= carryoverPayloadLength) {
                populateRRInfo(rrInfo, packetInfo, isExtractable, isTCP, direction);
            } else {
                populateRRInfo(rrInfo, previousPacket, isExtractable, isTCP, direction);
            }
            if (!rrInfo.isHeaderParseComplete()) {
                return rrInfo;
            } else {
                results.add(rrInfo);
                rrInfo.getHeaderData().write(streamArray, 0, storageReader.getIndex());
                remainingLength = streamArray.length - storageReader.getIndex();
                if (remainingLength <= 0) {
                    return rrInfo;
                }
                if (rrInfo.getContentLength() > 0) {
                    if (rrInfo.getContentLength() <= remainingLength) {
                        rrInfo.getPayloadData().write(streamArray, storageReader.getIndex(), rrInfo.getContentLength());
                        storageReader.setArrayIndex(storageReader.getIndex() + rrInfo.getContentLength());
                        remainingLength = streamArray.length - storageReader.getIndex();
                        if (remainingLength <= 0) {
                            return rrInfo;
                        }
                        // We have found the whole payload data for the current rrInfo. There's still remaining data which belongs to a new rrInfo object.
                        // Continue processing for the next rrInfo object.
                        carryoverPayloadForNewRRInfo = true;
                    } else {
                        rrInfo.getPayloadData().write(streamArray, storageReader.getIndex(), remainingLength);
                        return rrInfo;
                    }
                } else {
                    // We are not sure if content length is explicitly 0 in the response or if it is a set by default during the initialization of object.
                    // Try to create a new rrInfo object for next line.
                    carryoverPayloadForNewRRInfo = true;
                }
            }
        } while (true);
    } catch (Exception e) {
        LOGGER.error("Error extracting request response object for packet id " + packetInfo.getPacketId() + " and session port " + session.getLocalPort(), e);
    }
    // We have a carry over payload data belonging to previous rrInfo object
    if (tcpPacket != null && carryoverPayloadForNewRRInfo && remainingLength > 0) {
        rrInfo = results.get(results.size() - 1);
        rrInfo.getPayloadData().write(streamArray, readerIndex, remainingLength);
    }
    return rrInfo;
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) HttpDirection(com.att.aro.core.packetanalysis.pojo.HttpDirection) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 33 with HttpRequestResponseInfo

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

the class SessionManagerImpl method initializeRequestResponseObject.

private HttpRequestResponseInfo initializeRequestResponseObject(String line, Session session, PacketDirection packetDirection) {
    HttpRequestResponseInfo rrInfo = null;
    if (PacketDirection.UPLINK.equals(packetDirection)) {
        Matcher matcher = HttpPattern.strRequestType.matcher(line);
        if (matcher.lookingAt()) {
            rrInfo = new HttpRequestResponseInfo(session.getRemoteHostName(), packetDirection);
            rrInfo.setStatusLine(line);
            rrInfo.setRequestType(matcher.group(1));
            rrInfo.setDirection(HttpDirection.REQUEST);
            rrInfo.setObjName(matcher.group(2));
            rrInfo.setVersion(matcher.group(3));
            rrInfo.setPort(session.getRemotePort());
            String scheme = rrInfo.getVersion().split("/")[0];
            rrInfo.setScheme(scheme);
            try {
                if (rrInfo.getObjName().startsWith("/") || rrInfo.getObjName().startsWith(scheme.toLowerCase())) {
                    rrInfo.setObjUri(new URI(rrInfo.getObjName()));
                } else {
                    rrInfo.setObjUri(new URI(scheme.toLowerCase() + "://" + rrInfo.getObjName()));
                }
                rrInfo.setHostName(rrInfo.getObjUri().getHost());
            } catch (URISyntaxException e) {
                LOGGER.error(String.format("Problem creating a URI for line: %s", line), e);
            }
        }
    } else {
        Matcher matcher = HttpPattern.strReResponseResults.matcher(line);
        if (matcher.lookingAt()) {
            rrInfo = new HttpRequestResponseInfo(session.getRemoteHostName(), packetDirection);
            rrInfo.setStatusLine(line);
            rrInfo.setDirection(HttpDirection.RESPONSE);
            rrInfo.setVersion(matcher.group(1));
            rrInfo.setScheme(rrInfo.getVersion().split("/")[0]);
            rrInfo.setStatusCode(Integer.parseInt(matcher.group(2)));
            rrInfo.setResponseResult(matcher.group(3));
            rrInfo.setPort(session.getLocalPort());
        }
    }
    return rrInfo;
}
Also used : Matcher(java.util.regex.Matcher) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 34 with HttpRequestResponseInfo

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

the class SessionManagerImpl method analyzeRequestResponsesForQUICUDPSession.

/**
 * Estimate RequestResponseObjects for Secure Sessions
 * @param session
 * @return
 */
private ArrayList<HttpRequestResponseInfo> analyzeRequestResponsesForQUICUDPSession(Session session) {
    ArrayList<HttpRequestResponseInfo> results = new ArrayList<>();
    boolean flag = false;
    UDPPacket udpPacket = null;
    HttpRequestResponseInfo rrInfo = null;
    HttpRequestResponseInfo downlinkRRInfo = null;
    for (PacketInfo packetInfo : session.getAllPackets()) {
        udpPacket = (UDPPacket) packetInfo.getPacket();
        if (packetInfo.getDir() == PacketDirection.UPLINK) {
            if (udpPacket.getPacketLength() >= AVG_QUIC_UDP_PACKET_SIZE && !flag) {
                rrInfo = generateRequestResponseObjectsForSSLOrUDPSessions(session.getRemoteHostName(), packetInfo.getDir(), packetInfo, false);
                results.add(rrInfo);
                flag = true;
            }
            updateRequestResponseObject(rrInfo, packetInfo);
        }
        if (packetInfo.getDir() == PacketDirection.DOWNLINK) {
            if (flag) {
                downlinkRRInfo = generateRequestResponseObjectsForSSLOrUDPSessions(session.getRemoteHostName(), packetInfo.getDir(), packetInfo, false);
                results.add(downlinkRRInfo);
                flag = false;
            }
            updateRequestResponseObject(downlinkRRInfo, packetInfo);
        }
    }
    if (results.isEmpty() && !session.getUplinkPacketsSortedBySequenceNumbers().isEmpty() && !session.getDownlinkPacketsSortedBySequenceNumbers().isEmpty()) {
        PacketInfo packetInfo = identifyCorrectTransmissionStream(session.getUplinkPacketsSortedBySequenceNumbers().firstEntry().getValue(), session.getAckNumbers(), session, PacketDirection.UPLINK);
        rrInfo = generateRequestResponseObjectsForSSLOrUDPSessions(session.getRemoteHostName(), PacketDirection.UPLINK, packetInfo, false);
        packetInfo = identifyCorrectTransmissionStream(session.getUplinkPacketsSortedBySequenceNumbers().lastEntry().getValue(), session.getAckNumbers(), session, PacketDirection.UPLINK);
        rrInfo.setLastDataPacket(packetInfo);
        rrInfo.setExtractable(false);
        results.add(rrInfo);
        packetInfo = identifyCorrectTransmissionStream(session.getDownlinkPacketsSortedBySequenceNumbers().firstEntry().getValue(), session.getAckNumbers(), session, PacketDirection.DOWNLINK);
        downlinkRRInfo = generateRequestResponseObjectsForSSLOrUDPSessions(session.getRemoteHostName(), PacketDirection.DOWNLINK, packetInfo, false);
        packetInfo = identifyCorrectTransmissionStream(session.getDownlinkPacketsSortedBySequenceNumbers().lastEntry().getValue(), session.getAckNumbers(), session, PacketDirection.DOWNLINK);
        downlinkRRInfo.setLastDataPacket(packetInfo);
        downlinkRRInfo.setExtractable(false);
        results.add(downlinkRRInfo);
    }
    return results;
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) ArrayList(java.util.ArrayList) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) UDPPacket(com.att.aro.core.packetreader.pojo.UDPPacket)

Example 35 with HttpRequestResponseInfo

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

the class SessionManagerImpl method populateDataForRequestResponses.

private void populateDataForRequestResponses(Session session) {
    List<HttpRequestResponseInfo> requests = new ArrayList<HttpRequestResponseInfo>(session.getRequestResponseInfo().size());
    int requestCount = 0;
    int responseCount = 0;
    for (HttpRequestResponseInfo rrInfo : session.getRequestResponseInfo()) {
        rrInfo.setSession(session);
        if (rrInfo.getDirection() == HttpDirection.REQUEST) {
            ++requestCount;
            requests.add(rrInfo);
            if (session.getDomainName() == null) {
                String host = rrInfo.getHostName();
                if (host != null) {
                    session.setRemoteHostName(host);
                }
            }
        } else if (rrInfo.getDirection() == HttpDirection.RESPONSE) {
            ++responseCount;
            if (rrInfo.getContentLength() > 0) {
                session.setFileDownloadCount(session.getFileDownloadCount() + 1);
            }
            if (!requests.isEmpty()) {
                rrInfo.setAssocReqResp(requests.remove(0));
                rrInfo.getAssocReqResp().setAssocReqResp(rrInfo);
            }
        }
        // Build an absolute URI if possible
        if (rrInfo.getObjUri() != null && !rrInfo.getObjUri().isAbsolute()) {
            try {
                int port = Integer.valueOf(rrInfo.getPort()).equals(wellKnownPorts.get(rrInfo.getScheme())) ? -1 : rrInfo.getPort();
                rrInfo.setObjUri(new URI(rrInfo.getScheme().toLowerCase(), null, rrInfo.getHostName(), port, rrInfo.getObjUri().getPath(), rrInfo.getObjUri().getQuery(), rrInfo.getObjUri().getFragment()));
            } catch (URISyntaxException e) {
                LOGGER.info("Unexpected exception creating URI for request: " + e.getMessage() + ". Scheme=" + rrInfo.getScheme().toLowerCase() + ",Host name=" + rrInfo.getHostName() + ",Path=" + rrInfo.getObjUri().getPath() + ",Fragment=" + rrInfo.getObjUri().getFragment());
            }
        }
    }
    if (requestCount != responseCount) {
        LOGGER.trace("Session: " + session.getSessionKey() + ", Request Count: " + requestCount + ", Response Count: " + responseCount + " Don't match!");
    }
    if (!session.isUdpOnly()) {
        populateWaterfallContent(session);
    }
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

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