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);
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations