Search in sources :

Example 1 with TcpInfo

use of com.att.aro.core.packetanalysis.pojo.TcpInfo 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 2 with TcpInfo

use of com.att.aro.core.packetanalysis.pojo.TcpInfo 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)

Aggregations

PacketInfo (com.att.aro.core.packetanalysis.pojo.PacketInfo)2 TcpInfo (com.att.aro.core.packetanalysis.pojo.TcpInfo)2 Burst (com.att.aro.core.packetanalysis.pojo.Burst)1 BurstCategory (com.att.aro.core.packetanalysis.pojo.BurstCategory)1 PacketDirection (com.att.aro.core.packetreader.pojo.PacketDirection)1 TCPPacket (com.att.aro.core.packetreader.pojo.TCPPacket)1 CpuActivity (com.att.aro.core.peripheral.pojo.CpuActivity)1 UserEvent (com.att.aro.core.peripheral.pojo.UserEvent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1