Search in sources :

Example 1 with IPPacket

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());
}
Also used : UnknownHostException(java.net.UnknownHostException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IPacketListener(com.att.aro.core.packetreader.IPacketListener) NetworkTypeObject(com.att.aro.core.peripheral.pojo.NetworkTypeObject) InetAddress(java.net.InetAddress) TraceFileResult(com.att.aro.core.packetanalysis.pojo.TraceFileResult) Date(java.util.Date) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Example 2 with IPPacket

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();
}
Also used : Packet(com.att.aro.core.packetreader.pojo.Packet) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket) Burst(com.att.aro.core.packetanalysis.pojo.Burst) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) InetAddress(java.net.InetAddress) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket) HashSet(java.util.HashSet)

Example 3 with IPPacket

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;
}
Also used : TimeRange(com.att.aro.core.packetanalysis.pojo.TimeRange) Inet4Address(java.net.Inet4Address) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) ArrayList(java.util.ArrayList) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) Inet6Address(java.net.Inet6Address) UDPPacket(com.att.aro.core.packetreader.pojo.UDPPacket) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket)

Example 4 with IPPacket

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);
        }
    }
}
Also used : RRCState(com.att.aro.core.packetanalysis.pojo.RRCState) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) RrcStateRange(com.att.aro.core.packetanalysis.pojo.RrcStateRange) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) UDPPacket(com.att.aro.core.packetreader.pojo.UDPPacket) Profile(com.att.aro.core.configuration.pojo.Profile) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket)

Example 5 with IPPacket

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));
}
Also used : PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket)

Aggregations

IPPacket (com.att.aro.core.packetreader.pojo.IPPacket)14 PacketInfo (com.att.aro.core.packetanalysis.pojo.PacketInfo)9 TCPPacket (com.att.aro.core.packetreader.pojo.TCPPacket)9 UDPPacket (com.att.aro.core.packetreader.pojo.UDPPacket)8 InetAddress (java.net.InetAddress)8 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 BaseTest (com.att.aro.core.BaseTest)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 Packet (com.att.aro.core.packetreader.pojo.Packet)4 UnknownHostException (java.net.UnknownHostException)4 IPacketListener (com.att.aro.core.packetreader.IPacketListener)3 NetworkTypeObject (com.att.aro.core.peripheral.pojo.NetworkTypeObject)3 HashMap (java.util.HashMap)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 ScheduledAlarmInfo (com.att.aro.core.packetanalysis.pojo.ScheduledAlarmInfo)2 Session (com.att.aro.core.packetanalysis.pojo.Session)2 TraceDirectoryResult (com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult)2 DomainNameSystem (com.att.aro.core.packetreader.pojo.DomainNameSystem)2