- dut_cnt = len(Counter([self.containers[container].node['host']
- for container in self.containers]))
- mod = len(self.containers)/dut_cnt
- container_vat_template = 'memif_create_{topology}.vat'.format(
- topology=chain_topology)
-
- if chain_topology == 'chain':
- for i, container in enumerate(self.containers):
- mid1 = i % mod + 1
- mid2 = i % mod + 1
- sid1 = i % mod * 2 + 1
- sid2 = i % mod * 2 + 2
- self.engine.container = self.containers[container]
- self.engine.create_vpp_startup_config()
- self.engine.create_vpp_exec_config(container_vat_template, \
- mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2, \
- socket1='memif-{c.name}-{sid}'. \
- format(c=self.engine.container, sid=sid1), \
- socket2='memif-{c.name}-{sid}'. \
- format(c=self.engine.container, sid=sid2))
- elif chain_topology == 'cross_horiz':
- if mod > 1:
- raise RuntimeError('Container chain topology {topology} '
- 'supports only single container.'.
- format(topology=chain_topology))
- for i, container in enumerate(self.containers):
- mid1 = i % mod + 1
- sid1 = i % mod * 2 + 1
- self.engine.container = self.containers[container]
- if 'DUT1' in self.engine.container.name:
- if_pci = Topology.get_interface_pci_addr( \
- self.engine.container.node, dut1_if)
- if_name = Topology.get_interface_name( \
- self.engine.container.node, dut1_if)
- if 'DUT2' in self.engine.container.name:
- if_pci = Topology.get_interface_pci_addr( \
- self.engine.container.node, dut2_if)
- if_name = Topology.get_interface_name( \
- self.engine.container.node, dut2_if)
- self.engine.create_vpp_startup_config_dpdk_dev(if_pci)
- self.engine.create_vpp_exec_config(container_vat_template, \
- mid1=mid1, sid1=sid1, if_name=if_name, \
- socket1='memif-{c.name}-{sid}'. \
- format(c=self.engine.container, sid=sid1))
+ dut_cnt = len(
+ Counter(
+ [
+ self.containers[container].node[u"host"]
+ for container in self.containers
+ ]
+ )
+ )
+ mod = len(self.containers) // dut_cnt
+
+ for i, container in enumerate(self.containers):
+ mid1 = i % mod + 1
+ mid2 = i % mod + 1
+ sid1 = i % mod * 2 + 1
+ sid2 = i % mod * 2 + 2
+ self.engine.container = self.containers[container]
+ guest_dir = self.engine.container.mnt[0].split(u":")[1]
+
+ if chain_topology == u"chain":
+ self._configure_vpp_chain_l2xc(
+ mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
+ guest_dir=guest_dir, **kwargs
+ )
+ elif chain_topology == u"cross_horiz":
+ self._configure_vpp_cross_horiz(
+ mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
+ guest_dir=guest_dir, **kwargs
+ )
+ elif chain_topology == u"chain_functional":
+ self._configure_vpp_chain_functional(
+ mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
+ guest_dir=guest_dir, **kwargs
+ )
+ elif chain_topology == u"chain_ip4":
+ self._configure_vpp_chain_ip4(
+ mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
+ guest_dir=guest_dir, **kwargs
+ )
+ elif chain_topology == u"pipeline_ip4":
+ self._configure_vpp_pipeline_ip4(
+ mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
+ guest_dir=guest_dir, **kwargs
+ )
+ elif chain_topology == u"chain_vswitch":
+ self._configure_vpp_chain_vswitch(
+ mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
+ guest_dir=guest_dir, **kwargs)
+ elif chain_topology == u"chain_ipsec":
+ idx_match = search(r"\d+$", self.engine.container.name)
+ if idx_match:
+ idx = int(idx_match.group())
+ self._configure_vpp_chain_ipsec(
+ mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2,
+ guest_dir=guest_dir, nf_instance=idx, **kwargs)
+ else:
+ raise RuntimeError(
+ f"Container topology {chain_topology} not implemented"
+ )
+
+ def _configure_vpp_chain_l2xc(self, **kwargs):
+ """Configure VPP in chain topology with l2xc.
+
+ :param kwargs: Named parameters.
+ :type kwargs: dict
+ """
+ self.engine.create_vpp_startup_config()
+ self.engine.create_vpp_exec_config(
+ u"memif_create_chain_l2xc.exec",
+ mid1=kwargs[u"mid1"], mid2=kwargs[u"mid2"],
+ sid1=kwargs[u"sid1"], sid2=kwargs[u"sid2"],
+ socket1=f"{kwargs[u'guest_dir']}/memif-"
+ f"{self.engine.container.name}-{kwargs[u'sid1']}",
+ socket2=f"{kwargs[u'guest_dir']}/memif-"
+ f"{self.engine.container.name}-{kwargs[u'sid2']}"
+ )
+
+ def _configure_vpp_cross_horiz(self, **kwargs):
+ """Configure VPP in cross horizontal topology (single memif).
+
+ :param kwargs: Named parameters.
+ :type kwargs: dict
+ """
+ if u"DUT1" in self.engine.container.name:
+ if_pci = Topology.get_interface_pci_addr(
+ self.engine.container.node, kwargs[u"dut1_if"])
+ if_name = Topology.get_interface_name(
+ self.engine.container.node, kwargs[u"dut1_if"])
+ if u"DUT2" in self.engine.container.name:
+ if_pci = Topology.get_interface_pci_addr(
+ self.engine.container.node, kwargs[u"dut2_if"])
+ if_name = Topology.get_interface_name(
+ self.engine.container.node, kwargs[u"dut2_if"])
+ self.engine.create_vpp_startup_config_dpdk_dev(if_pci)
+ self.engine.create_vpp_exec_config(
+ u"memif_create_cross_horizon.exec",
+ mid1=kwargs[u"mid1"], sid1=kwargs[u"sid1"], if_name=if_name,
+ socket1=f"{kwargs[u'guest_dir']}/memif-"
+ f"{self.engine.container.name}-{kwargs[u'sid1']}"
+ )
+
+ def _configure_vpp_chain_functional(self, **kwargs):
+ """Configure VPP in chain topology with l2xc (functional).
+
+ :param kwargs: Named parameters.
+ :type kwargs: dict
+ """
+ self.engine.create_vpp_startup_config()
+ self.engine.create_vpp_exec_config(
+ u"memif_create_chain_functional.exec",
+ mid1=kwargs[u"mid1"], mid2=kwargs[u"mid2"],
+ sid1=kwargs[u"sid1"], sid2=kwargs[u"sid2"],
+ socket1=f"{kwargs[u'guest_dir']}/memif-"
+ f"{self.engine.container.name}-{kwargs[u'sid1']}",
+ socket2=f"{kwargs[u'guest_dir']}/memif-"
+ f"{self.engine.container.name}-{kwargs[u'sid2']}",
+ rx_mode=u"interrupt"
+ )
+
+ def _configure_vpp_chain_ip4(self, **kwargs):
+ """Configure VPP in chain topology with ip4.
+
+ :param kwargs: Named parameters.
+ :type kwargs: dict
+ """
+ self.engine.create_vpp_startup_config()
+
+ vif1_mac = kwargs[u"tg_pf1_mac"] \
+ if (kwargs[u"mid1"] - 1) % kwargs[u"nodes"] + 1 == 1 \
+ else f"52:54:00:00:{(kwargs[u'mid1'] - 1):02X}:02"
+ vif2_mac = kwargs[u"tg_pf2_mac"] \
+ if (kwargs[u"mid2"] - 1) % kwargs[u"nodes"] + 1 == kwargs[u"nodes"]\
+ else f"52:54:00:00:{(kwargs['mid2'] + 1):02X}:01"
+ self.engine.create_vpp_exec_config(
+ u"memif_create_chain_ip4.exec",
+ mid1=kwargs[u"mid1"], mid2=kwargs[u"mid2"],
+ sid1=kwargs[u"sid1"], sid2=kwargs[u"sid2"],
+ socket1=f"{kwargs[u'guest_dir']}/memif-"
+ f"{self.engine.container.name}-{kwargs[u'sid1']}",
+ socket2=f"{kwargs[u'guest_dir']}/memif-"
+ f"{self.engine.container.name}-{kwargs[u'sid2']}",
+ mac1=f"52:54:00:00:{kwargs[u'mid1']:02X}:01",
+ mac2=f"52:54:00:00:{kwargs[u'mid2']:02X}:02",
+ vif1_mac=vif1_mac, vif2_mac=vif2_mac
+ )
+
+ def _configure_vpp_chain_vswitch(self, **kwargs):
+ """Configure VPP as vswitch in container.
+
+ :param kwargs: Named parameters.
+ :type kwargs: dict
+ """
+ dut = self.engine.container.name.split(u"_")[0]
+ if dut == u"DUT1":
+ if1_pci = Topology.get_interface_pci_addr(
+ self.engine.container.node, kwargs[u"dut1_if2"])
+ if2_pci = Topology.get_interface_pci_addr(
+ self.engine.container.node, kwargs[u"dut1_if1"])
+ if_red_name = Topology.get_interface_name(
+ self.engine.container.node, kwargs[u"dut1_if2"])
+ if_black_name = Topology.get_interface_name(
+ self.engine.container.node, kwargs[u"dut1_if1"])
+ tg_pf_ip4 = kwargs[u"tg_pf2_ip4"]
+ tg_pf_mac = kwargs[u"tg_pf2_mac"]
+ else:
+ tg_pf_ip4 = kwargs[u"tg_pf1_ip4"]
+ tg_pf_mac = kwargs[u"tg_pf1_mac"]
+ if1_pci = Topology.get_interface_pci_addr(
+ self.engine.container.node, kwargs[u"dut2_if1"])
+ if2_pci = Topology.get_interface_pci_addr(
+ self.engine.container.node, kwargs[u"dut2_if2"])
+ if_red_name = Topology.get_interface_name(
+ self.engine.container.node, kwargs[u"dut2_if1"])
+ if_black_name = Topology.get_interface_name(
+ self.engine.container.node, kwargs[u"dut2_if2"])
+
+ n_instances = int(kwargs[u"n_instances"])
+ rxq = 1
+ if u"rxq" in kwargs:
+ rxq = int(kwargs[u"rxq"])
+ nodes = kwargs[u"nodes"]
+ cpuset_cpus = CpuUtils.get_affinity_nf(
+ nodes, dut, nf_chains=1, nf_nodes=1, nf_chain=1,
+ nf_node=1, vs_dtc=0, nf_dtc=8, nf_mtcr=1, nf_dtcr=1
+ )
+ self.engine.create_vpp_startup_config_vswitch(
+ cpuset_cpus, rxq, if1_pci, if2_pci
+ )
+
+ instances = []
+ for i in range(1, n_instances + 1):
+ instances.append(
+ f"create interface memif id {i} socket-id 1 master\n"
+ f"set interface state memif1/{i} up\n"
+ f"set interface l2 bridge memif1/{i} 1\n"
+ f"create interface memif id {i} socket-id 2 master\n"
+ f"set interface state memif2/{i} up\n"
+ f"set interface l2 bridge memif2/{i} 2\n"
+ f"set ip neighbor memif2/{i} {tg_pf_ip4} {tg_pf_mac} "
+ f"static\n\n"
+ )
+
+ self.engine.create_vpp_exec_config(
+ u"memif_create_chain_vswitch_ipsec.exec",
+ socket1=f"{kwargs[u'guest_dir']}/{dut}_memif-vswitch-1",
+ socket2=f"{kwargs[u'guest_dir']}/{dut}_memif-vswitch-2",
+ if_red_name=if_red_name,
+ if_black_name=if_black_name,
+ instances=u"\n\n".join(instances))
+
+
+ def _configure_vpp_chain_ipsec(self, **kwargs):
+ """Configure VPP in container with memifs.
+
+ :param kwargs: Named parameters.
+ :type kwargs: dict
+ """
+ nf_nodes = int(kwargs[u"nf_nodes"])
+ nf_instance = int(kwargs[u"nf_instance"])
+ nodes = kwargs[u"nodes"]
+ dut = self.engine.container.name.split(u"_")[0]
+ cpuset_cpus = CpuUtils.get_affinity_nf(
+ nodes, dut, nf_chains=1, nf_nodes=nf_nodes, nf_chain=1,
+ nf_node=nf_instance, vs_dtc=10, nf_dtc=1, nf_mtcr=1, nf_dtcr=1)
+ self.engine.create_vpp_startup_config_ipsec(cpuset_cpus)
+ local_ip_base = kwargs[u"dut2_if1_ip4"].rsplit(u".", 1)[0]
+
+ if dut == u"DUT1":
+ tnl_local_ip = f"{local_ip_base}.{nf_instance + 100}"
+ tnl_remote_ip = f"{local_ip_base}.{nf_instance}"
+ remote_ip_base = kwargs[u"dut1_if1_ip4"].rsplit(u".", 1)[0]
+ tg_pf_ip4 = kwargs[u"tg_pf1_ip4"]
+ tg_pf_mac = kwargs[u"tg_pf1_mac"]
+ raddr_ip4 = kwargs[u"laddr_ip4"]
+ l_mac1 = 17
+ l_mac2 = 18
+ r_mac = 1