import re


def parse_diag_dump_lacp_basic_counters(raw_result):
    """
    Parse the 'diag-dump lacp basic' command raw output related to LACP
    counters.

    :param str raw_result: vtysh raw result string.
    :rtype: dict
    :return: The parsed result of the getlacpcounters in a dictionary of the
             form:

     ::

         {
            'lag':
                {'interface':
                    {'lacp_pdus_sent': 0,
                    'marker_response_pdus_sent': 0,
                    'lacp_pdus_received' : 0,
                    'marker_pdus_received' : 0},
                'interface':
                    {'lacp_pdus_sent': 0,
                    'marker_response_pdus_sent': 0,
                    'lacp_pdus_received' : 0,
                    'marker_pdus_received' : 0},
                }
        }
    """

    getlacpcounters_re = (
        r'Interface: (?P<interface>\d+[-]?\d*)\s*'
        r'lacp_pdus_sent: (?P<lacp_pdus_sent>\d+)\s*'
        r'marker_response_pdus_sent: (?P<marker_response_pdus_sent>\d+)\s*'
        r'lacp_pdus_received: (?P<lacp_pdus_received>\d+)\s*'
        r'marker_pdus_received: (?P<marker_pdus_received>\d+)\s*'
    )

    result = {}
    result_interface = {}

    lag_block = raw_result.split('LAG lag')
    for block in lag_block:
        lag_id = block.split(':\n')[0]
        if lag_id:
            for re_partial in re.finditer(getlacpcounters_re, block):
                interface = re_partial.groupdict()
                interface_number = interface['interface']
                del interface['interface']
                for key, value in interface.items():
                    if value is None:
                        interface[key] = 0
                    elif value.isdigit():
                        interface[key] = int(value)
                result_interface[interface_number] = interface
            result[lag_id] = result_interface
            result_interface = {}
    return result