/test/test_tcp.py

https://gitlab.com/x1046882802/flexiroutervpp
Python | 115 lines | 80 code | 27 blank | 8 comment | 7 complexity | a5c34cd3b88ba4d555e76387e3dea0a7 MD5 | raw file
  1. #!/usr/bin/env python3
  2. import unittest
  3. from framework import VppTestCase, VppTestRunner
  4. from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
  5. class TestTCP(VppTestCase):
  6. """ TCP Test Case """
  7. @classmethod
  8. def setUpClass(cls):
  9. super(TestTCP, cls).setUpClass()
  10. @classmethod
  11. def tearDownClass(cls):
  12. super(TestTCP, cls).tearDownClass()
  13. def setUp(self):
  14. super(TestTCP, self).setUp()
  15. self.vapi.session_enable_disable(is_enable=1)
  16. self.create_loopback_interfaces(2)
  17. table_id = 0
  18. for i in self.lo_interfaces:
  19. i.admin_up()
  20. if table_id != 0:
  21. tbl = VppIpTable(self, table_id)
  22. tbl.add_vpp_config()
  23. i.set_table_ip4(table_id)
  24. i.config_ip4()
  25. table_id += 1
  26. # Configure namespaces
  27. self.vapi.app_namespace_add_del(namespace_id="0",
  28. sw_if_index=self.loop0.sw_if_index)
  29. self.vapi.app_namespace_add_del(namespace_id="1",
  30. sw_if_index=self.loop1.sw_if_index)
  31. def tearDown(self):
  32. for i in self.lo_interfaces:
  33. i.unconfig_ip4()
  34. i.set_table_ip4(0)
  35. i.admin_down()
  36. self.vapi.session_enable_disable(is_enable=0)
  37. super(TestTCP, self).tearDown()
  38. def test_tcp_transfer(self):
  39. """ TCP echo client/server transfer """
  40. # Add inter-table routes
  41. ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
  42. [VppRoutePath("0.0.0.0",
  43. 0xffffffff,
  44. nh_table_id=1)])
  45. ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
  46. [VppRoutePath("0.0.0.0",
  47. 0xffffffff,
  48. nh_table_id=0)], table_id=1)
  49. ip_t01.add_vpp_config()
  50. ip_t10.add_vpp_config()
  51. # Start builtin server and client
  52. uri = "tcp://" + self.loop0.local_ip4 + "/1234"
  53. error = self.vapi.cli("test echo server appns 0 fifo-size 4 uri " +
  54. uri)
  55. if error:
  56. self.logger.critical(error)
  57. self.assertNotIn("failed", error)
  58. error = self.vapi.cli("test echo client mbytes 10 appns 1 " +
  59. "fifo-size 4 no-output test-bytes " +
  60. "syn-timeout 2 uri " + uri)
  61. if error:
  62. self.logger.critical(error)
  63. self.assertNotIn("failed", error)
  64. # Delete inter-table routes
  65. ip_t01.remove_vpp_config()
  66. ip_t10.remove_vpp_config()
  67. class TestTCPUnitTests(VppTestCase):
  68. "TCP Unit Tests"
  69. @classmethod
  70. def setUpClass(cls):
  71. super(TestTCPUnitTests, cls).setUpClass()
  72. @classmethod
  73. def tearDownClass(cls):
  74. super(TestTCPUnitTests, cls).tearDownClass()
  75. def setUp(self):
  76. super(TestTCPUnitTests, self).setUp()
  77. self.vapi.session_enable_disable(is_enable=1)
  78. def tearDown(self):
  79. super(TestTCPUnitTests, self).tearDown()
  80. self.vapi.session_enable_disable(is_enable=0)
  81. def test_tcp_unittest(self):
  82. """ TCP Unit Tests """
  83. error = self.vapi.cli("test tcp all")
  84. if error:
  85. self.logger.critical(error)
  86. self.assertNotIn("failed", error)
  87. if __name__ == '__main__':
  88. unittest.main(testRunner=VppTestRunner)