blob: 9e272cafe3211635236d057f96d27598865bfb30 [file] [log] [blame]
Jakub Grajciar5de4fb72019-09-03 10:40:01 +02001from vpp_interface import VppInterface
2
3
4class 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 Vinciguerra073d74d2020-04-27 01:12:48 -040017 dump = self._test.vapi.sw_interface_tap_v2_dump(
18 sw_if_index=self.sw_if_index)
19 return dump
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020020
21 def add_vpp_config(self):
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020022 reply = self._test.vapi.tap_create_v2(
23 id=self._tap_id,
Paul Vinciguerra073d74d2020-04-27 01:12:48 -040024 use_random_mac=bool(self._mac_addr),
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020025 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 Vinciguerra073d74d2020-04-27 01:12:48 -040034 return bool(dump)
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020035
36 def object_id(self):
37 return "tap-%s" % self._tap_id