Skip to content
Open
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
102 changes: 41 additions & 61 deletions tests/packet_trimming/base_packet_trimming.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from tests.common.utilities import wait_until, configure_packet_aging
from tests.common.mellanox_data import is_mellanox_device
from tests.packet_trimming.constants import (
TRIM_SIZE, DEFAULT_PACKET_SIZE, DEFAULT_DSCP, MIN_PACKET_SIZE, TRIM_SIZE_MAX, CONFIG_TOGGLE_COUNT,
JUMBO_PACKET_SIZE, PORT_TOGGLE_COUNT, COUNTER_DSCP, TRIM_QUEUE)
DEFAULT_PACKET_SIZE, DEFAULT_DSCP, MIN_PACKET_SIZE, CONFIG_TOGGLE_COUNT,
JUMBO_PACKET_SIZE, PORT_TOGGLE_COUNT, COUNTER_DSCP)
from tests.packet_trimming.packet_trimming_config import PacketTrimmingConfig
from tests.packet_trimming.packet_trimming_helper import (
configure_trimming_action, configure_trimming_acl, verify_srv6_packet_with_trimming, cleanup_trimming_acl,
verify_trimmed_packet, reboot_dut, check_connected_route_ready, get_switch_trim_counters_json,
Expand All @@ -24,38 +25,38 @@ def configure_trimming_global_by_mode(self, duthost):
def get_srv6_recv_pkt_dscp(self):
raise NotImplementedError

def get_verify_trimmed_packet_kwargs(self, test_params):
def get_verify_trimmed_packet_kwargs(self, duthost, ptfadapter, test_params):
"""
Get kwargs for verify_trimmed_packet
"""
base_kwargs = dict(
duthost=test_params.get('duthost'),
ptfadapter=test_params.get('ptfadapter'),
duthost=duthost,
ptfadapter=ptfadapter,
ingress_port=test_params['ingress_port'],
egress_ports=test_params['egress_ports'],
block_queue=test_params['block_queue'],
send_pkt_size=DEFAULT_PACKET_SIZE,
send_pkt_dscp=DEFAULT_DSCP,
recv_pkt_size=TRIM_SIZE,
recv_pkt_size=PacketTrimmingConfig.get_trim_size(duthost),
expect_packets=True
)
base_kwargs.update(self.get_extra_trimmed_packet_kwargs())
logger.info(f"Base kwargs: {base_kwargs}")
return base_kwargs

def get_verify_trimmed_counter_packet_kwargs(self, trim_counter_params):
def get_verify_trimmed_counter_packet_kwargs(self, duthost, ptfadapter, trim_counter_params):
"""
Get kwargs for verify_trimmed_packet
"""
base_kwargs = dict(
duthost=trim_counter_params.get('duthost'),
ptfadapter=trim_counter_params.get('ptfadapter'),
duthost=duthost,
ptfadapter=ptfadapter,
ingress_port=trim_counter_params['ingress_port'],
egress_ports=trim_counter_params['egress_ports'],
block_queue=trim_counter_params['block_queue'],
send_pkt_size=DEFAULT_PACKET_SIZE,
send_pkt_dscp=COUNTER_DSCP,
recv_pkt_size=TRIM_SIZE,
recv_pkt_size=PacketTrimmingConfig.get_trim_size(duthost),
expect_packets=True
)
base_kwargs.update(self.get_extra_trimmed_packet_kwargs())
Expand Down Expand Up @@ -84,20 +85,18 @@ def test_packet_size_after_trimming(self, duthost, ptfadapter, test_params):
configure_trimming_action(duthost, test_params['trim_buffer_profiles'][buffer_profile], "on")

with allure.step("Verify trimming packet"):
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
verify_trimmed_packet(**kwargs)

with allure.step(f"Configure trimming in {self.trimming_mode} mode and update trim size to {TRIM_SIZE_MAX}"):
self.configure_trimming_global_by_mode(duthost, TRIM_SIZE_MAX)
max_trim_size = PacketTrimmingConfig.get_max_trim_size(duthost)
with allure.step(f"Configure trimming in {self.trimming_mode} mode and update trim size to {max_trim_size}"):
self.configure_trimming_global_by_mode(duthost, max_trim_size)

with allure.step("Send packets and verify trimming works after config update"):
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
kwargs.update({
'duthost': duthost,
'ptfadapter': ptfadapter,
'send_pkt_size': JUMBO_PACKET_SIZE,
'recv_pkt_size': TRIM_SIZE_MAX
'recv_pkt_size': max_trim_size
})
verify_trimmed_packet(**kwargs)

Expand All @@ -118,16 +117,13 @@ def test_dscp_remapping_after_trimming(self, duthost, ptfadapter, test_params):
configure_trimming_action(duthost, test_params['trim_buffer_profiles'][buffer_profile], "on")

with allure.step("Verify trimming packet"):
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
verify_trimmed_packet(**kwargs)

# When packet size is less than trimming size, the packet is not trimmed, but the DSCP value should be updated
with allure.step("Verify trim packet when packets size less than trimming size"):
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
kwargs.update({
'duthost': duthost,
'ptfadapter': ptfadapter,
'send_pkt_size': MIN_PACKET_SIZE,
'recv_pkt_size': MIN_PACKET_SIZE
})
Expand All @@ -149,28 +145,22 @@ def test_acl_action_with_trimming(self, duthost, ptfadapter, test_params, clean_
configure_trimming_action(duthost, test_params['trim_buffer_profiles'][buffer_profile], "on")

with allure.step("Verify trimming packet"):
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
verify_trimmed_packet(**kwargs)

with allure.step("Config ACL rule with DISABLE_TRIM_ACTION action"):
configure_trimming_acl(duthost, test_params['ingress_port']['name'])

with allure.step("Verify packets are dropped directly"):
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({
'duthost': duthost,
'ptfadapter': ptfadapter,
'expect_packets': False
})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
kwargs.update({'expect_packets': False})
verify_trimmed_packet(**kwargs)

with allure.step("Remove ACL table"):
cleanup_trimming_acl(duthost)

with allure.step("Send packets again and verify trimmed packets"):
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
verify_trimmed_packet(**kwargs)

def test_trimming_with_srv6(self, duthost, ptfadapter, setup_srv6, test_params):
Expand Down Expand Up @@ -198,7 +188,7 @@ def test_trimming_with_srv6(self, duthost, ptfadapter, setup_srv6, test_params):
block_queue=test_params['block_queue'],
send_pkt_size=DEFAULT_PACKET_SIZE,
send_pkt_dscp=DEFAULT_DSCP,
recv_pkt_size=TRIM_SIZE,
recv_pkt_size=PacketTrimmingConfig.get_trim_size(duthost),
recv_pkt_dscp=recv_pkt_dscp
)

Expand All @@ -216,8 +206,7 @@ def test_stability_during_feature_toggles(self, duthost, ptfadapter, test_params

with allure.step(f"Config and verify trimming in {self.trimming_mode} mode"):
self.configure_trimming_global_by_mode(duthost)
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
verify_trimmed_packet(**kwargs)

with allure.step("Disable trimming"):
Expand All @@ -226,12 +215,8 @@ def test_stability_during_feature_toggles(self, duthost, ptfadapter, test_params

with allure.step(f"Verify no trimming action in {self.trimming_mode} mode when disable trimming"):
self.configure_trimming_global_by_mode(duthost)
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({
'duthost': duthost,
'ptfadapter': ptfadapter,
'expect_packets': False
})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
kwargs.update({'expect_packets': False})
verify_trimmed_packet(**kwargs)

with allure.step("Enable trimming again"):
Expand All @@ -240,8 +225,7 @@ def test_stability_during_feature_toggles(self, duthost, ptfadapter, test_params

with allure.step(f"Verify trimming in {self.trimming_mode} mode after enable trimming"):
self.configure_trimming_global_by_mode(duthost)
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
verify_trimmed_packet(**kwargs)

with allure.step("Trimming config toggles"):
Expand All @@ -253,8 +237,7 @@ def test_stability_during_feature_toggles(self, duthost, ptfadapter, test_params

with allure.step(f"Verify trimming still works after feature toggles in {self.trimming_mode} mode"):
self.configure_trimming_global_by_mode(duthost)
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
verify_trimmed_packet(**kwargs)

def test_trimming_during_port_admin_toggle(self, duthost, ptfadapter, test_params):
Expand All @@ -273,8 +256,7 @@ def test_trimming_during_port_admin_toggle(self, duthost, ptfadapter, test_param
configure_trimming_action(duthost, test_params['trim_buffer_profiles'][buffer_profile], "on")

with allure.step("Verify trimming packet"):
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
verify_trimmed_packet(**kwargs)

with allure.step("Ports admin status toggles"):
Expand All @@ -292,8 +274,7 @@ def test_trimming_during_port_admin_toggle(self, duthost, ptfadapter, test_param
"Connected route is not ready")

with allure.step("Verify trimming still works after admin toggles"):
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
verify_trimmed_packet(**kwargs)

with allure.step("Verify packet trimming counter"):
Expand All @@ -317,8 +298,7 @@ def test_trimming_with_reload_and_reboot(self, duthost, ptfadapter, test_params,
configure_trimming_action(duthost, test_params['trim_buffer_profiles'][buffer_profile], "on")

with allure.step("Verify trimming packet"):
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
verify_trimmed_packet(**kwargs)

with allure.step("Randomly choose one action from reload/cold reboot"):
Expand Down Expand Up @@ -347,8 +327,7 @@ def test_trimming_with_reload_and_reboot(self, duthost, ptfadapter, test_params,
configure_packet_aging(duthost, disabled=True)

with allure.step(f"Verify trimming function in {self.trimming_mode} mode after reload/cold reboot"):
kwargs = self.get_verify_trimmed_packet_kwargs({**test_params})
kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
kwargs = self.get_verify_trimmed_packet_kwargs(duthost, ptfadapter, {**test_params})
verify_trimmed_packet(**kwargs)

with allure.step("Verify packet trimming counter"):
Expand All @@ -372,8 +351,7 @@ def test_trimming_counters(self, duthost, ptfadapter, test_params, trim_counter_
# Packets are trimmed on two queues, verify trimming counters in queue and port level
with allure.step("Verify trimming counters on two queues"):
# Trigger trimmed packets on queue0
counter_kwargs = self.get_verify_trimmed_counter_packet_kwargs({**trim_counter_params})
counter_kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter})
counter_kwargs = self.get_verify_trimmed_counter_packet_kwargs(duthost, ptfadapter, {**trim_counter_params})
verify_trimmed_packet(**counter_kwargs)

# Verify the consistency of the trim counter on the queue and the port level
Expand All @@ -399,18 +377,20 @@ def test_trimming_counters(self, duthost, ptfadapter, test_params, trim_counter_
"Trim sent counter on switch level is not equal to the sum of trim sent counter on port "
"level")

trim_queue = PacketTrimmingConfig.get_trim_queue(duthost)

with allure.step("Verify TrimDrop counters on switch level"):
original_schedulers = {}
try:
# Block the trimmed queue
for port in trim_counter_params['egress_ports']:
for dut_member in port['dut_members']:
original_scheduler = disable_egress_data_plane(duthost, dut_member, TRIM_QUEUE)
original_scheduler = disable_egress_data_plane(duthost, dut_member, trim_queue)
original_schedulers[dut_member] = original_scheduler

# Trigger trimmed packets on queue6
counter_kwargs = self.get_verify_trimmed_counter_packet_kwargs({**trim_counter_params})
counter_kwargs.update({'duthost': duthost, 'ptfadapter': ptfadapter, 'expect_packets': False})
counter_kwargs = self.get_verify_trimmed_counter_packet_kwargs(duthost, ptfadapter, {**trim_counter_params})
counter_kwargs.update({'expect_packets': False})
verify_trimmed_packet(**counter_kwargs)

# Get the TrimDrop counters on switch level
Expand All @@ -423,10 +403,10 @@ def test_trimming_counters(self, duthost, ptfadapter, test_params, trim_counter_
for port in trim_counter_params['egress_ports']:
for dut_member in port['dut_members']:
original_scheduler = original_schedulers.get(dut_member)
enable_egress_data_plane(duthost, dut_member, TRIM_QUEUE, original_scheduler)
enable_egress_data_plane(duthost, dut_member, trim_queue, original_scheduler)

with allure.step("Verify trimming counter when trimming feature toggles"):
trim_queue = 'UC'+str(TRIM_QUEUE)
trim_queue = 'UC'+str(trim_queue)

# Get queue level and port level counter when trimming is enabled
port = test_params['egress_ports'][0]['dut_members'][0]
Expand Down
36 changes: 3 additions & 33 deletions tests/packet_trimming/constants.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
# Default values for trimming configuration
TRIM_SIZE = 256
TRIM_DSCP = 48
TRIM_QUEUE = 6
TRIM_SIZE_MAX = 4084

VALID_TRIMMING_CONFIGS_SYM = [
(300, 32, 5), # Valid values
(256, 0, 0), # Min Boundary values
(4084, 63, 7) # Max Boundary values
]

INVALID_TRIMMING_CONFIGS_SYM = [
(1.1, 32, 5), # Invalid size value
(256, -1, 5), # Invalid dscp value
(256, 63, -3.0) # Invalid queue value
]

VALID_TRIMMING_CONFIGS_ASYM = [
(300, 'from-tc', 3, 5), # Valid values
(256, 'from-tc', 0, 0), # Min Boundary values
(4084, 'from-tc', 6, 14) # Max Boundary values
]

INVALID_TRIMMING_CONFIGS_ASYM = [
(1.1, 'from-tc', 3, 5), # Invalid size value
(256, 'test', 3, 5), # Invalid dscp value
(256, 'from-tc', -3.0, 5), # Invalid queue value
(300, 'from-tc', 3, 256) # Invalid tc value
]
from tests.packet_trimming.packet_trimming_config import PacketTrimmingConfig

# ACL configuration constants
ACL_TABLE_TYPE_NAME = "TRIMMING_L3"
Expand Down Expand Up @@ -63,7 +34,6 @@
STATIC_THRESHOLD_MULTIPLIER = 1.5 # Multiplier to ensure the buffer can be fully exhausted

# Asymmetric DSCP constants
ASYM_TC = TRIM_QUEUE
ASYM_PORT_1_DSCP = 10
ASYM_PORT_2_DSCP = 20

Expand Down Expand Up @@ -115,7 +85,7 @@
'dst_ipv6': '2001:1000:0100:0200::',
'exp_dst_ipv6': '2001:1000:0200::',
'exp_inner_dscp_pipe': None,
'exp_outer_dscp_uniform': TRIM_DSCP << 2,
'exp_outer_dscp_uniform': PacketTrimmingConfig.DSCP << 2,
'exp_srh_seg_left': None,
'inner_pkt_ver': '4',
'exp_process_result': 'forward',
Expand All @@ -133,7 +103,7 @@
'dst_ipv6': '2001:3000:0500::',
'exp_dst_ipv6': '2001:3000:0500:0600::',
'exp_inner_dscp_pipe': None,
'exp_outer_dscp_uniform': TRIM_DSCP << 2,
'exp_outer_dscp_uniform': PacketTrimmingConfig.DSCP << 2,
'exp_srh_seg_left': 0,
'inner_pkt_ver': '4',
'exp_process_result': 'forward'
Expand Down
Loading
Loading