Client Utilities

TRex YAML generator

class trex_yaml_gen.CTRexYaml(trex_files_path)[source]

This class functions as a YAML generator according to TRex YAML format.

CTRexYaml is compatible with both Python 2 and Python 3.

The initialization of this class creates a CTRexYaml object with empty ‘cap-info’, and with default client-server configuration.

Use class methods to add and assign pcap files and export the data to a YAML file.

Parameters:
trex_files_path : str

a path (on TRex server side) for the pcap files using which TRex can access it.

add_pcap_file(local_pcap_path)[source]

Adds a .pcap file with recorded traffic to the yaml object by linking the file with ‘cap-info’ template key fields.

Parameters:
local_pcap_path : str

a path (on client side) for the pcap file to be added.

Returns:

  • The index of the inserted item (as int) if item added successfully
  • -1 if pcap file already exists in ‘cap_info’.

dump()[source]

dumps with nice indentation the YAML format of the currently built yaml object.

Parameters:None
Returns:None
dump_as_python_obj()[source]

dumps with nice indentation the pythonic format (dictionaries and lists) of the currently built yaml object.

Parameters:None
Returns:None
get_file_list()[source]

Returns a list of all files related to the YAML object, including the YAML filename itself.

Tip

This method is especially useful for listing all the files that should be pushed to TRex server as part of the same yaml selection.

Parameters:None
Returns:a list of filepaths, each is a local client-machine file path.
get_pcap_idx(pcap_name)[source]

Checks if a certain .pcap file has been added into the yaml object.

Parameters:
pcap_name : str

the name of the pcap file to be searched

Returns:

  • The index of the pcap file (as int) if exists
  • -1 if not exists.

set_cap_info_param(param, value, seq)[source]

Set cap-info parameters’ value of a specific pcap file.

Parameters:
param : str

the name of the parameters to be set.

value : int/float

the desired value to be set to param key.

seq : int

an index to the relevant caps array to be changed (index supplied when adding new pcap file, see add_pcap_file()).

Returns:

True on success

Raises:

IndexError, in case an out-of range index was given.

set_generator_param(param, value)[source]

Set generator parameters’ value of the yaml object.

Parameters:
param : str

the name of the parameters to be set.

value : int/float/str

the desired value to be set to param key.

Returns:

None

to_yaml(filename)[source]

Exports to YAML file the built configuration into an actual YAML file.

Parameters:
filename : str

a path (on client side, including filename) to store the generated yaml file.

Returns:

None

Raises:
  • ValueError, in case no pcap files has been added to the object.
  • EnvironmentError, in case of any IO error of writing to the files or OSError when trying to open it for writing.

General Utilities

general_utils.find_path_to_pardir(pardir, base_path='/auto/srg-sce-swinfra-usr/emb/users/hhaim/work/depot/asr1k/emb/private/hhaim/bp_sim_git/trex-core/scripts/automation/trex_control_plane/doc')[source]

Finds the absolute path for some parent dir pardir, starting from base_path

The request is only valid if the stop initiator is the same client as the TRex run initiator.

Parameters:
pardir : str

name of an upper-level directory to which we want to find an absolute path for

base_path : str

a full (usually nested) path from which we want to find a parent folder.

default value : current working dir

Returns:

string representation of the full path to

general_utils.id_count_gen()[source]

A generator for creating an increasing id for objects, starting from 0

Parameters:None
Returns:an id (unsigned int) with each next() request.
general_utils.random_id_gen(length=8)[source]

A generator for creating a random chars id of specific length

Parameters:
length : int

the desired length of the generated id

default: 8

Returns:

a random id with each next() request.