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