use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.
the class CombineCsJssImpl method runTest.
@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
CombineCsJssResult result = new CombineCsJssResult();
// Changes for US432336
List<CsJssFilesDetails> fileDetails = new ArrayList<CsJssFilesDetails>();
int inefficientCssRequests = 0;
PacketInfo consecutiveCssJsFirstPacket = null;
int inefficientJsRequests = 0;
double cssLastTimeStamp = 0.0;
double jsLastTimeStamp = 0.0;
String contentType = "";
for (Session session : tracedata.getSessionlist()) {
HttpRequestResponseInfo lastRequestObj = null;
for (HttpRequestResponseInfo httpreq : session.getRequestResponseInfo()) {
if (httpreq.getDirection() == HttpDirection.REQUEST) {
lastRequestObj = httpreq;
}
if (httpreq.getDirection() == HttpDirection.RESPONSE && httpreq.getContentType() != null) {
PacketInfo pktInfo = httpreq.getFirstDataPacket();
if (pktInfo != null) {
contentType = httpreq.getContentType().toLowerCase().trim();
if (contentType.equalsIgnoreCase("text/css")) {
if (cssLastTimeStamp == 0.0) {
cssLastTimeStamp = pktInfo.getTimeStamp();
continue;
} else {
if ((pktInfo.getTimeStamp() - cssLastTimeStamp) <= 2.0) {
inefficientCssRequests++;
// Changes for US432336
CsJssFilesDetails cssFileDetails = new CsJssFilesDetails();
cssFileDetails.setTimeStamp(pktInfo.getTimeStamp());
if (httpreq.getObjName() != null) {
cssFileDetails.setFileName(httpreq.getObjName());
} else {
if (lastRequestObj != null) {
cssFileDetails.setFileName(lastRequestObj.getObjName());
}
}
cssFileDetails.setSize(httpreq.getContentLength());
fileDetails.add(cssFileDetails);
if (consecutiveCssJsFirstPacket == null) {
consecutiveCssJsFirstPacket = pktInfo;
}
}
cssLastTimeStamp = pktInfo.getTimeStamp();
}
} else if (contentType.equalsIgnoreCase("text/javascript") || contentType.equalsIgnoreCase("application/x-javascript") || contentType.equalsIgnoreCase("application/javascript")) {
if (jsLastTimeStamp == 0.0) {
jsLastTimeStamp = pktInfo.getTimeStamp();
continue;
} else {
if ((pktInfo.getTimeStamp() - jsLastTimeStamp) < 2.0) {
inefficientJsRequests++;
// Changes for US432336
CsJssFilesDetails jsFileDetails = new CsJssFilesDetails();
jsFileDetails.setTimeStamp(pktInfo.getTimeStamp());
if (httpreq.getObjName() != null) {
jsFileDetails.setFileName(httpreq.getObjName());
} else {
if (lastRequestObj != null) {
jsFileDetails.setFileName(lastRequestObj.getObjName());
}
}
jsFileDetails.setSize(httpreq.getContentLength());
fileDetails.add(jsFileDetails);
if (consecutiveCssJsFirstPacket == null) {
consecutiveCssJsFirstPacket = pktInfo;
}
}
jsLastTimeStamp = pktInfo.getTimeStamp();
}
}
}
}
}
}
result.setConsecutiveCssJsFirstPacket(consecutiveCssJsFirstPacket);
result.setInefficientCssRequests(inefficientCssRequests);
result.setInefficientJsRequests(inefficientJsRequests);
if (inefficientCssRequests < 1 && inefficientJsRequests < 1) {
result.setResultType(BPResultType.PASS);
result.setResultText(MessageFormat.format(textResultPass, ApplicationConfig.getInstance().getAppShortName()));
} else {
result.setResultType(BPResultType.FAIL);
result.setResultText(textResults);
// Changes for US432336
result.setFilesDetails(fileDetails);
}
result.setResultExcelText(result.getResultType().getDescription());
result.setAboutText(aboutText);
result.setDetailTitle(detailTitle);
result.setLearnMoreUrl(learnMoreUrl);
result.setOverviewTitle(overviewTitle);
result.setExportAllInefficientCssRequest(exportAllInefficientCssRequest);
result.setExportAllInefficientJsRequest(exportAllInefficientJsRequest);
return result;
}
use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.
the class HttpsUsageImpl method buildHttpsUsageEntry.
/*
* If an IP contains a session that does not contain any SSL packet, we
* create a HttpsUsageEntry for it.
*
* This method loops through the IP-sessions map, and returns the list of
* HttpsUsageEntry created. If no IP from the IP-sessions map contains a
* connection that we consider as HTTP, the method returns an empty list.
*/
private List<HttpsUsageEntry> buildHttpsUsageEntry(Map<InetAddress, List<Session>> ipSessionsMap) {
List<HttpsUsageEntry> results = new ArrayList<HttpsUsageEntry>();
for (Map.Entry<InetAddress, List<Session>> ipSessions : ipSessionsMap.entrySet()) {
int totalNumConnectionsCurrentIp = 0;
int totalNumHttpConnectionsCurrentIp = 0;
int totalHttpTrafficInByteCurrentIp = 0;
int totalTrafficInByteCurrentIp = 0;
int httpTrafficPercentage = 0;
for (Session session : ipSessions.getValue()) {
boolean isSslSession = false;
// Excluding UDP Sessions
if (session.isUdpOnly()) {
continue;
}
List<PacketInfo> packetsInfo = session.getTcpPackets();
if (packetsInfo.isEmpty()) {
LOGGER.error("Session without packets! Session's remote IP and port: " + session.getRemoteIP().getHostAddress() + ":" + session.getRemotePort());
continue;
}
/*
* Determine if the TCP session is using SSL/TLS. If we find at
* least one TCP packet that contains one or more SSL record(s),
* we consider that session a SSL session.
*/
for (PacketInfo packetInfo : packetsInfo) {
Packet packet = packetInfo.getPacket();
if ((packet instanceof TCPPacket) && ((TCPPacket) packet).containsSSLRecord()) {
isSslSession = true;
break;
}
}
/*
* Calculate traffic size for the TCP session
*/
// total packet size (ip header + tcp header + payload) of all
// the packets in the session
// total payload size of all the packets in the session
int totalPacketsPayloadSize = 0;
for (PacketInfo packetInfo : packetsInfo) {
totalPacketsPayloadSize += packetInfo.getPayloadLen();
}
totalNumConnectionsCurrentIp++;
totalTrafficInByteCurrentIp += totalPacketsPayloadSize;
if (!(totalPacketsPayloadSize == 0 || isSslSession)) {
totalHttpTrafficInByteCurrentIp += totalPacketsPayloadSize;
totalNumHttpConnectionsCurrentIp++;
}
}
// End all sessions associated to an IP
if (totalNumHttpConnectionsCurrentIp > 0) {
BigDecimal totalTrafficInKBCurrentIp = new BigDecimal(totalTrafficInByteCurrentIp).divide(new BigDecimal(1000), 3, RoundingMode.HALF_UP);
BigDecimal totalHttpTrafficInKBCurrentIp = new BigDecimal(totalHttpTrafficInByteCurrentIp).divide(new BigDecimal(1000), 3, RoundingMode.HALF_UP);
int httpConnectionsPercentage = getHttpConnectionsPercentage(totalNumHttpConnectionsCurrentIp, totalNumConnectionsCurrentIp);
/*
* Initialize percentage to be 0 to avoid getting the
* divide-by-zero exception for any unexpected reason.
*/
if (totalTrafficInByteCurrentIp <= 0) {
LOGGER.error("Total traffic size of all TCP sessions is zero or less (" + totalTrafficInByteCurrentIp + " byte)! IP: " + ipSessions.getKey().getHostAddress());
} else {
httpTrafficPercentage = getHttpTrafficPercentage(totalHttpTrafficInByteCurrentIp, totalTrafficInByteCurrentIp);
}
String parentDomainName = getParentDomainName(ipSessions.getKey(), ipSessions.getValue());
results.add(new HttpsUsageEntry(ipSessions.getKey().getHostAddress(), parentDomainName, totalNumConnectionsCurrentIp, totalNumHttpConnectionsCurrentIp, httpConnectionsPercentage, totalTrafficInKBCurrentIp, totalHttpTrafficInKBCurrentIp, httpTrafficPercentage));
}
totalNumHttpConnectionsCurrentTrace += totalNumHttpConnectionsCurrentIp;
totalNumConnectionsCurrentTrace += totalNumConnectionsCurrentIp;
}
// End all IPs
return results;
}
use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.
the class SessionManagerImpl method analyzeACK.
/**
* Analyze the packet to find the TCPInfo. Marked flags: TCP_ACK,
* TCP_ACK_DUP, TCP_WINDOW_UPDATE, TCP_KEEP_ALIVE_ACK
*/
private void analyzeACK(Session sess) {
Map<Long, Integer> ulAckWinSize = new HashMap<Long, Integer>();
Map<Long, Integer> dlAckWinSize = new HashMap<Long, Integer>();
Set<Long> ulAliveAck = new HashSet<Long>();
Set<Long> dlAliveAck = new HashSet<Long>();
for (PacketInfo pinfo : sess.getTcpPackets()) {
TCPPacket pack = (TCPPacket) pinfo.getPacket();
if (!pack.isACK()) {
continue;
}
long ackNum = pack.getAckNumber();
int win = pack.getWindow();
Map<Long, Integer> pAckWinSize;
Set<Long> pAliveAck;
Set<Long> pAliveAck2;
switch(pinfo.getDir()) {
case UPLINK:
pAckWinSize = ulAckWinSize;
pAliveAck = ulAliveAck;
pAliveAck2 = dlAliveAck;
break;
case DOWNLINK:
pAckWinSize = dlAckWinSize;
pAliveAck = dlAliveAck;
pAliveAck2 = ulAliveAck;
break;
default:
LOGGER.warn("97 - No direction for packet. Packet ID: " + pinfo.getPacketId());
continue;
}
if (pinfo.getTcpInfo() == TcpInfo.TCP_KEEP_ALIVE) {
pAliveAck.add(pack.getSequenceNumber());
continue;
}
int tcpFlag;
if (pack.isFIN()) {
tcpFlag = 1;
} else if (pack.isSYN()) {
tcpFlag = 2;
} else if (pack.isRST()) {
tcpFlag = 4;
} else {
tcpFlag = 0;
}
long key = ((ackNum << 32) | tcpFlag);
int payloadLen = pack.getPayloadLen();
if (pAliveAck2.contains(ackNum - 1) && payloadLen == 0 && !pack.isSYN() && !pack.isFIN() && !pack.isRST()) {
pinfo.setTcpInfo(TcpInfo.TCP_KEEP_ALIVE);
} else if (!pAckWinSize.containsKey(key)) {
pAckWinSize.put(key, win);
if (payloadLen == 0 && !pack.isSYN() && !pack.isFIN() && !pack.isRST()) {
pinfo.setTcpInfo(TcpInfo.TCP_ACK);
}
} else {
int prevWin = pAckWinSize.get(key);
if (win == prevWin) {
if (payloadLen == 0 && !pack.isRST() && pinfo.getTcpInfo() != TcpInfo.TCP_KEEP_ALIVE) {
pinfo.setTcpInfo(TcpInfo.TCP_ACK_DUP);
}
} else {
pAckWinSize.put(key, win);
if (payloadLen == 0 && !pack.isRST() && pinfo.getTcpInfo() != TcpInfo.TCP_KEEP_ALIVE) {
pinfo.setTcpInfo(TcpInfo.TCP_WINDOW_UPDATE);
}
}
}
}
}
use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.
the class SessionManagerImpl method processPacketsAndAssembleSessions.
/**
* Entry point into SessionManager from PacketAnalyzerImpl
*
* returns List<Session> sessionList
*/
public List<Session> processPacketsAndAssembleSessions(List<PacketInfo> packets) {
LOGGER.warn("processPacketsAndAssembleSessions -> Trace path: " + tracePath);
List<Session> sessions = new ArrayList<>();
List<PacketInfo> udpPackets = new ArrayList<>();
Map<InetAddress, String> hostMap = new HashMap<>();
Map<String, Session> udpSessions = new LinkedHashMap<>();
Map<String, PacketInfo> dnsRequestDomains = new HashMap<>();
Map<String, List<Session>> tcpSessions = new LinkedHashMap<>();
Map<InetAddress, PacketInfo> dnsResponsePackets = new HashMap<>();
if (packets != null) {
for (PacketInfo packetInfo : packets) {
Packet packet = packetInfo.getPacket();
if (packet instanceof UDPPacket) {
// UDP
udpPackets.add(packetInfo);
if (((UDPPacket) packet).isDNSPacket()) {
DomainNameSystem dns = ((UDPPacket) packet).getDns();
if (dns != null && dns.isResponse()) {
for (InetAddress inet : dns.getIpAddresses()) {
hostMap.put(inet, dns.getDomainName());
dnsResponsePackets.put(inet, packetInfo);
}
} else if (dns != null && !dns.isResponse()) {
dnsRequestDomains.put(dns.getDomainName(), packetInfo);
}
}
associatePacketToUDPSessionAndPopulateCollections(sessions, udpSessions, packetInfo, (UDPPacket) packet);
} else if (packet instanceof TCPPacket) {
// TCP
TCPPacket tcpPacket = (TCPPacket) packet;
packetInfo.setTcpInfo(null);
Session session = associatePacketToTCPSessionAndPopulateCollections(sessions, tcpSessions, packetInfo, tcpPacket);
populateTCPPacketInfo(packetInfo, tcpPacket);
session.setSsl(session.isSsl() ? session.isSsl() : tcpPacket.isSsl());
if (tcpPacket.isDecrypted()) {
tcpPacket.setDataOffset(0);
session.setDecrypted(true);
}
if (session.getDnsResponsePacket() == null && dnsResponsePackets.containsKey(session.getRemoteIP())) {
session.setDnsResponsePacket(dnsResponsePackets.get(session.getRemoteIP()));
session.setDomainName((((UDPPacket) (session.getDnsResponsePacket()).getPacket()).getDns()).getIpAddresses().stream().findFirst().get().getHostName());
}
if (session.getDnsRequestPacket() == null && StringUtils.isNotBlank(session.getDomainName()) && dnsRequestDomains.containsKey(session.getDomainName())) {
session.setRemoteHostName(session.getDomainName());
session.setDnsRequestPacket(dnsRequestDomains.get(session.getDomainName()));
} else {
session.setRemoteHostName(hostMap.get(session.getRemoteIP()));
}
if (tcpPacket.isSslHandshake()) {
session.setLastSslHandshakePacket(packetInfo);
if (tcpPacket.isClientHello() && StringUtils.isNotBlank(tcpPacket.getServerNameIndication())) {
session.setServerNameIndication(tcpPacket.getServerNameIndication());
}
}
if (packetInfo.getAppName() != null) {
session.getAppNames().add(packetInfo.getAppName());
}
if (!session.isSessionComplete() && (packetInfo.getTcpFlagString().contains("R") || packetInfo.getTcpFlagString().contains("F"))) {
session.setSessionComplete(true);
}
session.setLatency((!session.getSynAckPackets().isEmpty() && !session.getSynPackets().isEmpty()) ? calculateLatency(session) : -1);
}
}
}
Collections.sort(sessions);
analyzeRequestResponses(sessions);
return sessions;
}
use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.
the class SessionManagerImpl method readFileAndPopulateRequestResponse.
private ArrayList<HttpRequestResponseInfo> readFileAndPopulateRequestResponse(Session session, ArrayList<HttpRequestResponseInfo> results, String filePath, PacketDirection packetDirection, HttpDirection httpDirection) throws IOException {
String dataRead;
long timeStamp = 0;
HttpRequestResponseInfo rrInfo = null;
int requestCount = 0;
TreeMap<Double, PacketInfo> packetMap;
BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath));
Map<Double, PacketInfo> usedPackets = new HashMap<>();
if (packetDirection == PacketDirection.UPLINK) {
packetMap = new TreeMap<>(session.getAllPackets().stream().filter(packetInfo -> packetInfo.getDir().equals(PacketDirection.UPLINK)).collect(Collectors.toMap(PacketInfo::getTimeStamp, Function.identity(), (existing, replacement) -> existing)));
} else {
packetMap = new TreeMap<>(session.getAllPackets().stream().filter(packetInfo -> packetInfo.getDir().equals(PacketDirection.DOWNLINK)).collect(Collectors.toMap(PacketInfo::getTimeStamp, Function.identity(), (existing, replacement) -> existing)));
}
try {
while ((dataRead = bufferedReader.readLine()) != null) {
if (dataRead.length() > 0) {
String comparisonString = "RequestTime: ";
if (dataRead.startsWith(comparisonString)) {
++requestCount;
timeStamp = Long.parseLong(dataRead.substring(comparisonString.length(), dataRead.length()));
continue;
}
rrInfo = initializeRequestResponseObject(dataRead, session, packetDirection);
if (rrInfo != null) {
rrInfo.setTCP(true);
rrInfo.setRawSize(-1);
// Converting the System Time in Millis to Seconds and Microsecond format.
double time = ((double) timeStamp / 1000) + (((double) timeStamp % 1000) / 1000000.0);
// The math below allows the request time to have a start time relative to trace capture.
rrInfo.setTime(time - pcapTimeOffset);
// TODO: Will Review this after ARO22945-1645
if (packetMap.containsKey(rrInfo.getTime()) && !usedPackets.containsKey(rrInfo.getTime())) {
rrInfo.setFirstDataPacket(packetMap.get(rrInfo.getTime()));
usedPackets.put(rrInfo.getTime(), packetMap.get(rrInfo.getTime()));
} else {
Map.Entry<Double, PacketInfo> lowKey = packetMap.floorEntry(rrInfo.getTime());
Map.Entry<Double, PacketInfo> highKey = packetMap.ceilingEntry(rrInfo.getTime());
if (lowKey != null) {
setFirstAndLastDataPacket(results, usedPackets, rrInfo, packetMap, lowKey);
} else if (highKey != null) {
setFirstAndLastDataPacket(results, usedPackets, rrInfo, packetMap, highKey);
}
}
rrInfo.writeHeader(dataRead);
while ((dataRead = bufferedReader.readLine()) != null && dataRead.length() != 0) {
rrInfo.writeHeader(System.lineSeparator());
rrInfo.writeHeader(dataRead);
parseHeaderLine.parseHeaderLine(dataRead, rrInfo);
}
rrInfo.writeHeader(System.lineSeparator());
// Check for payload and read
File file = new File(filePath + "_" + requestCount);
if (file.exists()) {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
rrInfo.writePayload(bis);
bis.close();
}
results.add(rrInfo);
}
}
}
} finally {
bufferedReader.close();
}
return results;
}
Aggregations