import unittest from definitions import ROOT_DIR import Core.Controller as Ctrl pcap = ROOT_DIR + "/../resources/test/reference_1998.pcap" controller = Ctrl.Controller(pcap_file_path=pcap, do_extra_tests=False, non_verbose=False) controller.load_pcap_statistics(flag_write_file=False, flag_recalculate_stats=True, flag_print_statistics=False) ipAddresses = ['10.0.2.15', '104.83.103.45', '13.107.21.200', '131.253.61.100', '172.217.23.142', '172.217.23.174', '192.168.33.254', '204.79.197.200', '23.51.123.27', '35.161.3.50', '52.11.17.245', '52.34.37.177', '52.39.210.199', '52.41.250.141', '52.85.173.182', '54.149.74.139', '54.187.98.195', '54.192.44.108', '54.192.44.177', '72.247.178.113', '72.247.178.67', '93.184.220.29'] class UnitTestPyparsing(unittest.TestCase): def test_functionality(self): self.assertEqual(controller.statistics.get_pps_sent('10.0.2.15'),32) self.assertEqual(controller.statistics.get_general_file_statistics(), [('Avg. packet rate', 78.57034301757812, 'packets/sec'),('Avg. packet size', 0.0, 'kbytes'),('Avg. packets sent', 90.0, 'packets'),('Avg. bandwidth in', 9.529011726379395, 'kbit/s'), ('Avg. bandwidth out', 9.529012680053711, 'kbit/s')]) self.assertEqual(controller.statistics.get_most_used_ip_address(), '10.0.2.15') self.assertEqual(controller.statistics.get_ttl_distribution('10.0.2.15'), {128: 817}) self.assertEqual(controller.statistics.get_mss_distribution('10.0.2.15'), {1460: 36}) self.assertEqual(controller.statistics.get_tos_distribution('10.0.2.15'), {0: 817}) self.assertEqual(controller.statistics.get_ip_address_count(), 22) self.assertEqual(controller.statistics.get_ip_addresses(), ipAddresses) self.assertEqual(controller.statistics.get_ip_address_from_mac('08:00:27:a3:83:43'), '10.0.2.15') self.assertEqual(controller.statistics.get_mac_address('10.0.2.15'), '08:00:27:a3:83:43') self.assertEqual(controller.statistics.get_most_used_mss('10.0.2.15'), 1460) self.assertEqual(controller.statistics.get_most_used_ttl('10.0.2.15'), 128) # wrong input parameter with self.assertRaises(TypeError): self.assertEqual(controller.statistics.get_pps_sent('08:00:27:a3:83:43'), 32)