Merge "bugfix: remove pod_name in host and unify host parameter"
[yardstick.git] / yardstick / network_services / helpers / samplevnf_helper.py
index 7054b92..4718bbd 100644 (file)
@@ -55,6 +55,10 @@ SCRIPT_TPL = """
 
 {arp_config6}
 
+{arp_route_tbl}
+
+{arp_route_tbl6}
+
 {actions}
 
 {rules}
@@ -64,15 +68,15 @@ SCRIPT_TPL = """
 
 class PortPairs(object):
 
-    PUBLIC = "public"
-    PRIVATE = "private"
+    DOWNLINK = "downlink"
+    UPLINK = "uplink"
 
     def __init__(self, interfaces):
         super(PortPairs, self).__init__()
         self.interfaces = interfaces
         self._all_ports = None
-        self._priv_ports = None
-        self._pub_ports = None
+        self._uplink_ports = None
+        self._downlink_ports = None
         self._networks = None
         self._port_pair_list = None
         self._valid_networks = None
@@ -93,62 +97,63 @@ class PortPairs(object):
         return self._networks
 
     @classmethod
-    def get_public_id(cls, vld_id):
+    def get_downlink_id(cls, vld_id):
         # partition returns a tuple
-        parts = list(vld_id.partition(cls.PRIVATE))
+        parts = list(vld_id.partition(cls.UPLINK))
         if parts[0]:
-            # 'private' was not in or not leftmost in the string
+            # 'uplink' was not in or not leftmost in the string
             return
-        parts[1] = cls.PUBLIC
+        parts[1] = cls.DOWNLINK
         public_id = ''.join(parts)
         return public_id
 
     @property
-    # this only works for vnfs that have both private and public visible
+    # this only works for vnfs that have both uplink and public visible
     def valid_networks(self):
         if self._valid_networks is None:
             self._valid_networks = []
             for vld_id in self.networks:
-                public_id = self.get_public_id(vld_id)
-                if public_id in self.networks:
-                    self._valid_networks.append((vld_id, public_id))
+                downlink_id = self.get_downlink_id(vld_id)
+                if downlink_id in self.networks:
+                    self._valid_networks.append((vld_id, downlink_id))
         return self._valid_networks
 
     @property
     def all_ports(self):
         if self._all_ports is None:
-            self._all_ports = sorted(set(self.priv_ports + self.pub_ports))
+            self._all_ports = sorted(set(self.uplink_ports + self.downlink_ports))
         return self._all_ports
 
     @property
-    def priv_ports(self):
-        if self._priv_ports is None:
+    def uplink_ports(self):
+        if self._uplink_ports is None:
             intfs = chain.from_iterable(
                 intfs for vld_id, intfs in self.networks.items() if
-                vld_id.startswith(self.PRIVATE))
-            self._priv_ports = sorted(set(intfs))
-        return self._priv_ports
+                vld_id.startswith(self.UPLINK))
+            self._uplink_ports = sorted(set(intfs))
+        return self._uplink_ports
 
     @property
-    def pub_ports(self):
-        if self._pub_ports is None:
+    def downlink_ports(self):
+        if self._downlink_ports is None:
             intfs = chain.from_iterable(
-                intfs for vld_id, intfs in self.networks.items() if vld_id.startswith(self.PUBLIC))
-            self._pub_ports = sorted(set(intfs))
-        return self._pub_ports
+                intfs for vld_id, intfs in self.networks.items() if
+                vld_id.startswith(self.DOWNLINK))
+            self._downlink_ports = sorted(set(intfs))
+        return self._downlink_ports
 
     @property
     def port_pair_list(self):
         if self._port_pair_list is None:
             self._port_pair_list = []
 
-            for priv, pub in self.valid_networks:
-                for private_intf in self.networks[priv]:
-                    # only VNFs have private, public peers
-                    peer_intfs = self.networks.get(pub, [])
+            for uplink, downlink in self.valid_networks:
+                for uplink_intf in self.networks[uplink]:
+                    # only VNFs have uplink, public peers
+                    peer_intfs = self.networks.get(downlink, [])
                     if peer_intfs:
-                        for public_intf in peer_intfs:
-                            port_pair = private_intf, public_intf
+                        for downlink_intf in peer_intfs:
+                            port_pair = uplink_intf, downlink_intf
                             self._port_pair_list.append(port_pair)
         return self._port_pair_list
 
@@ -225,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
@@ -267,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():
@@ -288,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
@@ -341,35 +344,33 @@ class MultiPortConfig(object):
         priv_to_pub_map = [tuple(self.vnfd_helper.port_nums(x)) for x in self.port_pairs]
         # must be list to use .index()
         port_list = list(chain.from_iterable(priv_to_pub_map))
-        priv_ports = (x[0] for x in priv_to_pub_map)
+        uplink_ports = (x[0] for x in priv_to_pub_map)
         self.prv_que_handler = '({})'.format(
-            "".join(("{},".format(port_list.index(x)) for x in priv_ports)))
+            "".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)
@@ -384,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?
@@ -392,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
@@ -415,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
@@ -430,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])
@@ -451,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)
@@ -518,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
@@ -535,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
@@ -559,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):
@@ -710,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': '',
         }