test_pyparsing_functionality.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import unittest
  2. from definitions import ROOT_DIR
  3. import Core.Controller as Ctrl
  4. pcap = ROOT_DIR + "/../resources/test/reference_1998.pcap"
  5. controller = Ctrl.Controller(pcap_file_path=pcap, do_extra_tests=False, non_verbose=False)
  6. controller.load_pcap_statistics(flag_write_file=False, flag_recalculate_stats=True, flag_print_statistics=False)
  7. ipAddresses = ['10.0.2.15',
  8. '104.83.103.45',
  9. '13.107.21.200',
  10. '131.253.61.100',
  11. '172.217.23.142',
  12. '172.217.23.174',
  13. '192.168.33.254',
  14. '204.79.197.200',
  15. '23.51.123.27',
  16. '35.161.3.50',
  17. '52.11.17.245',
  18. '52.34.37.177',
  19. '52.39.210.199',
  20. '52.41.250.141',
  21. '52.85.173.182',
  22. '54.149.74.139',
  23. '54.187.98.195',
  24. '54.192.44.108',
  25. '54.192.44.177',
  26. '72.247.178.113',
  27. '72.247.178.67',
  28. '93.184.220.29']
  29. class UnitTestPyparsing(unittest.TestCase):
  30. def test_functionality(self):
  31. self.assertEqual(controller.statistics.get_pps_sent('10.0.2.15'),32)
  32. self.assertEqual(controller.statistics.get_general_file_statistics(), [('Avg. packet rate', 78.57034301757812,
  33. 'packets/sec'),('Avg. packet size', 0.0,
  34. 'kbytes'),('Avg. packets sent', 90.0,
  35. 'packets'),('Avg. bandwidth in',
  36. 9.529011726379395, 'kbit/s'),
  37. ('Avg. bandwidth out', 9.529012680053711,
  38. 'kbit/s')])
  39. self.assertEqual(controller.statistics.get_most_used_ip_address(), '10.0.2.15')
  40. self.assertEqual(controller.statistics.get_ttl_distribution('10.0.2.15'), {128: 817})
  41. self.assertEqual(controller.statistics.get_mss_distribution('10.0.2.15'), {1460: 36})
  42. self.assertEqual(controller.statistics.get_tos_distribution('10.0.2.15'), {0: 817})
  43. self.assertEqual(controller.statistics.get_ip_address_count(), 22)
  44. self.assertEqual(controller.statistics.get_ip_addresses(), ipAddresses)
  45. self.assertEqual(controller.statistics.get_ip_address_from_mac('08:00:27:a3:83:43'), '10.0.2.15')
  46. self.assertEqual(controller.statistics.get_mac_address('10.0.2.15'), '08:00:27:a3:83:43')
  47. self.assertEqual(controller.statistics.get_most_used_mss('10.0.2.15'), 1460)
  48. self.assertEqual(controller.statistics.get_most_used_ttl('10.0.2.15'), 128)