MIN_TOTAL_HUGE_PAGES = 1024
MAX_PERCENT_FOR_HUGE_PAGES = 70
+IPERFVM_XML = 'configs/iperf-vm.xml'
+IPERFVM_IMAGE = 'images/xenial-mod.img'
+IPERFVM_ISO = 'configs/cloud-config.iso'
+
class AutoConfig(object):
"""Auto Configuration Tools"""
self._hugepage_config = ""
self._clean = clean
self._loadconfig()
+ self._sockfilename = ""
def get_nodes(self):
"""
answer = raw_input("Please enter the netmask [n.n.n.n]: ")
plen = IPAddress(answer).netmask_bits()
return '{}/{}'.format(ipaddr, plen)
- except:
+ except None:
print "Please enter a valid IPv4 address."
- continue
@staticmethod
def _ask_user_range(question, first, last, default):
devices += ' num-tx-desc {}\n'.format(num_tx_desc)
devices += ' }'
- if total_mbufs is not 0:
+ # If the total mbufs is not 0 or less than the default, set num-bufs
+ logging.debug("Total mbufs: {}".format(total_mbufs))
+ if total_mbufs is not 0 and total_mbufs > 16384:
devices += '\n num-mbufs {}'.format(total_mbufs)
return devices
@staticmethod
- def _calc_vpp_workers(node, vpp_workers, numa_node,
- other_cpus_end, total_vpp_workers,
+ def _calc_vpp_workers(node, vpp_workers, numa_node, other_cpus_end, total_vpp_workers,
reserve_vpp_main_core):
"""
Calculate the VPP worker information
start += 1
workers_end = start + total_vpp_workers - 1
+
if workers_end <= end:
if reserve_vpp_main_core:
node['cpu']['vpp_main_core'] = start - 1
@staticmethod
def _calc_desc_and_queues(total_numa_nodes,
total_ports_per_numa,
- total_vpp_cpus,
+ total_rx_queues,
ports_per_numa_value):
"""
Calculate the number of descriptors and queues
:param total_numa_nodes: The total number of numa nodes
:param total_ports_per_numa: The total number of ports for this
numa node
- :param total_vpp_cpus: The total number of cpus to allocate for vpp
+ :param total_rx_queues: The total number of rx queues / port
:param ports_per_numa_value: The value from the ports_per_numa
dictionary
:type total_numa_nodes: int
:type total_ports_per_numa: int
- :type total_vpp_cpus: int
+ :type total_rx_queues: int
:type ports_per_numa_value: dict
:returns The total number of message buffers
- :returns: The total number of vpp workers
- :rtype: int
:rtype: int
"""
- # Get the total vpp workers
- total_vpp_workers = total_vpp_cpus
- ports_per_numa_value['total_vpp_workers'] = total_vpp_workers
-
# Get the number of rx queues
- rx_queues = max(1, total_vpp_workers)
- tx_queues = total_vpp_workers * total_numa_nodes + 1
+ rx_queues = max(1, total_rx_queues)
+ tx_queues = rx_queues * total_numa_nodes + 1
# Get the descriptor entries
desc_entries = 1024
total_ports_per_numa)
total_mbufs = total_mbufs
- return total_mbufs, total_vpp_workers
+ return total_mbufs
@staticmethod
def _create_ports_per_numa(node, interfaces):
# Get the number of cpus to skip, we never use the first cpu
other_cpus_start = 1
- other_cpus_end = other_cpus_start + \
- node['cpu']['total_other_cpus'] - 1
+ other_cpus_end = other_cpus_start + node['cpu']['total_other_cpus'] - 1
other_workers = None
if other_cpus_end is not 0:
other_workers = (other_cpus_start, other_cpus_end)
vpp_workers = []
reserve_vpp_main_core = node['cpu']['reserve_vpp_main_core']
total_vpp_cpus = node['cpu']['total_vpp_cpus']
+ total_rx_queues = node['cpu']['total_rx_queues']
# If total_vpp_cpus is 0 or is less than the numa nodes with ports
# then we shouldn't get workers
- total_with_main = total_vpp_cpus
+ total_workers_node = 0
+ if len(ports_per_numa):
+ total_workers_node = total_vpp_cpus / len(ports_per_numa)
+ total_main = 0
if reserve_vpp_main_core:
- total_with_main += 1
+ total_main = 1
total_mbufs = 0
- if total_with_main is not 0:
+ if total_main + total_workers_node is not 0:
for item in ports_per_numa.items():
numa_node = item[0]
value = item[1]
# Get the number of descriptors and queues
- mbufs, total_vpp_workers = self._calc_desc_and_queues(
- len(ports_per_numa),
- len(value['interfaces']), total_vpp_cpus, value)
+ mbufs = self._calc_desc_and_queues(len(ports_per_numa),
+ len(value['interfaces']), total_rx_queues, value)
total_mbufs += mbufs
# Get the VPP workers
- reserve_vpp_main_core = self._calc_vpp_workers(
- node, vpp_workers, numa_node, other_cpus_end,
- total_vpp_workers, reserve_vpp_main_core)
+ reserve_vpp_main_core = self._calc_vpp_workers(node, vpp_workers, numa_node,
+ other_cpus_end, total_workers_node,
+ reserve_vpp_main_core)
total_mbufs *= 2.5
total_mbufs = int(total_mbufs)
tcp = tcp + " v4-halfopen-table-buckets " + \
"{:d}".format((aos + pos) / 4) + "\n"
tcp = tcp + " v4-halfopen-table-memory 3g\n"
+ tcp = tcp + " local-endpoints-table-buckets " + "{:d}".format((aos + pos) / 4) + "\n"
+ tcp = tcp + " local-endpoints-table-memory 3g\n"
tcp = tcp + "}\n\n"
tcp = tcp + "tcp {\n"
tcp = tcp + " preallocated-connections " + "{:d}".format(aos + pos) + "\n"
if aos > 0:
tcp = tcp + " preallocated-half-open-connections " + "{:d}".format(aos) + "\n"
- tcp = tcp + " local-endpoints-table-buckets " + "{:d}".format((aos + pos) / 4) + "\n"
- tcp = tcp + " local-endpoints-table-memory 3g\n"
tcp = tcp + "}\n\n"
return tcp.rstrip('\n')
print "\nYour system has {} core(s) and {} Numa Nodes.". \
format(total_cpus, len(numa_nodes))
- print "To begin, we suggest not reserving any cores for VPP",
- print "or other processes."
- print "Then to improve performance try reserving cores as needed. "
-
- max_other_cores = total_cpus / 2
- question = '\nHow many core(s) do you want to reserve for processes \
-other than VPP? [0-{}][0]? '.format(str(max_other_cores))
- total_other_cpus = self._ask_user_range(question, 0, max_other_cores,
- 0)
- node['cpu']['total_other_cpus'] = total_other_cpus
+ print "To begin, we suggest not reserving any cores for VPP or other processes."
+ print "Then to improve performance start reserving cores and adding queues as needed. "
max_vpp_cpus = 4
total_vpp_cpus = 0
if max_vpp_cpus > 0:
- question = "How many core(s) shall we reserve for VPP workers[0-{}][0]? ". \
- format(max_vpp_cpus)
+ question = "\nHow many core(s) shall we reserve for VPP [0-{}][0]? ".format(max_vpp_cpus)
total_vpp_cpus = self._ask_user_range(question, 0, max_vpp_cpus, 0)
node['cpu']['total_vpp_cpus'] = total_vpp_cpus
- max_main_cpus = max_vpp_cpus - total_vpp_cpus
+ max_other_cores = (total_cpus - total_vpp_cpus) / 2
+ question = 'How many core(s) do you want to reserve for processes other than VPP? [0-{}][0]? '. \
+ format(str(max_other_cores))
+ total_other_cpus = self._ask_user_range(question, 0, max_other_cores, 0)
+ node['cpu']['total_other_cpus'] = total_other_cpus
+
+ max_main_cpus = max_vpp_cpus + 1 - total_vpp_cpus
reserve_vpp_main_core = False
if max_main_cpus > 0:
question = "Should we reserve 1 core for the VPP Main thread? "
node['cpu']['reserve_vpp_main_core'] = reserve_vpp_main_core
node['cpu']['vpp_main_core'] = 0
+ question = "How many RX queues per port shall we use for VPP [1-4][1]? ". \
+ format(max_vpp_cpus)
+ total_rx_queues = self._ask_user_range(question, 1, 4, 1)
+ node['cpu']['total_rx_queues'] = total_rx_queues
+
def modify_cpu(self, ask_questions=True):
"""
Modify the cpu configuration, asking for the user for the values.
node['cpu']['cpus_per_node'] = cpus_per_node
# Ask the user some questions
- if ask_questions:
+ if ask_questions and total_cpus >= 8:
self._modify_cpu_questions(node, total_cpus, numa_nodes)
# Populate the interfaces with the numa node
question += " the OS [y/N]? "
answer = self._ask_user_yn(question, 'n')
if answer == 'y':
- driver = device['unused'][0]
- VppPCIUtil.bind_vpp_device(node, driver, dvid)
- vppd[dvid] = device
+ if 'unused' in device and len(device['unused']) != 0 and device['unused'][0] != '':
+ driver = device['unused'][0]
+ ret = VppPCIUtil.bind_vpp_device(node, driver, dvid)
+ if ret:
+ logging.debug('Could not bind device {}'.format(dvid))
+ else:
+ vppd[dvid] = device
for dit in vppd.items():
dvid = dit[0]
device = dit[1]
for dit in vppd.items():
dvid = dit[0]
device = dit[1]
- dpdk_devices[dvid] = device
- del other_devices[dvid]
+ if 'unused' in device and len(device['unused']) != 0 and device['unused'][0] != '':
+ driver = device['unused'][0]
+ logging.debug('Binding device {} to driver {}'.format(dvid, driver))
+ ret = VppPCIUtil.bind_vpp_device(node, driver, dvid)
+ if ret:
+ logging.debug('Could not bind device {}'.format(dvid))
+ else:
+ dpdk_devices[dvid] = device
+ del other_devices[dvid]
def update_interfaces_config(self):
"""
for dit in vppd.items():
dvid = dit[0]
device = dit[1]
- dpdk_devices[dvid] = device
- del kernel_devices[dvid]
+ if 'unused' in device and len(device['unused']) != 0 and device['unused'][0] != '':
+ driver = device['unused'][0]
+ logging.debug('Binding device {} to driver {}'.format(dvid, driver))
+ ret = VppPCIUtil.bind_vpp_device(node, driver, dvid)
+ if ret:
+ logging.debug('Could not bind device {}'.format(dvid))
+ else:
+ dpdk_devices[dvid] = device
+ del kernel_devices[dvid]
dlen = len(dpdk_devices)
if dlen > 0:
for dit in vppd.items():
dvid = dit[0]
device = dit[1]
- driver = device['unused'][0]
- VppPCIUtil.bind_vpp_device(node, driver, dvid)
- kernel_devices[dvid] = device
- del dpdk_devices[dvid]
+ if 'unused' in device and len(device['unused']) != 0 and device['unused'][0] != '':
+ driver = device['unused'][0]
+ logging.debug('Binding device {} to driver {}'.format(dvid, driver))
+ ret = VppPCIUtil.bind_vpp_device(node, driver, dvid)
+ if ret:
+ logging.debug('Could not bind device {}'.format(dvid))
+ else:
+ kernel_devices[dvid] = device
+ del dpdk_devices[dvid]
interfaces = {}
for dit in dpdk_devices.items():
print "\nThere currently a total of {} huge pages.". \
format(total)
- question = \
- "How many huge pages do you want [{} - {}][{}]? ". \
+ question = "How many huge pages do you want [{} - {}][{}]? ". \
format(MIN_TOTAL_HUGE_PAGES, maxpages, MIN_TOTAL_HUGE_PAGES)
answer = self._ask_user_range(question, 1024, maxpages, 1024)
node['hugepages']['total'] = str(answer)
else:
print ("\nNo devices bound to DPDK drivers")
+ other_devs = vpp.get_other_devices()
+ if len(other_devs):
+ print ("\nDevices not bound to Kernel or DPDK drivers:")
+ vpp.show_vpp_devices(other_devs, show_interfaces=True,
+ show_header=False)
+ else:
+ print ("\nNo devices not bound to Kernel or DPDK drivers")
+
vpputl = VPPUtil()
interfaces = vpputl.get_hardware(node)
if interfaces == {}:
print ("None")
return
- print "{:30} {:6} {:4} {:7} {:4} {:7}". \
- format('Name', 'Socket', 'RXQs',
+ print "{:30} {:4} {:4} {:7} {:4} {:7}". \
+ format('Name', 'Numa', 'RXQs',
'RXDescs', 'TXQs', 'TXDescs')
for intf in sorted(interfaces.items()):
name = intf[0]
value = intf[1]
if name == 'local0':
continue
- socket = rx_qs = rx_ds = tx_qs = tx_ds = ''
- if 'cpu socket' in value:
- socket = int(value['cpu socket'])
+ numa = rx_qs = rx_ds = tx_qs = tx_ds = ''
+ if 'numa' in value:
+ numa = int(value['numa'])
if 'rx queues' in value:
rx_qs = int(value['rx queues'])
if 'rx descs' in value:
if 'tx descs' in value:
tx_ds = int(value['tx descs'])
- print ("{:30} {:>6} {:>4} {:>7} {:>4} {:>7}".
- format(name, socket, rx_qs, rx_ds, tx_qs, tx_ds))
+ print ("{:30} {:>4} {:>4} {:>7} {:>4} {:>7}".
+ format(name, numa, rx_qs, rx_ds, tx_qs, tx_ds))
@staticmethod
def hugepage_info(node):
question = "Would you like connect this interface {} to the VM [Y/n]? ".format(name)
answer = self._ask_user_yn(question, 'y')
if answer == 'y':
- sockfilename = '/tmp/sock{}.sock'.format(inum)
+ sockfilename = '/var/run/vpp/{}.sock'.format(name.replace('/', '_'))
if os.path.exists(sockfilename):
os.remove(sockfilename)
cmd = 'vppctl create vhost-user socket {} server'.format(sockfilename)
(ret, stdout, stderr) = vpputl.exec_command(cmd)
if ret != 0:
- raise RuntimeError("Create vhost failed on node {} {}."
- .format(node['host'], stderr))
+ raise RuntimeError("Couldn't execute the command {}, {}.".format(cmd, stderr))
vintname = stdout.rstrip('\r\n')
+ cmd = 'chmod 777 {}'.format(sockfilename)
+ (ret, stdout, stderr) = vpputl.exec_command(cmd)
+ if ret != 0:
+ raise RuntimeError("Couldn't execute the command {}, {}.".format(cmd, stderr))
+
interface = {'name': name, 'virtualinterface': '{}'.format(vintname),
'bridge': '{}'.format(inum)}
inum += 1
for intf in ints_with_vints:
vhoststr = 'comment { The following command creates the socket }\n'
vhoststr += 'comment { and returns a virtual interface }\n'
- vhoststr += 'comment {{ create vhost-user socket /tmp/sock{}.sock server }}\n'. \
+ vhoststr += 'comment {{ create vhost-user socket /var/run/vpp/sock{}.sock server }}\n'. \
format(intf['bridge'])
setintdnstr = 'set interface state {} down\n'.format(intf['name'])
print("\nA script as been created at {}".format(filename))
print("This script can be run using the following:")
print("vppctl exec {}\n".format(filename))
+
+ def _iperf_vm_questions(self, node):
+ """
+ Ask the user some questions and get a list of interfaces
+ and IPv4 addresses associated with those interfaces
+
+ :param node: Node dictionary.
+ :type node: dict
+ :returns: A list or interfaces with ip addresses
+ :rtype: list
+ """
+
+ vpputl = VPPUtil()
+ interfaces = vpputl.get_hardware(node)
+ if interfaces == {}:
+ return []
+
+ # First delete all the Virtual interfaces
+ for intf in sorted(interfaces.items()):
+ name = intf[0]
+ if name[:7] == 'Virtual':
+ cmd = 'vppctl delete vhost-user {}'.format(name)
+ (ret, stdout, stderr) = vpputl.exec_command(cmd)
+ if ret != 0:
+ logging.debug('{} failed on node {} {}'.format(
+ cmd, node['host'], stderr))
+
+ # Create a virtual interface, for each interface the user wants to use
+ interfaces = vpputl.get_hardware(node)
+ if interfaces == {}:
+ return []
+ interfaces_with_virtual_interfaces = []
+ inum = 1
+
+ while True:
+ print '\nPlease pick one interface to connect to the iperf VM.'
+ for intf in sorted(interfaces.items()):
+ name = intf[0]
+ if name == 'local0':
+ continue
+
+ question = "Would you like connect this interface {} to the VM [y/N]? ".format(name)
+ answer = self._ask_user_yn(question, 'n')
+ if answer == 'y':
+ self._sockfilename = '/var/run/vpp/{}.sock'.format(name.replace('/', '_'))
+ if os.path.exists(self._sockfilename):
+ os.remove(self._sockfilename)
+ cmd = 'vppctl create vhost-user socket {} server'.format(self._sockfilename)
+ (ret, stdout, stderr) = vpputl.exec_command(cmd)
+ if ret != 0:
+ raise RuntimeError("Couldn't execute the command {}, {}.".format(cmd, stderr))
+ vintname = stdout.rstrip('\r\n')
+
+ cmd = 'chmod 777 {}'.format(self._sockfilename)
+ (ret, stdout, stderr) = vpputl.exec_command(cmd)
+ if ret != 0:
+ raise RuntimeError("Couldn't execute the command {}, {}.".format(cmd, stderr))
+
+ interface = {'name': name, 'virtualinterface': '{}'.format(vintname),
+ 'bridge': '{}'.format(inum)}
+ inum += 1
+ interfaces_with_virtual_interfaces.append(interface)
+ return interfaces_with_virtual_interfaces
+
+ def create_and_bridge_iperf_virtual_interface(self):
+ """
+ After asking the user some questions, and create and bridge a virtual interface
+ to be used with iperf VM
+
+ """
+
+ for i in self._nodes.items():
+ node = i[1]
+
+ # Show the current bridge and interface configuration
+ print "\nThis the current bridge configuration:"
+ ifaces = VPPUtil.show_bridge(node)
+ question = "\nWould you like to keep this configuration [Y/n]? "
+ answer = self._ask_user_yn(question, 'y')
+ if answer == 'y':
+ self._sockfilename = '/var/run/vpp/{}.sock'.format(ifaces[0]['name'].replace('/', '_'))
+ if os.path.exists(self._sockfilename):
+ continue
+
+ # Create a script that builds a bridge configuration with physical interfaces
+ # and virtual interfaces
+ ints_with_vints = self._iperf_vm_questions(node)
+ content = ''
+ for intf in ints_with_vints:
+ vhoststr = 'comment { The following command creates the socket }\n'
+ vhoststr += 'comment { and returns a virtual interface }\n'
+ vhoststr += 'comment {{ create vhost-user socket /var/run/vpp/sock{}.sock server }}\n'. \
+ format(intf['bridge'])
+
+ setintdnstr = 'set interface state {} down\n'.format(intf['name'])
+
+ setintbrstr = 'set interface l2 bridge {} {}\n'.format(intf['name'], intf['bridge'])
+ setvintbrstr = 'set interface l2 bridge {} {}\n'.format(intf['virtualinterface'], intf['bridge'])
+
+ # set interface state VirtualEthernet/0/0/0 up
+ setintvststr = 'set interface state {} up\n'.format(intf['virtualinterface'])
+
+ # set interface state VirtualEthernet/0/0/0 down
+ setintupstr = 'set interface state {} up\n'.format(intf['name'])
+
+ content += vhoststr + setintdnstr + setintbrstr + setvintbrstr + setintvststr + setintupstr
+
+ # Write the content to the script
+ rootdir = node['rootdir']
+ filename = rootdir + '/vpp/vpp-config/scripts/create_iperf_vm'
+ with open(filename, 'w+') as sfile:
+ sfile.write(content)
+
+ # Execute the script
+ cmd = 'vppctl exec {}'.format(filename)
+ (ret, stdout, stderr) = VPPUtil.exec_command(cmd)
+ if ret != 0:
+ logging.debug(stderr)
+
+ print("\nA script as been created at {}".format(filename))
+ print("This script can be run using the following:")
+ print("vppctl exec {}\n".format(filename))
+
+ @staticmethod
+ def destroy_iperf_vm(name):
+ """
+ After asking the user some questions, create a VM and connect the interfaces
+ to VPP interfaces
+
+ :param name: The name of the VM to be be destroyed
+ :type name: str
+ """
+
+ cmd = 'virsh list'
+ (ret, stdout, stderr) = VPPUtil.exec_command(cmd)
+ if ret != 0:
+ logging.debug(stderr)
+ raise RuntimeError("Couldn't execute the command {} : {}".format(cmd, stderr))
+
+ if re.findall(name, stdout):
+ cmd = 'virsh destroy {}'.format(name)
+ (ret, stdout, stderr) = VPPUtil.exec_command(cmd)
+ if ret != 0:
+ logging.debug(stderr)
+ raise RuntimeError("Couldn't execute the command {} : {}".format(cmd, stderr))
+
+ def create_iperf_vm(self, vmname):
+ """
+ After asking the user some questions, create a VM and connect the interfaces
+ to VPP interfaces
+
+ """
+
+ # Read the iperf VM template file
+ distro = VPPUtil.get_linux_distro()
+ if distro[0] == 'Ubuntu':
+ tfilename = '{}/vpp/vpp-config/configs/iperf-ubuntu.xml.template'.format(self._rootdir)
+ else:
+ tfilename = '{}/vpp/vpp-config/configs/iperf-centos.xml.template'.format(self._rootdir)
+
+ with open(tfilename, 'r') as tfile:
+ tcontents = tfile.read()
+ tfile.close()
+
+ # Add the variables
+ imagename = '{}/vpp/vpp-config/{}'.format(self._rootdir, IPERFVM_IMAGE)
+ isoname = '{}/vpp/vpp-config/{}'.format(self._rootdir, IPERFVM_ISO)
+ tcontents = tcontents.format(vmname=vmname, imagename=imagename, isoname=isoname,
+ vhostsocketname=self._sockfilename)
+
+ # Write the xml
+ ifilename = '{}/vpp/vpp-config/{}'.format(self._rootdir, IPERFVM_XML)
+ with open(ifilename, 'w+') as ifile:
+ ifile.write(tcontents)
+ ifile.close()
+
+ cmd = 'virsh create {}'.format(ifilename)
+ (ret, stdout, stderr) = VPPUtil.exec_command(cmd)
+ if ret != 0:
+ logging.debug(stderr)
+ raise RuntimeError("Couldn't execute the command {} : {}".format(cmd, stderr))