use of com.att.aro.core.packetanalysis.pojo.Statistic in project VideoOptimzer by attdevsupport.
the class HtmlReportImpl method getTimeRangeAnalysisAndStatisticRows.
private String getTimeRangeAnalysisAndStatisticRows(PacketAnalyzerResult results) {
StringBuilder builder = new StringBuilder();
if (results != null) {
TimeRangeAnalysis timeRangeAnalysis = results.getTimeRangeAnalysis();
// Calculate time range
if (timeRangeAnalysis == null) {
AnalysisFilter filter = results.getFilter();
double beginTime = 0.0d;
double endTime = 0.0d;
boolean readyForAnalysis = false;
if (filter != null && filter.getTimeRange() != null) {
beginTime = filter.getTimeRange().getBeginTime();
endTime = filter.getTimeRange().getEndTime();
readyForAnalysis = true;
} else if (results.getTraceresult() != null) {
endTime = results.getTraceresult().getTraceDuration();
readyForAnalysis = true;
}
if (readyForAnalysis) {
timeRangeAnalysis = new TimeRangeAnalysis(beginTime, endTime, results);
}
}
if (timeRangeAnalysis != null) {
double traceDuration = timeRangeAnalysis.getEndTime() - timeRangeAnalysis.getStartTime();
long traceDurationLong = (long) traceDuration;
builder.append("<tr><th>Duration (second)</th><td>" + String.format("%.3f", traceDuration) + "</td></tr>");
builder.append("<tr><th>Duration (hh:mm:ss.sss)</th><td>" + String.format("%02d:%02d:%02d", traceDurationLong / 3600, (traceDurationLong % 3600) / 60, traceDurationLong % 60) + String.format("%.3f", traceDuration - Math.floor(traceDuration)).substring(1));
String timeRangeTitle = results.getTraceresult().getTimeRange().getTitle();
builder.append("<tr><th>Time Range Identifier</th><td>" + (timeRangeTitle != null ? timeRangeTitle : "") + "</td></tr>");
builder.append("<tr><th>Start Time (second)</th><td>" + doubleToFixedDecimal(timeRangeAnalysis.getStartTime(), 3) + "</td></tr>");
builder.append("<tr><th>End Time (second)</th><td>" + doubleToFixedDecimal(timeRangeAnalysis.getEndTime(), 3) + "</td></tr>");
}
Statistic statistic = results.getStatistic();
if (statistic != null) {
builder.append(tableLIne() + "<th>Total Data (Byte)</th><td>" + statistic.getTotalByte() + tableChange() + System.getProperty(lineSeperator()));
builder.append(tableLIne() + "<th>Total PayLoad Data (Byte)</th><td>" + statistic.getTotalPayloadBytes() + tableChange() + System.getProperty(lineSeperator()));
builder.append(tableLIne() + "<th>Total HTTPS Data (Byte)</th><td>" + statistic.getTotalHTTPSByte() + " (" + String.format("%.2f", statistic.getTotalHTTPSByte() * 100.0 / statistic.getTotalByte()) + "%)" + tableChange() + System.getProperty(lineSeperator()));
builder.append(tableLIne() + "<th>Total Unanalyzed HTTPS Data (Byte)</th><td>" + statistic.getTotalHTTPSBytesNotAnalyzed() + " (" + String.format("%.2f", statistic.getTotalHTTPSBytesNotAnalyzed() * 100.0 / statistic.getTotalByte()) + "%)</td>" + System.getProperty(lineSeperator()));
}
if (timeRangeAnalysis != null) {
builder.append("<tr><th>Average Throughput (kbps)</th><td>" + doubleToFixedDecimal(timeRangeAnalysis.getAverageThroughput(), 2) + "</td></tr>" + System.getProperty(lineSeperator()));
builder.append("<tr><th>Total Upload Data (Byte)</th><td>" + timeRangeAnalysis.getUplinkBytes() + "</td></tr>" + System.getProperty(lineSeperator()));
builder.append("<tr><th>Average Upload Throughput (kbps)</th><td>" + doubleToFixedDecimal(timeRangeAnalysis.getAverageUplinkThroughput(), 2) + "</td></tr>" + System.getProperty(lineSeperator()));
builder.append("<tr><th>Total Download Data (Byte)</th><td>" + timeRangeAnalysis.getDownlinkBytes() + "</td></tr>" + System.getProperty(lineSeperator()));
builder.append("<tr><th>Average Download Throughput (kbps)</th><td>" + doubleToFixedDecimal(timeRangeAnalysis.getAverageDownlinkThroughput(), 2) + "</td></tr>" + System.getProperty(lineSeperator()));
}
EnergyModel energyModel = results.getEnergyModel();
if (energyModel != null) {
builder.append("<tr><th>Total Energy Consumed (J)</th><td>" + doubleToFixedDecimal(energyModel.getTotalEnergyConsumed(), 2) + "</td></tr>" + System.getProperty(lineSeperator()));
}
}
return builder.toString();
}
use of com.att.aro.core.packetanalysis.pojo.Statistic in project VideoOptimzer by attdevsupport.
the class PacketAnalyzerImplTest method test_getStatisticResult.
@Test
public void test_getStatisticResult() throws UnknownHostException {
InetAddress iAdr = Mockito.mock(InetAddress.class);
InetAddress iAdr1 = Mockito.mock(InetAddress.class);
Mockito.when(iAdr.getAddress()).thenReturn(new byte[] { 89, 10, 1, 1 });
Mockito.when(iAdr1.getAddress()).thenReturn(new byte[] { 72, 12, 13, 1 });
Set<InetAddress> inetSet = new HashSet<InetAddress>();
inetSet.add(iAdr);
inetSet.add(iAdr1);
DomainNameSystem dns = Mockito.mock(DomainNameSystem.class);
Mockito.when(dns.getIpAddresses()).thenReturn(inetSet);
Mockito.when(dns.getDomainName()).thenReturn("www.att.com");
UDPPacket udpPacket = Mockito.mock(UDPPacket.class);
Mockito.when(udpPacket.isDNSPacket()).thenReturn(true);
Mockito.when(udpPacket.getDns()).thenReturn(dns);
Mockito.when(udpPacket.getSourcePort()).thenReturn(83);
Mockito.when(udpPacket.getDestinationPort()).thenReturn(84);
Mockito.when(udpPacket.getDestinationIPAddress()).thenReturn(iAdr);
PacketInfo packetInfo1 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo1.getPacket()).thenReturn(udpPacket);
Mockito.when(packetInfo1.getDir()).thenReturn(PacketDirection.UPLINK);
Mockito.when(packetInfo1.getPayloadLen()).thenReturn(0);
Mockito.when(packetInfo1.getLen()).thenReturn(10);
Mockito.when(packetInfo1.getAppName()).thenReturn("Test1");
Mockito.when(packetInfo1.getTcpFlagString()).thenReturn("TestString");
Mockito.when(packetInfo1.getTimeStamp()).thenReturn(500d);
InetAddress iAdr2 = Mockito.mock(InetAddress.class);
Mockito.when(iAdr2.getAddress()).thenReturn(new byte[] { 95, 10, 1, 1 });
TCPPacket tcpPacket = Mockito.mock(TCPPacket.class);
Mockito.when(tcpPacket.getSourcePort()).thenReturn(81);
Mockito.when(tcpPacket.getDestinationPort()).thenReturn(82);
Mockito.when(tcpPacket.getDestinationIPAddress()).thenReturn(iAdr2);
Mockito.when(tcpPacket.isSYN()).thenReturn(true);
Mockito.when(tcpPacket.isFIN()).thenReturn(true);
Mockito.when(tcpPacket.isRST()).thenReturn(true);
Mockito.when(tcpPacket.getTimeStamp()).thenReturn(1000d);
PacketInfo packetInfo2 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo2.getPacket()).thenReturn(tcpPacket);
Mockito.when(packetInfo2.getDir()).thenReturn(PacketDirection.UPLINK);
Mockito.when(packetInfo2.getTcpInfo()).thenReturn(TcpInfo.TCP_ESTABLISH);
Mockito.when(packetInfo2.getPayloadLen()).thenReturn(0);
Mockito.when(packetInfo2.getLen()).thenReturn(15);
Mockito.when(packetInfo2.getAppName()).thenReturn("Test2");
Mockito.when(packetInfo2.getTcpFlagString()).thenReturn("Test2String");
Mockito.when(packetInfo2.getTimeStamp()).thenReturn(10d);
TCPPacket tcpPacket2 = Mockito.mock(TCPPacket.class);
Mockito.when(tcpPacket2.getSourcePort()).thenReturn(95);
Mockito.when(tcpPacket2.getDestinationPort()).thenReturn(99);
Mockito.when(tcpPacket2.getDestinationIPAddress()).thenReturn(iAdr2);
Mockito.when(tcpPacket2.isSYN()).thenReturn(true);
Mockito.when(tcpPacket2.isFIN()).thenReturn(true);
Mockito.when(tcpPacket2.isRST()).thenReturn(false);
Mockito.when(tcpPacket2.getTimeStamp()).thenReturn(50d);
Inet4Address address = (Inet4Address) InetAddress.getByName("192.168.1.4");
PacketInfo packetInfo3 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo3.getPacket()).thenReturn(tcpPacket2);
Mockito.when(packetInfo3.getDir()).thenReturn(PacketDirection.UPLINK);
Mockito.when(packetInfo3.getTcpInfo()).thenReturn(TcpInfo.TCP_ESTABLISH);
Mockito.when(packetInfo3.getPayloadLen()).thenReturn(0);
Mockito.when(packetInfo3.getLen()).thenReturn(15);
Mockito.when(packetInfo3.getAppName()).thenReturn("Test2");
Mockito.when(packetInfo3.getTcpFlagString()).thenReturn("Test2String");
Mockito.when(packetInfo3.getTimeStamp()).thenReturn(10d);
Mockito.when(packetInfo3.getRemoteIPAddress()).thenReturn(address);
List<PacketInfo> packetsList = new ArrayList<PacketInfo>();
// Adding UDP Packet to the list
packetsList.add(packetInfo1);
packetsList.add(packetInfo2);
packetsList.add(packetInfo3);
Statistic testResult = iPacketAnalyzer.getStatistic(packetsList);
assertEquals(3, testResult.getTotalPackets());
}
use of com.att.aro.core.packetanalysis.pojo.Statistic in project VideoOptimzer by attdevsupport.
the class PacketAnalyzerImpl method finalResult.
protected PacketAnalyzerResult finalResult(AbstractTraceResult result, Profile profile, AnalysisFilter filter) {
PacketAnalyzerResult data = new PacketAnalyzerResult();
if (filter == null) {
double endTime = result.getAllpackets().size() > 0 ? Math.max(result.getAllpackets().get(result.getAllpackets().size() - 1).getTimeStamp(), result.getTraceDuration()) : 0.0;
result.setTimeRange(new TimeRange("Full", TimeRange.TimeRangeType.FULL, 0.0, endTime));
} else {
result.setTimeRange(filter.getTimeRange());
}
// List of packets included in analysis (application filtered)
List<PacketInfo> filteredPackets;
Profile aProfile = profile;
if (aProfile == null) {
// if the user doesn't load any profile.....
aProfile = profilefactory.createLTEdefault();
aProfile.setName("AT&T LTE");
}
// for the situation, filter out all no-ip packets and caused the allpackets is empty, need to refactor
if (result != null && result.getAllpackets() != null && result.getAllpackets().size() == 0) {
data.setTraceresult(result);
return data;
}
/* Purpose of this code block is to finish building out the filter, if needed, for TimeRange analysis
*
* This code block is excuted when:
* 1: time-range.json exists in trace folder
* a: and the json contains an entry with RangeType.AUTO
* 2: A TimeRange object was created and launched in TimeRangeEditorDialog
*
* AroController will have created an AnalysisFilter and so filter will not be null
*
*/
try {
if ((filter != null && filter.getTimeRange() != null && filter.getTimeRange().getPath() != null) || result.getAllAppNames().size() == 1) {
String app = TraceDataReaderImpl.UNKNOWN_APPNAME;
if (filter != null && filter.getAppSelections() != null && filter.getAppSelections().containsKey(app) && filter.getAppSelections().get(app).getIPAddressSelections().isEmpty()) {
LOGGER.debug("AUTO Time Range analysis: add all found appIps to " + app + ", then store in the filter");
ApplicationSelection appSelection = new ApplicationSelection(app, result.getAppIps().get(app));
filter.getAppSelections().put(app, appSelection);
}
}
} catch (Exception e) {
LOGGER.error("Error handling TimeRange JSON data", e);
}
TimeRange timeRange = null;
boolean isCSI = false;
filteredPackets = new ArrayList<PacketInfo>();
if (filter == null) {
if (result != null) {
filteredPackets = result.getAllpackets();
}
} else {
// do the filter
if (filter.isCSI() && filter.getManifestFilePath() != null) {
isCSI = true;
}
timeRange = filter.getTimeRange();
if (result != null) {
filteredPackets = filterPackets(filter, result.getAllpackets());
}
}
// Fix for Sev 2 Time Range Analysis Issue - DE187848
if (result != null) {
result.setAllpackets(filteredPackets);
SessionManagerImpl sessionMangerImpl = (SessionManagerImpl) sessionmanager;
sessionMangerImpl.setPcapTimeOffset(result.getPcapTimeOffset());
// for iOS trace
sessionmanager.setiOSSecureTracePath(result.getTraceDirectory());
// Check if secure trace path exists
if (result instanceof TraceDirectoryResult) {
File file = new File(((SessionManagerImpl) sessionmanager).getTracePath());
if (file.exists()) {
((TraceDirectoryResult) result).setSecureTrace(true);
}
}
}
Statistic stat = this.getStatistic(filteredPackets);
List<Session> sessionList = sessionmanager.processPacketsAndAssembleSessions(filteredPackets);
generateGetRequestMapAndPopulateLatencyStat(sessionList, stat);
if (result != null && stat.getAppName() != null && stat.getAppName().size() == 1 && stat.getAppName().contains(TraceDataReaderImpl.UNKNOWN_APPNAME)) {
stat.setAppName(new HashSet<String>(result.getAppInfos()));
}
// get Unanalyzed HTTPS bytes
boolean isSecureTrace = result instanceof TraceDirectoryResult ? ((TraceDirectoryResult) result).isSecureTrace() : false;
if (isSecureTrace) {
stat.setTotalHTTPSBytesNotAnalyzed(getHttpsBytesNotAnalyzed(sessionList));
} else {
stat.setTotalHTTPSBytesNotAnalyzed(stat.getTotalHTTPSByte());
}
// stat is used to get some info for RrcStateMachine etc
if (result != null) {
LOGGER.debug("Starting pre processing in PAI");
AbstractRrcStateMachine statemachine = statemachinefactory.create(filteredPackets, aProfile, stat.getPacketDuration(), result.getTraceDuration(), stat.getTotalByte(), timeRange);
EnergyModel energymodel = energymodelfactory.create(aProfile, statemachine.getTotalRRCEnergy(), result.getGpsInfos(), result.getCameraInfos(), result.getBluetoothInfos(), result.getScreenStateInfos());
BurstCollectionAnalysisData burstcollectiondata = burstcollectionanalyzer.analyze(filteredPackets, aProfile, stat.getPacketSizeToCountMap(), statemachine.getStaterangelist(), result.getUserEvents(), result.getCpuActivityList().getCpuActivities(), sessionList);
data.clearBPResults();
try {
List<BestPracticeType> videoBPList = BestPracticeType.getByCategory(BestPracticeType.Category.VIDEO);
data.setStreamingVideoData(videoTrafficCollector.clearData());
if (CollectionUtils.containsAny(SettingsUtil.retrieveBestPractices(), videoBPList)) {
if (isCSI || csiDataHelper.doesCSIFileExist(result.getTraceDirectory())) {
data.setStreamingVideoData(videoTrafficInferencer.inferVideoData(result, sessionList, (filter != null && filter.getManifestFilePath() != null) ? filter.getManifestFilePath() : result.getTraceDirectory()));
} else {
data.setStreamingVideoData(videoTrafficCollector.collect(result, sessionList, requestMap));
}
}
} catch (Exception ex) {
LOGGER.error("Error in Video usage analysis :", ex);
// Guarantee that StreamingVideoData is empty
data.setStreamingVideoData(videoTrafficCollector.clearData());
data.getStreamingVideoData().setFinished(true);
}
try {
List<BestPracticeType> imageBPList = new ArrayList<>();
imageBPList.add(BestPracticeType.IMAGE_MDATA);
imageBPList.add(BestPracticeType.IMAGE_CMPRS);
imageBPList.add(BestPracticeType.IMAGE_FORMAT);
imageBPList.add(BestPracticeType.IMAGE_COMPARE);
if (CollectionUtils.containsAny(SettingsUtil.retrieveBestPractices(), imageBPList)) {
imageExtractor.execute(result, sessionList, requestMap);
}
} catch (Exception ex) {
LOGGER.error("Error in Image extraction:" + ex.getMessage(), ex);
}
htmlExtractor.execute(result, sessionList, requestMap);
// Calculate time range analysis
double beginTime = 0.0d;
double endTime = 0.0d;
if (filter != null && filter.getTimeRange() != null) {
beginTime = filter.getTimeRange().getBeginTime();
endTime = filter.getTimeRange().getEndTime();
} else {
endTime = result.getTraceDuration();
}
data.setBurstCollectionAnalysisData(burstcollectiondata);
data.setEnergyModel(energymodel);
data.setSessionlist(sessionList);
data.setStatemachine(statemachine);
data.setStatistic(stat);
data.setTraceresult(result);
data.setProfile(aProfile);
data.setFilter(filter);
data.setDeviceKeywords(result.getDeviceKeywordInfos());
data.setTimeRangeAnalysis(new TimeRangeAnalysis(beginTime, endTime, data));
}
return data;
}
use of com.att.aro.core.packetanalysis.pojo.Statistic in project VideoOptimzer by attdevsupport.
the class HttpsUsageImplTest method testUDPSessionNotConsidered.
@Test
public void testUDPSessionNotConsidered() {
Session session1 = mock(Session.class);
Session session2 = mock(Session.class);
InetAddress ipAddr = mock(InetAddress.class);
when(ipAddr.getHostAddress()).thenReturn("157.56.19.80");
when(session1.isUdpOnly()).thenReturn(true);
when(session2.getRemoteIP()).thenReturn(ipAddr);
when(session2.getDomainName()).thenReturn("www.hotmail.com");
TCPPacket tcpPacket1 = mock(TCPPacket.class);
TCPPacket tcpPacket2 = mock(TCPPacket.class);
when(tcpPacket1.containsSSLRecord()).thenReturn(false);
when(tcpPacket2.containsSSLRecord()).thenReturn(false);
PacketInfo packetInfo_tcp1 = mock(PacketInfo.class);
PacketInfo packetInfo_tcp2 = mock(PacketInfo.class);
when(packetInfo_tcp1.getPayloadLen()).thenReturn(1);
when(packetInfo_tcp1.getPacket()).thenReturn(tcpPacket1);
when(packetInfo_tcp2.getPayloadLen()).thenReturn(1);
when(packetInfo_tcp2.getPacket()).thenReturn(tcpPacket2);
List<PacketInfo> packetsInfo = new ArrayList<PacketInfo>();
packetsInfo.add(packetInfo_tcp1);
packetsInfo.add(packetInfo_tcp2);
when(session2.getTcpPackets()).thenReturn(packetsInfo);
List<Session> sessions = new ArrayList<Session>();
sessions.add(session1);
sessions.add(session2);
pktAnalyzerResult.setSessionlist(sessions);
Statistic statistic = new Statistic();
statistic.setTotalByte(123);
statistic.setTotalHTTPSByte(123);
statistic.setTotalHTTPSBytesNotAnalyzed(123);
pktAnalyzerResult.setStatistic(statistic);
httpsUsageResult = (HttpsUsageResult) httpsUsageImpl.runTest(pktAnalyzerResult);
httpsUsageEntries = httpsUsageResult.getResults();
assertEquals(1, httpsUsageEntries.size());
}
use of com.att.aro.core.packetanalysis.pojo.Statistic in project VideoOptimzer by attdevsupport.
the class HttpsUsageImplTest method testIsSSLSessionsAlteration.
@Test
public void testIsSSLSessionsAlteration() {
Session session1 = mock(Session.class);
Session session2 = mock(Session.class);
Session session3 = mock(Session.class);
InetAddress ipAddrA = mock(InetAddress.class);
InetAddress ipAddrB = mock(InetAddress.class);
when(ipAddrA.getHostAddress()).thenReturn("157.56.19.80");
when(ipAddrB.getHostAddress()).thenReturn("216.58.194.196");
when(session1.getRemoteIP()).thenReturn(ipAddrA);
when(session1.getDomainName()).thenReturn("www.gstatic.com");
when(session2.getRemoteIP()).thenReturn(ipAddrA);
when(session2.getDomainName()).thenReturn("ssl.gstatic.com");
when(session3.getRemoteIP()).thenReturn(ipAddrB);
when(session3.getDomainName()).thenReturn("www.arotest.com");
TCPPacket tcpPacket1_1 = mock(TCPPacket.class);
TCPPacket tcpPacket1_2 = mock(TCPPacket.class);
TCPPacket tcpPacket2 = mock(TCPPacket.class);
TCPPacket tcpPacket3 = mock(TCPPacket.class);
when(tcpPacket1_1.containsSSLRecord()).thenReturn(false);
when(tcpPacket1_2.containsSSLRecord()).thenReturn(true);
when(tcpPacket2.containsSSLRecord()).thenReturn(false);
when(tcpPacket3.containsSSLRecord()).thenReturn(true);
PacketInfo packetInfo1_1 = mock(PacketInfo.class);
PacketInfo packetInfo1_2 = mock(PacketInfo.class);
PacketInfo packetInfo2 = mock(PacketInfo.class);
PacketInfo packetInfo3 = mock(PacketInfo.class);
when(packetInfo1_1.getPayloadLen()).thenReturn(1);
when(packetInfo1_1.getPacket()).thenReturn(tcpPacket1_1);
when(packetInfo1_2.getPayloadLen()).thenReturn(1);
when(packetInfo1_2.getPacket()).thenReturn(tcpPacket1_2);
when(packetInfo2.getPayloadLen()).thenReturn(1);
when(packetInfo2.getPacket()).thenReturn(tcpPacket2);
when(packetInfo3.getPayloadLen()).thenReturn(1);
when(packetInfo3.getPacket()).thenReturn(tcpPacket3);
List<PacketInfo> packetsInfo1 = new ArrayList<PacketInfo>();
List<PacketInfo> packetsInfo2 = new ArrayList<PacketInfo>();
List<PacketInfo> packetsInfo3 = new ArrayList<PacketInfo>();
packetsInfo1.add(packetInfo1_1);
packetsInfo1.add(packetInfo1_2);
packetsInfo2.add(packetInfo2);
packetsInfo3.add(packetInfo3);
when(session1.getTcpPackets()).thenReturn(packetsInfo1);
when(session2.getTcpPackets()).thenReturn(packetsInfo2);
when(session3.getTcpPackets()).thenReturn(packetsInfo3);
List<Session> sessions = new ArrayList<Session>();
sessions.add(session1);
sessions.add(session2);
sessions.add(session3);
pktAnalyzerResult.setSessionlist(sessions);
Statistic statistic = new Statistic();
statistic.setTotalByte(123);
statistic.setTotalHTTPSByte(123);
statistic.setTotalHTTPSBytesNotAnalyzed(123);
pktAnalyzerResult.setStatistic(statistic);
httpsUsageResult = (HttpsUsageResult) httpsUsageImpl.runTest(pktAnalyzerResult);
httpsUsageEntries = httpsUsageResult.getResults();
assertEquals(1, httpsUsageEntries.size());
assertEquals("gstatic.com", httpsUsageEntries.get(0).getParentDomainName());
}
Aggregations