import re


def parse_show_vrrp_statistics(raw_result):
    """
    Parse the 'show vrrp statistics' command raw output.

    :param str raw_result: vtysh raw result string.
    :rtype: dict
    :return: The parsed result of the show vrrp statistics command in a \
        dictionary of the form:

     ::

       {
            'invalid_grp_oth_reason': '0',
            'mast_to_backup': '0',
            'backup_to_init': '0',
            'group': '1',
            'address_family': 'IPv4',
            'grp_discard_pkts': '3856',
            'vrrp_v2_adv': 'sent 0 (errors 0) - rcvd 0',
            'ip_addr_own_conflicts': '0',
            'init_to_backup': '2 (Last change Mon Jun 16 11:19:36.316 UTC)',
            'state': 'MASTER',
            'adv_intv_err': '0',
            'init_to_mast': '0',
            'ip_conf_mismatch': '0',
            'adv_recv_in_init': '0',
            'interface': '1',
            'state_dur': '6 mins 55.006 secs',
            'backup_to_mast': '2 (Last change Mon Jun 16 11:19:39.926 UTC)',
            'vrrp_v3_adv': 'sent 4288 (errors 0) - rcvd 0',
            'mast_to_init': '1 (Last change Mon Jun 16 11:17:49.978 UTC)',
            'vrrpv2_incompat': None
       }
    """

    show_re = (

     r'VRRP Statistics for interface (?P<interface>.*) -' +
     ' Group (?P<group>\d+) - Address-Family (?P<address_family>\S+)\s*'
     r'State is (?P<state>.*)\n+\s*'
     r'State duration (?P<state_dur>.*)\n+\s*'
     r'(VRRPv3 Advertisements: (?P<vrrp_v3_adv>.*))?\s*'
     r'(VRRPv2 Advertisements: (?P<vrrp_v2_adv>.*))?\s*'
     r'(Group Discarded Packets: (?P<grp_discard_pkts>\d+))?\s*'
     r'(\s*VRRPv2 incompatibility: (?P<vrrpv2_incompat>\d+))?\s*'
     r'(\s*IP Address Owner conflicts: (?P<ip_addr_own_conflicts>\d+))?\s*'
     r'(\s*IP address configuration mismatch : (?P<ip_conf_mismatch>\d+))?\s*'
     r'(\s*Advert Interval errors : (?P<adv_intv_err>\d+))?\s*'
     r'(\s*Adverts received in Init state: (?P<adv_recv_in_init>\d+))?\s*'
     r'(\s*Invalid group other reason: (?P<invalid_grp_oth_reason>\d+))?\s*'
     r'(Group State transition:)?\s*'
     r'(\s*Init to master: (?P<init_to_mast>.*))?\s*'
     r'(\s*Init to backup: (?P<init_to_backup>.*))?\s*'
     r'(\s*Backup to master: (?P<backup_to_mast>.*))?\s*'
     r'(\s*Master to backup: (?P<mast_to_backup>.*))?\s*'
     r'(\s*Master to init: (?P<mast_to_init>.*))?\s*'
     r'(\s*Backup to init: (?P<backup_to_init>.*))?\s*'

    )
    re_result = re.search(show_re, raw_result)
    assert re_result

    result = re_result.groupdict()
    return result