2018-09-19 13:36:16 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from scapy.layers.l2 import Ether
|
|
|
|
from scapy.layers.inet import IP, ICMP
|
|
|
|
|
2023-08-31 00:47:44 -04:00
|
|
|
from framework import VppTestCase
|
|
|
|
from asfframework import (
|
|
|
|
tag_run_solo,
|
|
|
|
tag_fixme_debian11,
|
|
|
|
is_distro_debian11,
|
|
|
|
VppTestRunner,
|
|
|
|
)
|
|
|
|
from remote_test import RemoteClass, RemoteVppTestCase
|
2022-04-26 19:02:15 +02:00
|
|
|
from vpp_memif import remove_all_memif_vpp_config, VppSocketFilename, VppMemif
|
2018-05-01 05:17:55 -07:00
|
|
|
from vpp_ip_route import VppIpRoute, VppRoutePath
|
2019-08-21 10:51:21 +02:00
|
|
|
from vpp_papi import VppEnum
|
2024-03-11 10:38:46 +00:00
|
|
|
from config import config
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
|
2021-01-14 10:19:08 +00:00
|
|
|
@tag_run_solo
|
2022-09-20 21:52:18 -04:00
|
|
|
@tag_fixme_debian11
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf("memif" in config.excluded_plugins, "Exclude Memif plugin tests")
|
2018-09-19 13:36:16 +02:00
|
|
|
class TestMemif(VppTestCase):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Memif Test Case"""
|
|
|
|
|
2021-04-08 19:37:41 +02:00
|
|
|
remote_class = RemoteVppTestCase
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_cpus_required(cls):
|
2022-04-26 19:02:15 +02:00
|
|
|
return super().get_cpus_required() + cls.remote_class.get_cpus_required()
|
2021-04-08 19:37:41 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def assign_cpus(cls, cpus):
|
2022-04-26 19:02:15 +02:00
|
|
|
remote_cpus = cpus[: cls.remote_class.get_cpus_required()]
|
|
|
|
my_cpus = cpus[cls.remote_class.get_cpus_required() :]
|
2021-04-08 19:37:41 +02:00
|
|
|
cls.remote_class.assign_cpus(remote_cpus)
|
|
|
|
super().assign_cpus(my_cpus)
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
# fork new process before client connects to VPP
|
2021-04-08 19:37:41 +02:00
|
|
|
cls.remote_test = RemoteClass(cls.remote_class)
|
2018-09-19 13:36:16 +02:00
|
|
|
cls.remote_test.start_remote()
|
|
|
|
cls.remote_test.set_request_timeout(10)
|
|
|
|
super(TestMemif, cls).setUpClass()
|
2022-09-20 21:52:18 -04:00
|
|
|
if is_distro_debian11 == True and not hasattr(cls, "vpp"):
|
|
|
|
cls.remote_test.quit_remote()
|
|
|
|
return
|
2018-09-19 13:36:16 +02:00
|
|
|
cls.remote_test.setUpClass(cls.tempdir)
|
|
|
|
cls.create_pg_interfaces(range(1))
|
|
|
|
for pg in cls.pg_interfaces:
|
|
|
|
pg.config_ip4()
|
|
|
|
pg.admin_up()
|
|
|
|
pg.resolve_arp()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
cls.remote_test.tearDownClass()
|
|
|
|
cls.remote_test.quit_remote()
|
|
|
|
for pg in cls.pg_interfaces:
|
|
|
|
pg.unconfig_ip4()
|
|
|
|
pg.set_table_ip4(0)
|
|
|
|
pg.admin_down()
|
|
|
|
super(TestMemif, cls).tearDownClass()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
remove_all_memif_vpp_config(self)
|
|
|
|
remove_all_memif_vpp_config(self.remote_test)
|
|
|
|
super(TestMemif, self).tearDown()
|
|
|
|
|
|
|
|
def _check_socket_filename(self, dump, socket_id, filename):
|
|
|
|
for d in dump:
|
2022-04-26 19:02:15 +02:00
|
|
|
if (d.socket_id == socket_id) and (d.socket_filename == filename):
|
2018-09-19 13:36:16 +02:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def test_memif_socket_filename_add_del(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Memif socket filename add/del"""
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
# dump default socket filename
|
|
|
|
dump = self.vapi.memif_socket_filename_dump()
|
|
|
|
self.assertTrue(
|
2022-04-26 19:02:15 +02:00
|
|
|
self._check_socket_filename(dump, 0, "%s/memif.sock" % self.tempdir)
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
memif_sockets = []
|
|
|
|
# existing path
|
|
|
|
memif_sockets.append(
|
2022-04-26 19:02:15 +02:00
|
|
|
VppSocketFilename(self, 1, "%s/memif1.sock" % self.tempdir)
|
|
|
|
)
|
2018-10-09 12:28:21 +02:00
|
|
|
# default path (test tempdir)
|
2018-09-19 13:36:16 +02:00
|
|
|
memif_sockets.append(
|
2022-04-26 19:02:15 +02:00
|
|
|
VppSocketFilename(self, 2, "memif2.sock", add_default_folder=True)
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
# create new folder in default folder
|
|
|
|
memif_sockets.append(
|
2022-04-26 19:02:15 +02:00
|
|
|
VppSocketFilename(self, 3, "sock/memif3.sock", add_default_folder=True)
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
for sock in memif_sockets:
|
|
|
|
sock.add_vpp_config()
|
|
|
|
dump = sock.query_vpp_config()
|
|
|
|
self.assertTrue(
|
2022-04-26 19:02:15 +02:00
|
|
|
self._check_socket_filename(dump, sock.socket_id, sock.socket_filename)
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
for sock in memif_sockets:
|
|
|
|
sock.remove_vpp_config()
|
|
|
|
|
|
|
|
dump = self.vapi.memif_socket_filename_dump()
|
|
|
|
self.assertTrue(
|
2022-04-26 19:02:15 +02:00
|
|
|
self._check_socket_filename(dump, 0, "%s/memif.sock" % self.tempdir)
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
def _create_delete_test_one_interface(self, memif):
|
|
|
|
memif.add_vpp_config()
|
|
|
|
|
|
|
|
dump = memif.query_vpp_config()
|
|
|
|
|
|
|
|
self.assertTrue(dump)
|
|
|
|
self.assertEqual(dump.sw_if_index, memif.sw_if_index)
|
|
|
|
self.assertEqual(dump.role, memif.role)
|
|
|
|
self.assertEqual(dump.mode, memif.mode)
|
2022-04-26 19:02:15 +02:00
|
|
|
if memif.socket_id is not None:
|
2018-09-19 13:36:16 +02:00
|
|
|
self.assertEqual(dump.socket_id, memif.socket_id)
|
|
|
|
|
|
|
|
memif.remove_vpp_config()
|
|
|
|
|
|
|
|
dump = memif.query_vpp_config()
|
|
|
|
|
|
|
|
self.assertFalse(dump)
|
|
|
|
|
|
|
|
def _connect_test_one_interface(self, memif):
|
|
|
|
self.assertTrue(memif.wait_for_link_up(5))
|
|
|
|
dump = memif.query_vpp_config()
|
|
|
|
|
2019-08-21 10:51:21 +02:00
|
|
|
if memif.role == VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE:
|
2018-09-19 13:36:16 +02:00
|
|
|
self.assertEqual(dump.ring_size, memif.ring_size)
|
|
|
|
self.assertEqual(dump.buffer_size, memif.buffer_size)
|
|
|
|
else:
|
|
|
|
self.assertEqual(dump.ring_size, 1)
|
|
|
|
self.assertEqual(dump.buffer_size, 0)
|
|
|
|
|
|
|
|
def _connect_test_interface_pair(self, memif0, memif1):
|
|
|
|
memif0.add_vpp_config()
|
|
|
|
memif1.add_vpp_config()
|
|
|
|
|
|
|
|
memif0.admin_up()
|
|
|
|
memif1.admin_up()
|
|
|
|
|
|
|
|
self._connect_test_one_interface(memif0)
|
|
|
|
self._connect_test_one_interface(memif1)
|
|
|
|
|
|
|
|
memif0.remove_vpp_config()
|
|
|
|
memif1.remove_vpp_config()
|
|
|
|
|
|
|
|
def test_memif_create_delete(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Memif create/delete interface"""
|
2018-09-19 13:36:16 +02:00
|
|
|
|
2019-08-21 10:51:21 +02:00
|
|
|
memif = VppMemif(
|
|
|
|
self,
|
|
|
|
VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
|
2022-04-26 19:02:15 +02:00
|
|
|
VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
self._create_delete_test_one_interface(memif)
|
2019-08-21 10:51:21 +02:00
|
|
|
memif.role = VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER
|
2018-09-19 13:36:16 +02:00
|
|
|
self._create_delete_test_one_interface(memif)
|
|
|
|
|
|
|
|
def test_memif_create_custom_socket(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Memif create with non-default socket filename"""
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
memif_sockets = []
|
|
|
|
# existing path
|
|
|
|
memif_sockets.append(
|
2022-04-26 19:02:15 +02:00
|
|
|
VppSocketFilename(self, 1, "%s/memif1.sock" % self.tempdir)
|
|
|
|
)
|
2018-10-09 12:28:21 +02:00
|
|
|
# default path (test tempdir)
|
2018-09-19 13:36:16 +02:00
|
|
|
memif_sockets.append(
|
2022-04-26 19:02:15 +02:00
|
|
|
VppSocketFilename(self, 2, "memif2.sock", add_default_folder=True)
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
# create new folder in default folder
|
|
|
|
memif_sockets.append(
|
2022-04-26 19:02:15 +02:00
|
|
|
VppSocketFilename(self, 3, "sock/memif3.sock", add_default_folder=True)
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
|
2019-08-21 10:51:21 +02:00
|
|
|
memif = VppMemif(
|
|
|
|
self,
|
|
|
|
VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
|
2022-04-26 19:02:15 +02:00
|
|
|
VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
for sock in memif_sockets:
|
|
|
|
sock.add_vpp_config()
|
|
|
|
memif.socket_id = sock.socket_id
|
2019-08-21 10:51:21 +02:00
|
|
|
memif.role = VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE
|
2018-09-19 13:36:16 +02:00
|
|
|
self._create_delete_test_one_interface(memif)
|
2019-08-21 10:51:21 +02:00
|
|
|
memif.role = VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER
|
2018-09-19 13:36:16 +02:00
|
|
|
self._create_delete_test_one_interface(memif)
|
|
|
|
|
|
|
|
def test_memif_connect(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Memif connect"""
|
2019-08-21 10:51:21 +02:00
|
|
|
memif = VppMemif(
|
|
|
|
self,
|
|
|
|
VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
|
|
|
|
VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
|
|
|
|
ring_size=1024,
|
|
|
|
buffer_size=2048,
|
2022-04-26 19:02:15 +02:00
|
|
|
secret="abc",
|
|
|
|
)
|
2018-10-09 12:28:21 +02:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
remote_socket = VppSocketFilename(
|
|
|
|
self.remote_test, 1, "%s/memif.sock" % self.tempdir
|
|
|
|
)
|
2018-10-09 12:28:21 +02:00
|
|
|
remote_socket.add_vpp_config()
|
|
|
|
|
2019-08-21 10:51:21 +02:00
|
|
|
remote_memif = VppMemif(
|
|
|
|
self.remote_test,
|
|
|
|
VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
|
|
|
|
VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
|
|
|
|
socket_id=1,
|
|
|
|
ring_size=1024,
|
|
|
|
buffer_size=2048,
|
2022-04-26 19:02:15 +02:00
|
|
|
secret="abc",
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
self._connect_test_interface_pair(memif, remote_memif)
|
|
|
|
|
2019-08-21 10:51:21 +02:00
|
|
|
memif.role = VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER
|
|
|
|
remote_memif.role = VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
self._connect_test_interface_pair(memif, remote_memif)
|
|
|
|
|
|
|
|
def _create_icmp(self, pg, memif, num):
|
|
|
|
pkts = []
|
|
|
|
for i in range(num):
|
2022-04-26 19:02:15 +02:00
|
|
|
pkt = (
|
|
|
|
Ether(dst=pg.local_mac, src=pg.remote_mac)
|
|
|
|
/ IP(src=pg.remote_ip4, dst=str(memif.ip_prefix.network_address))
|
|
|
|
/ ICMP(id=memif.if_id, type="echo-request", seq=i)
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
pkts.append(pkt)
|
|
|
|
return pkts
|
|
|
|
|
|
|
|
def _verify_icmp(self, pg, memif, rx, seq):
|
|
|
|
ip = rx[IP]
|
2019-11-11 08:32:34 +00:00
|
|
|
self.assertEqual(ip.src, str(memif.ip_prefix.network_address))
|
2018-09-19 13:36:16 +02:00
|
|
|
self.assertEqual(ip.dst, pg.remote_ip4)
|
|
|
|
self.assertEqual(ip.proto, 1)
|
|
|
|
icmp = rx[ICMP]
|
|
|
|
self.assertEqual(icmp.type, 0) # echo-reply
|
|
|
|
self.assertEqual(icmp.id, memif.if_id)
|
|
|
|
self.assertEqual(icmp.seq, seq)
|
|
|
|
|
|
|
|
def test_memif_ping(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Memif ping"""
|
2018-05-01 05:17:55 -07:00
|
|
|
|
2019-08-21 10:51:21 +02:00
|
|
|
memif = VppMemif(
|
|
|
|
self,
|
|
|
|
VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
|
2022-04-26 19:02:15 +02:00
|
|
|
VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
|
|
|
|
)
|
2018-10-09 12:28:21 +02:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
remote_socket = VppSocketFilename(
|
|
|
|
self.remote_test, 1, "%s/memif.sock" % self.tempdir
|
|
|
|
)
|
2018-10-09 12:28:21 +02:00
|
|
|
remote_socket.add_vpp_config()
|
|
|
|
|
2019-08-21 10:51:21 +02:00
|
|
|
remote_memif = VppMemif(
|
|
|
|
self.remote_test,
|
|
|
|
VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
|
|
|
|
VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
|
2022-04-26 19:02:15 +02:00
|
|
|
socket_id=1,
|
|
|
|
)
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
memif.add_vpp_config()
|
|
|
|
memif.config_ip4()
|
|
|
|
memif.admin_up()
|
|
|
|
|
|
|
|
remote_memif.add_vpp_config()
|
|
|
|
remote_memif.config_ip4()
|
|
|
|
remote_memif.admin_up()
|
|
|
|
|
|
|
|
self.assertTrue(memif.wait_for_link_up(5))
|
|
|
|
self.assertTrue(remote_memif.wait_for_link_up(5))
|
|
|
|
|
|
|
|
# add routing to remote vpp
|
2022-04-26 19:02:15 +02:00
|
|
|
route = VppIpRoute(
|
|
|
|
self.remote_test,
|
|
|
|
self.pg0._local_ip4_subnet,
|
|
|
|
24,
|
|
|
|
[VppRoutePath(memif.ip_prefix.network_address, 0xFFFFFFFF)],
|
|
|
|
register=False,
|
|
|
|
)
|
2019-06-25 10:22:11 +02:00
|
|
|
|
|
|
|
route.add_vpp_config()
|
2018-09-19 13:36:16 +02:00
|
|
|
|
|
|
|
# create ICMP echo-request from local pg to remote memif
|
|
|
|
packet_num = 10
|
|
|
|
pkts = self._create_icmp(self.pg0, remote_memif, packet_num)
|
|
|
|
|
|
|
|
self.pg0.add_stream(pkts)
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
capture = self.pg0.get_capture(packet_num, timeout=2)
|
|
|
|
seq = 0
|
|
|
|
for c in capture:
|
|
|
|
self._verify_icmp(self.pg0, remote_memif, c, seq)
|
|
|
|
seq += 1
|
|
|
|
|
2019-06-25 10:22:11 +02:00
|
|
|
route.remove_vpp_config()
|
|
|
|
|
2021-11-03 08:55:04 +00:00
|
|
|
def test_memif_admin_up_down_up(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Memif admin up/down/up"""
|
2021-11-03 08:55:04 +00:00
|
|
|
memif = VppMemif(
|
|
|
|
self,
|
|
|
|
VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
|
|
|
|
VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
|
|
|
|
ring_size=1024,
|
|
|
|
buffer_size=2048,
|
2022-04-26 19:02:15 +02:00
|
|
|
secret="abc",
|
|
|
|
)
|
2021-11-03 08:55:04 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
remote_socket = VppSocketFilename(
|
|
|
|
self.remote_test, 1, "%s/memif.sock" % self.tempdir
|
|
|
|
)
|
2021-11-03 08:55:04 +00:00
|
|
|
remote_socket.add_vpp_config()
|
|
|
|
|
|
|
|
remote_memif = VppMemif(
|
|
|
|
self.remote_test,
|
|
|
|
VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
|
|
|
|
VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
|
|
|
|
socket_id=1,
|
|
|
|
ring_size=1024,
|
|
|
|
buffer_size=2048,
|
2022-04-26 19:02:15 +02:00
|
|
|
secret="abc",
|
|
|
|
)
|
2021-11-03 08:55:04 +00:00
|
|
|
|
|
|
|
memif.add_vpp_config()
|
|
|
|
remote_memif.add_vpp_config()
|
|
|
|
|
|
|
|
memif.admin_up()
|
|
|
|
remote_memif.admin_up()
|
|
|
|
memif.admin_down()
|
|
|
|
remote_memif.admin_down()
|
|
|
|
memif.admin_up()
|
|
|
|
remote_memif.admin_up()
|
|
|
|
|
|
|
|
self._connect_test_one_interface(memif)
|
|
|
|
self._connect_test_one_interface(remote_memif)
|
|
|
|
|
|
|
|
memif.remove_vpp_config()
|
|
|
|
remote_memif.remove_vpp_config()
|
|
|
|
remote_socket.remove_vpp_config()
|
|
|
|
|
2018-09-19 13:36:16 +02:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if __name__ == "__main__":
|
2018-09-19 13:36:16 +02:00
|
|
|
unittest.main(testRunner=VppTestRunner)
|