def _check_ipv6_address(self): """ Set and check scope link IPV6 address is well allocated :rtype: int :return: Global.FAILURE (-1) if Failed :rtype: str :return: Error Message in case of failure """ # Check scope link IPV6 address is well allocated ip_v6_local = self._networking_api.get_interface_ipv6_scopelink_address( self._device.get_cellular_network_interface()) # check if IPV6 allocated to the device is a valid IP address if NetworkingUtil.is_valid_ipv6_address(ip_v6_local): # check if IPV6 allocated to the device is a valid IP address self._logger.info( "The local IPv6 address assigned to the DUT is %s " % ip_v6_local) Code = Global.SUCCESS Msg = "The local IPv6 address assigned to the DUT is %s " % ip_v6_local else: Code = Global.FAILURE Msg = "DUT does not have a local IPv6 assigned" self._logger.info(Msg) return Code, Msg
def _pingv4only(self): # Ping IPV6 packet_lossv6 = self._networking_api.\ ping6(self._server_ip_v6_address, self._packet_size, self._nb_pings, blocking=False) # Check if IP V6 Fails if packet_lossv6.value == -1: # Check if DUT have an address IP V6 allocated self.ip_v6 = self._ns_data_4g.get_ip_address("IPV6", blocking=False) if NetworkingUtil.is_valid_ipv6_address(str(self.ip_v6)): self._error.Code = Global.FAILURE self._error.Msg = "DUT have a valid IPV6 address when NW is set to IPV4 only" self._logger.info(self._error.Msg) return self._error.Code, self._error.Msg else: msg = "PING IPV6: FAILED (as expected) because DUT does not have an IPV6 address allocated" self._logger.info(msg) self._error.Msg = msg else: self._error.Code = Global.FAILURE self._error.Msg = "ERROR :PING with IPV6 SHOULD FAIL, Measured IPV6 Packet Loss: %.0f%s (Target: %.0f%s)"\ % (packet_lossv6.value, packet_lossv6.units, self._target_ping_packet_loss_rate, packet_lossv6.units) self._logger.error(self._error.Msg) # Ping IPV4 packet_lossv4 = self._networking_api.\ ping(self._server_ip_address, self._packet_size, self._nb_pings) # Compute verdict depending on % of packet loss if packet_lossv4.value > self._target_ping_packet_loss_rate: self._error.Code = Global.FAILURE else: self._error.Code = Global.SUCCESS msg = "Ping IPV4: SUCCEEDED with Measured Packet Loss: %.0f%s (Target: %.0f%s)"\ % (packet_lossv4.value, packet_lossv4.units, self._target_ping_packet_loss_rate, packet_lossv4.units) self._logger.info(msg) self._error.Msg += " & " + msg return self._error.Code, self._error.Msg
def ping(self, ip_address, packet_size, packet_count, interval=1, flood_mode=False, unreach_loss=False): """ Pings a destination address :type ip_address: str :param ip_address: IP address to ping :type packet_size: integer :param packet_size: Packet size in bytes :type packet_count: integer :param packet_count: Number of packets to send :type interval: float :param interval: Interval in seconds between pings :type flood_mode: Boolean :param flood_mode: True if you want to use the ping in flood mode, False else. :type unreach_loss: Boolean :param unreach_loss: True if you want to count Destination host unreachable reply as ping loss, False else. :rtype: Measure object :return: packet loss """ if int(packet_count) > 0: if int(interval) > 0: ping_timeout = int(packet_count * interval) + 20 else: ping_timeout = int(packet_count) + 20 else: self._logger.error("'packet count' must be an Integer > 0") raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, "'packet count' must be an Integer > 0") if not flood_mode: flood_option = "" flood_txt = "" else: flood_option = " -f" flood_txt = "(flood mode) " self._logger.info("Ping address " + flood_txt + str(ip_address) + " with " + str(packet_count) + " packets of " + str(packet_size) + " bytes...") # Compute whether ip_address is V4 or V6 format. if NetworkingUtil.is_valid_ipv4_address(str(ip_address)): linux_cmd = "ping" win_cmd = "ping -4" elif NetworkingUtil.is_valid_ipv6_address(str(ip_address)): linux_cmd = "ping6" win_cmd = "ping -6" else: raise TestEquipmentException( TestEquipmentException.INVALID_PARAMETER, "%s is not a valid IP address" % str(ip_address)) if self._os == self.WINDOWS: if packet_count > 1 and interval != 1: # no interval option on Windows ping, loop temp_ret = 0 for _count in range(packet_count): start_time = time.time() ret = self.ping(ip_address, packet_size, 1, 1, flood_mode) temp_ret += ret.value end_time = time.time() if end_time - start_time < interval: time.sleep(interval - (end_time - start_time)) ret.value = temp_ret / packet_count return ret cmd = str(win_cmd) + " -l " + str(packet_size) + \ " -n " + str(packet_count) + " " + str(ip_address) else: cmd = str(linux_cmd) + " -s " + str(packet_size) + flood_option + \ " -c " + str(packet_count) + " -i " + str(interval) + \ " " + str(ip_address) output = self.run_cmd(cmd, ping_timeout) output = output["std"] output_lower = output.lower() packet_loss = Measure() # Search the loss rate if unreach_loss: # Get number of sent packet in output (here nb sent packet = 4): # Packets: Sent = 4, Received = 4, Lost = 0 (0% loss) search1 = re.search("packets: sent = ([0-9]+)", output_lower) # Get number of valid ping replies, a valid replies looks like: # Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 search2 = re.findall("ttl=([0-9]+)", output_lower) if search1 is not None: nb_sent_ping = int(search1.group(1)) nb_good_ping = len(search2) packet_loss.units = "%" packet_loss.value = ( 100 * (nb_sent_ping - nb_good_ping)) / nb_sent_ping else: error = "Ping command returned an error message (Output = %s)" \ % output self._logger.error(error) raise TestEquipmentException( TestEquipmentException.DEFAULT_ERROR_CODE, error) else: search = re.search("([0-9]+\.?[0-9]*)%[a-zA-Z ]*loss", output_lower) if search is not None: packet_loss.value = float(search.group(1)) packet_loss.units = "%" else: error = "Ping command returned an error message (Output = %s)" \ % output self._logger.error(error) raise TestEquipmentException( TestEquipmentException.DEFAULT_ERROR_CODE, error) return packet_loss
def ping(self, ip_address, packet_size, packet_count, interval=1, flood_mode=False): """ Pings a destination address :type ip_address: str :param ip_address: IP address to ping :type packet_size: integer :param packet_size: Packet size in bytes :type packet_count: integer :param packet_count: Number of packets to send :type interval: float :param interval: Interval in seconds between pings :type flood_mode: Boolean :param flood_mode: True if you want to use the ping in flood mode :rtype: Measure object :return: Packet loss in % """ # Compute whether ip_address is V4 or V6 format. if NetworkingUtil.is_valid_ipv4_address(str(ip_address)): linux_cmd = "ping" elif NetworkingUtil.is_valid_ipv6_address(str(ip_address)): linux_cmd = "ping6" else: raise TestEquipmentException(TestEquipmentException.INVALID_PARAMETER, "%s is not a valid IP address" % str(ip_address)) if not flood_mode: flood_option = "" flood_txt = "" else: flood_option = " -f" flood_txt = "(flood mode) " cmd = "%s -s " % linux_cmd + str(packet_size) + flood_option + \ " -c " + str(packet_count) + " -i " + str(interval) + \ " " + str(ip_address) self._logger.info("Ping address " + flood_txt + str(ip_address) + " with " + str(packet_count) + " packets of " + str(packet_size) + " bytes...") output = self.ssh_exec(self._host, self._login, cmd) output_lower = output.lower() packet_loss = Measure() # Search the loss rate search = re.search("([0-9]+\.?[0-9]*)%[a-zA-Z ]*loss", output_lower) if search is not None: packet_loss.value = float(search.group(1)) packet_loss.units = "%" else: error = "Ping command returned an error message (Output = %s)" \ % output self._logger.error(error) raise TestEquipmentException(TestEquipmentException.DEFAULT_ERROR_CODE, error) return packet_loss