Search in sources :

Example 11 with Packet

use of com.att.aro.core.packetreader.pojo.Packet in project VideoOptimzer by attdevsupport.

the class DashParser method estimateResponseEnd.

/**
 * Estimate Response download time duration (delta)
 * @param resp
 * @return duration delta
 */
public double estimateResponseEnd(HttpRequestResponseInfo response) {
    double delta = 0;
    Packet packet = response.getLastDataPacket().getPacket().getNextPacketInSession();
    if (packet != null) {
        delta = packet.getTimeStamp() - response.getLastDataPacket().getPacket().getTimeStamp();
    }
    if (delta == 0.0) {
        delta = .004;
    }
    return delta;
}
Also used : Packet(com.att.aro.core.packetreader.pojo.Packet)

Example 12 with Packet

use of com.att.aro.core.packetreader.pojo.Packet in project VideoOptimzer by attdevsupport.

the class TraceDataReaderImpl method readPcapTraceFile.

private AbstractTraceResult readPcapTraceFile(String filepath, Double startTime, Double duration, AbstractTraceResult dresult) throws IOException {
    if (!filereader.fileExist(filepath)) {
        if (LOGGER != null) {
            LOGGER.error("No packet file found at: " + filepath);
        }
        return null;
    }
    AbstractTraceResult result = dresult;
    if (this.packetreader == null) {
        // this.packetreader = new PacketReaderImpl();
        throw new NullPointerException("this.packetreader is null");
    }
    this.packetreader.readPacket(filepath, this);
    double pcapTime0 = 0;
    double traceDuration = 0;
    // Determine application name associated with each packet
    if (!allPackets.isEmpty()) {
        pcapTime0 = startTime != null ? startTime.doubleValue() : allPackets.get(0).getPacket().getTimeStamp();
        traceDuration = duration != null ? duration.doubleValue() : allPackets.get(allPackets.size() - 1).getPacket().getTimeStamp() - pcapTime0;
        List<Integer> appIds = result.getAppIds();
        if (appIds == null) {
            appIds = Collections.emptyList();
            result.setAppIds(appIds);
        }
        // Determine if timezone difference needs to be accounted for
        int tzDiff = 0;
        int captureOffset = result.getCaptureOffset();
        if (captureOffset != -1) {
            int localOffset = Calendar.getInstance().getTimeZone().getRawOffset() / 1000;
            int collectorOffset = captureOffset * 60 * -1;
            tzDiff = collectorOffset - localOffset;
        }
        result.setPcapTimeOffset(pcapTime0 - tzDiff);
        int packetIdx = 0;
        List<String> appInfos = result.getAppInfos();
        Set<String> allAppNames = result.getAllAppNames();
        Map<String, Set<InetAddress>> appIps = result.getAppIps();
        for (Iterator<PacketInfo> iter = allPackets.iterator(); iter.hasNext(); ) {
            PacketInfo packetInfo = iter.next();
            // Filter out non-IP packets
            if (!(packetInfo.getPacket() instanceof IPPacket)) {
                iter.remove();
                continue;
            }
            IPPacket ipPacket = (IPPacket) packetInfo.getPacket();
            PacketDirection packetDirection = determinePacketDirection(packetInfo, ipPacket.getSourceIPAddress(), ipPacket.getDestinationIPAddress());
            if (packetDirection.equals(PacketDirection.UNKNOWN) && (ipPacket instanceof TCPPacket || ipPacket instanceof UDPPacket)) {
                unknownPackets.add(packetInfo);
            }
            packetInfo.setDir(packetDirection);
            packetInfo.setTimestamp(ipPacket.getTimeStamp() - pcapTime0 - tzDiff);
            // Associate application ID with the packet
            String appName = getAppNameForPacket(packetIdx, appIds, appInfos);
            packetInfo.setAppName(appName);
            allAppNames.add(appName);
            // Group IPs by app
            Set<InetAddress> ips = appIps.get(appName);
            if (ips == null) {
                ips = new HashSet<InetAddress>();
                appIps.put(appName, ips);
            }
            ips.add(packetInfo.getRemoteIPAddress());
            // Set packet ID to match Wireshark ID
            packetInfo.setPacketId(++packetIdx);
        }
        if (!unknownPackets.isEmpty()) {
            for (Iterator<PacketInfo> iterator = unknownPackets.iterator(); iterator.hasNext(); ) {
                PacketInfo packetInfo = iterator.next();
                IPPacket ipPacket = (IPPacket) packetInfo.getPacket();
                PacketDirection packetDirection = determinePacketDirection(packetInfo, ipPacket.getSourceIPAddress(), ipPacket.getDestinationIPAddress());
                iterator.remove();
                if (packetDirection.equals(PacketDirection.UNKNOWN)) {
                    packetDirection = PacketDirection.UPLINK;
                    Packet packet = packetInfo.getPacket();
                    if (packet instanceof TCPPacket) {
                        int sourcePort = ((TCPPacket) packet).getSourcePort();
                        int destinationPort = ((TCPPacket) packet).getDestinationPort();
                        this.localIPAddresses.add(ipPacket.getSourceIPAddress().getHostAddress());
                        this.remoteIPAddresses.add(ipPacket.getDestinationIPAddress().getHostAddress());
                        this.localPortNumbers.add(sourcePort);
                        this.remotePortNumbers.add(destinationPort);
                    } else if (packet instanceof UDPPacket) {
                        int sourcePort = ((UDPPacket) packet).getSourcePort();
                        int destinationPort = ((UDPPacket) packet).getDestinationPort();
                        this.localIPAddresses.add(ipPacket.getSourceIPAddress().getHostAddress());
                        this.remoteIPAddresses.add(ipPacket.getDestinationIPAddress().getHostAddress());
                        this.localPortNumbers.add(sourcePort);
                        this.remotePortNumbers.add(destinationPort);
                    }
                }
                packetInfo.setDir(packetDirection);
            }
        }
        if (!unknownPackets.isEmpty()) {
            LOGGER.error("Packets with no direction identified.");
        }
        Collections.sort(allPackets);
    } else {
        pcapTime0 = startTime != null ? startTime.doubleValue() : filereader.getLastModified(filepath) / 1000.0;
        traceDuration = duration != null ? duration.doubleValue() : 0.0;
    }
    Date traceDateTime = new Date((long) (pcapTime0 * 1000));
    result.setPcapTime0(pcapTime0);
    result.setTraceDuration(traceDuration);
    result.setTraceDateTime(traceDateTime);
    return result;
}
Also used : TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) Packet(com.att.aro.core.packetreader.pojo.Packet) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket) UDPPacket(com.att.aro.core.packetreader.pojo.UDPPacket) Set(java.util.Set) HashSet(java.util.HashSet) PacketDirection(com.att.aro.core.packetreader.pojo.PacketDirection) UDPPacket(com.att.aro.core.packetreader.pojo.UDPPacket) Date(java.util.Date) AbstractTraceResult(com.att.aro.core.packetanalysis.pojo.AbstractTraceResult) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) InetAddress(java.net.InetAddress) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket)

Example 13 with Packet

use of com.att.aro.core.packetreader.pojo.Packet in project VideoOptimzer by attdevsupport.

the class PacketServiceImpl method createPacket.

/**
 * Returns a new instance of the Packet class, using the specified
 * parameters to initialize the class members.
 *
 * @param network
 *            The datalink to the network.
 * @param seconds
 *            The number of seconds for the packet.
 * @param microSeconds
 *            The number of microseconds for the packet.
 * @param len
 *            The length of the data portion of the packet (in bytes).
 * @param datalinkHdrLen
 *            The length of the header portion of the packet (in bytes).
 * @param data
 *            An array of bytes that is the data portion of the packet.
 *
 * @return The newly created packet.
 */
@Override
public Packet createPacket(short network, long seconds, long microSeconds, int len, int datalinkHdrLen, byte[] data) {
    Packet packet = null;
    // Minimum IP header length is 20 bytes
    ByteBuffer bytes = ByteBuffer.wrap(data);
    if (network == IPV6 && data.length >= datalinkHdrLen + 40) {
        // Determine IPV6 protocol
        Pair pair = new Pair(data[datalinkHdrLen + 6], 0);
        calculateLengthOfExtensionHeaders(data, datalinkHdrLen + 40, pair);
        // Create IPPacket
        switch(pair.protocol) {
            case // TCP
            6:
                packet = new TCPPacket(seconds, microSeconds, len, datalinkHdrLen, pair.protocol, pair.extensionHeadersLength, data);
                break;
            case // UDP
            17:
                packet = createUDPPacket(seconds, microSeconds, len, datalinkHdrLen, pair.protocol, pair.extensionHeadersLength, data);
                break;
            default:
                packet = new IPPacket(seconds, microSeconds, len, datalinkHdrLen, pair.protocol, pair.extensionHeadersLength, data);
                break;
        }
    } else if (network == IPV4 && data.length >= datalinkHdrLen + 20) {
        byte iphlen = (byte) ((bytes.get(datalinkHdrLen) & 0x0f) << 2);
        if (data.length < datalinkHdrLen + iphlen) {
            // Truncated packet
            packet = new Packet(seconds, microSeconds, len, datalinkHdrLen, data);
        } else {
            // Determine IP protocol
            byte protocol = bytes.get(datalinkHdrLen + 9);
            switch(protocol) {
                case // TCP
                6:
                    if (data.length >= datalinkHdrLen + iphlen + 20) {
                        packet = new TCPPacket(seconds, microSeconds, len, datalinkHdrLen, null, null, data);
                    } else {
                        packet = new Packet(seconds, microSeconds, len, datalinkHdrLen, data);
                    }
                    break;
                case // UDP
                17:
                    if (data.length >= datalinkHdrLen + iphlen + 6) {
                        packet = createUDPPacket(seconds, microSeconds, len, datalinkHdrLen, null, null, data);
                    } else {
                        packet = new Packet(seconds, microSeconds, len, datalinkHdrLen, data);
                    }
                    break;
                default:
                    packet = new IPPacket(seconds, microSeconds, len, datalinkHdrLen, null, null, data);
            }
        }
    } else {
        packet = new Packet(seconds, microSeconds, len, datalinkHdrLen, data);
    }
    return packet;
}
Also used : UDPPacket(com.att.aro.core.packetreader.pojo.UDPPacket) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) Packet(com.att.aro.core.packetreader.pojo.Packet) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) ByteBuffer(java.nio.ByteBuffer) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket)

Example 14 with Packet

use of com.att.aro.core.packetreader.pojo.Packet 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);
    }
}
Also used : Packet(com.att.aro.core.packetreader.pojo.Packet) IPacketAnalyzer(com.att.aro.core.packetanalysis.IPacketAnalyzer) PeriodicTransferResult(com.att.aro.core.bestpractice.pojo.PeriodicTransferResult) AnalysisFilter(com.att.aro.core.packetanalysis.pojo.AnalysisFilter) ArrayList(java.util.ArrayList) BestPracticeType(com.att.aro.core.bestpractice.pojo.BestPracticeType) AROTraceData(com.att.aro.core.pojo.AROTraceData) Profile(com.att.aro.core.configuration.pojo.Profile) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) PacketAnalyzerResult(com.att.aro.core.packetanalysis.pojo.PacketAnalyzerResult) TraceFileResult(com.att.aro.core.packetanalysis.pojo.TraceFileResult) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Example 15 with Packet

use of com.att.aro.core.packetreader.pojo.Packet in project VideoOptimzer by attdevsupport.

the class AROServiceImplTest method analyzeDirectoryTest.

@Test
public void analyzeDirectoryTest() throws IOException {
    TraceDirectoryResult traceresult = new TraceDirectoryResult();
    List<PacketInfo> allpackets = new ArrayList<PacketInfo>();
    allpackets.add(new PacketInfo(new Packet(0, 0, 0, 0, null)));
    traceresult.setAllpackets(allpackets);
    PacketAnalyzerResult analyze = new PacketAnalyzerResult();
    analyze.setTraceresult(traceresult);
    CacheAnalysis cacheAnalysis = new CacheAnalysis();
    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.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_VARIABLE_BITRATE);
    req.add(BestPracticeType.HTTPS_USAGE);
    req.add(BestPracticeType.TRANSMISSION_PRIVATE_DATA);
    req.add(BestPracticeType.DISPLAY_NONE_IN_CSS);
    req.add(BestPracticeType.VIDEO_CONCURRENT_SESSION);
    req.add(BestPracticeType.AUDIO_STREAM);
    req.add(BestPracticeType.MULTI_SIMULCONN);
    List<BestPracticeType> list = SettingsUtil.retrieveBestPractices();
    SettingsUtil.saveBestPractices(req);
    when(packetanalyzer.analyzeTraceDirectory(any(String.class), any(Profile.class), any(AnalysisFilter.class))).thenReturn(analyze);
    when(worker.runTest(any(PacketAnalyzerResult.class))).thenReturn(periodicTransferResult);
    when(cacheAnalyzer.analyze(anyListOf(Session.class))).thenReturn(cacheAnalysis);
    try {
        AROTraceData testResult = aro.analyzeDirectory(req, Util.getCurrentRunningDir());
        assertEquals(null, testResult.getBestPracticeResults());
    } finally {
        SettingsUtil.saveBestPractices(list);
    }
}
Also used : Packet(com.att.aro.core.packetreader.pojo.Packet) PeriodicTransferResult(com.att.aro.core.bestpractice.pojo.PeriodicTransferResult) AnalysisFilter(com.att.aro.core.packetanalysis.pojo.AnalysisFilter) ArrayList(java.util.ArrayList) BestPracticeType(com.att.aro.core.bestpractice.pojo.BestPracticeType) AROTraceData(com.att.aro.core.pojo.AROTraceData) Profile(com.att.aro.core.configuration.pojo.Profile) CacheAnalysis(com.att.aro.core.packetanalysis.pojo.CacheAnalysis) ICacheAnalysis(com.att.aro.core.packetanalysis.ICacheAnalysis) TraceDirectoryResult(com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) PacketAnalyzerResult(com.att.aro.core.packetanalysis.pojo.PacketAnalyzerResult) Session(com.att.aro.core.packetanalysis.pojo.Session) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Aggregations

Packet (com.att.aro.core.packetreader.pojo.Packet)16 PacketInfo (com.att.aro.core.packetanalysis.pojo.PacketInfo)10 TCPPacket (com.att.aro.core.packetreader.pojo.TCPPacket)8 BaseTest (com.att.aro.core.BaseTest)7 UDPPacket (com.att.aro.core.packetreader.pojo.UDPPacket)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 InetAddress (java.net.InetAddress)6 PacketAnalyzerResult (com.att.aro.core.packetanalysis.pojo.PacketAnalyzerResult)5 Session (com.att.aro.core.packetanalysis.pojo.Session)5 IPPacket (com.att.aro.core.packetreader.pojo.IPPacket)5 BestPracticeType (com.att.aro.core.bestpractice.pojo.BestPracticeType)3 Burst (com.att.aro.core.packetanalysis.pojo.Burst)3 AROTraceData (com.att.aro.core.pojo.AROTraceData)3 AbstractBestPracticeResult (com.att.aro.core.bestpractice.pojo.AbstractBestPracticeResult)2 PeriodicTransferResult (com.att.aro.core.bestpractice.pojo.PeriodicTransferResult)2 Profile (com.att.aro.core.configuration.pojo.Profile)2 AnalysisFilter (com.att.aro.core.packetanalysis.pojo.AnalysisFilter)2 BurstCollectionAnalysisData (com.att.aro.core.packetanalysis.pojo.BurstCollectionAnalysisData)2 HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)2