Merge "bugfix: remove pod_name in host and unify host parameter"
[yardstick.git] / yardstick / network_services / helpers / samplevnf_helper.py
index 5f87f78..4718bbd 100644 (file)
@@ -55,6 +55,10 @@ SCRIPT_TPL = """
 
 {arp_config6}
 
+{arp_route_tbl}
+
+{arp_route_tbl6}
+
 {actions}
 
 {rules}
@@ -226,7 +230,7 @@ class MultiPortConfig(object):
         self.tmp_file = os.path.join("/tmp", tmp_file)
         self.pktq_out_os = []
         self.socket = socket
-        self.start_core = ""
+        self.start_core = 0
         self.pipeline_counter = ""
         self.txrx_pipeline = ""
         self._port_pairs = None
@@ -268,9 +272,8 @@ class MultiPortConfig(object):
 
     def update_timer(self):
         timer_tpl = self.get_config_tpl_data('TIMER')
-        timer_tpl['core'] = self.gen_core(self.start_core)
+        timer_tpl['core'] = self.gen_core(0)
         self.update_write_parser(timer_tpl)
-        self.start_core += 1
 
     def get_config_tpl_data(self, type_value):
         for section in self.read_parser.sections():
@@ -289,7 +292,6 @@ class MultiPortConfig(object):
     def init_write_parser_template(self, type_value='ARPICMP'):
         for section in self.read_parser.sections():
             if type_value == self.parser_get(self.read_parser, section, 'type', object()):
-                self.start_core = self.read_parser.getint(section, 'core')
                 self.pipeline_counter = self.read_parser.getint(section, 'core')
                 self.txrx_pipeline = self.read_parser.getint(section, 'core')
                 return
@@ -347,30 +349,28 @@ class MultiPortConfig(object):
             "".join(("{},".format(port_list.index(x)) for x in uplink_ports)))
 
     def generate_arp_route_tbl(self):
-        arp_route_tbl_tmpl = "({port0_dst_ip_hex},{port0_netmask_hex},{port_num}," \
-                             "{next_hop_ip_hex})"
+        arp_route_tbl_tmpl = "routeadd net {port_num} {port_dst_ip} 0x{port_netmask_hex}"
 
         def build_arp_config(port):
             dpdk_port_num = self.vnfd_helper.port_num(port)
             interface = self.vnfd_helper.find_interface(name=port)["virtual-interface"]
             # We must use the dst because we are on the VNF and we need to
             # reach the TG.
-            dst_port0_ip = ipaddress.ip_interface(six.text_type(
+            dst_port_ip = ipaddress.ip_interface(six.text_type(
                 "%s/%s" % (interface["dst_ip"], interface["netmask"])))
 
             arp_vars = {
-                "port0_dst_ip_hex": ip_to_hex(dst_port0_ip.network.network_address.exploded),
-                "port0_netmask_hex": ip_to_hex(dst_port0_ip.network.netmask.exploded),
+                "port_netmask_hex": ip_to_hex(dst_port_ip.network.netmask.exploded),
                 # this is the port num that contains port0 subnet and next_hop_ip_hex
                 # this is LINKID which should be based on DPDK port number
                 "port_num": dpdk_port_num,
                 # next hop is dst in this case
                 # must be within subnet
-                "next_hop_ip_hex": ip_to_hex(dst_port0_ip.ip.exploded),
+                "port_dst_ip": str(dst_port_ip.ip),
             }
             return arp_route_tbl_tmpl.format(**arp_vars)
 
-        return ' '.join(build_arp_config(port) for port in self.all_ports)
+        return '\n'.join(build_arp_config(port) for port in self.all_ports)
 
     def generate_arpicmp_data(self):
         swq_in_str = self.make_range_str('SWQ{}', self.swq, offset=self.lb_count)
@@ -385,7 +385,7 @@ class MultiPortConfig(object):
                         self.port_pair_list)
 
         arpicmp_data = {
-            'core': self.gen_core(self.start_core),
+            'core': self.gen_core(0),
             'pktq_in': swq_in_str,
             'pktq_out': swq_out_str,
             # we need to disable ports_mac_list?
@@ -393,11 +393,6 @@ class MultiPortConfig(object):
             # 'ports_mac_list': ' '.join(mac_iter),
             'pktq_in_prv': ' '.join(pktq_in_iter),
             'prv_to_pub_map': self.set_priv_to_pub_mapping(),
-            'arp_route_tbl': self.generate_arp_route_tbl(),
-            # nd_route_tbl must be set or we get segault on random OpenStack IPv6 traffic
-            # 'nd_route_tbl': "(0064:ff9b:0:0:0:0:9810:6414,120,0,0064:ff9b:0:0:0:0:9810:6414)"
-            # safe default?  route discard prefix to localhost
-            'nd_route_tbl': "(0100::,64,0,::1)"
         }
         self.pktq_out_os = swq_out_str.split(' ')
         # HWLB is a run to complition. So override the pktq_in/pktq_out
@@ -416,7 +411,7 @@ class MultiPortConfig(object):
 
         return arpicmp_data
 
-    def generate_final_txrx_data(self):
+    def generate_final_txrx_data(self, core=0):
         swq_start = self.swq - self.ports_len * self.worker_threads
 
         txq_start = 0
@@ -431,7 +426,7 @@ class MultiPortConfig(object):
             'pktq_in': swq_str,
             'pktq_out': txq_str,
             'pipeline_txrx_type': 'TXTX',
-            'core': self.gen_core(self.start_core),
+            'core': self.gen_core(core),
         }
         pktq_in = rxtx_data['pktq_in']
         pktq_in = '{0} {1}'.format(pktq_in, self.pktq_out_os[self.lb_index - 1])
@@ -452,7 +447,7 @@ class MultiPortConfig(object):
             'core': self.gen_core(self.start_core),
         }
         self.pipeline_counter += 1
-        return txrx_data
+        return self.start_core, txrx_data
 
     def generate_lb_data(self):
         pktq_in = self.make_range_str('SWQ{}', self.swq, offset=self.ports_len)
@@ -519,11 +514,13 @@ class MultiPortConfig(object):
         self.arpicmp_tpl.update(arpicmp_data)
         self.update_write_parser(self.arpicmp_tpl)
 
-        self.start_core += 1
         if self.vnf_type == 'CGNAPT':
             self.pipeline_counter += 1
             self.update_timer()
 
+        if self.lb_config == 'HW':
+            self.start_core = 1
+
         for lb in self.lb_to_port_pair_mapping:
             self.lb_index = lb
             self.mul = 0
@@ -536,7 +533,7 @@ class MultiPortConfig(object):
             self.ports_len = port_pair_count * 2
             self.set_priv_que_handler()
             if self.lb_config == 'SW':
-                txrx_data = self.generate_initial_txrx_data()
+                core, txrx_data = self.generate_initial_txrx_data()
                 self.txrx_tpl.update(txrx_data)
                 self.update_write_parser(self.txrx_tpl)
                 self.start_core += 1
@@ -560,10 +557,9 @@ class MultiPortConfig(object):
                 self.generate_next_core_id()
 
             if self.lb_config == 'SW':
-                txrx_data = self.generate_final_txrx_data()
+                txrx_data = self.generate_final_txrx_data(core)
                 self.txrx_tpl.update(txrx_data)
                 self.update_write_parser(self.txrx_tpl)
-                self.start_core += 1
             self.vnf_tpl = self.get_config_tpl_data(self.vnf_type)
 
     def generate_config(self):
@@ -711,6 +707,9 @@ class MultiPortConfig(object):
             # disable IPv6 for now
             # 'arp_config6': self.generate_arp_config6(),
             'arp_config6': "",
+            'arp_config': self.generate_arp_config(),
+            'arp_route_tbl': self.generate_arp_route_tbl(),
+            'arp_route_tbl6': "",
             'actions': '',
             'rules': '',
         }