Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 1 | from vpp_interface import VppInterface |
| 2 | |
| 3 | |
| 4 | class VppTAPInterface(VppInterface): |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 5 | @property |
| 6 | def tap_id(self): |
| 7 | """TAP id""" |
| 8 | return self._tap_id |
| 9 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 10 | def __init__(self, test, tap_id=0xFFFFFFFF, mac_addr=None): |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 11 | self._test = test |
| 12 | self._tap_id = tap_id |
| 13 | self._mac_addr = mac_addr |
| 14 | |
| 15 | def get_vpp_dump(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 16 | dump = self._test.vapi.sw_interface_tap_v2_dump(sw_if_index=self.sw_if_index) |
Paul Vinciguerra | 073d74d | 2020-04-27 01:12:48 -0400 | [diff] [blame] | 17 | return dump |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 18 | |
| 19 | def add_vpp_config(self): |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 20 | reply = self._test.vapi.tap_create_v2( |
| 21 | id=self._tap_id, |
Paul Vinciguerra | 073d74d | 2020-04-27 01:12:48 -0400 | [diff] [blame] | 22 | use_random_mac=bool(self._mac_addr), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 23 | mac_address=self._mac_addr, |
| 24 | ) |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 25 | self.set_sw_if_index(reply.sw_if_index) |
| 26 | self._test.registry.register(self, self.test.logger) |
| 27 | |
| 28 | def remove_vpp_config(self): |
| 29 | self._test.vapi.tap_delete_v2(sw_if_index=self.sw_if_index) |
| 30 | |
| 31 | def query_vpp_config(self): |
| 32 | dump = self.get_vpp_dump() |
Paul Vinciguerra | 073d74d | 2020-04-27 01:12:48 -0400 | [diff] [blame] | 33 | return bool(dump) |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 34 | |
| 35 | def object_id(self): |
| 36 | return "tap-%s" % self._tap_id |