From f9d3363ff9ad5d268b518e8bdd3356b983d30fe7 Mon Sep 17 00:00:00 2001 From: afaure Date: Fri, 27 Jun 2025 16:08:45 +0200 Subject: [PATCH 1/3] fix ASTF python api l7_percent bug --- .../trex/astf/trex_astf_profile.py | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py b/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py index 1969003b80..78d21ff2a8 100644 --- a/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py +++ b/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py @@ -2100,13 +2100,31 @@ def __init__(self, default_ip_gen, default_c_glob_info=None, default_s_glob_info d_ports[d_port] = cap_file all_cap_info.append({"ip_gen": ip_gen, "prog_c": prog_c, "prog_s": prog_s, "glob_c": glob_c, "glob_s": glob_s, - "cps": cps, "d_port": d_port, "my_assoc": my_assoc,"limit":cap.limit, "cont":cap.cont, "tg_name": cap.tg_name}) + "cps": cps, "l7_percent": l7_percent, "d_port": d_port, "my_assoc": my_assoc,"limit":cap.limit, "cont":cap.cont, "tg_name": cap.tg_name}) # calculate cps from l7 percent + # first know how much percent it represents from the trafic + # 100 | ? + # total_payload | payload_len + # + # trafic percent = payload * 100 / total_payload + # + # then go from actual trafic percent to expected trafic percent + # + # 1 cps | trafic percent + # ? cps | expected_percent + # + # final_cps = expected_percent / trafic_percent if mode == "l7_percent": percent_sum = 0 for c in all_cap_info: - c["cps"] = c["prog_c"].payload_len * 100.0 / total_payload - percent_sum += c["cps"] + payload_percent = c["prog_c"].payload_len * 100.0 / total_payload + + target_cps = c["l7_percent"] / payload_percent + + if target_cps < 0.5: # avoid format error + target_cps = 0.5 + + percent_sum += c["l7_percent"] if percent_sum != 100: raise ASTFError("l7_percent values must sum up to 100") From 388165384826c74322ac21fe3b1b0919260f43dd Mon Sep 17 00:00:00 2001 From: afaure Date: Fri, 27 Jun 2025 16:43:17 +0200 Subject: [PATCH 2/3] improve l7_percent bug fix --- .../interactive/trex/astf/trex_astf_profile.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py b/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py index 78d21ff2a8..c774fddd23 100644 --- a/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py +++ b/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py @@ -2119,11 +2119,13 @@ def __init__(self, default_ip_gen, default_c_glob_info=None, default_s_glob_info for c in all_cap_info: payload_percent = c["prog_c"].payload_len * 100.0 / total_payload - target_cps = c["l7_percent"] / payload_percent - if target_cps < 0.5: # avoid format error - target_cps = 0.5 + # the 10 here is because Trex doesnt like CPS under 0.5 + # so we try to go up an order of magnitude + # since most users will just multiply this again with the global multiplier after + target_cps = c["l7_percent"] / payload_percent * 10.0 + c["cps"] = target_cps percent_sum += c["l7_percent"] if percent_sum != 100: raise ASTFError("l7_percent values must sum up to 100") From 902824997a12458dd75c5a1bf92c8fcda8aaf2d7 Mon Sep 17 00:00:00 2001 From: afaure Date: Fri, 27 Jun 2025 17:16:24 +0200 Subject: [PATCH 3/3] more elegant solution for the 0,5 cps limit --- .../interactive/trex/astf/trex_astf_profile.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py b/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py index c774fddd23..ab739faf96 100644 --- a/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py +++ b/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_profile.py @@ -2115,6 +2115,7 @@ def __init__(self, default_ip_gen, default_c_glob_info=None, default_s_glob_info # # final_cps = expected_percent / trafic_percent if mode == "l7_percent": + lowest = 1 percent_sum = 0 for c in all_cap_info: payload_percent = c["prog_c"].payload_len * 100.0 / total_payload @@ -2123,12 +2124,20 @@ def __init__(self, default_ip_gen, default_c_glob_info=None, default_s_glob_info # the 10 here is because Trex doesnt like CPS under 0.5 # so we try to go up an order of magnitude # since most users will just multiply this again with the global multiplier after - target_cps = c["l7_percent"] / payload_percent * 10.0 + target_cps = c["l7_percent"] / payload_percent c["cps"] = target_cps + + if target_cps < lowest: + lowest = target_cps percent_sum += c["l7_percent"] if percent_sum != 100: raise ASTFError("l7_percent values must sum up to 100") + # normalize it all so that lowest = 1 + mult = 1 / lowest + for c in all_cap_info: + c["cps"] = c["cps"] * mult + for c in all_cap_info: temp_c = ASTFTCPClientTemplate(program=c["prog_c"], glob_info=c["glob_c"], ip_gen=c["ip_gen"], port=c["d_port"],