5 from vpp_object import VppObject
19 def get_if_dump(dump, sw_if_index):
21 if (d.sw_if_index == sw_if_index):
25 def query_all_memif_vpp_config(_test):
26 return _test.vapi.memif_dump()
29 def remove_all_memif_vpp_config(_test):
30 dump = _test.vapi.memif_dump()
32 _test.vapi.memif_delete(d.sw_if_index)
33 dump = _test.vapi.memif_socket_filename_dump()
36 _test.vapi.memif_socket_filename_add_del(
37 0, d.socket_id, d.socket_filename)
40 class VppSocketFilename(VppObject):
41 def __init__(self, test, socket_id, socket_filename,
42 add_default_folder=False):
44 self.socket_id = socket_id
45 self.socket_filename = socket_filename
47 # if True insert default socket folder before socket filename,
48 # after adding vpp config
49 self.add_default_folder = add_default_folder
51 def add_vpp_config(self):
52 rv = self._test.vapi.memif_socket_filename_add_del(
53 1, self.socket_id, self.socket_filename)
54 if self.add_default_folder:
55 self.socket_filename = b"%s/%s" % (
56 six.ensure_binary(self._test.tempdir, encoding='utf-8'),
60 def remove_vpp_config(self):
61 return self._test.vapi.memif_socket_filename_add_del(
62 0, self.socket_id, self.socket_filename)
64 def query_vpp_config(self):
65 return self._test.vapi.memif_socket_filename_dump()
68 return self.object_id()
71 return "%d" % (self.socket_id)
74 class VppMemif(VppObject):
75 def __init__(self, test, role, mode, rx_queues=0, tx_queues=0, if_id=0,
76 socket_id=0, secret="", ring_size=0, buffer_size=0,
81 self.rx_queues = rx_queues
82 self.tx_queues = tx_queues
84 self.socket_id = socket_id
86 self.ring_size = ring_size
87 self.buffer_size = buffer_size
88 self.hw_addr = hw_addr
89 self.sw_if_index = None
90 self.ip4_addr = "192.168.%d.%d" % (self.if_id + 1, self.role + 1)
91 self.ip4_addr_len = 24
93 def add_vpp_config(self):
94 rv = self._test.vapi.memif_create(self.role, self.mode, self.rx_queues,
95 self.tx_queues, self.if_id,
96 self.socket_id, self.secret,
97 self.ring_size, self.buffer_size,
99 self.sw_if_index = rv.sw_if_index
100 return self.sw_if_index
104 return self._test.vapi.sw_interface_set_flags(self.sw_if_index, 1)
106 def admin_down(self):
108 return self._test.vapi.sw_interface_set_flags(self.sw_if_index, 0)
110 def wait_for_link_up(self, timeout, step=1):
111 if not self.sw_if_index:
114 dump = self.query_vpp_config()
115 if dump.link_up_down == 1:
117 self._test.sleep(step)
122 def config_ip4(self):
123 return self._test.vapi.sw_interface_add_del_address(
124 sw_if_index=self.sw_if_index, address=socket.inet_pton(
125 socket.AF_INET, self.ip4_addr),
126 address_length=self.ip4_addr_len)
128 def remove_vpp_config(self):
129 self._test.vapi.memif_delete(self.sw_if_index)
130 self.sw_if_index = None
132 def query_vpp_config(self):
133 if not self.sw_if_index:
135 dump = self._test.vapi.memif_dump()
136 return get_if_dump(dump, self.sw_if_index)
139 return self.object_id()
143 return "%d:%d:%d" % (self.role, self.if_id, self.sw_if_index)
145 return "%d:%d:None" % (self.role, self.if_id)