Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crm] Fix issues in static_route test case #3740

Closed
wants to merge 1 commit into from
Closed
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
85 changes: 66 additions & 19 deletions tests/route/test_static_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,33 +118,79 @@ def check_route_redistribution(duthost, prefix, ipv6, removed=False):
assert prefix in adv_routes


def run_static_route_test(duthost, ptfadapter, ptfhost, tbinfo, prefix, nexthop_addrs, prefix_len, nexthop_devs, ipv6=False, config_reload_test=False):
def run_static_route_test(duthost, ptfadapter, ptfhost, tbinfo, prefix, nexthop_addrs, prefix_len, nexthop_devs, vlan_intf_addr, vlan_intf_devname,ipv6=False, config_reload_test=False):
kevinskwang marked this conversation as resolved.
Show resolved Hide resolved
# Add ipaddresses in ptf
add_ipaddr(ptfhost, nexthop_addrs, prefix_len, nexthop_devs, ipv6=ipv6)

try:
ip_dst = str(ipaddress.ip_network(unicode(prefix))[1])
# Add static route
duthost.shell("sonic-db-cli CONFIG_DB hmset 'STATIC_ROUTE|{}' nexthop {}".format(prefix, ",".join(nexthop_addrs)))
time.sleep(5)

# Check traffic get forwarded to the nexthop
ip_dst = str(ipaddress.ip_network(unicode(prefix))[1])
generate_and_verify_traffic(duthost, ptfadapter, tbinfo, ip_dst, nexthop_devs, ipv6=ipv6)

# Check the route is advertised to the neighbors
check_route_redistribution(duthost, prefix, ipv6)

kevinskwang marked this conversation as resolved.
Show resolved Hide resolved
# Config save and reload if specified
if config_reload_test:
duthost.shell('config save -y')
config_reload(duthost)
generate_and_verify_traffic(duthost, ptfadapter, tbinfo, ip_dst, nexthop_devs, ipv6=ipv6)
check_route_redistribution(duthost, prefix, ipv6)

if ipv6:
duthost.shell("sonic-clear ndp")
for idx, addr in enumerate(nexthop_addrs):
# Add static neighbor
duthost.shell(
"ip -6 neigh add {} lladdr {} dev {}".format(addr, ptfadapter.dataplane.get_mac(0, nexthop_devs[idx]),
vlan_intf_devname))
pkt = testutils.simple_icmpv6_packet(
eth_dst=duthost.facts["router_mac"],
eth_src=ptfadapter.dataplane.get_mac(0, nexthop_devs[idx]),
ipv6_src=addr,
ipv6_dst=vlan_intf_addr,
ipv6_hlim=64,
icmp_code=0,
icmp_type=128
)
# Send pkt to update DUT's FDB table to avoid flooding
testutils.send(ptfadapter, nexthop_devs[idx], pkt)
else:
duthost.shell("sonic-clear arp")
for idx, addr in enumerate(nexthop_addrs):
# Add static neighbor
duthost.shell(
"ip neigh add {} lladdr {} dev {}".format(addr, ptfadapter.dataplane.get_mac(0, nexthop_devs[idx]),
vlan_intf_devname))

pkt = testutils.simple_icmp_packet(
eth_dst=duthost.facts["router_mac"],
eth_src=ptfadapter.dataplane.get_mac(0, nexthop_devs[idx]),
ip_src=addr,
ip_dst=vlan_intf_addr,
icmp_type=8,
icmp_code=0,
ip_ttl=64
)
# Send pkt to update DUT's FDB table to avoid flooding
testutils.send(ptfadapter, nexthop_devs[idx], pkt)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this part does the neighbor resolution? If so, we probably need to avoid it since the automatic neighbor resolution is part of the static route feature, we need to check that. I think the current failures of the test come from two aspects: 1. the arp_update script has a period of 300 seconds, whereas the config reload waiting time is shorter than that; 2. according to sonic-net/sonic-buildimage#4930 the arp_update some times fails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is to fill the FDB entry for all interfaces on the DUT to avoid flooding unknown unicast packets. I think we may not need this changes anymore if we can wait until arp_update script is finished.


# Check traffic get forwarded to the nexthop
generate_and_verify_traffic(duthost, ptfadapter, tbinfo, ip_dst, nexthop_devs, ipv6=ipv6)

# Check the route is advertised to the neighbors
check_route_redistribution(duthost, prefix, ipv6)
finally:
# Remove static route
duthost.shell("sonic-db-cli CONFIG_DB del 'STATIC_ROUTE|{}'".format(prefix), module_ignore_errors=True)

# Remove static neighbor entry
for idx, addr in enumerate(nexthop_addrs):
if ipv6:
duthost.shell(
"ip -6 neigh del {} lladdr {} dev {}".format(addr, ptfadapter.dataplane.get_mac(0, nexthop_devs[idx]),
vlan_intf_devname))
else:
duthost.shell(
"ip neigh del {} lladdr {} dev {}".format(addr, ptfadapter.dataplane.get_mac(0, nexthop_devs[idx]),
vlan_intf_devname))

# Delete ipaddresses in ptf
del_ipaddr(ptfhost, nexthop_addrs, prefix_len, nexthop_devs, ipv6=ipv6)

Expand All @@ -161,6 +207,7 @@ def get_nexthops(duthost, tbinfo, ipv6=False, count=1):
mg_facts = duthost.get_extended_minigraph_facts(tbinfo)
vlan_intf = mg_facts['minigraph_vlan_interfaces'][1 if ipv6 else 0]
prefix_len = vlan_intf['prefixlen']
vlan_intf_addr = vlan_intf['addr']

if is_dualtor(tbinfo):
server_ips = mux_cable_server_ip(duthost)
Expand All @@ -176,36 +223,36 @@ def get_nexthops(duthost, tbinfo, ipv6=False, count=1):
nexthop_addrs = [str(vlan_subnet[i + 2]) for i in range(len(nexthop_devs))]
count = min(count, len(nexthop_devs))
indices = random.sample(list(range(len(nexthop_devs))), k=count)
return prefix_len, [nexthop_addrs[_] for _ in indices], [nexthop_devs[_] for _ in indices]
return vlan_intf_addr, prefix_len, [nexthop_addrs[_] for _ in indices], [nexthop_devs[_] for _ in indices], vlan_intf['attachto']


def test_static_route(rand_selected_dut, ptfadapter, ptfhost, tbinfo, toggle_all_simulator_ports_to_rand_selected_tor):
duthost = rand_selected_dut
skip_201911_and_older(duthost)
prefix_len, nexthop_addrs, nexthop_devs = get_nexthops(duthost, tbinfo)
vlan_intf_addr, prefix_len, nexthop_addrs, nexthop_devs, vlan_intf_devname = get_nexthops(duthost, tbinfo)
run_static_route_test(duthost, ptfadapter, ptfhost, tbinfo, "1.1.1.0/24",
nexthop_addrs, prefix_len, nexthop_devs)
nexthop_addrs, prefix_len, nexthop_devs, vlan_intf_addr, vlan_intf_devname)


def test_static_route_ecmp(rand_selected_dut, ptfadapter, ptfhost, tbinfo, toggle_all_simulator_ports_to_rand_selected_tor):
duthost = rand_selected_dut
skip_201911_and_older(duthost)
prefix_len, nexthop_addrs, nexthop_devs = get_nexthops(duthost, tbinfo, count=3)
vlan_intf_addr, prefix_len, nexthop_addrs, nexthop_devs, vlan_intf_devname = get_nexthops(duthost, tbinfo, count=3)
run_static_route_test(duthost, ptfadapter, ptfhost, tbinfo, "2.2.2.0/24",
nexthop_addrs, prefix_len, nexthop_devs, config_reload_test=True)
nexthop_addrs, prefix_len, nexthop_devs, vlan_intf_addr, vlan_intf_devname, config_reload_test=True)


def test_static_route_ipv6(rand_selected_dut, ptfadapter, ptfhost, tbinfo, toggle_all_simulator_ports_to_rand_selected_tor):
duthost = rand_selected_dut
skip_201911_and_older(duthost)
prefix_len, nexthop_addrs, nexthop_devs = get_nexthops(duthost, tbinfo, ipv6=True)
vlan_intf_addr, prefix_len, nexthop_addrs, nexthop_devs, vlan_intf_devname = get_nexthops(duthost, tbinfo, ipv6=True)
run_static_route_test(duthost, ptfadapter, ptfhost, tbinfo, "2000:1::/64",
nexthop_addrs, prefix_len, nexthop_devs, ipv6=True)
nexthop_addrs, prefix_len, nexthop_devs, vlan_intf_addr, vlan_intf_devname, ipv6=True)


def test_static_route_ecmp_ipv6(rand_selected_dut, ptfadapter, ptfhost, tbinfo, toggle_all_simulator_ports_to_rand_selected_tor):
duthost = rand_selected_dut
skip_201911_and_older(duthost)
prefix_len, nexthop_addrs, nexthop_devs = get_nexthops(duthost, tbinfo, ipv6=True, count=3)
vlan_intf_addr, prefix_len, nexthop_addrs, nexthop_devs, vlan_intf_devname = get_nexthops(duthost, tbinfo, ipv6=True, count=3)
run_static_route_test(duthost, ptfadapter, ptfhost, tbinfo, "2000:2::/64",
nexthop_addrs, prefix_len, nexthop_devs, ipv6=True, config_reload_test=True)
nexthop_addrs, prefix_len, nexthop_devs, vlan_intf_addr, vlan_intf_devname, ipv6=True, config_reload_test=True)