/** * Returns a collection of DomainTCPSessions objects from the collection TCPSession objects found * in the trace. * * @param sessions The collection TCPSession objects found in the trace. * @return The collection of domain tcp sessions. */ public static Collection<DomainTCPSessions> extractDomainTCPSessions( Collection<TCPSession> sessions) { if (sessions == null || sessions.size() <= 0) { return Collections.emptyList(); } // Aggregate TCP sessions by domain Map<String, ArrayList<TCPSession>> distinctMap = new HashMap<String, ArrayList<TCPSession>>(); for (TCPSession tcpSession : sessions) { if (null != tcpSession) { String domainName = tcpSession.getDomainName(); ArrayList<TCPSession> tempList = distinctMap.get(domainName); if (tempList == null) { tempList = new ArrayList<TCPSession>(); distinctMap.put(domainName, tempList); } tempList.add(tcpSession); } } // Formulate result list List<DomainTCPSessions> result = new ArrayList<DomainTCPSessions>(distinctMap.size()); for (Map.Entry<String, ArrayList<TCPSession>> entry : distinctMap.entrySet()) { ArrayList<TCPSession> tempList = entry.getValue(); tempList.trimToSize(); result.add(new DomainTCPSessions(entry.getKey(), tempList)); } return result; }
/** * A factory method that returns a Collection of DomainTCPSessions objects extracted from a * collection of TCPSession objects. * * @param sessions A Collection of TCPSession objects from which to extract the data. * @return A Collection of DomainTCPSessions objects. */ private DomainTCPSessions(String domainName, Collection<TCPSession> sessions) { this.domainName = domainName; this.sessions = Collections.unmodifiableCollection(sessions); double sessionLength = 0; for (TCPSession session : sessions) { sessionLength += session.getSessionEndTime() - session.getSessionStartTime(); numFiles += session.getFileDownloadCount(); } int size = sessions.size(); this.avgSessionLength = (double) sessionLength / size; }
/** Burst data's analyzed to categorize the periodic bursts. */ private void diagnosisPeriodicRequest() { Map<String, List<Double>> requestHost2tsList = new HashMap<String, List<Double>>(); Map<String, List<Double>> requestObj2tsList = new HashMap<String, List<Double>>(); Map<InetAddress, List<Double>> connIP2tsList = new HashMap<InetAddress, List<Double>>(); Set<String> hostPeriodicInfoSet = new HashSet<String>(); periodicCount = 0; diffPeriodicCount = 0; minimumPeriodicRepeatTime = 0.0; for (TCPSession b : analysis.getTcpSessions()) { // Get a list of timestamps of established sessions with each remote // IP PacketInfo p = b.getPackets().get(0); if (p.getTcpInfo() == TcpInfo.TCP_ESTABLISH) { List<Double> res = connIP2tsList.get(b.getRemoteIP()); if (res == null) { res = new ArrayList<Double>(); connIP2tsList.put(b.getRemoteIP(), res); } res.add(Double.valueOf(p.getTimeStamp())); } // Get a list of timestamps of HTTP requests to hosts/object names for (HttpRequestResponseInfo rr : b.getRequestResponseInfo()) { PacketInfo pkt = rr.getFirstDataPacket(); if (rr.getDirection() == HttpRequestResponseInfo.Direction.REQUEST) { Double ts0 = Double.valueOf(pkt.getTimeStamp()); if (rr.getHostName() != null) { List<Double> tempRequestHostEventList = requestHost2tsList.get(rr.getHostName()); if (tempRequestHostEventList == null) { tempRequestHostEventList = new ArrayList<Double>(); requestHost2tsList.put(rr.getHostName(), tempRequestHostEventList); } tempRequestHostEventList.add(ts0); } if (rr.getObjName() != null) { String objName = rr.getObjNameWithoutParams(); List<Double> tempRequestObjEventList = requestObj2tsList.get(objName); if (tempRequestObjEventList == null) { tempRequestObjEventList = new ArrayList<Double>(); requestObj2tsList.put(objName, tempRequestObjEventList); } tempRequestObjEventList.add(ts0); } } } } Set<String> hostList = new HashSet<String>(); for (Map.Entry<String, List<Double>> iter : requestHost2tsList.entrySet()) { if (SelfCorr(iter.getValue())) { hostList.add(iter.getKey()); } } Set<String> objList = new HashSet<String>(); for (Map.Entry<String, List<Double>> iter : requestObj2tsList.entrySet()) { if (SelfCorr(iter.getValue())) { objList.add(iter.getKey()); } } Set<InetAddress> ipList = new HashSet<InetAddress>(); for (Map.Entry<InetAddress, List<Double>> iter : connIP2tsList.entrySet()) { if (SelfCorr(iter.getValue())) { ipList.add(iter.getKey()); } } for (Burst burst : burstCollection) { if (!burst.getBurstInfos().contains(BurstInfo.BURST_CLIENT_DELAY)) { continue; } Packet beginPacket = burst.getBeginPacket().getPacket(); if (beginPacket instanceof IPPacket) { IPPacket ip = (IPPacket) beginPacket; if (ipList.contains(ip.getDestinationIPAddress()) || ipList.contains(ip.getSourceIPAddress())) { periodicCount++; burst.setBurstInfo(BurstInfo.BURST_PERIODICAL); if (ipList.contains(ip.getDestinationIPAddress())) { hostPeriodicInfoSet.add(ip.getDestinationIPAddress().toString()); } else { hostPeriodicInfoSet.add(ip.getSourceIPAddress().toString()); } continue; } } PacketInfo firstUplinkPayloadPacket = null; for (PacketInfo p : burst.getPackets()) { if (p.getDir() == Direction.UPLINK && p.getPayloadLen() > 0) { firstUplinkPayloadPacket = p; break; } } for (TCPSession session : analysis.getTcpSessions()) { for (HttpRequestResponseInfo rr : session.getRequestResponseInfo()) { if (rr.getDirection() == HttpRequestResponseInfo.Direction.REQUEST && (hostList.contains(rr.getHostName()) || objList.contains(rr.getObjNameWithoutParams()))) { if (rr.getFirstDataPacket() == firstUplinkPayloadPacket) { periodicCount++; burst.setBurstInfo(BurstInfo.BURST_PERIODICAL); burst.setFirstUplinkDataPacket(firstUplinkPayloadPacket); if (hostList.contains(rr.getHostName())) { hostPeriodicInfoSet.add(rr.getHostName()); } else { hostPeriodicInfoSet.add(rr.getObjNameWithoutParams()); } continue; } } } } } diffPeriodicCount = hostPeriodicInfoSet.size(); }