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;
}
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;
}
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());
}
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);
}
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();
}
Aggregations