import re


def parse_host_interfaces(hifs):
    """
    parse host interfaces

    Support 3 formats:
    1. Legacy format (non multi-dut): vlan_index
    2. new format (multi-dut): dut_index.vlan_index,dut_index.vlan_index
    3. new format (multi-dut): dut_index.vlan_index@ptf_port_index,dut_index.vlan_index@ptf_port_index
    """

    if isinstance(hifs, int):
        dut_index = 0
        vlan_index = int(hifs)

        return [(dut_index, vlan_index)]

    ret = []
    for hif in hifs.split(','):
        indices = tuple([int(x) for x in re.split(r'\.|@', hif.strip())])
        ret.append(indices)   # (dut_index, vlan_index) or (dut_index, vlan_index, ptf_port_index)

    return ret