- 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_if1_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_if2_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_if_ip4 = kwargs[u"tg_if2_ip4"]
+ tg_if_mac = kwargs[u"tg_if2_mac"]