use of com.att.aro.core.packetreader.pojo.IPPacket 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.packetreader.pojo.IPPacket in project VideoOptimzer by attdevsupport.
the class PeriodicTransferImpl method determinePeriodicity.
/**
* Determine periodicity
*
* @param hostList
* @param objList
* @param ipList
*/
private void determinePeriodicity(Set<String> hostList, Set<String> objList, Set<InetAddress> ipList, List<Burst> burstCollection, Profile profile, List<Session> sessionlist) {
Set<String> hostPeriodicInfoSet = new HashSet<String>();
for (int i = 0; i < burstCollection.size(); i++) {
Burst burst = burstCollection.get(i);
if (burst.getBurstInfos() != BurstCategory.CLIENT_APP) {
continue;
}
if (isCloseSpacedBurst(i, burst, profile.getCloseSpacedBurstThreshold(), burstCollection)) {
continue;
}
Packet beginPacket = burst.getBeginPacket().getPacket();
if (beginPacket instanceof IPPacket) {
IPPacket iPkt = (IPPacket) beginPacket;
InetAddress iAddr = iPkt.getDestinationIPAddress();
if (isIpInIpList(ipList, hostPeriodicInfoSet, burst, iAddr)) {
periodicCount++;
continue;
}
iAddr = iPkt.getSourceIPAddress();
if (isIpInIpList(ipList, hostPeriodicInfoSet, burst, iAddr)) {
periodicCount++;
continue;
}
}
PacketInfo firstUplinkPayloadPacket = null;
for (PacketInfo pInfo : burst.getPackets()) {
if (pInfo.getDir() == PacketDirection.UPLINK && pInfo.getPayloadLen() > 0) {
firstUplinkPayloadPacket = pInfo;
break;
}
}
periodicCount += findPeriodicalBursts(hostPeriodicInfoSet, hostList, objList, burst, firstUplinkPayloadPacket, sessionlist);
}
diffPeriodicCount = hostPeriodicInfoSet.size();
}
use of com.att.aro.core.packetreader.pojo.IPPacket in project VideoOptimzer by attdevsupport.
the class PacketAnalyzerImpl method filterPackets.
/**
* Runs the filtering process on the specified packets/PacketInfos.
*
* @return packets/PacketInfos filtered
*/
public List<PacketInfo> filterPackets(AnalysisFilter filter, List<PacketInfo> packetsInfo) {
// create new packets according to the filter setting
List<PacketInfo> filteredPackets = new ArrayList<PacketInfo>();
TimeRange timeRange = filter.getTimeRange();
int packetIdx = 0;
// Ff you select the check box, you want to include it.
// All of of the skip-flags are false at first.
boolean ipv4Skip = !filter.isIpv4Sel();
boolean ipv6Skip = !filter.isIpv6Sel();
boolean tcpSkip = !filter.isTcpSel();
boolean udpSkip = !filter.isUdpSel();
boolean dnsSkip = !filter.isDnsSelection();
for (PacketInfo packetInfo : packetsInfo) {
if (packetInfo.getRemoteIPAddress() != null) {
if (ipv4Skip && packetInfo.getRemoteIPAddress() instanceof Inet4Address) {
continue;
}
if (ipv6Skip && packetInfo.getRemoteIPAddress() instanceof Inet6Address) {
continue;
}
} else {
IPPacket ipPacket = (IPPacket) packetInfo.getPacket();
if (ipPacket != null) {
if (ipv4Skip && ipPacket.getIPVersion() == 4) {
continue;
}
if (ipv6Skip && ipPacket.getIPVersion() == 6) {
continue;
}
}
}
if (tcpSkip && packetInfo.getPacket() instanceof TCPPacket) {
continue;
}
if (udpSkip && packetInfo.getPacket() instanceof UDPPacket) {
UDPPacket udpPacket = (UDPPacket) packetInfo.getPacket();
if (!(DNS_PORT == udpPacket.getDestinationPort() || DNS_PORT == udpPacket.getSourcePort())) {
continue;
}
}
if (dnsSkip && packetInfo.getPacket() instanceof UDPPacket) {
UDPPacket udpPacket = (UDPPacket) packetInfo.getPacket();
if (DNS_PORT == udpPacket.getDestinationPort() || DNS_PORT == udpPacket.getSourcePort()) {
continue;
}
}
// Check time range
double timestamp = packetInfo.getTimeStamp();
if (timeRange != null && (timeRange.getBeginTime() > timestamp || timeRange.getEndTime() < timestamp)) {
// Not in time range
continue;
}
// Check to see if application is selected
if (filter.getPacketColor(packetInfo) == null) {
// App unknown by filter
continue;
}
packetInfo.setPacketId(++packetIdx);
filteredPackets.add(packetInfo);
}
return filteredPackets;
}
use of com.att.aro.core.packetreader.pojo.IPPacket in project VideoOptimzer by attdevsupport.
the class TimeRangeAnalysis method performTimeRangeAnalysis.
/**
* Performs a TimeRangeAnalysis on the trace data.
* @param analysisData Packet analyzer result object
*/
private void performTimeRangeAnalysis(PacketAnalyzerResult analysisData) {
if (analysisData != null) {
List<RrcStateRange> rrcCollection = analysisData.getStatemachine().getStaterangelist();
List<PacketInfo> packets = analysisData.getTraceresult().getAllpackets();
if (controller != null) {
PacketAnalyzerImpl packetAnalyzerImpl = (PacketAnalyzerImpl) (controller.getAROService().getAnalyzer());
packets = packetAnalyzerImpl.filterPackets(analysisData.getFilter(), packets);
}
Profile profile = analysisData.getProfile();
int packetNum = packets.size();
for (int i = 0; i < packetNum; i++) {
PacketInfo packetInfo = packets.get(i);
if ((!ipv4Present || !ipv6Present) && packetInfo.getPacket() instanceof IPPacket) {
IPPacket p = (IPPacket) packetInfo.getPacket();
if (p.getIPVersion() == 4) {
ipv4Present = true;
} else if (p.getIPVersion() == 6) {
ipv6Present = true;
}
}
if (!tcpPresent && packetInfo.getPacket() instanceof TCPPacket) {
tcpPresent = true;
} else if ((!udpPresent || !dnsPresent) && packetInfo.getPacket() instanceof UDPPacket) {
UDPPacket p = (UDPPacket) packetInfo.getPacket();
udpPresent = true;
if (p.isDNSPacket()) {
dnsPresent = true;
}
}
if (packetInfo.getTimeStamp() >= startTime && packetInfo.getTimeStamp() <= endTime) {
payloadLen += packetInfo.getPayloadLen();
totalBytes += packetInfo.getLen();
if (packetInfo.getDir().equals(PacketDirection.UPLINK)) {
uplinkBytes += packetInfo.getLen();
} else if (packetInfo.getDir().equals(PacketDirection.DOWNLINK)) {
downlinkBytes += packetInfo.getLen();
}
}
}
int collectionSize = rrcCollection.size();
for (int i = 0; i < collectionSize; i++) {
double beginTime;
double endTime;
RrcStateRange rrc = rrcCollection.get(i);
if (rrc.getEndTime() < this.startTime) {
continue;
}
if (rrc.getBeginTime() > this.endTime) {
continue;
}
if (rrc.getBeginTime() >= this.startTime) {
beginTime = rrc.getBeginTime();
} else {
beginTime = this.startTime;
}
if (rrc.getEndTime() <= this.endTime) {
endTime = rrc.getEndTime();
} else {
endTime = this.endTime;
}
RRCState rrcState = rrc.getState();
rrcEnergy += updateEnergy(analysisData, profile, beginTime, endTime, rrcState);
activeTime += updateActiveTime(profile, beginTime, endTime, rrcState);
}
}
}
use of com.att.aro.core.packetreader.pojo.IPPacket in project VideoOptimzer by attdevsupport.
the class TraceDataReaderImpl method addToAllPackets.
private void addToAllPackets(String appName, Packet packet) {
if (packet instanceof IPPacket) {
IPPacket ipack = (IPPacket) packet;
if ((ipack.getIPVersion() == 4) && (ipack.getFragmentOffset() != 0)) {
LOGGER.warn("226 - no IP fragmentation");
}
addIpCount(ipack.getSourceIPAddress());
addIpCount(ipack.getDestinationIPAddress());
}
allPackets.add(new PacketInfo(appName, packet));
}
Aggregations