use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.
the class SessionManagerImpl method generateRequestResponseObjectsForSSLOrUDPSessions.
/**
* Generates a Dummy RequestResponseObjects for Secure Sessions
* @param remoteHostName
* @param packetDirection
* @param packetInfo
* @return
*/
private HttpRequestResponseInfo generateRequestResponseObjectsForSSLOrUDPSessions(String remoteHostName, PacketDirection packetDirection, PacketInfo packetInfo, boolean isTCP) {
HttpRequestResponseInfo rrInfo = new HttpRequestResponseInfo(remoteHostName, packetDirection);
populateRRInfo(rrInfo, packetInfo, false, isTCP, (packetDirection == PacketDirection.UPLINK ? HttpDirection.REQUEST : HttpDirection.RESPONSE));
return rrInfo;
}
use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.
the class CacheAnalysisImpl method analyze.
@Override
public CacheAnalysis analyze(List<Session> sessionlist) {
long analysisStartTime = System.currentTimeMillis();
CacheAnalysis result = new CacheAnalysis();
long totalRequestResponseBytes = 0;
long totalRequestResponseDupBytes = 0;
double duplicateContentBytesRatio = 0.0;
Map<String, CacheEntry> cacheEntries = new HashMap<String, CacheEntry>();
Map<String, CacheEntry> dupEntries = new HashMap<String, CacheEntry>();
Map<String, SortedSet<Range>> rangeEntries = new HashMap<String, SortedSet<Range>>();
List<CacheEntry> diagnosisResults = new ArrayList<CacheEntry>();
List<CacheEntry> duplicateContent = new ArrayList<CacheEntry>();
List<CacheEntry> duplicateContentWithOriginals = new ArrayList<CacheEntry>();
Map<CacheExpiration, List<CacheEntry>> cacheExpirationResponses = result.getCacheExpirationResponses();
duplicateEntries = new ArrayList<DuplicateEntry>();
// Initialize cache expiration lists
for (CacheExpiration expiration : CacheExpiration.values()) {
cacheExpirationResponses.put(expiration, new ArrayList<CacheEntry>());
}
// Build a sorted list of all of the HTTP request/response in the trace
List<HttpRequestResponseInfoWithSession> rrInfo = new ArrayList<HttpRequestResponseInfoWithSession>();
for (Session session : sessionlist) {
if (!session.isUdpOnly()) {
// rrInfo.addAll(session.getRequestResponseInfo());
for (HttpRequestResponseInfo item : session.getRequestResponseInfo()) {
HttpRequestResponseInfoWithSession itemsession = new HttpRequestResponseInfoWithSession();
itemsession.setInfo(item);
itemsession.setSession(session);
rrInfo.add(itemsession);
}
}
}
Collections.sort(rrInfo);
// Iterate through responses looking for duplicates
for (HttpRequestResponseInfoWithSession httpreqres : rrInfo) {
HttpRequestResponseInfo response = httpreqres.getInfo();
Session session = httpreqres.getSession();
PacketInfo firstPacket = session.getTcpPackets().get(0);
if (response.getDirection() == HttpDirection.REQUEST) {
// We only want to process responses
continue;
}
// Check whether response is valid
int statusCode = response.getStatusCode();
if (statusCode == 0) {
diagnosisResults.add(new CacheEntry(null, response, Diagnosis.CACHING_DIAG_INVALID_RESPONSE, 0, firstPacket));
continue;
}
if (statusCode != 200 && statusCode != 206) {
diagnosisResults.add(new CacheEntry(null, response, Diagnosis.CACHING_DIAG_INVALID_REQUEST, 0, firstPacket));
continue;
}
// [A] Find corresponding request
HttpRequestResponseInfo request = response.getAssocReqResp();
if (request == null) {
diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_REQUEST_NOT_FOUND, 0, firstPacket));
continue;
}
totalRequestResponseBytes += response.getContentLength();
// Request must by GET, POST, or PUT
String requestType = request.getRequestType();
if (!HttpRequestResponseInfo.HTTP_GET.equals(requestType) && !HttpRequestResponseInfo.HTTP_PUT.equals(requestType) && !HttpRequestResponseInfo.HTTP_POST.equals(requestType)) {
diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_INVALID_REQUEST, 0, firstPacket));
continue;
}
// Check for valid object name and host name
if (request.getHostName() == null || request.getObjName() == null) {
diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_INVALID_OBJ_NAME, 0, firstPacket));
continue;
}
// [B] Object cacheable?
if (response.isNoStore() || request.isNoStore() || HttpRequestResponseInfo.HTTP_POST.equals(requestType) || HttpRequestResponseInfo.HTTP_PUT.equals(requestType)) {
cacheEntries.remove(getObjFullName(request, response));
dupEntries.remove(getObjDuplicateName(request, response));
diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_NOT_CACHABLE, 0, firstPacket));
continue;
}
// [C] Does it hit the cache?
CacheEntry cacheEntry = cacheEntries.get(getObjFullName(request, response));
CacheEntry cacheDuplicateEntry = dupEntries.get(getObjDuplicateName(request, response));
CacheEntry newCacheEntry;
if (cacheEntry == null) {
Diagnosis diagnosis = Diagnosis.CACHING_DIAG_CACHE_MISSED;
newCacheEntry = new CacheEntry(request, response, diagnosis, firstPacket);
newCacheEntry.setSession(session);
addToCache(newCacheEntry, rangeEntries, cacheEntries, dupEntries, session);
newCacheEntry.setCacheCount(1);
diagnosisResults.add(newCacheEntry);
if (cacheDuplicateEntry != null) {
diagnosis = Diagnosis.CACHING_DIAG_ETAG_DUPLICATE;
}
duplicateEntries.add(new DuplicateEntry(request, response, diagnosis, firstPacket, session, getContent(response, session)));
continue;
} else {
int oldCount = cacheEntry.getCacheCount();
cacheEntry.setCacheCount(oldCount + 1);
}
CacheExpiration expStatus = cacheExpired(cacheEntry, request.getAbsTimeStamp());
SortedSet<Range> ranges = rangeEntries.get(getObjFullName(cacheEntry.getRequest(), cacheEntry.getResponse()));
boolean isfullcachehit = isFullCacheHit(response, ranges);
if (isfullcachehit) {
// [D] Is it expired?
switch(expStatus) {
case CACHE_EXPIRED:
case CACHE_EXPIRED_HEURISTIC:
newCacheEntry = handleCacheExpired(session, response, request, firstPacket, cacheEntry);
diagnosisResults.add(newCacheEntry);
break;
case CACHE_NOT_EXPIRED:
case CACHE_NOT_EXPIRED_HEURISTIC:
newCacheEntry = new CacheEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP, firstPacket);
duplicateEntries.add(new DuplicateEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP, firstPacket, session, getContent(response, session)));
diagnosisResults.add(newCacheEntry);
break;
default:
// Should not occur
newCacheEntry = null;
}
} else {
long bytesInCache = getBytesInCache(response, ranges);
// [D] Is it expired?
switch(expStatus) {
case CACHE_EXPIRED:
case CACHE_EXPIRED_HEURISTIC:
newCacheEntry = handleCacheExpiredWithByteInCache(session, response, request, firstPacket, cacheEntry, bytesInCache);
diagnosisResults.add(newCacheEntry);
break;
case CACHE_NOT_EXPIRED:
case CACHE_NOT_EXPIRED_HEURISTIC:
newCacheEntry = new CacheEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT, bytesInCache, firstPacket);
duplicateEntries.add(new DuplicateEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP, firstPacket, session, getContent(response, session)));
diagnosisResults.add(newCacheEntry);
break;
default:
// Should not occur
newCacheEntry = null;
}
}
cacheExpirationResponses.get(expStatus).add(newCacheEntry);
if (newCacheEntry != null) {
newCacheEntry.setCacheHit(cacheEntry);
}
// addToCache(newCacheEntry);
}
// END: Iterate through responses looking for duplicates
// Get cache problems
Set<CacheEntry> dupsWithOrig = new HashSet<CacheEntry>();
Map<String, DuplicateEntry> duplicateEntriesMap = new HashMap<String, DuplicateEntry>();
CacheEntry cache;
for (DuplicateEntry dupEntry : duplicateEntries) {
if (dupEntry.getContentLength() > 0) {
String key = dupEntry.getRequest().getHostName() + dupEntry.getHttpObjectName() + dupEntry.getContentLength();
if (dupEntry.getHttpObjectName() != null) {
if (!duplicateEntriesMap.containsKey(key)) {
dupEntry.setCount(1);
duplicateEntriesMap.put(key, dupEntry);
} else {
if (Arrays.equals(duplicateEntriesMap.get(key).getContent(), dupEntry.getContent())) {
int count = duplicateEntriesMap.get(key).getCount();
if (count == 1) {
cache = new CacheEntry(duplicateEntriesMap.get(key).getRequest(), duplicateEntriesMap.get(key).getResponse(), duplicateEntriesMap.get(key).getDiagnosis(), duplicateEntriesMap.get(key).getSessionFirstPacket());
cache.setSession(dupEntry.getSession());
dupsWithOrig.add(cache);
}
cache = new CacheEntry(dupEntry.getRequest(), dupEntry.getResponse(), dupEntry.getDiagnosis(), dupEntry.getSessionFirstPacket());
dupsWithOrig.add(cache);
dupEntry = new DuplicateEntry(dupEntry.getRequest(), dupEntry.getResponse(), dupEntry.getDiagnosis(), dupEntry.getSessionFirstPacket(), dupEntry.getSession(), dupEntry.getContent());
dupEntry.setCount(count + 1);
duplicateEntriesMap.replace(key, dupEntry);
}
}
}
}
}
for (Entry<String, DuplicateEntry> cacheEntry2 : duplicateEntriesMap.entrySet()) {
if (cacheEntry2.getValue().getCount() > 1) {
int count = cacheEntry2.getValue().getCount();
cache = new CacheEntry(cacheEntry2.getValue().getRequest(), cacheEntry2.getValue().getResponse(), cacheEntry2.getValue().getDiagnosis(), cacheEntry2.getValue().getSessionFirstPacket());
cache.setHitCount(count);
if (count > 2) {
totalRequestResponseDupBytes += (cacheEntry2.getValue().getHttpRequestResponse().getContentLength() * (count - 1));
} else {
totalRequestResponseDupBytes += cacheEntry2.getValue().getHttpRequestResponse().getContentLength();
}
duplicateContent.add(cache);
}
}
duplicateContentWithOriginals.addAll(dupsWithOrig);
Collections.sort(duplicateContentWithOriginals);
duplicateContentBytesRatio = totalRequestResponseBytes != 0 ? (double) totalRequestResponseDupBytes / totalRequestResponseBytes : 0.0;
result.setCacheExpirationResponses(cacheExpirationResponses);
result.setDiagnosisResults(diagnosisResults);
result.setDuplicateContent(duplicateContent);
result.setDuplicateContentBytesRatio(duplicateContentBytesRatio);
result.setDuplicateContentWithOriginals(duplicateContentWithOriginals);
result.setTotalRequestResponseBytes(totalRequestResponseBytes);
result.setTotalRequestResponseDupBytes(totalRequestResponseDupBytes);
GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsTimings(cacheAnalysisTitle, System.currentTimeMillis() - analysisStartTime, analysisCategory);
return result;
}
use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.
the class ImageExtractor method scanAndExtractImages.
public void scanAndExtractImages(List<Session> sessionlist) {
if (fileManager.directoryExistAndNotEmpty(imagePath)) {
return;
}
for (Session session : sessionlist) {
for (HttpRequestResponseInfo reqResp : session.getRequestResponseInfo()) {
if (reqResp.getDirection() == HttpDirection.RESPONSE && reqResp.getContentType() != null && reqResp.getContentType().contains("image/")) {
HttpRequestResponseInfo req = reqResp.getAssocReqResp();
if (req == null) {
LOGGER.error(String.format("BROKEN req/resp link @ %s", reqResp.getAllHeaders()));
continue;
}
if (req.getObjName() == null || reqResp.getAssocReqResp() == null) {
LOGGER.error("Probable Request/Response linkage problem with " + req + ", " + reqResp);
continue;
}
String imageObject = reqResp.getAssocReqResp().getObjName();
if (imageObject != null && reqResp.getContentType() != null) {
if (imageObject.indexOf("?v=") >= 0) {
String fullName = Util.extractFullNameFromLink(imageObject);
String extension = "." + reqResp.getContentType().substring(reqResp.getContentType().indexOf("image/") + 6, reqResp.getContentType().length());
extractImage(session, reqResp, fullName + extension);
}
}
}
}
}
}
use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.
the class ImageExtractor method execute.
public void execute(AbstractTraceResult result, List<Session> sessionList, Map<Double, HttpRequestResponseInfo> requestMap) {
imagePath = result.getTraceDirectory() + Util.FILE_SEPARATOR + "Image" + Util.FILE_SEPARATOR;
long analysisStartTime = System.currentTimeMillis();
if (!fileManager.directoryExist(imagePath)) {
imageExtractionRequired = true;
fileManager.mkDir(imagePath);
} else {
imageExtractionRequired = false;
}
for (HttpRequestResponseInfo req : requestMap.values()) {
LOGGER.info(req.toString());
if (req.getAssocReqResp() == null) {
continue;
}
String fullName = VideoImageAnalysisUtil.extractFullNameFromRRInfo(req);
String extn = VideoImageAnalysisUtil.extractExtensionFromName(req.getFileName(), stringParse);
if (StringUtils.isNotBlank(extn)) {
switch(extn) {
case ".jpg":
case ".gif":
case ".tif":
case ".png":
case ".jpeg":
if (imageExtractionRequired) {
fullName = VideoImageAnalysisUtil.extractFullNameFromRRInfo(req);
extractImage(req, fullName);
}
break;
default:
break;
}
}
scanAndExtractImages(sessionList);
GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsTimings(imageAnalysisTitle, System.currentTimeMillis() - analysisStartTime, analysisCategory);
}
}
use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.
the class ManifestBuilder method findManifest.
/**
* @param request
* @return ManifestCollection, null if not found
*/
public ManifestCollection findManifest(HttpRequestResponseInfo request) {
LOG.debug(String.format("locating manifest for|<%s>|", request.getObjUri().toString()));
if (CollectionUtils.isEmpty(manifestCollectionMap)) {
return null;
}
// initial
manifestCollectionToBeReturned = null;
identifiedManifestRequestTime = 0;
byteRangeKey = "";
double manifestReqTime = 0;
double lastManifestReqTime = 0;
for (Map<Double, ManifestCollection> innerMap : manifestCollectionMap.values()) {
for (ManifestCollection manifestCollection : innerMap.values()) {
if (manifestCollection.getManifest().getRequestTime() < request.getTimeStamp()) {
manifestReqTime = manifestCollection.getManifest().getRequestTime();
if (lastManifestReqTime == 0 || lastManifestReqTime < manifestReqTime) {
for (UrlMatchDef urlMatchDef : manifestCollection.getManifest().getMasterManifest().getSegUrlMatchDef()) {
key = buildUriNameKey(urlMatchDef, request);
// VID-TODO find #EXT-X-MAP:URI="5b3733a4-e7db-4700-975b-4e842c158274/3cec-BUMPER/02/1200K/map.mp4"
key += "|" + formatTimeKey(manifestCollection.getManifest().getRequestTime());
if (!StringUtils.isEmpty(key)) {
if (locatePatKey(segmentManifestCollectionMap, key, request, urlMatchDef) != null) {
manifestCollectionToBeReturned = manifestCollection;
lastManifestReqTime = manifestReqTime;
return manifestCollectionToBeReturned;
}
}
}
}
}
}
}
for (UrlMatchDef urlMatchDef : masterManifest.getSegUrlMatchDef()) {
key = buildUriNameKey(urlMatchDef, request);
if (StringUtils.isEmpty(key) && segmentManifestCollectionMap.selectKey("#EXT-X-BYTERANGE:") != null) {
String[] range = stringParse.parse(request.getAllHeaders(), "Range: bytes=(\\d+)-(\\d+)");
if (range != null) {
// #EXT-X-BYTERANGE:207928@0 //
String segName = String.format("#EXT-X-BYTERANGE:%.0f@%s", StringParse.stringToDouble(range[1], 0D) + 1, range[0]);
key = segmentManifestCollectionMap.selectKey(segName);
if (key.startsWith(segName)) {
key = keyMatch(request, segName, urlMatchDef);
byteRangeKey = segName;
} else {
LOG.error(String.format("Bad key match <%s> %s<>", segName, key));
key = "";
}
}
}
String key1 = StringUtils.substringBefore(key, "|");
try {
List<Entry<String, String>> tempList = segmentManifestCollectionMap.entrySet().parallelStream().filter(segmentManifestCollectionMapEntry -> segmentManifestCollectionMapEntry.getKey().contains(key)).collect(Collectors.toList());
if (tempList.size() > 1) {
tempList.stream().forEach(x -> {
manifestCollectionMap.entrySet().stream().filter(y -> y.getKey().contains(x.getValue())).forEach(y -> {
y.getValue().entrySet().stream().forEach(z -> {
if (request.getTimeStamp() > z.getKey() && z.getKey() > identifiedManifestRequestTime) {
identifiedManifestRequestTime = z.getKey();
manifestCollectionToBeReturned = z.getValue();
}
});
});
});
} else if (tempList.size() == 1 && !manifestCollectionMap.isEmpty()) {
String key = tempList.get(0).getValue();
manifestCollectionMap.entrySet().stream().filter(f -> f.getKey().endsWith(key)).forEach(outerMap -> {
outerMap.getValue().entrySet().stream().filter(f -> f.getKey() <= request.getTimeStamp() && f.getValue().getSegmentChildManifestTrie().containsKey(key1)).forEach(innerMap -> {
manifestCollectionToBeReturned = innerMap.getValue();
});
});
if (manifestCollectionToBeReturned == null) {
manifestCollectionMap.entrySet().stream().filter(f -> f.getKey().endsWith(key)).forEach(outerMap -> {
outerMap.getValue().entrySet().stream().filter(f -> f.getKey() <= request.getTimeStamp()).forEach(innerMap -> {
manifestCollectionToBeReturned = innerMap.getValue();
});
});
}
}
} catch (Exception e) {
LOG.error("Failed to locate manifestCollection: ", e);
}
if (manifestCollectionToBeReturned != null) {
break;
}
}
return manifestCollectionToBeReturned;
}
Aggregations