|
| 1 | +import time |
| 2 | +import pytest |
| 3 | +import logging |
| 4 | + |
| 5 | +logger = logging.getLogger(__name__) |
| 6 | + |
| 7 | +pytestmark = [ |
| 8 | + pytest.mark.topology('any'), |
| 9 | + pytest.mark.device_type('vs') |
| 10 | +] |
| 11 | + |
| 12 | + |
| 13 | +def clear_queue_counters(duthost): |
| 14 | + duthost.shell("sonic-clear queuecounters") |
| 15 | + |
| 16 | + |
| 17 | +def get_queue_counters(duthost, port, queue): |
| 18 | + """ |
| 19 | + Return the counter for a given queue in given port |
| 20 | + """ |
| 21 | + cmd = "show queue counters {}".format(port) |
| 22 | + output = duthost.shell(cmd)['stdout_lines'] |
| 23 | + txq = "UC{}".format(queue) |
| 24 | + for line in output: |
| 25 | + fields = line.split() |
| 26 | + if fields[1] == txq: |
| 27 | + return int(fields[2]) |
| 28 | + return -1 |
| 29 | + |
| 30 | + |
| 31 | +def test_bgp_queues(duthosts, enum_frontend_dut_hostname, enum_asic_index, tbinfo): |
| 32 | + duthost = duthosts[enum_frontend_dut_hostname] |
| 33 | + clear_queue_counters(duthost) |
| 34 | + time.sleep(10) |
| 35 | + bgp_facts = duthost.bgp_facts(instance_id=enum_asic_index)['ansible_facts'] |
| 36 | + mg_facts = duthost.get_extended_minigraph_facts(tbinfo) |
| 37 | + |
| 38 | + arp_dict = {} |
| 39 | + ndp_dict = {} |
| 40 | + processed_intfs = set() |
| 41 | + show_arp = duthost.command('show arp') |
| 42 | + show_ndp = duthost.command('show ndp') |
| 43 | + for arp_entry in show_arp['stdout_lines']: |
| 44 | + items = arp_entry.split() |
| 45 | + if (len(items) != 4): |
| 46 | + continue |
| 47 | + ip = items[0] |
| 48 | + iface = items[2] |
| 49 | + arp_dict[ip] = iface |
| 50 | + for ndp_entry in show_ndp['stdout_lines']: |
| 51 | + items = ndp_entry.split() |
| 52 | + if (len(items) != 5): |
| 53 | + continue |
| 54 | + ip = items[0] |
| 55 | + iface = items[2] |
| 56 | + ndp_dict[ip] = iface |
| 57 | + |
| 58 | + for k, v in list(bgp_facts['bgp_neighbors'].items()): |
| 59 | + # Only consider established bgp sessions |
| 60 | + if v['state'] == 'established': |
| 61 | + assert (k in arp_dict.keys() or k in ndp_dict.keys()) |
| 62 | + if k in arp_dict: |
| 63 | + ifname = arp_dict[k].split('.', 1)[0] |
| 64 | + else: |
| 65 | + ifname = ndp_dict[k].split('.', 1)[0] |
| 66 | + if ifname in processed_intfs: |
| 67 | + continue |
| 68 | + if (ifname.startswith("PortChannel")): |
| 69 | + for port in mg_facts['minigraph_portchannels'][ifname]['members']: |
| 70 | + logger.info("PortChannel '{}' : port {}".format(ifname, port)) |
| 71 | + for q in range(0, 7): |
| 72 | + assert(get_queue_counters(duthost, port, q) == 0) |
| 73 | + else: |
| 74 | + logger.info(ifname) |
| 75 | + for q in range(0, 7): |
| 76 | + assert(get_queue_counters(duthost, ifname, q) == 0) |
| 77 | + processed_intfs.add(ifname) |
0 commit comments