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