Hi all, I'm writing python script with T-Rex API using stf lib: from .trex_stf_lib.trex_client.
In my code I want it to run a DNS CPS test,
and if its all goes right then i want to increase the rate multiplier
(when i said "all goes right i mean there were no drops in all test).
I want it to happen in the same session as started,
mean when i stared the test with rate of 1,000 CPS and all test passed
without and trop, i want to increase the CPS in some multiplier and
start all test with the new CPS rate, but without stop and start new session.
I’m adding here the code I wrote so far,
in my code it’s terminating the TRex session and starting a new one each time (if it didn’t find any drops)
I would like to avoid that and to be able to increase “m” without terminating the session
is it possible?
from trex_client.stf.trex_stf_lib.trex_client import CTRexClient, CTRexResult
import time
import json
# Output Filename JSON-Format
filename = "log-trex.json"
cps = 1000 # Initial Rate Multiplier
trex = CTRexClient(trex_host='1.1.1.1', max_history_size=100)
while True:
trex.start_trex(
c=4, # Number of cores
m=cps, # Rate Multiplier
f='astf/dns-CDP-File.py', # Test file
k=10, # run traffic for warm up
d=30, # Duration
astf=True, # Enable ASTF mode
nc=True, # if it's true, no wait
cfg='/etc/trex-config.cfg' # Configuration file
)
print("Started TRex...")
result = CTRexResult(max_history_size=100, filtered_latency_amount=0.001)
last_res = dict()
while trex.is_running(dump_out=last_res):
obj: result = trex.get_result_obj()
# Get the live statistics
live_stats = trex.get_result_obj().get_value_list('*')
# Iterate over each "trex-global" object in live_stats
for item in live_stats:
trex_global = item.get('trex-global')
if trex_global:
# Check the required parameters
m_total_queue_drop = trex_global['data'].get('m_total_queue_drop')
m_rx_drop_bps = trex_global['data'].get('m_rx_drop_bps')
m_tx_cps = trex_global['data'].get('m_tx_cps')
print("Running DNS CPS with " + str(m_tx_cps) + " CPS")
# Compare the values
if m_total_queue_drop == 0 and m_rx_drop_bps == 0.0:
print("No errors or drops occurred")
else:
print("**DROP** Parameters are not equal for 'trex-global'")
print(m_rx_drop_bps)
print(m_total_queue_drop)
time.sleep(1) # Delay between printing live statistics
ret = trex.stop_trex()
# Read the result object
result_obj = trex.get_result_obj()
# Get the result value list
result_value_list = result_obj.get_value_list('*')
# Save the result to JSON file
with open(filename, 'w') as file:
json.dump(result_value_list, file, indent=4)
print("Saved results to", filename)
print("Terminating TRex...")
# Check if both m_total_queue_drop and m_rx_drop_bps are 0.0
if m_total_queue_drop == 0 and m_rx_drop_bps == 0.0:
cps += 1000 # Increase Rate Multiplier by 1000 for the next iteration
else:
break # Stop the loop if there are drops or errors