use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.
the class SessionManagerImplTest method assembleSessionTest1.
@Test
public void assembleSessionTest1() {
Date date = new Date();
/* InetAddress iAdr = null;
InetAddress iAdr1 = null;
try {
iAdr = InetAddress.getByAddress(new byte[]{89,10,1,1});
iAdr1 = InetAddress.getByAddress(new byte[]{89,10,1,1});
} catch (UnknownHostException e) {
e.printStackTrace();
}*/
InetAddress iAdr = Mockito.mock(InetAddress.class);
Mockito.when(iAdr.getAddress()).thenReturn(new byte[] { 89, 10, 1, 1 });
Mockito.when(iAdr.getHostAddress()).thenReturn("@att");
Mockito.when(iAdr.getHostName()).thenReturn("att");
InetAddress iAdr1 = Mockito.mock(InetAddress.class);
Mockito.when(iAdr1.getAddress()).thenReturn(new byte[] { 89, 10, 1, 1 });
Mockito.when(iAdr1.getHostAddress()).thenReturn("@att");
Mockito.when(iAdr1.getHostName()).thenReturn("att");
Set<InetAddress> inetSet = new HashSet<InetAddress>();
inetSet.add(iAdr);
inetSet.add(iAdr1);
IPPacket ipPack = Mockito.mock(IPPacket.class);
Mockito.when(ipPack.getDestinationIPAddress()).thenReturn(iAdr1);
Mockito.when(ipPack.getSourceIPAddress()).thenReturn(iAdr);
Mockito.when(ipPack.getLen()).thenReturn(20);
Mockito.when(ipPack.getPacketLength()).thenReturn(20);
Mockito.when(ipPack.getPayloadLen()).thenReturn(10);
DomainNameSystem dns = Mockito.mock(DomainNameSystem.class);
Mockito.when(dns.getIpAddresses()).thenReturn(inetSet);
Mockito.when(dns.getDomainName()).thenReturn("www.att.com");
Mockito.when(dns.isResponse()).thenReturn(true);
Mockito.when(dns.getCname()).thenReturn("ATT");
Mockito.when(dns.getPacket()).thenReturn(ipPack);
// UDP Packet Mock
UDPPacket udpPacket = Mockito.mock(UDPPacket.class);
Mockito.when(udpPacket.isDNSPacket()).thenReturn(false);
Mockito.when(udpPacket.getDns()).thenReturn(dns);
Mockito.when(udpPacket.getSourcePort()).thenReturn(83);
Mockito.when(udpPacket.getDestinationPort()).thenReturn(84);
Mockito.when(udpPacket.getSourceIPAddress()).thenReturn(iAdr);
Mockito.when(udpPacket.getDestinationIPAddress()).thenReturn(iAdr1);
PacketInfo packetInfo1 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo1.getPacket()).thenReturn(udpPacket);
Mockito.when(packetInfo1.getDir()).thenReturn(PacketDirection.UPLINK);
// Mockito.when(packetInfo1.getDir()).thenReturn(PacketDirection.UNKNOWN);
// Mockito.when(packetInfo1.getPayloadLen()).thenReturn(10);
Mockito.when(packetInfo1.getPayloadLen()).thenReturn(20);
Mockito.when(packetInfo1.getLen()).thenReturn(10);
Mockito.when(packetInfo1.getAppName()).thenReturn("Test1");
Mockito.when(packetInfo1.getTcpFlagString()).thenReturn("TestString");
InetAddress iAdr2 = Mockito.mock(InetAddress.class);
Mockito.when(iAdr2.getAddress()).thenReturn(new byte[] { 89, 10, 1, 1 });
Mockito.when(iAdr2.getHostAddress()).thenReturn("@att");
Mockito.when(iAdr2.getHostName()).thenReturn("att");
/* InetAddress iAdr2 = null;
InetAddress iAdr3 = null;
try {
iAdr2 = InetAddress.getByAddress(new byte[]{89,10,1,1});
iAdr3 = InetAddress.getByAddress(new byte[]{89,10,1,1});
} catch (UnknownHostException e) {
e.printStackTrace();
}
*/
TCPPacket tcpPacket = Mockito.mock(TCPPacket.class);
Mockito.when(tcpPacket.getSourcePort()).thenReturn(81);
Mockito.when(tcpPacket.getDestinationPort()).thenReturn(82);
Mockito.when(tcpPacket.getDestinationIPAddress()).thenReturn(iAdr2);
Mockito.when(tcpPacket.getSourceIPAddress()).thenReturn(iAdr2);
Mockito.when(tcpPacket.getAckNumber()).thenReturn(0L);
Mockito.when(tcpPacket.getLen()).thenReturn(50);
Mockito.when(tcpPacket.isSYN()).thenReturn(true);
Mockito.when(tcpPacket.isFIN()).thenReturn(true);
Mockito.when(tcpPacket.isRST()).thenReturn(true);
Mockito.when(tcpPacket.getSequenceNumber()).thenReturn(-3L);
Mockito.when(tcpPacket.getTimeStamp()).thenReturn((double) date.getTime() - 3000);
// Mockito.when(tcpPacket.getTimeStamp()).thenReturn((double)date.getTime()-10000);
PacketInfo packetInfo2 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo2.getPacket()).thenReturn(tcpPacket);
Mockito.when(packetInfo2.getDir()).thenReturn(PacketDirection.DOWNLINK);
Mockito.when(packetInfo2.getTcpInfo()).thenReturn(TcpInfo.TCP_ESTABLISH);
Mockito.when(packetInfo2.getPayloadLen()).thenReturn(10);
Mockito.when(packetInfo2.getLen()).thenReturn(15);
Mockito.when(packetInfo2.getAppName()).thenReturn("Test2");
Mockito.when(packetInfo2.getTcpFlagString()).thenReturn("Test2String");
InetAddress iAdr3 = Mockito.mock(InetAddress.class);
Mockito.when(iAdr3.getAddress()).thenReturn(new byte[] { 89, 10, 1, 1 });
Mockito.when(iAdr3.getHostAddress()).thenReturn("@att");
Mockito.when(iAdr3.getHostName()).thenReturn("att");
TCPPacket tcpPacket2 = Mockito.mock(TCPPacket.class);
Mockito.when(tcpPacket2.getSourcePort()).thenReturn(95);
Mockito.when(tcpPacket2.getDestinationPort()).thenReturn(99);
Mockito.when(tcpPacket2.getDestinationIPAddress()).thenReturn(iAdr3);
Mockito.when(tcpPacket2.getSourceIPAddress()).thenReturn(iAdr3);
Mockito.when(tcpPacket.getAckNumber()).thenReturn(0L);
Mockito.when(tcpPacket2.isSYN()).thenReturn(true);
Mockito.when(tcpPacket2.isFIN()).thenReturn(true);
Mockito.when(tcpPacket2.isRST()).thenReturn(true);
Mockito.when(tcpPacket.getSequenceNumber()).thenReturn(1L);
Mockito.when(tcpPacket2.getTimeStamp()).thenReturn(10000d);
PacketInfo packetInfo3 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo3.getPacket()).thenReturn(tcpPacket2);
Mockito.when(packetInfo3.getDir()).thenReturn(PacketDirection.UPLINK);
Mockito.when(packetInfo3.getTcpInfo()).thenReturn(TcpInfo.TCP_ACK_RECOVER);
Mockito.when(packetInfo3.getPayloadLen()).thenReturn(30);
Mockito.when(packetInfo3.getLen()).thenReturn(20);
Mockito.when(packetInfo3.getAppName()).thenReturn("Test3");
Mockito.when(packetInfo3.getTcpFlagString()).thenReturn("Test3String");
/*
PacketInfo packetInfo4 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo4.getPacket()).thenReturn(tcpPacket2);
Mockito.when(packetInfo4.getDir()).thenReturn(PacketDirection.DOWNLINK);
Mockito.when(packetInfo4.getTcpInfo()).thenReturn(TcpInfo.TCP_ACK);
PacketInfo packetInfo5 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo5.getPacket()).thenReturn(tcpPacket2);
Mockito.when(packetInfo5.getDir()).thenReturn(PacketDirection.DOWNLINK);
Mockito.when(packetInfo5.getTcpInfo()).thenReturn(TcpInfo.TCP_DATA_RECOVER);
*/
InetAddress iAdr4 = Mockito.mock(InetAddress.class);
InetAddress iAdr5 = Mockito.mock(InetAddress.class);
Mockito.when(iAdr4.getAddress()).thenReturn(new byte[] { 89, 10, 5, 1 });
Mockito.when(iAdr4.getHostAddress()).thenReturn("@microfoft");
Mockito.when(iAdr4.getHostName()).thenReturn("microfoft");
Mockito.when(iAdr5.getAddress()).thenReturn(new byte[] { 72, 12, 23, 1 });
Mockito.when(iAdr5.getHostAddress()).thenReturn("@apple");
Mockito.when(iAdr5.getHostName()).thenReturn("apple");
Set<InetAddress> inetSet1 = new HashSet<InetAddress>();
inetSet1.add(iAdr4);
inetSet1.add(iAdr5);
IPPacket ipPack1 = Mockito.mock(IPPacket.class);
Mockito.when(ipPack1.getDestinationIPAddress()).thenReturn(iAdr5);
Mockito.when(ipPack1.getSourceIPAddress()).thenReturn(iAdr4);
Mockito.when(ipPack1.getLen()).thenReturn(30);
Mockito.when(ipPack1.getPacketLength()).thenReturn(40);
Mockito.when(ipPack1.getPayloadLen()).thenReturn(40);
DomainNameSystem dns1 = Mockito.mock(DomainNameSystem.class);
Mockito.when(dns1.getIpAddresses()).thenReturn(inetSet);
Mockito.when(dns1.getDomainName()).thenReturn("www.microsft.com");
Mockito.when(dns1.isResponse()).thenReturn(false);
Mockito.when(dns1.getCname()).thenReturn("microsoft");
Mockito.when(dns1.getPacket()).thenReturn(ipPack1);
// UDP Packet Mock
UDPPacket udpPacket1 = Mockito.mock(UDPPacket.class);
Mockito.when(udpPacket1.isDNSPacket()).thenReturn(true);
Mockito.when(udpPacket1.getDns()).thenReturn(dns1);
Mockito.when(udpPacket1.getSourcePort()).thenReturn(90);
Mockito.when(udpPacket1.getSourceIPAddress()).thenReturn(iAdr4);
Mockito.when(udpPacket1.getDestinationPort()).thenReturn(91);
Mockito.when(udpPacket1.getDestinationIPAddress()).thenReturn(iAdr5);
PacketInfo packetInfo4 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo4.getPacket()).thenReturn(udpPacket);
Mockito.when(packetInfo4.getDir()).thenReturn(PacketDirection.DOWNLINK);
// Mockito.when(packetInfo4.getDir()).thenReturn(PacketDirection.UNKNOWN);
// Mockito.when(packetInfo1.getDir()).thenReturn(PacketDirection.UPLINK);
// Mockito.when(packetInfo1.getPayloadLen()).thenReturn(10);
Mockito.when(packetInfo4.getPayloadLen()).thenReturn(20);
Mockito.when(packetInfo4.getLen()).thenReturn(10);
Mockito.when(packetInfo4.getAppName()).thenReturn("Test2");
Mockito.when(packetInfo4.getTcpFlagString()).thenReturn("TestString2");
PacketInfo packetInfo5 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo5.getPacket()).thenReturn(tcpPacket);
Mockito.when(packetInfo5.getDir()).thenReturn(PacketDirection.UPLINK);
Mockito.when(packetInfo5.getTcpInfo()).thenReturn(TcpInfo.TCP_ESTABLISH);
Mockito.when(packetInfo5.getPayloadLen()).thenReturn(20);
Mockito.when(packetInfo5.getLen()).thenReturn(15);
Mockito.when(packetInfo5.getAppName()).thenReturn("Test2");
Mockito.when(packetInfo5.getTcpFlagString()).thenReturn("Test2String");
// UDP Packet Mock
UDPPacket udpPacket2 = Mockito.mock(UDPPacket.class);
Mockito.when(udpPacket2.isDNSPacket()).thenReturn(true);
Mockito.when(udpPacket2.getDns()).thenReturn(dns1);
Mockito.when(udpPacket2.getSourcePort()).thenReturn(90);
Mockito.when(udpPacket2.getSourceIPAddress()).thenReturn(iAdr4);
Mockito.when(udpPacket2.getDestinationPort()).thenReturn(91);
Mockito.when(udpPacket2.getDestinationIPAddress()).thenReturn(iAdr5);
PacketInfo packetInfo6 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo6.getPacket()).thenReturn(udpPacket);
// Mockito.when(packetInfo6.getDir()).thenReturn(PacketDirection.DOWNLINK);
Mockito.when(packetInfo6.getDir()).thenReturn(PacketDirection.UNKNOWN);
// Mockito.when(packetInfo1.getDir()).thenReturn(PacketDirection.UPLINK);
// Mockito.when(packetInfo1.getPayloadLen()).thenReturn(10);
Mockito.when(packetInfo6.getPayloadLen()).thenReturn(30);
Mockito.when(packetInfo6.getLen()).thenReturn(10);
Mockito.when(packetInfo6.getAppName()).thenReturn("Test2");
Mockito.when(packetInfo6.getTcpFlagString()).thenReturn("TestString2");
InetAddress iAdr6 = Mockito.mock(InetAddress.class);
Mockito.when(iAdr6.getAddress()).thenReturn(new byte[] { 60, 100, 1, 1 });
Mockito.when(iAdr6.getHostAddress()).thenReturn("@hari");
Mockito.when(iAdr6.getHostName()).thenReturn("hari");
TCPPacket tcpPacket6 = Mockito.mock(TCPPacket.class);
Mockito.when(tcpPacket6.getSourcePort()).thenReturn(95);
Mockito.when(tcpPacket6.getDestinationPort()).thenReturn(96);
Mockito.when(tcpPacket6.getDestinationIPAddress()).thenReturn(iAdr6);
Mockito.when(tcpPacket6.getSourceIPAddress()).thenReturn(iAdr6);
Mockito.when(tcpPacket6.getAckNumber()).thenReturn(1L);
Mockito.when(tcpPacket6.getLen()).thenReturn(50);
Mockito.when(tcpPacket6.isSYN()).thenReturn(true);
Mockito.when(tcpPacket6.isFIN()).thenReturn(true);
Mockito.when(tcpPacket6.isRST()).thenReturn(false);
Mockito.when(tcpPacket6.getSequenceNumber()).thenReturn(5L);
Mockito.when(tcpPacket6.getTimeStamp()).thenReturn((double) date.getTime() - 20000);
// Mockito.when(tcpPacket.getTimeStamp()).thenReturn((double)date.getTime()-10000);
PacketInfo packetInfo7 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo7.getPacket()).thenReturn(tcpPacket);
Mockito.when(packetInfo7.getDir()).thenReturn(PacketDirection.UNKNOWN);
Mockito.when(packetInfo7.getTcpInfo()).thenReturn(TcpInfo.TCP_ACK_DUP);
Mockito.when(packetInfo7.getPayloadLen()).thenReturn(10);
Mockito.when(packetInfo7.getLen()).thenReturn(15);
Mockito.when(packetInfo7.getAppName()).thenReturn("Test2");
Mockito.when(packetInfo7.getTcpFlagString()).thenReturn("Test2String");
List<PacketInfo> packetsList = new ArrayList<PacketInfo>();
// Adding UDP Packet to the list
packetsList.add(packetInfo1);
// Adding TCP Packet to the list
packetsList.add(packetInfo2);
packetsList.add(packetInfo3);
packetsList.add(packetInfo4);
packetsList.add(packetInfo5);
packetsList.add(packetInfo6);
packetsList.add(packetInfo7);
List<Session> sessionsList = sessionMgr.processPacketsAndAssembleSessions(packetsList);
assertEquals(5, sessionsList.size());
}
use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.
the class SessionManagerImplTest method assembleSessionTest.
@Test
public void assembleSessionTest() {
Date date = new Date();
InetAddress iAdr = null;
InetAddress iAdr1 = null;
try {
iAdr = InetAddress.getByAddress(new byte[] { 89, 10, 1, 1 });
iAdr1 = InetAddress.getByAddress(new byte[] { 89, 10, 1, 1 });
} catch (UnknownHostException e) {
e.printStackTrace();
}
// Mockito.when(iAdr.getAddress()).thenReturn(new byte[]{89,10,1,1});
// Mockito.when(iAdr.getHostAddress()).thenReturn("@att");
// Mockito.when(iAdr.getHostName()).thenReturn("att");
// Mockito.when(iAdr1.getAddress()).thenReturn(new byte[]{89,10,1,1});
// Mockito.when(iAdr1.getHostAddress()).thenReturn("@att");
// Mockito.when(iAdr1.getHostName()).thenReturn("att");
Set<InetAddress> inetSet = new HashSet<InetAddress>();
inetSet.add(iAdr);
inetSet.add(iAdr1);
IPPacket ipPack = Mockito.mock(IPPacket.class);
Mockito.when(ipPack.getDestinationIPAddress()).thenReturn(iAdr1);
Mockito.when(ipPack.getSourceIPAddress()).thenReturn(iAdr);
Mockito.when(ipPack.getLen()).thenReturn(20);
Mockito.when(ipPack.getPacketLength()).thenReturn(20);
Mockito.when(ipPack.getPayloadLen()).thenReturn(20);
DomainNameSystem dns = Mockito.mock(DomainNameSystem.class);
Mockito.when(dns.getIpAddresses()).thenReturn(inetSet);
Mockito.when(dns.getDomainName()).thenReturn("www.att.com");
Mockito.when(dns.isResponse()).thenReturn(true);
Mockito.when(dns.getCname()).thenReturn("ATT");
Mockito.when(dns.getPacket()).thenReturn(ipPack);
// UDP Packet Mock
UDPPacket udpPacket = Mockito.mock(UDPPacket.class);
Mockito.when(udpPacket.isDNSPacket()).thenReturn(true);
Mockito.when(udpPacket.getDns()).thenReturn(dns);
Mockito.when(udpPacket.getSourcePort()).thenReturn(83);
Mockito.when(udpPacket.getDestinationPort()).thenReturn(84);
Mockito.when(udpPacket.getSourceIPAddress()).thenReturn(iAdr);
Mockito.when(udpPacket.getDestinationIPAddress()).thenReturn(iAdr1);
PacketInfo packetInfo1 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo1.getPacket()).thenReturn(udpPacket);
Mockito.when(packetInfo1.getDir()).thenReturn(PacketDirection.UPLINK);
// Mockito.when(packetInfo1.getDir()).thenReturn(PacketDirection.UNKNOWN);
// Mockito.when(packetInfo1.getPayloadLen()).thenReturn(10);
Mockito.when(packetInfo1.getPayloadLen()).thenReturn(10);
Mockito.when(packetInfo1.getLen()).thenReturn(10);
Mockito.when(packetInfo1.getAppName()).thenReturn("Test1");
Mockito.when(packetInfo1.getTcpFlagString()).thenReturn("TestString");
/* InetAddress iAdr2 = Mockito.mock(InetAddress.class);
Mockito.when(iAdr2.getAddress()).thenReturn(new byte[]{89,10,1,1});
Mockito.when(iAdr2.getHostAddress()).thenReturn("@att");
Mockito.when(iAdr2.getHostName()).thenReturn("att");*/
InetAddress iAdr2 = null;
InetAddress iAdr3 = null;
try {
iAdr2 = InetAddress.getByAddress(new byte[] { 89, 10, 1, 1 });
iAdr3 = InetAddress.getByAddress(new byte[] { 89, 10, 1, 1 });
} catch (UnknownHostException e) {
e.printStackTrace();
}
TCPPacket tcpPacket = Mockito.mock(TCPPacket.class);
Mockito.when(tcpPacket.getSourcePort()).thenReturn(81);
Mockito.when(tcpPacket.getDestinationPort()).thenReturn(82);
Mockito.when(tcpPacket.getDestinationIPAddress()).thenReturn(iAdr2);
Mockito.when(tcpPacket.getSourceIPAddress()).thenReturn(iAdr2);
Mockito.when(tcpPacket.getAckNumber()).thenReturn(0L);
Mockito.when(tcpPacket.getLen()).thenReturn(50);
Mockito.when(tcpPacket.isSYN()).thenReturn(true);
Mockito.when(tcpPacket.isFIN()).thenReturn(true);
Mockito.when(tcpPacket.isRST()).thenReturn(true);
Mockito.when(tcpPacket.getSequenceNumber()).thenReturn(20L);
Mockito.when(tcpPacket.getTimeStamp()).thenReturn((double) date.getTime() - 3000);
// Mockito.when(tcpPacket.getTimeStamp()).thenReturn((double)date.getTime()-10000);
PacketInfo packetInfo2 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo2.getPacket()).thenReturn(tcpPacket);
Mockito.when(packetInfo2.getDir()).thenReturn(PacketDirection.UPLINK);
Mockito.when(packetInfo2.getTcpInfo()).thenReturn(TcpInfo.TCP_ESTABLISH);
Mockito.when(packetInfo2.getPayloadLen()).thenReturn(20);
Mockito.when(packetInfo2.getLen()).thenReturn(15);
Mockito.when(packetInfo2.getAppName()).thenReturn("Test2");
Mockito.when(packetInfo2.getTcpFlagString()).thenReturn("Test2String");
/* InetAddress iAdr3 = Mockito.mock(InetAddress.class);
Mockito.when(iAdr3.getAddress()).thenReturn(new byte[]{89,10,1,1});
Mockito.when(iAdr3.getHostAddress()).thenReturn("@att");
Mockito.when(iAdr3.getHostName()).thenReturn("att");
*/
TCPPacket tcpPacket2 = Mockito.mock(TCPPacket.class);
Mockito.when(tcpPacket2.getSourcePort()).thenReturn(95);
Mockito.when(tcpPacket2.getDestinationPort()).thenReturn(99);
Mockito.when(tcpPacket2.getDestinationIPAddress()).thenReturn(iAdr3);
Mockito.when(tcpPacket2.getSourceIPAddress()).thenReturn(iAdr3);
Mockito.when(tcpPacket.getAckNumber()).thenReturn(0L);
Mockito.when(tcpPacket2.isSYN()).thenReturn(true);
Mockito.when(tcpPacket2.isFIN()).thenReturn(true);
Mockito.when(tcpPacket2.isRST()).thenReturn(true);
Mockito.when(tcpPacket.getSequenceNumber()).thenReturn(1L);
Mockito.when(tcpPacket2.getTimeStamp()).thenReturn(10000d);
PacketInfo packetInfo3 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo3.getPacket()).thenReturn(tcpPacket2);
Mockito.when(packetInfo3.getDir()).thenReturn(PacketDirection.DOWNLINK);
Mockito.when(packetInfo3.getTcpInfo()).thenReturn(TcpInfo.TCP_ACK_RECOVER);
Mockito.when(packetInfo3.getPayloadLen()).thenReturn(30);
Mockito.when(packetInfo3.getLen()).thenReturn(20);
Mockito.when(packetInfo3.getAppName()).thenReturn("Test3");
Mockito.when(packetInfo3.getTcpFlagString()).thenReturn("Test3String");
/*
PacketInfo packetInfo4 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo4.getPacket()).thenReturn(tcpPacket2);
Mockito.when(packetInfo4.getDir()).thenReturn(PacketDirection.DOWNLINK);
Mockito.when(packetInfo4.getTcpInfo()).thenReturn(TcpInfo.TCP_ACK);
PacketInfo packetInfo5 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo5.getPacket()).thenReturn(tcpPacket2);
Mockito.when(packetInfo5.getDir()).thenReturn(PacketDirection.DOWNLINK);
Mockito.when(packetInfo5.getTcpInfo()).thenReturn(TcpInfo.TCP_DATA_RECOVER);
*/
InetAddress iAdr4 = Mockito.mock(InetAddress.class);
InetAddress iAdr5 = Mockito.mock(InetAddress.class);
Mockito.when(iAdr4.getAddress()).thenReturn(new byte[] { 89, 10, 5, 1 });
Mockito.when(iAdr4.getHostAddress()).thenReturn("@microfoft");
Mockito.when(iAdr4.getHostName()).thenReturn("microfoft");
Mockito.when(iAdr5.getAddress()).thenReturn(new byte[] { 72, 12, 23, 1 });
Mockito.when(iAdr5.getHostAddress()).thenReturn("@apple");
Mockito.when(iAdr5.getHostName()).thenReturn("apple");
Set<InetAddress> inetSet1 = new HashSet<InetAddress>();
inetSet1.add(iAdr4);
inetSet1.add(iAdr5);
IPPacket ipPack1 = Mockito.mock(IPPacket.class);
Mockito.when(ipPack1.getDestinationIPAddress()).thenReturn(iAdr5);
Mockito.when(ipPack1.getSourceIPAddress()).thenReturn(iAdr4);
Mockito.when(ipPack1.getLen()).thenReturn(30);
Mockito.when(ipPack1.getPacketLength()).thenReturn(40);
Mockito.when(ipPack1.getPayloadLen()).thenReturn(40);
DomainNameSystem dns1 = Mockito.mock(DomainNameSystem.class);
Mockito.when(dns1.getIpAddresses()).thenReturn(inetSet);
Mockito.when(dns1.getDomainName()).thenReturn("www.att.com");
Mockito.when(dns1.isResponse()).thenReturn(false);
Mockito.when(dns1.getCname()).thenReturn("ATT");
Mockito.when(dns1.getPacket()).thenReturn(ipPack1);
// UDP Packet Mock
UDPPacket udpPacket1 = Mockito.mock(UDPPacket.class);
Mockito.when(udpPacket1.isDNSPacket()).thenReturn(true);
Mockito.when(udpPacket1.getDns()).thenReturn(dns1);
Mockito.when(udpPacket1.getSourcePort()).thenReturn(90);
Mockito.when(udpPacket1.getSourceIPAddress()).thenReturn(iAdr4);
Mockito.when(udpPacket1.getDestinationPort()).thenReturn(91);
Mockito.when(udpPacket1.getDestinationIPAddress()).thenReturn(iAdr5);
PacketInfo packetInfo4 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo4.getPacket()).thenReturn(udpPacket);
Mockito.when(packetInfo4.getDir()).thenReturn(PacketDirection.DOWNLINK);
// Mockito.when(packetInfo4.getDir()).thenReturn(PacketDirection.UNKNOWN);
// Mockito.when(packetInfo1.getDir()).thenReturn(PacketDirection.UPLINK);
// Mockito.when(packetInfo1.getPayloadLen()).thenReturn(10);
Mockito.when(packetInfo4.getPayloadLen()).thenReturn(30);
Mockito.when(packetInfo4.getLen()).thenReturn(10);
Mockito.when(packetInfo4.getAppName()).thenReturn("Test2");
Mockito.when(packetInfo4.getTcpFlagString()).thenReturn("TestString2");
PacketInfo packetInfo5 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo5.getPacket()).thenReturn(tcpPacket);
Mockito.when(packetInfo5.getDir()).thenReturn(PacketDirection.DOWNLINK);
Mockito.when(packetInfo5.getTcpInfo()).thenReturn(TcpInfo.TCP_ESTABLISH);
Mockito.when(packetInfo5.getPayloadLen()).thenReturn(20);
Mockito.when(packetInfo5.getLen()).thenReturn(15);
Mockito.when(packetInfo5.getAppName()).thenReturn("Test2");
Mockito.when(packetInfo5.getTcpFlagString()).thenReturn("Test2String");
// UDP Packet Mock
UDPPacket udpPacket2 = Mockito.mock(UDPPacket.class);
Mockito.when(udpPacket2.isDNSPacket()).thenReturn(true);
Mockito.when(udpPacket2.getDns()).thenReturn(dns1);
Mockito.when(udpPacket2.getSourcePort()).thenReturn(90);
Mockito.when(udpPacket2.getSourceIPAddress()).thenReturn(iAdr4);
Mockito.when(udpPacket2.getDestinationPort()).thenReturn(91);
Mockito.when(udpPacket2.getDestinationIPAddress()).thenReturn(iAdr5);
PacketInfo packetInfo6 = Mockito.mock(PacketInfo.class);
Mockito.when(packetInfo6.getPacket()).thenReturn(udpPacket);
// Mockito.when(packetInfo6.getDir()).thenReturn(PacketDirection.DOWNLINK);
Mockito.when(packetInfo6.getDir()).thenReturn(PacketDirection.UNKNOWN);
// Mockito.when(packetInfo1.getDir()).thenReturn(PacketDirection.UPLINK);
// Mockito.when(packetInfo1.getPayloadLen()).thenReturn(10);
Mockito.when(packetInfo6.getPayloadLen()).thenReturn(30);
Mockito.when(packetInfo6.getLen()).thenReturn(10);
Mockito.when(packetInfo6.getAppName()).thenReturn("Test2");
Mockito.when(packetInfo6.getTcpFlagString()).thenReturn("TestString2");
List<PacketInfo> packetsList = new ArrayList<PacketInfo>();
// Adding UDP Packet to the list
packetsList.add(packetInfo1);
// Adding TCP Packet to the list
packetsList.add(packetInfo2);
packetsList.add(packetInfo3);
packetsList.add(packetInfo4);
packetsList.add(packetInfo5);
packetsList.add(packetInfo6);
List<Session> sessionsList = sessionMgr.processPacketsAndAssembleSessions(packetsList);
assertEquals(5, sessionsList.size());
}
use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.
the class CacheAnalysisImplTest method analyze_.
@Test
public void analyze_() {
List<PacketInfo> packets = new ArrayList<PacketInfo>();
pktInfo01 = Mockito.mock(PacketInfo.class);
pktInfo02 = Mockito.mock(PacketInfo.class);
for (int i = 0; i < 60; i++) {
httpRequestInfoArray[i] = mock(HttpRequestResponseInfo.class);
}
for (int i = 0; i < 20; i++) {
when(httpRequestInfoArray[i].isNoStore()).thenReturn(true);
if (i % 2 == 1) {
when(httpRequestInfoArray[i].getDirection()).thenReturn(HttpDirection.REQUEST);
when(httpRequestInfoArray[i].getHostName()).thenReturn("www.google.com");
when(httpRequestInfoArray[i].getObjName()).thenReturn(Util.getCurrentRunningDir());
} else {
when(httpRequestInfoArray[i].getDirection()).thenReturn(HttpDirection.RESPONSE);
when(httpRequestInfoArray[18].getStatusCode()).thenReturn(304);
}
}
for (int i = 20; i < 60; i++) {
when(httpRequestInfoArray[i].isNoStore()).thenReturn(false);
when(httpRequestInfoArray[i].getHostName()).thenReturn("www.google.com" + i);
when(httpRequestInfoArray[i].getObjName()).thenReturn(Util.getCurrentRunningDir());
when(httpRequestInfoArray[i - 2].isRangeResponse()).thenReturn(true);
if ((i - 20) % 2 == 1) {
when(httpRequestInfoArray[i].getDirection()).thenReturn(HttpDirection.REQUEST);
} else {
when(httpRequestInfoArray[i].getDirection()).thenReturn(HttpDirection.RESPONSE);
when(httpRequestInfoArray[i].getStatusCode()).thenReturn(206);
}
}
when(httpRequestInfoArray[2].getAssocReqResp()).thenReturn(httpRequestInfoArray[1]);
when(httpRequestInfoArray[4].getAssocReqResp()).thenReturn(httpRequestInfoArray[3]);
when(httpRequestInfoArray[6].getAssocReqResp()).thenReturn(httpRequestInfoArray[5]);
when(httpRequestInfoArray[8].getAssocReqResp()).thenReturn(httpRequestInfoArray[7]);
when(httpRequestInfoArray[10].getAssocReqResp()).thenReturn(httpRequestInfoArray[9]);
when(httpRequestInfoArray[12].getAssocReqResp()).thenReturn(httpRequestInfoArray[11]);
when(httpRequestInfoArray[14].getAssocReqResp()).thenReturn(httpRequestInfoArray[13]);
for (int i = 18; i < 60; i++) {
when(httpRequestInfoArray[i].getAssocReqResp()).thenReturn(httpRequestInfoArray[i - 1]);
}
for (int i = 50; i < 60; i++) {
when(httpRequestInfoArray[i].isRangeResponse()).thenReturn(false);
when(httpRequestInfoArray[i].isChunked()).thenReturn(true);
}
for (int i = 0; i < 50; i++) {
when(httpRequestInfoArray[i].isRangeResponse()).thenReturn(true);
}
when(httpRequestInfoArray[7].getHostName()).thenReturn(null);
when(httpRequestInfoArray[7].getObjName()).thenReturn(null);
when(httpRequestInfoArray[0].getStatusCode()).thenReturn(400);
when(httpRequestInfoArray[2].getStatusCode()).thenReturn(200);
when(httpRequestInfoArray[4].getStatusCode()).thenReturn(200);
when(httpRequestInfoArray[6].getStatusCode()).thenReturn(200);
when(httpRequestInfoArray[8].getStatusCode()).thenReturn(206);
when(httpRequestInfoArray[10].getStatusCode()).thenReturn(206);
when(httpRequestInfoArray[12].getStatusCode()).thenReturn(206);
when(httpRequestInfoArray[14].getStatusCode()).thenReturn(304);
when(httpRequestInfoArray[16].getStatusCode()).thenReturn(304);
when(httpRequestInfoArray[18].getStatusCode()).thenReturn(304);
when(httpRequestInfoArray[1].getRequestType()).thenReturn(HttpRequestResponseInfo.UTF8);
when(httpRequestInfoArray[3].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_POST);
when(httpRequestInfoArray[5].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_PUT);
when(httpRequestInfoArray[7].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
when(httpRequestInfoArray[9].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_POST);
when(httpRequestInfoArray[11].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
when(httpRequestInfoArray[13].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
when(httpRequestInfoArray[15].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_POST);
when(httpRequestInfoArray[17].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_PUT);
when(httpRequestInfoArray[19].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_PUT);
when(httpRequestInfoArray[20].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
when(httpRequestInfoArray[21].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
for (int i = 22; i < 60; i++) {
if (i % 2 == 1) {
when(httpRequestInfoArray[i].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
}
}
// Friday, January 16, 2015
Date date01 = new Date(1421384400000L);
// 5:00:00 AM GMT
Date date02 = new Date(1421384400000L - 76400000L);
Date date03 = new Date(1421384400000L - 86400000L);
Date date04 = new Date(1421383400000L - 176400000L);
for (int i = 0; i < 60; i++) {
when(httpRequestInfoArray[i].getMaxAge()).thenReturn(86400000L);
}
for (int i = 0; i < 60; i++) {
if (i % 2 == 1) {
when(httpRequestInfoArray[i].getExpires()).thenReturn(date03);
when(httpRequestInfoArray[i].getDate()).thenReturn(date02);
when(httpRequestInfoArray[i].getAbsTimeStamp()).thenReturn(date02);
when(httpRequestInfoArray[i].getLastModified()).thenReturn(date);
} else {
if (i < 40) {
when(httpRequestInfoArray[i].getLastModified()).thenReturn(date01);
when(httpRequestInfoArray[i].getRangeFirst()).thenReturn(0);
when(httpRequestInfoArray[i].getRangeLast()).thenReturn(5);
when(httpRequestInfoArray[i].getAbsTimeStamp()).thenReturn(date02);
when(httpRequestInfoArray[i].getExpires()).thenReturn(date);
when(httpRequestInfoArray[i].getDate()).thenReturn(date03);
} else {
when(httpRequestInfoArray[i].getLastModified()).thenReturn(date02);
when(httpRequestInfoArray[i].getExpires()).thenReturn(date04);
when(httpRequestInfoArray[i].getDate()).thenReturn(date);
when(httpRequestInfoArray[i].getAbsTimeStamp()).thenReturn(date);
when(httpRequestInfoArray[i].getRangeFirst()).thenReturn(0);
when(httpRequestInfoArray[i].getRangeLast()).thenReturn(13);
}
}
}
when(httpRequestInfoArray[30].isRangeResponse()).thenReturn(false);
when(httpRequestInfoArray[31].isRangeResponse()).thenReturn(false);
when(rrhelper.getActualByteCount(any(HttpRequestResponseInfo.class), any(Session.class))).thenReturn(2L);
List<HttpRequestResponseInfo> value = new ArrayList<HttpRequestResponseInfo>();
for (int i = 0; i < 60; i++) {
value.add(httpRequestInfoArray[i]);
}
packets.add(pktInfo01);
packets.add(pktInfo02);
session01.setTcpPackets(packets);
session02.setTcpPackets(packets);
when(session01.getRequestResponseInfo()).thenReturn(value);
when(session01.isUdpOnly()).thenReturn(false);
when(session01.getTcpPackets()).thenReturn(packets);
when(session02.isUdpOnly()).thenReturn(false);
when(session02.getRequestResponseInfo()).thenReturn(value);
when(session02.getTcpPackets()).thenReturn(packets);
List<Session> sessionList = new ArrayList<Session>();
sessionList.add(session01);
sessionList.add(session02);
CacheAnalysis testResult = cacheAnalysis.analyze(sessionList);
assertEquals(4, testResult.getCacheExpirationResponses().size());
assertEquals(60, testResult.getDiagnosisResults().size());
assertEquals(0, testResult.getDuplicateContentBytes());
assertEquals(0, testResult.getDuplicateContentBytesRatio(), 0.0);
assertEquals(0, testResult.getDuplicateContentWithOriginals().size());
}
use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.
the class RrcStateMachineFactoryImplTest method create_T3GStateIsPROMO_IDLE_DCH.
@Test
public void create_T3GStateIsPROMO_IDLE_DCH() {
List<PacketInfo> packetlist1 = new ArrayList<PacketInfo>();
when(profilefactory.energy3G(any(double.class), any(double.class), any(RRCState.class), any(Profile3G.class))).thenReturn(100.0);
Profile3G profile14 = mock(Profile3G.class);
when(profile14.getProfileType()).thenReturn(ProfileType.T3G);
List<RrcStateRange> staterangelist = new ArrayList<RrcStateRange>();
RrcStateRange[] rrcStateRangeArray = new RrcStateRange[5];
for (int i = 0; i < 5; i++) {
rrcStateRangeArray[i] = mock(RrcStateRange.class);
when(rrcStateRangeArray[i].getState()).thenReturn(RRCState.PROMO_IDLE_DCH);
when(rrcStateRangeArray[i].getBeginTime()).thenReturn((double) date.getTime() + 2 * i * 500);
when(rrcStateRangeArray[i].getEndTime()).thenReturn((double) date.getTime() + (2 * i + 1) * 500.0);
}
for (int i = 0; i < 5; i++) {
staterangelist.add(rrcStateRangeArray[i]);
}
when(staterange.create(any(ArrayList.class), any(Profile.class), any(double.class))).thenReturn(staterangelist);
RrcStateMachine3G rrcStateMachine3G = (RrcStateMachine3G) machineFactoryimpl.create(packetlist1, profile14, packetDuration, traceDuration, totalBytes * 100, null);
assertEquals(50.0, rrcStateMachine3G.getJoulesPerKilobyte(), 0.0);
assertEquals(5, rrcStateMachine3G.getIdleToDch(), 0.0);
assertEquals(2500, rrcStateMachine3G.getIdleToDchTime(), 0.0);
assertEquals(500, rrcStateMachine3G.getIdleToDchEnergy(), 0.0);
}
use of com.att.aro.core.packetanalysis.pojo.PacketInfo in project VideoOptimzer by attdevsupport.
the class RrcStateMachineFactoryImplTest method create_T3GStateIsSTATE_IDLE.
@Test
public void create_T3GStateIsSTATE_IDLE() {
List<PacketInfo> packetlist1 = new ArrayList<PacketInfo>();
when(profilefactory.energy3G(any(double.class), any(double.class), any(RRCState.class), any(Profile3G.class))).thenReturn(100.0);
Profile3G profile10 = mock(Profile3G.class);
when(profile10.getProfileType()).thenReturn(ProfileType.T3G);
List<RrcStateRange> staterangelist = new ArrayList<RrcStateRange>();
RrcStateRange[] rrcStateRangeArray = new RrcStateRange[5];
for (int i = 0; i < 5; i++) {
rrcStateRangeArray[i] = mock(RrcStateRange.class);
when(rrcStateRangeArray[i].getState()).thenReturn(RRCState.STATE_IDLE);
when(rrcStateRangeArray[i].getBeginTime()).thenReturn((double) date.getTime() + 2 * i * 500);
when(rrcStateRangeArray[i].getEndTime()).thenReturn((double) date.getTime() + (2 * i + 1) * 500.0);
}
for (int i = 0; i < 5; i++) {
staterangelist.add(rrcStateRangeArray[i]);
}
when(staterange.create(any(ArrayList.class), any(Profile.class), any(double.class))).thenReturn(staterangelist);
RrcStateMachine3G rrcStateMachine3G = (RrcStateMachine3G) machineFactoryimpl.create(packetlist1, profile10, packetDuration, traceDuration, totalBytes * 100, null);
assertEquals(50.0, rrcStateMachine3G.getJoulesPerKilobyte(), 0.0);
assertEquals(2500, rrcStateMachine3G.getIdleTime(), 0.0);
assertEquals(500, rrcStateMachine3G.getIdleEnergy(), 0.0);
}
Aggregations