use of com.att.aro.core.packetanalysis.pojo.TraceFileResult in project VideoOptimzer by attdevsupport.
the class AROServiceImplTest method analyzeFileNullTest.
@Test
public void analyzeFileNullTest() throws IOException {
PacketAnalyzerResult analyze = new PacketAnalyzerResult();
TraceFileResult traceresult = new TraceFileResult();
List<PacketInfo> allpackets = new ArrayList<PacketInfo>();
allpackets.add(new PacketInfo(new Packet(0, 0, 0, 0, null)));
analyze.setTraceresult(traceresult);
List<BestPracticeType> req = new ArrayList<BestPracticeType>();
req.add(BestPracticeType.UNNECESSARY_CONNECTIONS);
AROTraceData testResult = aro.analyzeFile(req, "traffic.cap");
assertEquals(null, testResult.getBestPracticeResults());
}
use of com.att.aro.core.packetanalysis.pojo.TraceFileResult in project VideoOptimzer by attdevsupport.
the class TraceDataReaderImplTest method readTraceFile_.
@Test
public void readTraceFile_() throws IOException {
Date date = new Date();
traceDataReaderImpl.setFileReader(filereader);
Mockito.doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
byte b = 4;
short s = 1;
InetAddress address1 = null;
InetAddress address2 = null;
try {
address2 = InetAddress.getByName("78.46.84.177");
address1 = InetAddress.getByName("78.46.84.171");
} catch (UnknownHostException e) {
e.printStackTrace();
}
Date date1 = new Date();
IPPacket ippack01 = mock(IPPacket.class);
when(ippack01.getIPVersion()).thenReturn(b);
when(ippack01.getFragmentOffset()).thenReturn(s);
when(ippack01.getSourceIPAddress()).thenReturn(address1);
when(ippack01.getDestinationIPAddress()).thenReturn(address2);
when(ippack01.getTimeStamp()).thenReturn((double) date1.getTime());
// pretend jpcap lib
traceDataReaderImpl.packetArrived("flipboard.app", ippack01);
// pretend jpcap lib
traceDataReaderImpl.packetArrived("com.google.android.youtube", ippack01);
traceDataReaderImpl.packetArrived("flipboard.app", ippack01);
return null;
}
}).when(packetreader).readPacket(any(String.class), any(IPacketListener.class));
when(filereader.fileExist(any(String.class))).thenReturn(true);
when(filereader.getDirectory(any(String.class))).thenReturn(Util.getCurrentRunningDir());
when(filereader.getLastModified(any(String.class))).thenReturn(date.getTime());
TraceFileResult result = traceDataReaderImpl.readTraceFile(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "traffic.cap");
assertSame(-1, result.getCaptureOffset());
}
use of com.att.aro.core.packetanalysis.pojo.TraceFileResult in project VideoOptimzer by attdevsupport.
the class TraceDataReaderImpl method readTraceFile.
/**
* Read a trace file. (ie traffic.cap)
*
* @param traceFilePath
* full path to a trace file
* @return TraceFileResult
* @throws IOException
*/
public TraceFileResult readTraceFile(String traceFilePath) throws IOException {
if (!filereader.fileExist(traceFilePath)) {
throw new FileNotFoundException("Trace file not found: " + traceFilePath);
}
// read pcap file only
TraceFileResult result = new TraceFileResult();
String traceDirectory = filereader.getDirectory(traceFilePath);
if (traceDirectory == null) {
traceDirectory = "";
}
result.setTraceFile(traceFilePath);
result.setTraceDirectory(traceDirectory);
this.init();
this.ipCountMap = result.getIpCountMap();
result = (TraceFileResult) this.readPcapTraceFile(traceFilePath, null, null, result);
if (result == null) {
return null;
}
readVideoTime(result);
result.setAllpackets(allPackets);
readPrivateData(result);
return result;
}
use of com.att.aro.core.packetanalysis.pojo.TraceFileResult in project VideoOptimzer by attdevsupport.
the class PacketAnalyzerImplTest method Test_analyzeTraceFile_returnIsPacketAnalyzerResult.
@Test
@Ignore
public void Test_analyzeTraceFile_returnIsPacketAnalyzerResult() throws Exception {
iPacketAnalyzer.setProfileFactory(profilefactory);
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);
TraceFileResult mockTraceResult = mock(TraceFileResult.class);
List<PacketInfo> filteredPackets = new ArrayList<PacketInfo>();
filteredPackets.add(mock(PacketInfo.class));
when(mockTraceResult.getAllpackets()).thenReturn(packetsList);
CpuActivityList cpuList = new CpuActivityList();
cpuList.add(new CpuActivity());
when(mockTraceResult.getCpuActivityList()).thenReturn(cpuList);
when(tracereader.readTraceFile(any(String.class))).thenReturn(mockTraceResult);
when(mockTraceResult.getTraceResultType()).thenReturn(TraceResultType.TRACE_FILE);
ProfileLTE profileLTE = new ProfileLTE();
when(profilefactory.createLTEdefault()).thenReturn(profileLTE);
AnalysisFilter filter = mock(AnalysisFilter.class);
filter.setIpv4Sel(false);
filter.setIpv6Sel(false);
filter.setUdpSel(false);
iPacketAnalyzer.setEnergyModelFactory(energymodelfactory);
iPacketAnalyzer.setBurstCollectionAnalayzer(burstcollectionanalyzer);
iPacketAnalyzer.setRrcStateMachineFactory(statemachinefactory);
RrcStateMachineLTE rrcstate = mock(RrcStateMachineLTE.class);
EnergyModel energymodel = mock(EnergyModel.class);
List<RrcStateRange> rrcstatelist = new ArrayList<RrcStateRange>();
when(statemachinefactory.create(any(List.class), any(Profile.class), any(double.class), any(double.class), any(double.class), any(TimeRange.class))).thenReturn(rrcstate);
when(rrcstate.getStaterangelist()).thenReturn(rrcstatelist);
when(rrcstate.getTotalRRCEnergy()).thenReturn(1.0);
when(energymodelfactory.create(any(Profile.class), any(double.class), any(List.class), any(List.class), any(List.class), any(List.class))).thenReturn(energymodel);
BurstCollectionAnalysisData burstvalue = mock(BurstCollectionAnalysisData.class);
when(burstcollectionanalyzer.analyze(any(List.class), any(Profile.class), any(Map.class), any(List.class), any(List.class), any(List.class), any(List.class))).thenReturn(burstvalue);
// when(pktTimeUtil.getTimeRangeResult(any(AbstractTraceResult.class), any(AnalysisFilter.class)))
// .thenReturn(value);
PacketAnalyzerResult testResult = iPacketAnalyzer.analyzeTraceFile("", null, filter);
assertSame(false, testResult.getFilter().isIpv4Sel());
}
use of com.att.aro.core.packetanalysis.pojo.TraceFileResult in project VideoOptimzer by attdevsupport.
the class AROServiceImplTest method analyzeFileTest.
@Test
public void analyzeFileTest() throws IOException {
PacketAnalyzerResult analyze = new PacketAnalyzerResult();
TraceFileResult traceresult = new TraceFileResult();
List<PacketInfo> allpackets = new ArrayList<PacketInfo>();
allpackets.add(new PacketInfo(new Packet(0, 0, 0, 0, null)));
traceresult.setAllpackets(allpackets);
analyze.setTraceresult(traceresult);
PeriodicTransferResult periodicTransferResult = new PeriodicTransferResult();
List<BestPracticeType> req = new ArrayList<BestPracticeType>();
req.add(BestPracticeType.UNNECESSARY_CONNECTIONS);
req.add(BestPracticeType.CONNECTION_CLOSING);
req.add(BestPracticeType.CONNECTION_OPENING);
req.add(BestPracticeType.PERIODIC_TRANSFER);
req.add(BestPracticeType.SCREEN_ROTATION);
req.add(BestPracticeType.ACCESSING_PERIPHERALS);
req.add(BestPracticeType.COMBINE_CS_JSS);
req.add(BestPracticeType.HTTP_1_0_USAGE);
req.add(BestPracticeType.CACHE_CONTROL);
req.add(BestPracticeType.USING_CACHE);
req.add(BestPracticeType.DUPLICATE_CONTENT);
req.add(BestPracticeType.HTTP_4XX_5XX);
req.add(BestPracticeType.HTTP_3XX_CODE);
req.add(BestPracticeType.FILE_COMPRESSION);
req.add(BestPracticeType.IMAGE_SIZE);
req.add(BestPracticeType.MINIFICATION);
req.add(BestPracticeType.EMPTY_URL);
req.add(BestPracticeType.SPRITEIMAGE);
req.add(BestPracticeType.SCRIPTS_URL);
req.add(BestPracticeType.ASYNC_CHECK);
req.add(BestPracticeType.DISPLAY_NONE_IN_CSS);
req.add(BestPracticeType.FILE_ORDER);
req.add(BestPracticeType.MULTI_SIMULCONN);
req.add(BestPracticeType.VIDEO_STALL);
req.add(BestPracticeType.STARTUP_DELAY);
req.add(BestPracticeType.BUFFER_OCCUPANCY);
req.add(BestPracticeType.NETWORK_COMPARISON);
req.add(BestPracticeType.TCP_CONNECTION);
req.add(BestPracticeType.CHUNK_SIZE);
req.add(BestPracticeType.CHUNK_PACING);
req.add(BestPracticeType.VIDEO_REDUNDANCY);
req.add(BestPracticeType.VIDEO_CONCURRENT_SESSION);
req.add(BestPracticeType.VIDEO_VARIABLE_BITRATE);
req.add(BestPracticeType.HTTPS_USAGE);
req.add(BestPracticeType.TRANSMISSION_PRIVATE_DATA);
req.add(BestPracticeType.DISPLAY_NONE_IN_CSS);
packetanalyzer = Mockito.mock(IPacketAnalyzer.class);
aro.setPacketAnalyzer(packetanalyzer);
when(packetanalyzer.analyzeTraceFile(any(String.class), any(Profile.class), any(AnalysisFilter.class))).thenReturn(analyze);
when(worker.runTest(any(PacketAnalyzerResult.class))).thenReturn(periodicTransferResult);
List<BestPracticeType> list = SettingsUtil.retrieveBestPractices();
SettingsUtil.saveBestPractices(req);
try {
AROTraceData testResult = aro.analyzeFile(req, "traffic.cap");
assertEquals(TOTAL_BPTESTS, testResult.getBestPracticeResults().size());
} finally {
SettingsUtil.saveBestPractices(list);
}
}
Aggregations