blob: cff08e844353fae7df65d41e487f8936703a8240 [file] [log] [blame]
Jakub Grajciar5de4fb72019-09-03 10:40:01 +02001from vpp_interface import VppInterface
2
3
4class VppTAPInterface(VppInterface):
Jakub Grajciar5de4fb72019-09-03 10:40:01 +02005 @property
6 def tap_id(self):
7 """TAP id"""
8 return self._tap_id
9
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020010 def __init__(self, test, tap_id=0xFFFFFFFF, mac_addr=None):
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020011 self._test = test
12 self._tap_id = tap_id
13 self._mac_addr = mac_addr
14
15 def get_vpp_dump(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020016 dump = self._test.vapi.sw_interface_tap_v2_dump(sw_if_index=self.sw_if_index)
Paul Vinciguerra073d74d2020-04-27 01:12:48 -040017 return dump
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020018
19 def add_vpp_config(self):
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020020 reply = self._test.vapi.tap_create_v2(
21 id=self._tap_id,
Paul Vinciguerra073d74d2020-04-27 01:12:48 -040022 use_random_mac=bool(self._mac_addr),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020023 mac_address=self._mac_addr,
24 )
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020025 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 Vinciguerra073d74d2020-04-27 01:12:48 -040033 return bool(dump)
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020034
35 def object_id(self):
36 return "tap-%s" % self._tap_id