<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ping( self, destination, source=C.PING_SOURCE, ttl=C.PING_TTL, timeout=C.PING_TIMEOUT, size=C.PING_SIZE, count=C.PING_COUNT, vrf=C.PING_VRF, ):
 """ Execute ping on the device and returns a dictionary with the result. Output dictionary has one of following keys: * success * error In case of success, inner dictionary will have the followin keys: * probes_sent (int) * packet_loss (int) * rtt_min (float) * rtt_max (float) * rtt_avg (float) * rtt_stddev (float) * results (list) 'results' is a list of dictionaries with the following keys: * ip_address (str) * rtt (float) """

        ping_dict = {}
        # vrf needs to be right after the ping command
        if vrf:
            command = "ping vrf {} {}".format(vrf, destination)
        else:
            command = "ping {}".format(destination)
        command += " timeout {}".format(timeout)
        command += " size {}".format(size)
        command += " repeat {}".format(count)
        if source != "":
            command += " source {}".format(source)

        output = self._send_command(command)
        if "%" in output:
            ping_dict["error"] = output
        elif "Sending" in output:
            ping_dict["success"] = {
                "probes_sent": 0,
                "packet_loss": 0,
                "rtt_min": 0.0,
                "rtt_max": 0.0,
                "rtt_avg": 0.0,
                "rtt_stddev": 0.0,
                "results": [],
            }

            for line in output.splitlines():
                if "Success rate is" in line:
                    sent_and_received = re.search(r"\((\d*)/(\d*)\)", line)
                    probes_sent = int(sent_and_received.group(2))
                    probes_received = int(sent_and_received.group(1))
                    ping_dict["success"]["probes_sent"] = probes_sent
                    ping_dict["success"]["packet_loss"] = probes_sent - probes_received
                    # If there were zero valid response packets, we are done
                    if "Success rate is 0 " in line:
                        break

                    min_avg_max = re.search(r"(\d*)/(\d*)/(\d*)", line)
                    ping_dict["success"].update(
                        {
                            "rtt_min": float(min_avg_max.group(1)),
                            "rtt_avg": float(min_avg_max.group(2)),
                            "rtt_max": float(min_avg_max.group(3)),
                        }
                    )
                    results_array = []
                    for i in range(probes_received):
                        results_array.append(
                            {
                                "ip_address": py23_compat.text_type(destination),
                                "rtt": 0.0,
                            }
                        )
                    ping_dict["success"].update({"results": results_array})

        return ping_dict