Skip to content

Commit d374e74

Browse files
authored
[Test gap]Add new testcase test_everflow_packet_format, verify that mirrored packets do not contain VLAN tags or unexpected fields. (sonic-net#17500)
What is the motivation for this PR? [Test gap]Add new testcase test_everflow_packet_format, verify that mirrored packets do not contain VLAN tags or unexpected fields. How did you do it? Config everflow Send packet Validate packet Conditioanl mark is same as the previous testcase test_everflow_per_interface How did you verify/test it? Run the new testcase test_everflow_packet_format on physical testbed and check the result. Signed-off-by: Chun'ang Li <chunangli@microsoft.com>
1 parent 833f71c commit d374e74

File tree

3 files changed

+96
-8
lines changed

3 files changed

+96
-8
lines changed

tests/common/plugins/conditional_mark/tests_mark_conditions.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,36 @@ everflow/test_everflow_per_interface.py:
849849
- "platform in ['x86_64-8800_lc_48h_o-r0', 'x86_64-8800_lc_48h-r0']"
850850
- "(is_multi_asic==True) and https://github.com/sonic-net/sonic-buildimage/issues/11776"
851851

852+
everflow/test_everflow_per_interface.py::test_everflow_packet_format[ipv6-default]:
853+
skip:
854+
reason: "Skip everflow packet integrity IPv6 test on unsupported platforms"
855+
conditions_logical_operator: or
856+
conditions:
857+
- "asic_type in ['cisco-8000', 'marvell', 'mellanox'] or (asic_subtype in ['broadcom-dnx'] and https://github.com/sonic-net/sonic-swss/issues/2204)"
858+
- "'dualtor' in topo_name"
859+
- "platform in ['x86_64-8800_lc_48h_o-r0', 'x86_64-8800_lc_48h-r0']"
860+
- "(is_multi_asic==True) and https://github.com/sonic-net/sonic-buildimage/issues/11776"
861+
862+
everflow/test_everflow_per_interface.py::test_everflow_packet_format[ipv6-m0_l3_scenario]:
863+
skip:
864+
reason: "Skip m0 everflow packet integrity IPv6 test on unsupported platforms"
865+
conditions_logical_operator: or
866+
conditions:
867+
- "asic_type in ['marvell']"
868+
- "'dualtor' in topo_name"
869+
- "platform in ['x86_64-8800_lc_48h_o-r0', 'x86_64-8800_lc_48h-r0']"
870+
- "(is_multi_asic==True) and https://github.com/sonic-net/sonic-buildimage/issues/11776"
871+
872+
everflow/test_everflow_per_interface.py::test_everflow_packet_format[ipv6-m0_vlan_scenario]:
873+
skip:
874+
reason: "Skip m0 everflow packet integrity IPv6 test on unsupported platforms"
875+
conditions_logical_operator: or
876+
conditions:
877+
- "asic_type in ['marvell']"
878+
- "'dualtor' in topo_name"
879+
- "platform in ['x86_64-8800_lc_48h_o-r0', 'x86_64-8800_lc_48h-r0']"
880+
- "(is_multi_asic==True) and https://github.com/sonic-net/sonic-buildimage/issues/11776"
881+
852882
everflow/test_everflow_per_interface.py::test_everflow_per_interface[ipv6-default]:
853883
skip:
854884
reason: "Skip everflow per interface IPv6 test on unsupported platforms"

tests/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,7 @@ def pytest_runtest_makereport(item, call):
10561056
# DummyTestUtils would always return True for all verify function in ptf.testutils.
10571057
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
10581058
def pytest_runtest_call(item):
1059+
# See tests/common/plugins/conditional_mark/tests_mark_conditions_skip_traffic_test.yaml
10591060
if "skip_traffic_test" in item.keywords:
10601061
logger.info("Got skip_traffic_test marker, will skip traffic test")
10611062
with DummyTestUtils():

tests/everflow/test_everflow_per_interface.py

+65-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
import pytest
55
import os
66
import ptf.testutils as testutils
7+
from scapy.layers.l2 import Ether
8+
from scapy.contrib.mpls import MPLS
9+
from scapy.layers.l2 import Dot1Q
10+
from scapy.layers.vxlan import VXLAN
711
from . import everflow_test_utilities as everflow_utils
812

9-
from .everflow_test_utilities import BaseEverflowTest, erspan_ip_ver # noqa: F401
13+
from .everflow_test_utilities import BaseEverflowTest, erspan_ip_ver # noqa: F401
1014
from .everflow_test_utilities import TEMPLATE_DIR, EVERFLOW_RULE_CREATE_TEMPLATE, \
11-
DUT_RUN_DIR, EVERFLOW_RULE_CREATE_FILE, UP_STREAM
15+
DUT_RUN_DIR, EVERFLOW_RULE_CREATE_FILE, UP_STREAM
1216
from tests.common.helpers.assertions import pytest_require
1317

14-
from .everflow_test_utilities import setup_info, EVERFLOW_DSCP_RULES, STABILITY_BUFFER # noqa: F401
18+
from .everflow_test_utilities import setup_info, EVERFLOW_DSCP_RULES, STABILITY_BUFFER # noqa: F401
1519
from tests.common.dualtor.mux_simulator_control import toggle_all_simulator_ports_to_rand_selected_tor # noqa: F401
1620

1721
pytestmark = [
@@ -79,7 +83,7 @@ def build_acl_rule_vars(candidate_ports, ip_ver):
7983

8084

8185
@pytest.fixture(scope='module')
82-
def apply_mirror_session(setup_info, erspan_ip_ver): # noqa F811
86+
def apply_mirror_session(setup_info, erspan_ip_ver): # noqa F811
8387
mirror_session_info = BaseEverflowTest.mirror_session_info(
8488
EVERFLOW_SESSION_NAME, setup_info[UP_STREAM]['everflow_dut'].facts["asic_type"])
8589
logger.info("Applying mirror session to DUT")
@@ -93,7 +97,7 @@ def apply_mirror_session(setup_info, erspan_ip_ver): # noqa F811
9397

9498

9599
@pytest.fixture(scope='module')
96-
def setup_mirror_session_dest_ip_route(tbinfo, setup_info, apply_mirror_session, erspan_ip_ver): # noqa F811
100+
def setup_mirror_session_dest_ip_route(tbinfo, setup_info, apply_mirror_session, erspan_ip_ver): # noqa F811
97101
"""
98102
Setup the route for mirror session destination ip and update monitor port list.
99103
Remove the route as part of cleanup.
@@ -124,7 +128,7 @@ def ip_ver(request):
124128

125129

126130
@pytest.fixture(scope='module')
127-
def apply_acl_rule(setup_info, tbinfo, setup_mirror_session_dest_ip_route, ip_ver): # noqa F811
131+
def apply_acl_rule(setup_info, tbinfo, setup_mirror_session_dest_ip_route, ip_ver): # noqa F811
128132
"""
129133
Apply ACL rule for matching input_ports
130134
"""
@@ -148,7 +152,7 @@ def apply_acl_rule(setup_info, tbinfo, setup_mirror_session_dest_ip_route, ip_ve
148152
dest=os.path.join(DUT_RUN_DIR, EVERFLOW_RULE_CREATE_FILE))
149153
logger.info("Applying acl rule config to DUT")
150154
command = "acl-loader update full {} --table_name {} --session_name {}" \
151-
.format(os.path.join(DUT_RUN_DIR, EVERFLOW_RULE_CREATE_FILE), table_name, EVERFLOW_SESSION_NAME)
155+
.format(os.path.join(DUT_RUN_DIR, EVERFLOW_RULE_CREATE_FILE), table_name, EVERFLOW_SESSION_NAME)
152156
setup_info[UP_STREAM]['everflow_dut'].shell(cmd=command)
153157
ret = {
154158
"candidate_ports": candidate_ports,
@@ -192,7 +196,7 @@ def send_and_verify_packet(ptfadapter, packet, expected_packet, tx_port, rx_port
192196
testutils.verify_no_packet_any(ptfadapter, pkt=expected_packet, ports=rx_ports)
193197

194198

195-
def test_everflow_per_interface(ptfadapter, setup_info, apply_acl_rule, tbinfo, # noqa F811
199+
def test_everflow_per_interface(ptfadapter, setup_info, apply_acl_rule, tbinfo, # noqa F811
196200
toggle_all_simulator_ports_to_rand_selected_tor, ip_ver, erspan_ip_ver): # noqa F811
197201
"""Verify packet ingress from candidate ports are captured by EVERFLOW, while packets
198202
ingress from unselected ports are not captured
@@ -213,3 +217,56 @@ def test_everflow_per_interface(ptfadapter, setup_info, apply_acl_rule, tbinfo,
213217
for port, ptf_idx in list(everflow_config['unselected_ports'].items()):
214218
logger.info("Verifying packet ingress from {} is not mirrored".format(port))
215219
send_and_verify_packet(ptfadapter, packet, exp_packet, ptf_idx, uplink_ports, False)
220+
221+
222+
def test_everflow_packet_format(ptfadapter, setup_info, apply_acl_rule, tbinfo, # noqa F811
223+
toggle_all_simulator_ports_to_rand_selected_tor, ip_ver, erspan_ip_ver): # noqa F811
224+
"""Verify that mirrored packets do not contain VLAN tags or unexpected fields."""
225+
everflow_config = apply_acl_rule
226+
packet, exp_packet = generate_testing_packet(ptfadapter, setup_info[UP_STREAM]['everflow_dut'],
227+
everflow_config['mirror_session_info'],
228+
setup_info[UP_STREAM]['ingress_router_mac'], setup_info, ip_ver,
229+
erspan_ip_ver)
230+
uplink_ports = everflow_config["monitor_port_ptf_ids"]
231+
232+
# Send test packet
233+
candidate_port, ptf_idx = list(everflow_config['candidate_ports'].items())[0]
234+
logger.info(f"Sending test packet from candidate port {candidate_port}")
235+
ptfadapter.dataplane.flush()
236+
testutils.send(ptfadapter, pkt=packet, port_id=ptf_idx)
237+
238+
# Capture mirrored packet
239+
logger.info("Capturing mirrored packet to verify format")
240+
res = testutils.verify_packet_any_port(ptfadapter,
241+
pkt=exp_packet,
242+
ports=uplink_ports,
243+
timeout=5)
244+
245+
# Skip traffic test if the return value is true.
246+
# See tests.conftest.pytest_runtest_call and tests.common.plugins.ptfadapter.dummy_testutils.wrapped
247+
if res is True:
248+
logger.info("Skipped. Ptf.testutils is set to DummyTestUtils to skip traffic test.")
249+
return
250+
251+
port_idx, raw_captured_packet = res
252+
# Ensure packet is not empty
253+
assert raw_captured_packet, "Captured packet is empty or None"
254+
255+
captured_packet = Ether(raw_captured_packet)
256+
257+
# Debugging: Print packet summary if assertions fail
258+
packet_summary = captured_packet.summary()
259+
260+
# Ensure no VLAN tag
261+
assert not captured_packet.haslayer(Dot1Q), \
262+
f"Mirrored packet should not contain VLAN tag: {packet_summary}"
263+
264+
# Check for unexpected MPLS headers
265+
assert not captured_packet.haslayer(MPLS), \
266+
f"Mirrored packet contains unexpected MPLS label: {packet_summary}"
267+
268+
# Check for unexpected VXLAN encapsulation
269+
assert not captured_packet.haslayer(VXLAN), \
270+
f"Mirrored packet should not have VXLAN encapsulation: {packet_summary}"
271+
272+
logger.info(f"Mirrored packet format verified: {packet_summary}")

0 commit comments

Comments
 (0)