blob: 1a9d0ac56b8aace5ad142912c2ba0625a7a5625d [file] [log] [blame]
Jakub Grajciar5de4fb72019-09-03 10:40:01 +02001import unittest
2import os
3
Pratikshya Prasai657bdf72022-08-18 11:09:38 -04004from asfframework import VppTestCase, VppTestRunner
Jakub Grajciar5de4fb72019-09-03 10:40:01 +02005from vpp_devices import VppTAPInterface
6
7
8def check_tuntap_driver_access():
Paul Vinciguerrade35cdb2019-12-16 18:24:24 -05009 return os.access("/dev/net/tun", os.R_OK and os.W_OK)
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020010
11
Andrew Yourtchenkof63bf6a2020-01-11 17:57:31 +000012@unittest.skip("Requires root")
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020013class TestTAP(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020014 """TAP Test Case"""
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020015
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 Vinciguerra073d74d2020-04-27 01:12:48 -040022 def test_tap_dump(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020023 """Test api dump w/ and w/o sw_if_index filtering"""
Paul Vinciguerra073d74d2020-04-27 01:12:48 -040024 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 Sekerad9b0c6f2022-04-26 19:02:15 +020032 details = self.vapi.sw_interface_tap_v2_dump(tap_instances[5].sw_if_index)
Paul Vinciguerra073d74d2020-04-27 01:12:48 -040033 self.assertEqual(1, len(details))
34
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020035
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020036if __name__ == "__main__":
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020037 unittest.main(testRunner=VppTestRunner)