diff --git a/ansible/roles/test/files/ptftests/dhcpv6_counter_test.py b/ansible/roles/test/files/ptftests/dhcpv6_counter_test.py index 9f204997998..73b82a67fec 100644 --- a/ansible/roles/test/files/ptftests/dhcpv6_counter_test.py +++ b/ansible/roles/test/files/ptftests/dhcpv6_counter_test.py @@ -1,4 +1,6 @@ +import os import ast +import time import subprocess # Packet Test Framework imports @@ -56,6 +58,7 @@ def setUp(self): self.server_ip = self.test_params['server_ip'] self.relay_iface_ip = self.test_params['relay_iface_ip'] self.relay_iface_mac = self.test_params['relay_iface_mac'] + self.dut_mac = self.test_params['dut_mac'] self.vlan_ip = self.test_params['vlan_ip'] self.client_mac = self.dataplane.get_mac(0, self.client_port_index) @@ -93,7 +96,7 @@ def create_packet(self, message): return packet def create_server_packet(self, message): - packet = Ether(dst=self.relay_iface_mac) + packet = Ether(dst=self.dut_mac) packet /= IPv6(src=self.server_ip, dst=self.relay_iface_ip) packet /= UDP(sport=self.DHCP_SERVER_PORT, dport=self.DHCP_SERVER_PORT) packet /= DHCP6_RelayReply(msgtype=13, linkaddr=self.vlan_ip, peeraddr=self.client_link_local) @@ -112,6 +115,9 @@ def client_send(self): for message in client_messages: packet = self.create_packet(message) testutils.send_packet(self, self.client_port_index, packet) + # sleep a short time to low down packet sending rate in case multicast packets + # flooding cause packets drop on dhcpv6 relay filter raw socket + time.sleep(1) def server_send(self): server_messages = [DHCP6_Advertise, DHCP6_Reply] @@ -119,6 +125,7 @@ def server_send(self): packet = self.create_server_packet(message) packet.src = self.dataplane.get_mac(0, self.server_port_indices[0]) testutils.send_packet(self, self.server_port_indices[0], packet) + time.sleep(1) def runTest(self): self.client_send() diff --git a/tests/dhcp_relay/test_dhcpv6_relay.py b/tests/dhcp_relay/test_dhcpv6_relay.py index 7baa74c2490..1d911f50c7d 100644 --- a/tests/dhcp_relay/test_dhcpv6_relay.py +++ b/tests/dhcp_relay/test_dhcpv6_relay.py @@ -13,6 +13,8 @@ from tests.common.platform.processes_utils import wait_critical_processes from tests.common.utilities import wait_until from tests.common.helpers.assertions import pytest_assert +from tests.common.dualtor.mux_simulator_control import toggle_all_simulator_ports_to_rand_selected_tor_m # noqa F401 + pytestmark = [ pytest.mark.topology('t0', 'm0'), @@ -24,6 +26,14 @@ logger = logging.getLogger(__name__) + +def wait_all_bgp_up(duthost): + config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] + bgp_neighbors = config_facts.get('BGP_NEIGHBOR', {}) + if not wait_until(60, 10, 0, duthost.check_bgp_session_state, bgp_neighbors.keys()): + pytest.fail("not all bgp sessions are up after config change") + + @pytest.fixture(scope="module", params=[SINGLE_TOR_MODE, DUAL_TOR_MODE]) def testing_config(request, duthosts, rand_one_dut_hostname, tbinfo): testing_mode = request.param @@ -160,7 +170,8 @@ def test_interface_binding(duthosts, rand_one_dut_hostname, dut_dhcp_relay_data) for dhcp_relay in dut_dhcp_relay_data: assert ("*:{}".format(dhcp_relay['downlink_vlan_iface']['name']) or "*:*" in output, "{} is not found in {}".format("*:{}".format(dhcp_relay['downlink_vlan_iface']['name']), output)) or ("*:*" in output, "dhcp6relay socket is not properly binded") -def test_dhcpv6_relay_counter(ptfhost, duthosts, rand_one_dut_hostname, dut_dhcp_relay_data): +def test_dhcpv6_relay_counter(ptfhost, duthosts, rand_one_dut_hostname, dut_dhcp_relay_data, + toggle_all_simulator_ports_to_rand_selected_tor_m): # noqa F811 """ Test DHCPv6 Counter """ duthost = duthosts[rand_one_dut_hostname] skip_release(duthost, ["201911", "202106"]) @@ -185,6 +196,7 @@ def test_dhcpv6_relay_counter(ptfhost, duthosts, rand_one_dut_hostname, dut_dhcp "server_ip": str(dhcp_relay['downlink_vlan_iface']['dhcpv6_server_addrs'][0]), "relay_iface_ip": str(dhcp_relay['downlink_vlan_iface']['addr']), "relay_iface_mac": str(dhcp_relay['downlink_vlan_iface']['mac']), + "dut_mac": str(dhcp_relay['uplink_mac']), "relay_link_local": str(dhcp_relay['uplink_interface_link_local']), "vlan_ip": str(dhcp_relay['downlink_vlan_iface']['addr'])}, log_file="/tmp/dhcpv6_relay_test.DHCPCounterTest.log") @@ -247,7 +259,7 @@ def test_dhcp_relay_after_link_flap(ptfhost, duthosts, rand_one_dut_hostname, du duthost.shell('ifconfig {} up'.format(iface)) # Sleep a bit to ensure uplinks are up - time.sleep(20) + wait_all_bgp_up(duthost) # Run the DHCP relay test on the PTF host ptf_runner(ptfhost, @@ -302,7 +314,7 @@ def test_dhcp_relay_start_with_uplinks_down(ptfhost, duthosts, rand_one_dut_host duthost.shell('ifconfig {} up'.format(iface)) # Sleep a bit to ensure uplinks are up - time.sleep(20) + wait_all_bgp_up(duthost) # Run the DHCP relay test on the PTF host ptf_runner(ptfhost,