64f911c7bfaa810070888e307a2a86871c7c661d
[vpp.git] / test / asf / test_http.py
1 #!/usr/bin/env python3
2 """ Vpp HTTP tests """
3
4 import unittest
5 import http.client
6 from asfframework import VppAsfTestCase, VppTestRunner
7
8
9 @unittest.skip("Requires root")
10 class TestHttpTps(VppAsfTestCase):
11     """HTTP test class"""
12
13     @classmethod
14     def setUpClass(cls):
15         super(TestHttpTps, cls).setUpClass()
16
17     @classmethod
18     def tearDownClass(cls):
19         super(TestHttpTps, cls).tearDownClass()
20
21     def setUp(self):
22         self.client_ip4 = "172.0.0.2"
23         self.server_ip4 = "172.0.0.1"
24         self.vapi.cli(f"create tap id 0 host-ip4-addr {self.client_ip4}/24")
25         self.vapi.cli(f"set int ip addr tap0 {self.server_ip4}/24")
26         self.vapi.cli("set int state tap0 up")
27         self.vapi.session_enable_disable(is_enable=1)
28
29     def test_http_tps(self):
30         fname = "test_file_1M"
31         self.vapi.cli("http tps uri tcp://0.0.0.0/8080")
32         con = http.client.HTTPConnection(f"{self.server_ip4}", 8080)
33         con.request("GET", f"/{fname}")
34         r = con.getresponse()
35         self.assertEqual(len(r.read()), 1 << 20)
36
37
38 if __name__ == "__main__":
39     unittest.main(testRunner=VppTestRunner)