Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion tests/common/devices/sonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,49 @@ def check_bgp_session_nsf(self, neighbor_ip):
return True
return False

def _parse_route_summary(self, output):
"""
Sample command output:
Route Source Routes FIB (vrf default)
kernel 34 34
connected 11 11
static 1 0
ebgp 6404 6404
ibgp 0 0
------
Totals 6450 6449

Sample parsing output:
{
'kernel' : { 'routes' : 34 , 'FIB' : 34 },
... ...
'Totals' : { 'routes' : 6450, 'FIB' : 6449 }
}
"""
ret = {}
for line in output:
tokens = line.split()
if len(tokens) > 1:
key = tokens[0]
val = {}
if tokens[1].isdigit():
val['routes'] = tokens[1]
val['FIB'] = tokens[2] if len(tokens) > 2 and tokens[2].isdigit() else None
ret[key] = val
return ret

def get_ip_route_summary(self):
"""
@summary: issue "show ip[v6] route summary" and parse output into dicitionary.
Going forward, this show command should use tabular output so that
we can simply call show_and_parse() function.
"""
ipv4_output = self.shell("show ip route sum")["stdout_lines"]
ipv4_summary = self._parse_route_summary(ipv4_output)
ipv6_output = self.shell("show ipv6 route sum")["stdout_lines"]
ipv6_summary = self._parse_route_summary(ipv6_output)
return ipv4_summary, ipv6_summary

def get_dut_iface_mac(self, iface_name):
"""
Gets the MAC address of specified interface.
Expand Down Expand Up @@ -1228,7 +1271,7 @@ def get_extended_minigraph_facts(self, tbinfo, namespace = DEFAULT_NAMESPACE):
self.update_backend_flag(tbinfo, mg_facts)

return mg_facts

def update_backend_flag(self, tbinfo, mg_facts):
mg_facts[constants.IS_BACKEND_TOPOLOGY_KEY] = self.assert_topo_is_backend(tbinfo)

Expand Down
32 changes: 18 additions & 14 deletions tests/platform_tests/link_flap/link_flap_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,25 @@ def check_orch_cpu_utilization(dut, orch_cpu_threshold):
return int(float(orch_cpu)) < orch_cpu_threshold


def check_bgp_routes(dut, start_time_ip_route_counts, ipv4=False):
def check_bgp_routes(dut, start_time_ipv4_route_counts, start_time_ipv6_route_counts):
"""
Make Sure all ip routes are relearned with jitter of ~5
Make Sure all ip routes are relearned with jitter of ~MAX_DIFF

Args:
dut: DUT host object
start_time_ip_route_counts: IP route counts at start
ipv4: Version of IP
"""
if ipv4:
end_time_ip_route_counts = dut.shell("show ip route summary | grep Total | awk '{print $2}'")["stdout"]
logger.info("IPv4 routes at end: %s", end_time_ip_route_counts)
else:
end_time_ip_route_counts = dut.shell("show ipv6 route summary | grep Total | awk '{print $2}'")["stdout"]
logger.info("IPv6 routes at end: %s", end_time_ip_route_counts)

incr_ip_route_counts = abs(int(float(start_time_ip_route_counts)) - int(float(end_time_ip_route_counts)))
return incr_ip_route_counts < 5
start_time_ipv4_route_counts: IPv4 route counts at start
start_time_ipv6_route_counts: IPv6 route counts at start
"""
MAX_DIFF = 5

sumv4, sumv6 = dut.get_ip_route_summary()
totalsv4 = sumv4.get('Totals', {})
totalsv6 = sumv6.get('Totals', {})
routesv4 = totalsv4.get('routes', 0)
routesv6 = totalsv6.get('routes', 0)
logger.info("IPv4 routes: start {} end {}, summary {}".format(start_time_ipv4_route_counts, routesv4, sumv4))
logger.info("IPv6 routes: start {} end {}, summary {}".format(start_time_ipv6_route_counts, routesv6, sumv6))

incr_ipv4_route_counts = abs(int(float(start_time_ipv4_route_counts)) - int(float(routesv4)))
incr_ipv6_route_counts = abs(int(float(start_time_ipv6_route_counts)) - int(float(routesv6)))
return incr_ipv4_route_counts < MAX_DIFF and incr_ipv6_route_counts < MAX_DIFF
24 changes: 11 additions & 13 deletions tests/platform_tests/link_flap/test_cont_link_flap.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ def test_cont_link_flap(self, request, duthosts, enum_rand_one_per_hwsku_fronten
logging.info("Redis Memory: %s M", start_time_redis_memory)

# Record ipv4 route counts at start
start_time_ipv4_route_counts = duthost.shell("show ip route summary | grep Total | awk '{print $2}'")["stdout"]
logging.info("IPv4 routes at start: %s", start_time_ipv4_route_counts)

# Record ipv6 route counts at start
start_time_ipv6_route_counts = duthost.shell("show ipv6 route summary | grep Total | awk '{print $2}'")["stdout"]
logging.info("IPv6 routes at start %s", start_time_ipv6_route_counts)
sumv4, sumv6 = duthost.get_ip_route_summary()
totalsv4 = sumv4.get('Totals', {})
totalsv6 = sumv6.get('Totals', {})
start_time_ipv4_route_counts = totalsv4.get('routes', 0)
start_time_ipv6_route_counts = totalsv6.get('routes', 0)
logging.info("IPv4 routes: start {}, summary {}".format(start_time_ipv4_route_counts, sumv4))
logging.info("IPv6 routes: start {}, summary {}".format(start_time_ipv6_route_counts, sumv6))

# Make Sure Orch CPU < orch_cpu_threshold before starting test.
logging.info("Make Sure orchagent CPU utilization is less that %d before link flap", orch_cpu_threshold)
Expand All @@ -81,13 +82,10 @@ def test_cont_link_flap(self, request, duthosts, enum_rand_one_per_hwsku_fronten
for dut_port, fanout, fanout_port in candidates:
toggle_one_link(duthost, dut_port, fanout, fanout_port, watch=True)

# Make Sure all ipv4 routes are relearned with jitter of ~5
logging.info("IPv4 routes at start: %s", start_time_ipv4_route_counts)
pytest_assert(wait_until(60, 1, check_bgp_routes, duthost, start_time_ipv4_route_counts, True), "Ipv4 routes are not equal after link flap")

# Make Sure all ipv6 routes are relearned with jitter of ~5
logging.info("IPv6 routes at start: %s", start_time_ipv6_route_counts)
pytest_assert(wait_until(60, 1, check_bgp_routes, duthost, start_time_ipv6_route_counts), "Ipv6 routes are not equal after link flap")
# Make Sure all ipv4/ipv6 routes are relearned with jitter of ~5
if not wait_until(60, 1, check_bgp_routes, duthost, start_time_ipv4_route_counts, start_time_ipv6_route_counts):
endv4, endv6 = duthost.get_ip_route_summary()
pytest.fail("IP routes are not equal after link flap: before ipv4 {} ipv6 {}, after ipv4 {} ipv6 {}".format(sumv4, sumv6, endv4, endv6))

# Record memory status at end
memory_output = duthost.shell("show system-memory")["stdout"]
Expand Down