Search in sources :

Example 1 with Packet

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

the class HttpsUsageImpl method buildHttpsUsageEntry.

/*
	 * If an IP contains a session that does not contain any SSL packet, we
	 * create a HttpsUsageEntry for it.
	 *
	 * This method loops through the IP-sessions map, and returns the list of
	 * HttpsUsageEntry created. If no IP from the IP-sessions map contains a
	 * connection that we consider as HTTP, the method returns an empty list.
	 */
private List<HttpsUsageEntry> buildHttpsUsageEntry(Map<InetAddress, List<Session>> ipSessionsMap) {
    List<HttpsUsageEntry> results = new ArrayList<HttpsUsageEntry>();
    for (Map.Entry<InetAddress, List<Session>> ipSessions : ipSessionsMap.entrySet()) {
        int totalNumConnectionsCurrentIp = 0;
        int totalNumHttpConnectionsCurrentIp = 0;
        int totalHttpTrafficInByteCurrentIp = 0;
        int totalTrafficInByteCurrentIp = 0;
        int httpTrafficPercentage = 0;
        for (Session session : ipSessions.getValue()) {
            boolean isSslSession = false;
            // Excluding UDP Sessions
            if (session.isUdpOnly()) {
                continue;
            }
            List<PacketInfo> packetsInfo = session.getTcpPackets();
            if (packetsInfo.isEmpty()) {
                LOGGER.error("Session without packets! Session's remote IP and port: " + session.getRemoteIP().getHostAddress() + ":" + session.getRemotePort());
                continue;
            }
            /*
				 * Determine if the TCP session is using SSL/TLS. If we find at
				 * least one TCP packet that contains one or more SSL record(s),
				 * we consider that session a SSL session.
				 */
            for (PacketInfo packetInfo : packetsInfo) {
                Packet packet = packetInfo.getPacket();
                if ((packet instanceof TCPPacket) && ((TCPPacket) packet).containsSSLRecord()) {
                    isSslSession = true;
                    break;
                }
            }
            /*
				 * Calculate traffic size for the TCP session
				 */
            // total packet size (ip header + tcp header + payload) of all
            // the packets in the session
            // total payload size of all the packets in the session
            int totalPacketsPayloadSize = 0;
            for (PacketInfo packetInfo : packetsInfo) {
                totalPacketsPayloadSize += packetInfo.getPayloadLen();
            }
            totalNumConnectionsCurrentIp++;
            totalTrafficInByteCurrentIp += totalPacketsPayloadSize;
            if (!(totalPacketsPayloadSize == 0 || isSslSession)) {
                totalHttpTrafficInByteCurrentIp += totalPacketsPayloadSize;
                totalNumHttpConnectionsCurrentIp++;
            }
        }
        // End all sessions associated to an IP
        if (totalNumHttpConnectionsCurrentIp > 0) {
            BigDecimal totalTrafficInKBCurrentIp = new BigDecimal(totalTrafficInByteCurrentIp).divide(new BigDecimal(1000), 3, RoundingMode.HALF_UP);
            BigDecimal totalHttpTrafficInKBCurrentIp = new BigDecimal(totalHttpTrafficInByteCurrentIp).divide(new BigDecimal(1000), 3, RoundingMode.HALF_UP);
            int httpConnectionsPercentage = getHttpConnectionsPercentage(totalNumHttpConnectionsCurrentIp, totalNumConnectionsCurrentIp);
            /*
				 * Initialize percentage to be 0 to avoid getting the
				 * divide-by-zero exception for any unexpected reason.
				 */
            if (totalTrafficInByteCurrentIp <= 0) {
                LOGGER.error("Total traffic size of all TCP sessions is zero or less (" + totalTrafficInByteCurrentIp + " byte)! IP: " + ipSessions.getKey().getHostAddress());
            } else {
                httpTrafficPercentage = getHttpTrafficPercentage(totalHttpTrafficInByteCurrentIp, totalTrafficInByteCurrentIp);
            }
            String parentDomainName = getParentDomainName(ipSessions.getKey(), ipSessions.getValue());
            results.add(new HttpsUsageEntry(ipSessions.getKey().getHostAddress(), parentDomainName, totalNumConnectionsCurrentIp, totalNumHttpConnectionsCurrentIp, httpConnectionsPercentage, totalTrafficInKBCurrentIp, totalHttpTrafficInKBCurrentIp, httpTrafficPercentage));
        }
        totalNumHttpConnectionsCurrentTrace += totalNumHttpConnectionsCurrentIp;
        totalNumConnectionsCurrentTrace += totalNumConnectionsCurrentIp;
    }
    // End all IPs
    return results;
}
Also used : TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) Packet(com.att.aro.core.packetreader.pojo.Packet) ArrayList(java.util.ArrayList) HttpsUsageEntry(com.att.aro.core.bestpractice.pojo.HttpsUsageEntry) BigDecimal(java.math.BigDecimal) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) InetAddress(java.net.InetAddress) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 2 with Packet

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

the class SessionManagerImpl method processPacketsAndAssembleSessions.

/**
 * Entry point into SessionManager from PacketAnalyzerImpl
 *
 * returns List<Session> sessionList
 */
public List<Session> processPacketsAndAssembleSessions(List<PacketInfo> packets) {
    LOGGER.warn("processPacketsAndAssembleSessions -> Trace path: " + tracePath);
    List<Session> sessions = new ArrayList<>();
    List<PacketInfo> udpPackets = new ArrayList<>();
    Map<InetAddress, String> hostMap = new HashMap<>();
    Map<String, Session> udpSessions = new LinkedHashMap<>();
    Map<String, PacketInfo> dnsRequestDomains = new HashMap<>();
    Map<String, List<Session>> tcpSessions = new LinkedHashMap<>();
    Map<InetAddress, PacketInfo> dnsResponsePackets = new HashMap<>();
    if (packets != null) {
        for (PacketInfo packetInfo : packets) {
            Packet packet = packetInfo.getPacket();
            if (packet instanceof UDPPacket) {
                // UDP
                udpPackets.add(packetInfo);
                if (((UDPPacket) packet).isDNSPacket()) {
                    DomainNameSystem dns = ((UDPPacket) packet).getDns();
                    if (dns != null && dns.isResponse()) {
                        for (InetAddress inet : dns.getIpAddresses()) {
                            hostMap.put(inet, dns.getDomainName());
                            dnsResponsePackets.put(inet, packetInfo);
                        }
                    } else if (dns != null && !dns.isResponse()) {
                        dnsRequestDomains.put(dns.getDomainName(), packetInfo);
                    }
                }
                associatePacketToUDPSessionAndPopulateCollections(sessions, udpSessions, packetInfo, (UDPPacket) packet);
            } else if (packet instanceof TCPPacket) {
                // TCP
                TCPPacket tcpPacket = (TCPPacket) packet;
                packetInfo.setTcpInfo(null);
                Session session = associatePacketToTCPSessionAndPopulateCollections(sessions, tcpSessions, packetInfo, tcpPacket);
                populateTCPPacketInfo(packetInfo, tcpPacket);
                session.setSsl(session.isSsl() ? session.isSsl() : tcpPacket.isSsl());
                if (tcpPacket.isDecrypted()) {
                    tcpPacket.setDataOffset(0);
                    session.setDecrypted(true);
                }
                if (session.getDnsResponsePacket() == null && dnsResponsePackets.containsKey(session.getRemoteIP())) {
                    session.setDnsResponsePacket(dnsResponsePackets.get(session.getRemoteIP()));
                    session.setDomainName((((UDPPacket) (session.getDnsResponsePacket()).getPacket()).getDns()).getIpAddresses().stream().findFirst().get().getHostName());
                }
                if (session.getDnsRequestPacket() == null && StringUtils.isNotBlank(session.getDomainName()) && dnsRequestDomains.containsKey(session.getDomainName())) {
                    session.setRemoteHostName(session.getDomainName());
                    session.setDnsRequestPacket(dnsRequestDomains.get(session.getDomainName()));
                } else {
                    session.setRemoteHostName(hostMap.get(session.getRemoteIP()));
                }
                if (tcpPacket.isSslHandshake()) {
                    session.setLastSslHandshakePacket(packetInfo);
                    if (tcpPacket.isClientHello() && StringUtils.isNotBlank(tcpPacket.getServerNameIndication())) {
                        session.setServerNameIndication(tcpPacket.getServerNameIndication());
                    }
                }
                if (packetInfo.getAppName() != null) {
                    session.getAppNames().add(packetInfo.getAppName());
                }
                if (!session.isSessionComplete() && (packetInfo.getTcpFlagString().contains("R") || packetInfo.getTcpFlagString().contains("F"))) {
                    session.setSessionComplete(true);
                }
                session.setLatency((!session.getSynAckPackets().isEmpty() && !session.getSynPackets().isEmpty()) ? calculateLatency(session) : -1);
            }
        }
    }
    Collections.sort(sessions);
    analyzeRequestResponses(sessions);
    return sessions;
}
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) DomainNameSystem(com.att.aro.core.packetreader.pojo.DomainNameSystem) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) UDPPacket(com.att.aro.core.packetreader.pojo.UDPPacket) LinkedHashMap(java.util.LinkedHashMap) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) ArrayList(java.util.ArrayList) List(java.util.List) InetAddress(java.net.InetAddress) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 3 with Packet

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

the class AROServiceImplTest method analyzeFileNullTest.

@Test
public void analyzeFileNullTest() 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)));
    analyze.setTraceresult(traceresult);
    List<BestPracticeType> req = new ArrayList<BestPracticeType>();
    req.add(BestPracticeType.UNNECESSARY_CONNECTIONS);
    AROTraceData testResult = aro.analyzeFile(req, "traffic.cap");
    assertEquals(null, testResult.getBestPracticeResults());
}
Also used : Packet(com.att.aro.core.packetreader.pojo.Packet) ArrayList(java.util.ArrayList) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) BestPracticeType(com.att.aro.core.bestpractice.pojo.BestPracticeType) PacketAnalyzerResult(com.att.aro.core.packetanalysis.pojo.PacketAnalyzerResult) TraceFileResult(com.att.aro.core.packetanalysis.pojo.TraceFileResult) AROTraceData(com.att.aro.core.pojo.AROTraceData) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Example 4 with Packet

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

the class PacketServiceImplTest method createPacketFromPcapTest.

@Test
public void createPacketFromPcapTest() {
    ReflectionTestUtils.setField(service, "pcapngHelper", helper);
    byte[] data = new byte[64];
    data[0] = 0;
    data[1] = 0;
    data[2] = 0;
    data[3] = 0;
    data[4] = 12;
    data[5] = 15;
    Packet packet = service.createPacketFromPcap(13, 1, 1, 1, data, "abcde");
    assertNotNull(packet);
    assertEquals(packet.getData()[5], 15);
}
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) Test(org.junit.Test) BaseTest(com.att.aro.core.BaseTest)

Example 5 with Packet

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

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