import logging
import re


def get_queue_id_of_received_packet(
    duthosts, 
    rand_one_dut_hostname, 
    rand_selected_interface
):
    """
    Get queue id of the packet received on destination
    """
    duthost = duthosts[rand_one_dut_hostname]
    queue_counter = duthost.shell('show queue counters {} | grep "UC"'.format(rand_selected_interface[0]))['stdout']
    logging.info('queue_counter:\n{}'.format(queue_counter))

    """ 
    regex search will look for following pattern in queue_counter o/p for interface
    ----------------------------------------------------------------------------_---
    Port           TxQ    Counter/pkts     Counter/bytes     Drop/pkts    Drop/bytes
    -----------  -----  --------------  ---------------  -----------  --------------
    Ethernet124    UC1              10             1000            0             0
    """
    result = re.search(r'\S+\s+UC\d\s+10+\s+\S+\s+\S+\s+\S+', queue_counter)

    if result is not None:
        output = result.group(0)
        output_list = output.split()
        queue = int(output_list[1][2])
    else:
        logging.info("Error occured while fetching queue counters from DUT")
        return None

    return queue