T-Rex API -issue in updating the rate multiplier

167 views
Skip to first unread message

Jony Singer

unread,
May 22, 2023, 9:44:46 AM5/22/23
to TRex Traffic Generator
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

Besart Dollma

unread,
May 24, 2023, 3:12:04 AM5/24/23
to TRex Traffic Generator
Avoid this client, it is old and deprecated. 
Move to ASTF please.
Thanks

Jony Singer

unread,
May 24, 2023, 8:42:18 AM5/24/23
to TRex Traffic Generator
In the code I provided I enabled astf under start trex (astf=True)
so what library should I use?
Thank you in advance.
Jony
ב-יום רביעי, 24 במאי 2023 בשעה 10:12:04 UTC+3, besi7...@gmail.com כתב/ה:

Besart Dollma

unread,
May 31, 2023, 3:39:53 AM5/31/23
to TRex Traffic Generator

Jony Singer

unread,
Jun 8, 2023, 5:23:15 AM6/8/23
to TRex Traffic Generator
Hi, thanks for response.
Can i have an example of connection with trex_astf_client please?
From what i understood, the connection is no longer using the trex daemon server so how can i make the script perform the same actions that are written here:
trex.start_trex(
c=4, # Number of cores
m=cps, # Packet size (rate multiplier)
f='astf/dns-.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-.cfg' # Configuration file
)
With a specific configuration file and traffic file.
How exactly is the connection made and what must be in the server to enable the connection.
When i tried to make a connection with astf i got an error : trex_client.interactive.trex.common.trex_exceptions.TRexError: *** [RPC] - Failed to get server response from tcp://1.1.1.1:4500



ב-יום רביעי, 31 במאי 2023 בשעה 10:39:53 UTC+3, besi7...@gmail.com כתב/ה:
Reply all
Reply to author
Forward
0 new messages