def set_device_rate(self, pci_slot, rate_type, rate_kbps): """Set device rate: rate (max_tx_rate), min_tx_rate @param pci_slot: Virtual Function address @param rate_type: device rate name type. Could be 'rate' and 'min_tx_rate'. @param rate_kbps: device rate in kbps """ vf_index = self._get_vf_index(pci_slot) #NOTE(ralonsoh): ip link sets rate in Mbps therefore we need to convert #the rate_kbps value from kbps to Mbps. #Zero means to disable the rate so the lowest rate available is 1Mbps. #Floating numbers are not allowed if rate_kbps > 0 and rate_kbps < 1000: rate_mbps = 1 else: rate_mbps = utils.round_val(rate_kbps / 1000.0) log_dict = { 'rate_mbps': rate_mbps, 'rate_kbps': rate_kbps, 'vf_index': vf_index, 'rate_type': rate_type } if rate_kbps % 1000 != 0: LOG.debug( "'%(rate_type)s' for SR-IOV ports is counted in Mbps; " "setting %(rate_mbps)s Mbps limit for port %(vf_index)s " "instead of %(rate_kbps)s kbps", log_dict) else: LOG.debug("Setting %(rate_mbps)s Mbps limit for port %(vf_index)s", log_dict) return self.pci_dev_wrapper.set_vf_rate(vf_index, rate_type, rate_mbps)
def test_round_val_ok(self): for expected, value in ((0, 0), (0, 0.1), (1, 0.5), (1, 1.49), (2, 1.5)): self.assertEqual(expected, utils.round_val(value))
def set_device_max_rate(self, pci_slot, max_kbps): """Set device max rate. @param pci_slot: Virtual Function address @param max_kbps: device max rate in kbps """ vf_index = self._get_vf_index(pci_slot) #(Note): ip link set max rate in Mbps therefore #we need to convert the max_kbps to Mbps. #Zero means to disable the rate so the lowest rate #available is 1Mbps. Floating numbers are not allowed if max_kbps > 0 and max_kbps < 1000: max_mbps = 1 else: max_mbps = utils.round_val(max_kbps / 1000.0) log_dict = { 'max_rate': max_mbps, 'max_kbps': max_kbps, 'vf_index': vf_index } if max_kbps % 1000 != 0: LOG.debug( "Maximum rate for SR-IOV ports is counted in Mbps; " "setting %(max_rate)s Mbps limit for port %(vf_index)s " "instead of %(max_kbps)s kbps", log_dict) else: LOG.debug("Setting %(max_rate)s Mbps limit for port %(vf_index)s", log_dict) return self.pci_dev_wrapper.set_vf_max_rate(vf_index, max_mbps)
def set_device_max_rate(self, pci_slot, max_kbps): """Set device max rate. @param pci_slot: Virtual Function address @param max_kbps: device max rate in kbps """ vf_index = self._get_vf_index(pci_slot) # (Note): ip link set max rate in Mbps therefore # we need to convert the max_kbps to Mbps. # Zero means to disable the rate so the lowest rate # available is 1Mbps. Floating numbers are not allowed if max_kbps > 0 and max_kbps < 1000: max_mbps = 1 else: max_mbps = utils.round_val(max_kbps / 1000.0) log_dict = {"max_rate": max_mbps, "max_kbps": max_kbps, "vf_index": vf_index} if max_kbps % 1000 != 0: LOG.debug( "Maximum rate for SR-IOV ports is counted in Mbps; " "setting %(max_rate)s Mbps limit for port %(vf_index)s " "instead of %(max_kbps)s kbps", log_dict, ) else: LOG.debug("Setting %(max_rate)s Mbps limit for port %(vf_index)s", log_dict) return self.pci_dev_wrapper.set_vf_max_rate(vf_index, max_mbps)
def set_device_rate(self, pci_slot, rate_type, rate_kbps): """Set device rate: rate (max_tx_rate), min_tx_rate @param pci_slot: Virtual Function address @param rate_type: device rate name type. Could be 'rate' and 'min_tx_rate'. @param rate_kbps: device rate in kbps """ vf_index = self._get_vf_index(pci_slot) #NOTE(ralonsoh): ip link sets rate in Mbps therefore we need to convert #the rate_kbps value from kbps to Mbps. #Zero means to disable the rate so the lowest rate available is 1Mbps. #Floating numbers are not allowed if rate_kbps > 0 and rate_kbps < 1000: rate_mbps = 1 else: rate_mbps = utils.round_val(rate_kbps / 1000.0) log_dict = { 'rate_mbps': rate_mbps, 'rate_kbps': rate_kbps, 'vf_index': vf_index, 'rate_type': rate_type } if rate_kbps % 1000 != 0: LOG.debug("'%(rate_type)s' for SR-IOV ports is counted in Mbps; " "setting %(rate_mbps)s Mbps limit for port %(vf_index)s " "instead of %(rate_kbps)s kbps", log_dict) else: LOG.debug("Setting %(rate_mbps)s Mbps limit for port %(vf_index)s", log_dict) return self.pci_dev_wrapper.set_vf_rate(vf_index, rate_type, rate_mbps)