Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 1 | import unittest |
| 2 | import os |
| 3 | |
Pratikshya Prasai | 657bdf7 | 2022-08-18 11:09:38 -0400 | [diff] [blame] | 4 | from asfframework import VppTestCase, VppTestRunner |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 5 | from vpp_devices import VppTAPInterface |
| 6 | |
| 7 | |
| 8 | def check_tuntap_driver_access(): |
Paul Vinciguerra | de35cdb | 2019-12-16 18:24:24 -0500 | [diff] [blame] | 9 | return os.access("/dev/net/tun", os.R_OK and os.W_OK) |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 10 | |
| 11 | |
Andrew Yourtchenko | f63bf6a | 2020-01-11 17:57:31 +0000 | [diff] [blame] | 12 | @unittest.skip("Requires root") |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 13 | class TestTAP(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 14 | """TAP Test Case""" |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 15 | |
| 16 | def test_tap_add_del(self): |
| 17 | """Create TAP interface""" |
| 18 | tap0 = VppTAPInterface(self, tap_id=0) |
| 19 | tap0.add_vpp_config() |
| 20 | self.assertTrue(tap0.query_vpp_config()) |
| 21 | |
Paul Vinciguerra | 073d74d | 2020-04-27 01:12:48 -0400 | [diff] [blame] | 22 | def test_tap_dump(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 23 | """Test api dump w/ and w/o sw_if_index filtering""" |
Paul Vinciguerra | 073d74d | 2020-04-27 01:12:48 -0400 | [diff] [blame] | 24 | MAX_INSTANCES = 10 |
| 25 | tap_instances = [] |
| 26 | for instance in range(MAX_INSTANCES): |
| 27 | i = VppTAPInterface(self, tap_id=instance) |
| 28 | i.add_vpp_config() |
| 29 | tap_instances.append(i) |
| 30 | details = self.vapi.sw_interface_tap_v2_dump() |
| 31 | self.assertEqual(MAX_INSTANCES, len(details)) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 32 | details = self.vapi.sw_interface_tap_v2_dump(tap_instances[5].sw_if_index) |
Paul Vinciguerra | 073d74d | 2020-04-27 01:12:48 -0400 | [diff] [blame] | 33 | self.assertEqual(1, len(details)) |
| 34 | |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 35 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 36 | if __name__ == "__main__": |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 37 | unittest.main(testRunner=VppTestRunner) |