def check_route_redistribution(duthost, prefix, ipv6, removed=False):
    if ipv6:
        bgp_neighbor_addr_regex = re.compile('^([0-9a-fA-F]{1,4}:[0-9a-fA-F:]+)')
        SHOW_BGP_SUMMARY_CMD = 'show ipv6 bgp summary'
        SHOW_BGP_ADV_ROUTES_CMD_TEMPLATE = 'show ipv6 bgp neighbor {} advertised-routes'
    else:
        bgp_neighbor_addr_regex = re.compile('^([0-9]{1,3}\\.){3}[0-9]{1,3}')
        SHOW_BGP_SUMMARY_CMD = 'show ip bgp summary'
        SHOW_BGP_ADV_ROUTES_CMD_TEMPLATE = 'show ip bgp neighbor {} advertised-routes'
    bgp_summary = duthost.shell(SHOW_BGP_SUMMARY_CMD, module_ignore_errors=True)['stdout'].split('\n')
    bgp_neighbors = []
    for line in bgp_summary:
        matched = bgp_neighbor_addr_regex.match(line)
        if matched:
            bgp_neighbors.append(str(matched.group(0)))
    for neighbor in bgp_neighbors:
        adv_routes = duthost.shell(SHOW_BGP_ADV_ROUTES_CMD_TEMPLATE.format(neighbor))['stdout']
        if removed:
            assert (prefix not in adv_routes)
        else:
            assert (prefix in adv_routes)
def check_route_redistribution(duthost, prefix, ipv6, removed=False):
    if ipv6:
        bgp_neighbor_addr_regex = re.compile('^([0-9a-fA-F]{1,4}:[0-9a-fA-F:]+)')
        SHOW_BGP_SUMMARY_CMD = 'show ipv6 bgp summary'
        SHOW_BGP_ADV_ROUTES_CMD_TEMPLATE = 'show ipv6 bgp neighbor {} advertised-routes'
    else:
        bgp_neighbor_addr_regex = re.compile('^([0-9]{1,3}\\.){3}[0-9]{1,3}')
        SHOW_BGP_SUMMARY_CMD = 'show ip bgp summary'
        SHOW_BGP_ADV_ROUTES_CMD_TEMPLATE = 'show ip bgp neighbor {} advertised-routes'
    bgp_summary = duthost.shell(SHOW_BGP_SUMMARY_CMD, module_ignore_errors=True)['stdout'].split('\n')
    bgp_neighbors = []
    for line in bgp_summary:
        matched = bgp_neighbor_addr_regex.match(line)
        if matched:
            bgp_neighbors.append(str(matched.group(0)))
    for neighbor in bgp_neighbors:
        adv_routes = duthost.shell(SHOW_BGP_ADV_ROUTES_CMD_TEMPLATE.format(neighbor))['stdout']
        if removed:
            assert (prefix not in adv_routes)
        else:
            assert (prefix in adv_routes)