Search in sources :

Example 71 with PacketInfo

use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.

the class BurstCollectionAnalysisImpl method analyzeBursts.

/**
 * Assigns burst category to each burst in a collection of bursts.
 * The collection of bursts have been populated prior to this API call.
 */
private int analyzeBursts(List<Burst> burstCollection, List<UserEvent> userEvents, List<CpuActivity> cpuEvents, Profile profile) {
    int userEventsSize = userEvents.size();
    int cpuEventsSize = cpuEvents.size();
    int userEventPointer = 0;
    int cpuPointer = 0;
    int longBurstCount = 0;
    // Analyze each burst
    Burst burst = null;
    Burst lastBurst;
    for (Iterator<Burst> iterator = burstCollection.iterator(); iterator.hasNext(); ) {
        lastBurst = burst;
        burst = iterator.next();
        List<PacketInfo> burstPacketCollection = new ArrayList<PacketInfo>(burst.getPackets().size());
        int burstPayloadLen = 0;
        Set<TcpInfo> burstPacketTcpInfo = new HashSet<TcpInfo>();
        for (PacketInfo pInfo : burst.getPackets()) {
            burstPayloadLen += pInfo.getPayloadLen();
            burstPacketCollection.add(pInfo);
            TcpInfo tcp = pInfo.getTcpInfo();
            if (tcp != null) {
                burstPacketTcpInfo.add(tcp);
            }
        }
        PacketInfo pkt0 = null;
        TcpInfo info0 = null;
        double time0 = 0;
        if (!burstPacketCollection.isEmpty()) {
            pkt0 = burstPacketCollection.get(0);
            info0 = pkt0.getTcpInfo();
            time0 = pkt0.getTimeStamp();
        }
        /*
			 * Mark the burst as Long Burst based on the
			 * burst duration and size of the payload. 
			 */
        if (burst.getEndTime() - burst.getBeginTime() > profile.getLargeBurstDuration() && burstPayloadLen > profile.getLargeBurstSize()) {
            burst.setBurstInfo(BurstCategory.LONG);
            ++longBurstCount;
            continue;
        }
        /*
			 * For bursts with no payload assign burst type based on
			 * the the type of TCP packets. 
			 */
        if (burstPayloadLen == 0) {
            if (burstPacketTcpInfo.contains(TcpInfo.TCP_CLOSE) || burstPacketTcpInfo.contains(TcpInfo.TCP_ESTABLISH) || burstPacketTcpInfo.contains(TcpInfo.TCP_RESET) || burstPacketTcpInfo.contains(TcpInfo.TCP_KEEP_ALIVE) || burstPacketTcpInfo.contains(TcpInfo.TCP_KEEP_ALIVE_ACK) || burstPacketTcpInfo.contains(TcpInfo.TCP_ZERO_WINDOW) || burstPacketTcpInfo.contains(TcpInfo.TCP_WINDOW_UPDATE)) {
                burst.setBurstInfo(BurstCategory.TCP_PROTOCOL);
                continue;
            }
            if (info0 == TcpInfo.TCP_ACK_RECOVER || info0 == TcpInfo.TCP_ACK_DUP) {
                burst.setBurstInfo(BurstCategory.TCP_LOSS_OR_DUP);
                continue;
            }
        }
        if (pkt0 == null) {
            continue;
        }
        // Step 4: Server delay
        if (pkt0.getDir() == PacketDirection.DOWNLINK && (info0 == TcpInfo.TCP_DATA || info0 == TcpInfo.TCP_ACK)) {
            burst.setBurstInfo(BurstCategory.SERVER_NET_DELAY);
            continue;
        }
        // Step 5: Loss recover
        if (info0 == TcpInfo.TCP_ACK_DUP || info0 == TcpInfo.TCP_DATA_DUP) {
            burst.setBurstInfo(BurstCategory.TCP_LOSS_OR_DUP);
            continue;
        }
        if (info0 == TcpInfo.TCP_DATA_RECOVER || info0 == TcpInfo.TCP_ACK_RECOVER) {
            burst.setBurstInfo(BurstCategory.TCP_LOSS_OR_DUP);
            continue;
        }
        // Step 6: User triggered
        final double USER_EVENT_SMALL_TOLERATE = profile.getUserInputTh();
        if (burstPayloadLen > 0) {
            UserEvent uevent = null;
            while ((userEventPointer < userEventsSize) && ((uevent = userEvents.get(userEventPointer)).getReleaseTime() < (time0 - USER_EVENT_TOLERATE))) {
                ++userEventPointer;
            }
            BurstCategory userInputBurst = null;
            if (uevent != null) {
                if (uevent.getEventType() == UserEventType.SCREEN_LANDSCAPE || uevent.getEventType() == UserEventType.SCREEN_PORTRAIT) {
                    userInputBurst = BurstCategory.SCREEN_ROTATION;
                } else {
                    userInputBurst = BurstCategory.USER_INPUT;
                }
            }
            int userEventCount = userEventPointer;
            double minGap = Double.MAX_VALUE;
            while (userEventCount < userEventsSize) {
                UserEvent uEvent = userEvents.get(userEventCount);
                if (withinTolerate(uEvent.getPressTime(), time0)) {
                    double gap = time0 - uEvent.getPressTime();
                    if (gap < minGap) {
                        minGap = gap;
                    }
                }
                if (withinTolerate(uEvent.getReleaseTime(), time0)) {
                    double gap = time0 - uEvent.getReleaseTime();
                    if (gap < minGap) {
                        minGap = gap;
                    }
                }
                if (uEvent.getPressTime() > time0) {
                    break;
                }
                userEventCount++;
            }
            if (minGap < USER_EVENT_SMALL_TOLERATE) {
                burst.setBurstInfo(userInputBurst);
                continue;
            } else if (minGap < USER_EVENT_TOLERATE && (lastBurst == null || lastBurst.getEndTime() < burst.getBeginTime() - minGap)) {
                double cpuBegin = time0 - minGap;
                double cpuEnd = time0;
                // Check CPU usage
                while (cpuPointer < cpuEventsSize) {
                    double eventTimeStamp = cpuEvents.get(cpuPointer).getTimeStamp();
                    if (eventTimeStamp < burst.getBeginTime() - USER_EVENT_TOLERATE) {
                        ++cpuPointer;
                    } else {
                        break;
                    }
                }
                int cpuActivityKey = cpuPointer;
                double totalCpuUsage = 0.0f;
                int cEventsCount = 0;
                while (cpuActivityKey < cpuEventsSize) {
                    CpuActivity cpuAct = cpuEvents.get(cpuActivityKey);
                    double caTimeStamp = cpuAct.getTimeStamp();
                    if (caTimeStamp > cpuBegin && caTimeStamp < cpuEnd) {
                        totalCpuUsage += cpuAct.getTotalCpuUsage();
                        cEventsCount++;
                    }
                    if (caTimeStamp >= cpuEnd) {
                        break;
                    }
                    cpuActivityKey++;
                }
                if (cEventsCount > 0 && (totalCpuUsage / cEventsCount) > AVG_CPU_USAGE_THRESHOLD) {
                    burst.setBurstInfo(BurstCategory.CPU);
                    continue;
                } else {
                    burst.setBurstInfo(userInputBurst);
                    continue;
                }
            }
        }
        // Step 7: Client delay
        if (burstPayloadLen == 0) {
            burst.setBurstInfo(BurstCategory.UNKNOWN);
            continue;
        } else {
            burst.setBurstInfo(BurstCategory.CLIENT_APP);
            continue;
        }
    }
    return longBurstCount;
}
Also used : TcpInfo(com.att.aro.core.packetanalysis.pojo.TcpInfo) ArrayList(java.util.ArrayList) UserEvent(com.att.aro.core.peripheral.pojo.UserEvent) BurstCategory(com.att.aro.core.packetanalysis.pojo.BurstCategory) Burst(com.att.aro.core.packetanalysis.pojo.Burst) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) CpuActivity(com.att.aro.core.peripheral.pojo.CpuActivity) HashSet(java.util.HashSet)

Example 72 with PacketInfo

use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.

the class BurstCollectionAnalysisImpl method normalizeCore.

/**
 * Method orginally found in whatif.cpp
 *
 * @param packets
 *            returns timestampList - List of doubles
 */
private Map<PacketInfo, Double> normalizeCore(List<PacketInfo> packets, List<RrcStateRange> rrcstaterangelist) {
    // Step 1: Identify Promotions
    List<RrcStateRange> promoDelays = new ArrayList<RrcStateRange>();
    for (RrcStateRange rrc : rrcstaterangelist) {
        RRCState state = rrc.getState();
        if ((state == RRCState.PROMO_FACH_DCH) || (state == RRCState.PROMO_IDLE_DCH)) {
            promoDelays.add(rrc);
        }
    }
    Collections.sort(promoDelays);
    PacketTimestamp[] timeStampList = new PacketTimestamp[packets.size()];
    for (int i = 0; i < packets.size(); i++) {
        timeStampList[i] = new PacketTimestamp(packets.get(i));
    }
    // Step 2: Remove all promo delays
    int pdSize = promoDelays.size();
    double timeStampShift = 0.0f;
    int pdKey = 0;
    // "in-the-middle" position
    int pdMiddlePosKey = -1;
    // How to initialize??
    double middlePos = 0;
    for (int i = 0; i < timeStampList.length; i++) {
        double timeStamp = timeStampList[i].timestamp;
        while (pdKey < pdSize && timeStamp >= promoDelays.get(pdKey).getEndTime() - EPS) {
            if (pdMiddlePosKey != -1) {
                // assert (pdMiddlePosKey == pdKey && i > 0 && promoDelays.get(pdKey).getEndTime() >= middlePos);
                timeStampShift += promoDelays.get(pdKey).getEndTime() - middlePos;
                pdMiddlePosKey = -1;
            } else {
                timeStampShift += promoDelays.get(pdKey).getEndTime() - promoDelays.get(pdKey).getBeginTime();
            }
            pdKey++;
        }
        if (pdKey < pdSize && (promoDelays.get(pdKey).getBeginTime() - EPS) < timeStamp && timeStamp < (promoDelays.get(pdKey).getEndTime() + EPS)) {
            if (pdMiddlePosKey == -1) {
                timeStampShift += timeStamp - promoDelays.get(pdKey).getBeginTime();
                middlePos = timeStamp;
                pdMiddlePosKey = pdKey;
            } else {
                // assert (pdMiddlePosKey == pdKey && i > 0);
                // assert (timeStamp >= middlePos);
                timeStampShift += timeStamp - middlePos;
                middlePos = timeStamp;
            }
        }
        timeStampList[i].timestamp = timeStampList[i].timestamp - timeStampShift;
    // assert (i == 0 || timeStampList[i].timestamp >= timeStampList[i - 1].timestamp);
    }
    Map<PacketInfo, Double> result = new LinkedHashMap<PacketInfo, Double>(timeStampList.length);
    for (int i = 0; i < timeStampList.length; ++i) {
        result.put(timeStampList[i].packet, timeStampList[i].timestamp);
    }
    return result;
}
Also used : RRCState(com.att.aro.core.packetanalysis.pojo.RRCState) ArrayList(java.util.ArrayList) RrcStateRange(com.att.aro.core.packetanalysis.pojo.RrcStateRange) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 73 with PacketInfo

use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.

the class SessionManagerImpl method analyzeRecoverPkts.

/**
 * Analyze the packet to find the TCPInfo. Marked flags: TCP_DATA_RECOVER,
 * TCP_ACK_RECOVER
 */
private void analyzeRecoverPkts(Session sess) {
    // "Recover data": its seq equals to the duplicated ACK
    // "Recover ack": its ack equals to the duplicated DATA + payload len
    Map<Long, TCPPacket> dupAckUl = new HashMap<Long, TCPPacket>();
    Map<Long, TCPPacket> dupAckDl = new HashMap<Long, TCPPacket>();
    Map<Long, TCPPacket> dupSeqUl = new HashMap<Long, TCPPacket>();
    Map<Long, TCPPacket> dupSeqDl = new HashMap<Long, TCPPacket>();
    for (PacketInfo pInfo : sess.getTcpPackets()) {
        TCPPacket tPacket = (TCPPacket) pInfo.getPacket();
        TcpInfo pType = pInfo.getTcpInfo();
        PacketDirection dir = pInfo.getDir();
        if (pType == TcpInfo.TCP_DATA_DUP) {
            if (dir == PacketDirection.UPLINK) {
                dupSeqUl.put(tPacket.getSequenceNumber() + tPacket.getPayloadLen(), tPacket);
            } else {
                dupSeqDl.put(tPacket.getSequenceNumber() + tPacket.getPayloadLen(), tPacket);
            }
        }
        // Duplicated data means duplicated ack as well
        if (pType == TcpInfo.TCP_ACK_DUP || pType == TcpInfo.TCP_DATA_DUP) {
            if (dir == PacketDirection.UPLINK) {
                dupAckUl.put(tPacket.getAckNumber(), tPacket);
            } else {
                dupAckDl.put(tPacket.getAckNumber(), tPacket);
            }
        }
        if (pType == TcpInfo.TCP_DATA) {
            if (dir == PacketDirection.UPLINK && dupAckDl.containsKey(tPacket.getSequenceNumber())) {
                pInfo.setTcpInfo(TcpInfo.TCP_DATA_RECOVER);
            }
            if (dir == PacketDirection.DOWNLINK && dupAckUl.containsKey(tPacket.getSequenceNumber())) {
                pInfo.setTcpInfo(TcpInfo.TCP_DATA_RECOVER);
            }
        }
        if (pType == TcpInfo.TCP_ACK) {
            if (dir == PacketDirection.UPLINK && dupSeqDl.containsKey(tPacket.getAckNumber())) {
                pInfo.setTcpInfo(TcpInfo.TCP_DATA_RECOVER);
            }
            if (dir == PacketDirection.DOWNLINK && dupSeqUl.containsKey(tPacket.getAckNumber())) {
                pInfo.setTcpInfo(TcpInfo.TCP_DATA_RECOVER);
            }
        }
        // UL: TCP_DATA with seq = 1 <==== This is NOT a DATA_RECOVER
        if (pType == TcpInfo.TCP_ACK || pType == TcpInfo.TCP_ACK_DUP || pType == TcpInfo.TCP_ACK_RECOVER) {
            if (dir == PacketDirection.UPLINK) {
                dupAckDl.remove(tPacket.getSequenceNumber());
            }
            if (dir == PacketDirection.DOWNLINK) {
                dupAckUl.remove(tPacket.getSequenceNumber());
            }
        }
        // But vise versa is not true
        if (pType == TcpInfo.TCP_DATA || pType == TcpInfo.TCP_DATA_RECOVER) {
            if (dir == PacketDirection.UPLINK) {
                dupAckUl.remove(tPacket.getAckNumber());
            }
            if (dir == PacketDirection.DOWNLINK) {
                dupAckDl.remove(tPacket.getAckNumber());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) TcpInfo(com.att.aro.core.packetanalysis.pojo.TcpInfo) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) PacketDirection(com.att.aro.core.packetreader.pojo.PacketDirection)

Example 74 with PacketInfo

use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.

the class SessionManagerImpl method identifyCorrectTransmissionStream.

/**
 * Check and return which packet in the initial packet list by sequence number received the first ACK in the communication
 * @param packetInfoListForSequenceNumber Initial packet list by a sequence number
 * @param ackNumbersSet Set of all the ACK numbers
 * @param session Session object
 * @param direction Packet direction Uplink or Downlink
 * @return Returns a packet from the packetInfoListForSequenceNumber which has received an ACK in the whole TCP communication.
 * 		   Returns the last packet in the list if no ACK is received.
 */
private PacketInfo identifyCorrectTransmissionStream(List<PacketInfo> packetInfoListForSequenceNumber, Set<Long> ackNumbersSet, Session session, PacketDirection direction) {
    if (packetInfoListForSequenceNumber.size() == 1) {
        return packetInfoListForSequenceNumber.get(0);
    }
    PacketInfo currentPacket = null;
    // Iterate through the parent packet list by sequence number
    for (PacketInfo packetInfo : packetInfoListForSequenceNumber) {
        currentPacket = packetInfo;
        TCPPacket tcpPacket = (TCPPacket) packetInfo.getPacket();
        long nextSequenceOrAckNumber = tcpPacket.getSequenceNumber() + tcpPacket.getPayloadLen();
        List<PacketInfo> packetInfoListForNextSequenceNumber = PacketDirection.DOWNLINK.equals(direction) ? session.getDownlinkPacketsSortedBySequenceNumbers().get(nextSequenceOrAckNumber) : session.getUplinkPacketsSortedBySequenceNumbers().get(nextSequenceOrAckNumber);
        if (ackNumbersSet.contains(nextSequenceOrAckNumber) || identifyCorrectTCPTransmissionStreamHelper(packetInfoListForNextSequenceNumber, ackNumbersSet, session, direction)) {
            return currentPacket;
        }
    }
    return currentPacket;
}
Also used : TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo)

Example 75 with PacketInfo

use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.

the class SessionManagerImpl method analyzeRequestResponses.

/**
 * Traverse all Sessions of all types UDP/TCP/
 *
 * @param sessions
 */
private void analyzeRequestResponses(List<Session> sessions) {
    ArrayList<HttpRequestResponseInfo> results;
    for (Session session : sessions) {
        int limit = 0;
        results = new ArrayList<>();
        PacketInfo previousPacket = null;
        if (session.isUdpOnly()) {
            // UDP
            HttpRequestResponseInfo rrInfo = null;
            HttpRequestResponseInfo recentUpRRInfo = null;
            HttpRequestResponseInfo recentDnRRInfo = null;
            for (PacketInfo udpPacketInfo : session.getUdpPackets()) {
                try {
                    switch(udpPacketInfo.getDir()) {
                        case UPLINK:
                            if (!session.isDataInaccessible()) {
                                rrInfo = extractHttpRequestResponseInfo(results, session, udpPacketInfo, udpPacketInfo.getDir(), previousPacket, limit);
                            }
                            if (rrInfo != null) {
                                recentUpRRInfo = rrInfo;
                            } else {
                                if (443 == session.getLocalPort() || 443 == session.getRemotePort() || 80 == session.getLocalPort() || 80 == session.getRemotePort()) {
                                    session.setDataInaccessible(true);
                                    results = analyzeRequestResponsesForQUICUDPSession(session);
                                    break;
                                }
                                if (recentUpRRInfo == null) {
                                    // Creating a Request Objects when no actual requests were found.
                                    session.setDataInaccessible(true);
                                    rrInfo = new HttpRequestResponseInfo(session.getRemoteHostName(), udpPacketInfo.getDir());
                                    populateRRInfo(rrInfo, udpPacketInfo, false, false, HttpDirection.REQUEST);
                                    results.add(rrInfo);
                                    recentUpRRInfo = rrInfo;
                                }
                                if (udpPacketInfo.getPayloadLen() != 0) {
                                    updateRequestResponseObject(recentUpRRInfo, udpPacketInfo);
                                }
                            }
                            rrInfo = null;
                            recentUpRRInfo.writePayload(udpPacketInfo, false, 0);
                            recentUpRRInfo.addUDPPacket(udpPacketInfo);
                            break;
                        case DOWNLINK:
                            if (!session.isDataInaccessible()) {
                                rrInfo = extractHttpRequestResponseInfo(results, session, udpPacketInfo, udpPacketInfo.getDir(), previousPacket, limit);
                            }
                            if (rrInfo != null) {
                                recentDnRRInfo = rrInfo;
                            } else {
                                if (recentDnRRInfo == null) {
                                    rrInfo = new HttpRequestResponseInfo(session.getRemoteHostName(), udpPacketInfo.getDir());
                                    populateRRInfo(rrInfo, udpPacketInfo, false, false, HttpDirection.RESPONSE);
                                    results.add(rrInfo);
                                    recentDnRRInfo = rrInfo;
                                }
                                if (udpPacketInfo.getPayloadLen() != 0) {
                                    updateRequestResponseObject(recentDnRRInfo, udpPacketInfo);
                                }
                            }
                            rrInfo = null;
                            recentDnRRInfo.writePayload(udpPacketInfo, false, 0);
                            recentDnRRInfo.addUDPPacket(udpPacketInfo);
                            break;
                        default:
                            LOGGER.warn("91 - No direction for packet");
                            continue;
                    }
                } catch (IOException e) {
                    LOGGER.error("Error Storing data to UDP Request Response Obect. Session ID: " + session.getSessionKey());
                }
            }
        } else {
            // TCP
            analyzeACK(session);
            analyzeZeroWindow(session);
            analyzeRecoverPkts(session);
            PacketInfo packetInfo = null;
            TCPPacket tcpPacket = null;
            HttpRequestResponseInfo rrInfo = null;
            HttpRequestResponseInfo tempRRInfo = null;
            try {
                long expectedUploadSeqNo = 0;
                for (long uploadSequenceNumber : session.getUplinkPacketsSortedBySequenceNumbers().keySet()) {
                    // Identify correct packet from the whole transmission stream
                    packetInfo = identifyCorrectTransmissionStream(session.getUplinkPacketsSortedBySequenceNumbers().get(uploadSequenceNumber), session.getAckNumbers(), session, PacketDirection.UPLINK);
                    tcpPacket = (TCPPacket) packetInfo.getPacket();
                    if (packetInfo.getPayloadLen() > 0) {
                        if (!session.isDataInaccessible()) {
                            rrInfo = extractHttpRequestResponseInfo(results, session, packetInfo, packetInfo.getDir(), previousPacket, limit);
                        }
                        if (rrInfo != null) {
                            tempRRInfo = rrInfo;
                            String host = rrInfo.getHostName();
                            if (host != null) {
                                URI referrer = rrInfo.getReferrer();
                                session.setRemoteHostName(host);
                                session.setDomainName(referrer != null ? referrer.getHost() : host);
                            }
                            if (isAnIOSSecureSession(session)) {
                                break;
                            }
                            expectedUploadSeqNo = uploadSequenceNumber + tcpPacket.getPayloadLen();
                        } else if (tempRRInfo != null) {
                            int headerDelta = 0;
                            boolean flag = false;
                            if (!session.isDataInaccessible() && !tempRRInfo.isHeaderParseComplete()) {
                                flag = true;
                                headerDelta = setHeaderOffset(tempRRInfo, packetInfo, tcpPacket);
                                tempRRInfo.writeHeader(packetInfo, headerDelta);
                            }
                            tempRRInfo.setLastDataPacket(packetInfo);
                            tempRRInfo.setRawSize(tempRRInfo.getRawSize() + packetInfo.getLen() - headerDelta);
                            if (tcpPacket.getSequenceNumber() == expectedUploadSeqNo) {
                                expectedUploadSeqNo = tcpPacket.getSequenceNumber() + tcpPacket.getPayloadLen();
                                tempRRInfo.writePayload(packetInfo, flag, headerDelta);
                            } else if (tcpPacket.getSequenceNumber() < expectedUploadSeqNo) {
                                tcpPacket.setRetransmission(true);
                            } else {
                                LOGGER.warn("Identified the following Request is corrupt. Session: " + session.getSessionKey() + ". Request Age: " + tempRRInfo.getAge());
                                tempRRInfo.setCorrupt(true);
                                tempRRInfo.writePayload(packetInfo, false, 0);
                            }
                        } else {
                            if (session.isDecrypted()) {
                                continue;
                            } else if (session.isSsl()) {
                                break;
                            }
                            session.setDataInaccessible(true);
                            rrInfo = new HttpRequestResponseInfo(session.getRemoteHostName(), packetInfo.getDir());
                            expectedUploadSeqNo = uploadSequenceNumber + tcpPacket.getPayloadLen();
                            populateRRInfo(rrInfo, packetInfo, false, true, HttpDirection.REQUEST);
                            results.add(rrInfo);
                            tempRRInfo = rrInfo;
                        }
                        rrInfo = null;
                        tempRRInfo.addTCPPacket(uploadSequenceNumber, packetInfo);
                    }
                }
                rrInfo = null;
                tempRRInfo = null;
                if (!(session.isIOSSecureSession() || (session.isSsl() && !session.isDecrypted()))) {
                    long expectedDownloadSeqNo = 0;
                    for (long downloadSequenceNumber : session.getDownlinkPacketsSortedBySequenceNumbers().keySet()) {
                        // Identify correct packet from the whole transmission stream
                        packetInfo = identifyCorrectTransmissionStream(session.getDownlinkPacketsSortedBySequenceNumbers().get(downloadSequenceNumber), session.getAckNumbers(), session, PacketDirection.DOWNLINK);
                        tcpPacket = (TCPPacket) packetInfo.getPacket();
                        if (packetInfo.getPayloadLen() > 0) {
                            if (!session.isDataInaccessible()) {
                                rrInfo = extractHttpRequestResponseInfo(results, session, packetInfo, packetInfo.getDir(), previousPacket, limit);
                                limit = 0;
                                if (rrInfo != null && !rrInfo.isHeaderParseComplete()) {
                                    previousPacket = packetInfo;
                                    continue;
                                } else {
                                    previousPacket = null;
                                }
                            }
                            if (rrInfo != null) {
                                tempRRInfo = rrInfo;
                                expectedDownloadSeqNo = downloadSequenceNumber + tcpPacket.getPayloadLen();
                            } else if (tempRRInfo != null) {
                                boolean flag = false;
                                int headerDelta = 0;
                                tempRRInfo.setLastDataPacket(packetInfo);
                                if (tcpPacket.getSequenceNumber() == expectedDownloadSeqNo) {
                                    expectedDownloadSeqNo = tcpPacket.getSequenceNumber() + tcpPacket.getPayloadLen();
                                    if (tempRRInfo.getContentLength() == 0 || ((tempRRInfo.getPayloadData().size() + packetInfo.getPayloadLen()) <= tempRRInfo.getContentLength())) {
                                        tempRRInfo.writePayload(packetInfo, flag, headerDelta);
                                        tempRRInfo.setRawSize(tempRRInfo.getRawSize() + packetInfo.getLen() - headerDelta);
                                    } else if (tempRRInfo.getContentLength() > 0 && (tempRRInfo.getPayloadData().size() + packetInfo.getPayloadLen()) > tempRRInfo.getContentLength()) {
                                        limit = tempRRInfo.getContentLength() - tempRRInfo.getPayloadData().size();
                                        tempRRInfo.writePayload(packetInfo, limit);
                                        previousPacket = packetInfo;
                                    // TODO: Update RAW SIZE
                                    }
                                } else if (tcpPacket.getSequenceNumber() < expectedDownloadSeqNo) {
                                    tcpPacket.setRetransmission(true);
                                } else {
                                    LOGGER.warn("Identified the following Response is corrupt. Session: " + session.getSessionKey() + ". Request Age: " + tempRRInfo.getAge());
                                    tempRRInfo.setCorrupt(true);
                                    tempRRInfo.writePayload(packetInfo, false, 0);
                                }
                            } else {
                                if (session.isDecrypted()) {
                                    continue;
                                }
                                rrInfo = new HttpRequestResponseInfo(session.getRemoteHostName(), packetInfo.getDir());
                                expectedDownloadSeqNo = downloadSequenceNumber + tcpPacket.getPayloadLen();
                                populateRRInfo(rrInfo, packetInfo, false, true, HttpDirection.RESPONSE);
                                results.add(rrInfo);
                                tempRRInfo = rrInfo;
                            }
                            rrInfo = null;
                            tempRRInfo.addTCPPacket(downloadSequenceNumber, packetInfo);
                        }
                    }
                }
            } catch (IOException e) {
                LOGGER.error("Error Storing data to TCP Request Response Obect. Session ID: " + session.getSessionKey());
            }
            if (session.isIOSSecureSession()) {
                results = analyzeRequestResponsesForIOSSecureSessions(session);
            } else if (session.isSsl() && !session.isDecrypted()) {
                results = analyzeRequestResponsesForSecureSessions(session);
            }
        }
        Collections.sort(results);
        session.setRequestResponseInfo(results);
        populateDataForRequestResponses(session);
        if (session.getDomainName() == null) {
            session.setDomainName(session.getRemoteIP().getHostName());
        }
    }
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) IOException(java.io.IOException) URI(java.net.URI) Session(com.att.aro.core.packetanalysis.pojo.Session)

Aggregations

PacketInfo (com.att.aro.core.packetanalysis.pojo.PacketInfo)119 ArrayList (java.util.ArrayList)92 BaseTest (com.att.aro.core.BaseTest)63 Test (org.junit.Test)63 RrcStateRange (com.att.aro.core.packetanalysis.pojo.RrcStateRange)48 Session (com.att.aro.core.packetanalysis.pojo.Session)33 TCPPacket (com.att.aro.core.packetreader.pojo.TCPPacket)30 Profile3G (com.att.aro.core.configuration.pojo.Profile3G)26 Profile (com.att.aro.core.configuration.pojo.Profile)25 InetAddress (java.net.InetAddress)25 RRCState (com.att.aro.core.packetanalysis.pojo.RRCState)21 ProfileLTE (com.att.aro.core.configuration.pojo.ProfileLTE)18 HashSet (java.util.HashSet)16 HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)14 UDPPacket (com.att.aro.core.packetreader.pojo.UDPPacket)14 Packet (com.att.aro.core.packetreader.pojo.Packet)11 HashMap (java.util.HashMap)11 BurstCollectionAnalysisData (com.att.aro.core.packetanalysis.pojo.BurstCollectionAnalysisData)9 DomainNameSystem (com.att.aro.core.packetreader.pojo.DomainNameSystem)9 IPPacket (com.att.aro.core.packetreader.pojo.IPPacket)9