summaryrefslogtreecommitdiffstats
path: root/scripts/automation
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/automation')
-rwxr-xr-xscripts/automation/trex_control_plane/doc/conf.py8
-rw-r--r--scripts/automation/trex_control_plane/doc_stl/Makefile192
-rw-r--r--scripts/automation/trex_control_plane/doc_stl/_static/no_scrollbars.css10
-rw-r--r--scripts/automation/trex_control_plane/doc_stl/api/client_code.rst17
-rw-r--r--scripts/automation/trex_control_plane/doc_stl/api/index.rst13
-rw-r--r--scripts/automation/trex_control_plane/doc_stl/conf.py312
-rw-r--r--scripts/automation/trex_control_plane/doc_stl/index.rst31
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py696
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py67
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py234
10 files changed, 1318 insertions, 262 deletions
diff --git a/scripts/automation/trex_control_plane/doc/conf.py b/scripts/automation/trex_control_plane/doc/conf.py
index aeee475f..9d32ca24 100755
--- a/scripts/automation/trex_control_plane/doc/conf.py
+++ b/scripts/automation/trex_control_plane/doc/conf.py
@@ -123,10 +123,12 @@ todo_include_todos = True
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
-html_theme = 'sphinx_rtd_theme'
-html_theme_options = {
+#html_theme = 'sphinx_rtd_theme'
+html_theme = 'classic'
+
+#html_theme_options = {
# "rightsidebar": "true"
- }
+ # }
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
diff --git a/scripts/automation/trex_control_plane/doc_stl/Makefile b/scripts/automation/trex_control_plane/doc_stl/Makefile
new file mode 100644
index 00000000..37a28d0f
--- /dev/null
+++ b/scripts/automation/trex_control_plane/doc_stl/Makefile
@@ -0,0 +1,192 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER =
+BUILDDIR = _build
+
+# User-friendly check for sphinx-build
+ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
+$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
+endif
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext
+
+help:
+ @echo "Please use \`make <target>' where <target> is one of"
+ @echo " html to make standalone HTML files"
+ @echo " dirhtml to make HTML files named index.html in directories"
+ @echo " singlehtml to make a single large HTML file"
+ @echo " pickle to make pickle files"
+ @echo " json to make JSON files"
+ @echo " htmlhelp to make HTML files and a HTML help project"
+ @echo " qthelp to make HTML files and a qthelp project"
+ @echo " applehelp to make an Apple Help Book"
+ @echo " devhelp to make HTML files and a Devhelp project"
+ @echo " epub to make an epub"
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
+ @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
+ @echo " text to make text files"
+ @echo " man to make manual pages"
+ @echo " texinfo to make Texinfo files"
+ @echo " info to make Texinfo files and run them through makeinfo"
+ @echo " gettext to make PO message catalogs"
+ @echo " changes to make an overview of all changed/added/deprecated items"
+ @echo " xml to make Docutils-native XML files"
+ @echo " pseudoxml to make pseudoxml-XML files for display purposes"
+ @echo " linkcheck to check all external links for integrity"
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
+ @echo " coverage to run coverage check of the documentation (if enabled)"
+
+clean:
+ rm -rf $(BUILDDIR)/*
+
+html:
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+ @echo
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+ @echo
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/T-RexProjectControlPlain.qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/T-RexProjectControlPlain.qhc"
+
+applehelp:
+ $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
+ @echo
+ @echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
+ @echo "N.B. You won't be able to view it unless you put it in" \
+ "~/Library/Documentation/Help or install it in your application" \
+ "bundle."
+
+devhelp:
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+ @echo
+ @echo "Build finished."
+ @echo "To view the help file:"
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/T-RexProjectControlPlain"
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/T-RexProjectControlPlain"
+ @echo "# devhelp"
+
+epub:
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+ @echo
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
+ "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through pdflatex..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+latexpdfja:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through platex and dvipdfmx..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+ @echo
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+ @echo
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo
+ @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+ @echo "Run \`make' in that directory to run these through makeinfo" \
+ "(use \`make info' here to do that automatically)."
+
+info:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo "Running Texinfo files through makeinfo..."
+ make -C $(BUILDDIR)/texinfo info
+ @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+ $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+ @echo
+ @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+ @echo
+ @echo "Link check complete; look for any errors in the above output " \
+ "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
+
+coverage:
+ $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
+ @echo "Testing of coverage in the sources finished, look at the " \
+ "results in $(BUILDDIR)/coverage/python.txt."
+
+xml:
+ $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
+ @echo
+ @echo "Build finished. The XML files are in $(BUILDDIR)/xml."
+
+pseudoxml:
+ $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
+ @echo
+ @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
diff --git a/scripts/automation/trex_control_plane/doc_stl/_static/no_scrollbars.css b/scripts/automation/trex_control_plane/doc_stl/_static/no_scrollbars.css
new file mode 100644
index 00000000..f86e823a
--- /dev/null
+++ b/scripts/automation/trex_control_plane/doc_stl/_static/no_scrollbars.css
@@ -0,0 +1,10 @@
+/* override table width restrictions */
+.wy-table-responsive table td, .wy-table-responsive table th {
+ /* !important prevents the common CSS stylesheets from
+ overriding this as on RTD they are loaded after this stylesheet */
+ white-space: normal !important;
+}
+
+.wy-table-responsive {
+ overflow: visible !important;
+} \ No newline at end of file
diff --git a/scripts/automation/trex_control_plane/doc_stl/api/client_code.rst b/scripts/automation/trex_control_plane/doc_stl/api/client_code.rst
new file mode 100644
index 00000000..ef7feb61
--- /dev/null
+++ b/scripts/automation/trex_control_plane/doc_stl/api/client_code.rst
@@ -0,0 +1,17 @@
+
+Module documentation
+================================
+
+STLClient class
+-----------------
+
+.. autoclass:: trex_stl_lib.trex_stl_client.STLClient
+ :members:
+
+Stream class
+-----------------
+
+.. automodule:: trex_stl_lib.trex_stl_streams
+ :members:
+
+
diff --git a/scripts/automation/trex_control_plane/doc_stl/api/index.rst b/scripts/automation/trex_control_plane/doc_stl/api/index.rst
new file mode 100644
index 00000000..4e4be230
--- /dev/null
+++ b/scripts/automation/trex_control_plane/doc_stl/api/index.rst
@@ -0,0 +1,13 @@
+
+TRex Stateless API Reference
+============================
+
+**TRex Modules**
+
+.. toctree::
+ :maxdepth: 4
+
+ client_code
+
+**TRex JSON Template**
+
diff --git a/scripts/automation/trex_control_plane/doc_stl/conf.py b/scripts/automation/trex_control_plane/doc_stl/conf.py
new file mode 100644
index 00000000..fe6b27bc
--- /dev/null
+++ b/scripts/automation/trex_control_plane/doc_stl/conf.py
@@ -0,0 +1,312 @@
+# -*- coding: utf-8 -*-
+#
+# TRex Control Plain documentation build configuration file, created by
+# sphinx-quickstart on Tue Jun 2 07:48:10 2015.
+#
+# This file is execfile()d with the current directory set to its
+# containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys
+import os
+import shlex
+
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+sys.path.insert(0, os.path.abspath('../stl'))
+## add all external libs path manually
+external_libs_path = os.path.join(os.pardir, os.pardir, os.pardir, "external_libs")
+external_libs_pkgs = [os.path.join(external_libs_path, p)
+ for p in os.listdir(external_libs_path)
+ if os.path.isdir(os.path.join(external_libs_path, p))]
+for p in external_libs_pkgs:
+ sys.path.insert(1, p)
+
+# -- General configuration ------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+ 'sphinx.ext.autodoc',
+ 'sphinx.ext.todo',
+ 'sphinx.ext.viewcode',
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix(es) of source filenames.
+# You can specify multiple suffix as a list of string:
+# source_suffix = ['.rst', '.md']
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'TRex Stateless Python API'
+copyright = u'2015, Cisco Systems Inc.'
+author = u'TRex team, Cisco Systems Inc.'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '1.94'
+# The full version, including alpha/beta/rc tags.
+release = '1.7.1'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#
+# This is also used if you do content translation via gettext catalogs.
+# Usually you set "language" from the command line for these cases.
+language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = ['_build']
+
+# The reST default role (used for this markup: `text`) to use for all
+# documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+# If true, keep warnings as "system message" paragraphs in the built documents.
+#keep_warnings = False
+
+# If true, `todo` and `todoList` produce output, else they produce nothing.
+todo_include_todos = True
+
+
+# -- Options for HTML output ----------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+#html_theme = 'sphinx_rtd_theme'
+html_theme = 'classic'
+#html_theme = 'sphinxdoc'
+
+#html_theme_options = {
+# "rightsidebar": "true"
+# }
+
+autodoc_docstring_signature = True
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further. For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents. If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar. Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# Add any extra paths that contain custom files (such as robots.txt or
+# .htaccess) here, relative to this directory. These files are copied
+# directly to the root of the documentation.
+#html_extra_path = []
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it. The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Language to be used for generating the HTML full-text search index.
+# Sphinx supports the following languages:
+# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
+# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr'
+#html_search_language = 'en'
+
+# A dictionary with options for the search language support, empty by default.
+# Now only 'ja' uses this config value
+#html_search_options = {'type': 'default'}
+
+# The name of a javascript file (relative to the configuration directory) that
+# implements a search results scorer. If empty, the default will be used.
+#html_search_scorer = 'scorer.js'
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'TRexControlPlaindoc'
+
+# -- Options for LaTeX output ---------------------------------------------
+
+latex_elements = {
+# The paper size ('letterpaper' or 'a4paper').
+#'papersize': 'letterpaper',
+
+# The font size ('10pt', '11pt' or '12pt').
+#'pointsize': '10pt',
+
+# Additional stuff for the LaTeX preamble.
+#'preamble': '',
+
+# Latex figure (float) alignment
+#'figure_align': 'htbp',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title,
+# author, documentclass [howto, manual, or own class]).
+latex_documents = [
+ (master_doc, 'TRexControlPlain.tex', u'TRex Control Plain Documentation',
+ u'hhaim', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output ---------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+ (master_doc, 'TRexcontrolplain', u'TRex Control Plain Documentation',
+ [author], 1)
+]
+
+# If true, show URL addresses after external links.
+#man_show_urls = False
+
+
+# -- Options for Texinfo output -------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+# dir menu entry, description, category)
+texinfo_documents = [
+ (master_doc, 'TRexControlPlain', u'TRex Control Plain Documentation',
+ author, 'TRexControlPlain', 'One line description of project.',
+ 'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#texinfo_appendices = []
+
+# If false, no module index is generated.
+#texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#texinfo_show_urls = 'footnote'
+
+# If true, do not generate a @detailmenu in the "Top" node's menu.
+#texinfo_no_detailmenu = False
+
+
+# show documentation for both __init__ methods and class methods
+autoclass_content = "both"
+
+# A workaround for the responsive tables always having annoying scrollbars.
+def setup(app):
+ app.add_stylesheet("no_scrollbars.css") \ No newline at end of file
diff --git a/scripts/automation/trex_control_plane/doc_stl/index.rst b/scripts/automation/trex_control_plane/doc_stl/index.rst
new file mode 100644
index 00000000..fe58db25
--- /dev/null
+++ b/scripts/automation/trex_control_plane/doc_stl/index.rst
@@ -0,0 +1,31 @@
+.. TRex Stateless Python API documentation
+ sphinx-quickstart on Tue Jun 2 07:48:10 2015.
+ contain the root `toctree` directive.
+
+TRex Stateless Python API
+==============================================
+
+TRex is a **traffic generator**
+
+This site covers the Python API of TRex and explains how to utilize it to your needs.
+To understand the entirely how the API works and how to set up the server side, check out the `trex-core Wiki <https://github.com/cisco-system-traffic-generator/trex-core/wiki>`_ under the documentation section of TRex website.
+
+**Use the table of contents below or the menu to your left to navigate through the site**
+
+API Reference
+=============
+.. toctree::
+ :maxdepth: 2
+
+ api/index
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+
+
+.. rubric:: Footnotes
+
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
index 5ecb1120..c7503ab0 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
@@ -13,7 +13,7 @@ from trex_stl_async_client import CTRexAsyncClient
from utils import parsing_opts, text_tables, common
from utils.text_opts import *
-
+from functools import wraps
from collections import namedtuple
from yaml import YAMLError
@@ -380,7 +380,7 @@ class CCommLink(object):
############################ #############################
class STLClient(object):
- """docstring for STLClient"""
+ """TRex Stateless client object- gives operations per TRex/user"""
def __init__(self,
username = common.get_current_user(),
@@ -390,7 +390,29 @@ class STLClient(object):
verbose_level = LoggerApi.VERBOSE_QUIET,
logger = None,
virtual = False):
+ """
+ Set the connection setting
+
+ :parameters:
+ username : string
+ the user name, for example imarom
+
+ server : string
+ the server name or ip
+ sync_port : int
+ the RPC port
+
+ async_port : int
+ the ASYNC port
+
+ :return:
+ None
+
+ :raises:
+ None
+
+ """
self.username = username
@@ -835,6 +857,7 @@ class STLClient(object):
def __api_check(connected = True):
def wrap (f):
+ @wraps(f)
def wrap2(*args, **kwargs):
client = args[0]
@@ -873,36 +896,141 @@ class STLClient(object):
# return verbose level of the logger
def get_verbose (self):
+ """
+ get the verbose mode
+
+ :parameters:
+ none
+
+ :return:
+ get the verbose mode as Bool
+
+ :raises:
+ None
+
+ """
return self.logger.get_verbose()
# is the client on read only mode ?
def is_all_ports_acquired (self):
+ """
+ is_all_ports_acquired
+
+ :parameters:
+ none
+
+ :return:
+ return True if all ports are acquired
+
+ :raises:
+ None
+
+ """
+
return not (self.get_all_ports() == self.get_acquired_ports())
# is the client connected ?
def is_connected (self):
+ """
+
+ :parameters:
+ none
+
+ :return:
+ is_connected
+
+ :raises:
+ None
+
+ """
+
return self.connected and self.comm_link.is_connected
# get connection info
def get_connection_info (self):
+ """
+
+ :parameters:
+ none
+
+ :return:
+ connection dict
+
+ :raises:
+ None
+
+ """
+
return self.connection_info
# get supported commands by the server
def get_server_supported_cmds(self):
+ """
+
+ :parameters:
+ none
+
+ :return:
+ connection dict
+
+ :raises:
+ None
+
+ """
+
return self.supported_cmds
# get server version
def get_server_version(self):
+ """
+
+ :parameters:
+ none
+
+ :return:
+ connection dict
+
+ :raises:
+ None
+
+ """
+
return self.server_version
# get server system info
def get_server_system_info(self):
+ """
+
+ :parameters:
+ none
+
+ :return:
+ connection dict
+
+ :raises:
+ None
+
+ """
+
return self.system_info
# get port count
def get_port_count(self):
+ """
+
+ :parameters:
+ none
+
+ :return:
+ connection dict
+
+ :raises:
+ None
+
+ """
+
return len(self.ports)
@@ -917,6 +1045,19 @@ class STLClient(object):
# get all ports as IDs
def get_all_ports (self):
+ """
+
+ :parameters:
+ none
+
+ :return:
+ connection dict
+
+ :raises:
+ None
+
+ """
+
return self.ports.keys()
# get all acquired ports
@@ -982,20 +1123,20 @@ class STLClient(object):
############################ #############################
- """
- Sets verbose level
+ def set_verbose (self, level):
+ """
+ Sets verbose level
- :parameters:
- level : str
- "high"
- "low"
- "normal"
+ :parameters:
+ level : str
+ "high"
+ "low"
+ "normal"
- :raises:
- None
+ :raises:
+ None
- """
- def set_verbose (self, level):
+ """
modes = {'low' : LoggerApi.VERBOSE_QUIET, 'normal': LoggerApi.VERBOSE_REGULAR, 'high': LoggerApi.VERBOSE_HIGH}
if not level in modes.keys():
@@ -1004,35 +1145,38 @@ class STLClient(object):
self.logger.set_verbose(modes[level])
- """
- Connects to the TRex server
+ @__api_check(False)
+ def connect (self):
+ """
+ def connect(self):
- :parameters:
- None
+ Connects to the TRex server
- :raises:
- + :exc:`STLError`
+ :parameters:
+ None
+
+ :raises:
+ + :exc:`STLError`
+
+ """
- """
- @__api_check(False)
- def connect (self):
rc = self.__connect()
if not rc:
raise STLError(rc)
- """
- Disconnects from the server
-
- :parameters:
- stop_traffic : bool
- tries to stop traffic before disconnecting
- release_ports : bool
- tries to release all the acquired ports
-
- """
@__api_check(False)
def disconnect (self, stop_traffic = True, release_ports = True):
+ """
+ Disconnects from the server
+
+ :parameters:
+ stop_traffic : bool
+ tries to stop traffic before disconnecting
+ release_ports : bool
+ tries to release all the acquired ports
+
+ """
# try to stop ports but do nothing if not possible
if stop_traffic:
@@ -1049,21 +1193,21 @@ class STLClient(object):
- """
- Acquires ports for executing commands
+ @__api_check(True)
+ def acquire (self, ports = None, force = False):
+ """
+ Acquires ports for executing commands
- :parameters:
- ports : list
- ports to execute the command
- force : bool
- force acquire the ports
+ :parameters:
+ ports : list
+ ports to execute the command
+ force : bool
+ force acquire the ports
- :raises:
- + :exc:`STLError`
+ :raises:
+ + :exc:`STLError`
- """
- @__api_check(True)
- def acquire (self, ports = None, force = False):
+ """
# by default use all ports
ports = ports if ports is not None else self.get_all_ports()
@@ -1084,19 +1228,19 @@ class STLClient(object):
raise STLError(rc)
- """
- Release ports
+ @__api_check(True)
+ def release (self, ports = None):
+ """
+ Release ports
- :parameters:
- ports : list
- ports to execute the command
+ :parameters:
+ ports : list
+ ports to execute the command
- :raises:
- + :exc:`STLError`
+ :raises:
+ + :exc:`STLError`
- """
- @__api_check(True)
- def release (self, ports = None):
+ """
ports = ports if ports is not None else self.get_acquired_ports()
ports = self._validate_port_list(ports)
@@ -1108,19 +1252,20 @@ class STLClient(object):
if not rc:
raise STLError(rc)
- """
- Pings the server
+ @__api_check(True)
+ def ping(self):
+ """
+ Pings the server
- :parameters:
- None
-
+ :parameters:
+ None
- :raises:
- + :exc:`STLError`
- """
- @__api_check(True)
- def ping(self):
+ :raises:
+ + :exc:`STLError`
+
+ """
+
self.logger.pre_cmd( "Pinging the server on '{0}' port '{1}': ".format(self.connection_info['server'],
self.connection_info['sync_port']))
rc = self._transmit("ping")
@@ -1132,6 +1277,18 @@ class STLClient(object):
@__api_check(True)
def get_active_pgids(self):
+ """
+ Get active group ids
+
+ :parameters:
+ None
+
+
+ :raises:
+ + :exc:`STLError`
+
+ """
+
self.logger.pre_cmd( "Getting active packet group ids")
rc = self._transmit("get_active_pgids")
@@ -1142,20 +1299,21 @@ class STLClient(object):
raise STLError(rc)
- """
- force acquire ports, stop the traffic, remove all streams and clear stats
+ @__api_check(True)
+ def reset(self, ports = None):
+ """
+ force acquire ports, stop the traffic, remove all streams and clear stats
- :parameters:
- ports : list
- ports to execute the command
-
+ :parameters:
+ ports : list
+ ports to execute the command
- :raises:
- + :exc:`STLError`
- """
- @__api_check(True)
- def reset(self, ports = None):
+ :raises:
+ + :exc:`STLError`
+
+ """
+
ports = ports if ports is not None else self.get_all_ports()
ports = self._validate_port_list(ports)
@@ -1166,20 +1324,21 @@ class STLClient(object):
self.clear_stats(ports)
- """
- remove all streams from port(s)
+ @__api_check(True)
+ def remove_all_streams (self, ports = None):
+ """
+ remove all streams from port(s)
- :parameters:
- ports : list
- ports to execute the command
-
+ :parameters:
+ ports : list
+ ports to execute the command
- :raises:
- + :exc:`STLError`
- """
- @__api_check(True)
- def remove_all_streams (self, ports = None):
+ :raises:
+ + :exc:`STLError`
+
+ """
+
ports = ports if ports is not None else self.get_acquired_ports()
ports = self._validate_port_list(ports)
@@ -1192,24 +1351,25 @@ class STLClient(object):
raise STLError(rc)
- """
- add a list of streams to port(s)
+ @__api_check(True)
+ def add_streams (self, streams, ports = None):
+ """
+ add a list of streams to port(s)
- :parameters:
- ports : list
- ports to execute the command
- streams: list
- streams to attach (or profile)
+ :parameters:
+ ports : list
+ ports to execute the command
+ streams: list
+ streams to attach (or profile)
- :returns:
- list of stream IDs in order of the stream list
+ :returns:
+ list of stream IDs in order of the stream list
- :raises:
- + :exc:`STLError`
+ :raises:
+ + :exc:`STLError`
+
+ """
- """
- @__api_check(True)
- def add_streams (self, streams, ports = None):
ports = ports if ports is not None else self.get_acquired_ports()
ports = self._validate_port_list(ports)
@@ -1235,22 +1395,23 @@ class STLClient(object):
return [stream.get_id() for stream in streams]
- """
- remove a list of streams from ports
+ @__api_check(True)
+ def remove_streams (self, stream_id_list, ports = None):
+ """
+ remove a list of streams from ports
- :parameters:
- ports : list
- ports to execute the command
- stream_id_list: list
- stream id list to remove
+ :parameters:
+ ports : list
+ ports to execute the command
+ stream_id_list: list
+ stream id list to remove
- :raises:
- + :exc:`STLError`
+ :raises:
+ + :exc:`STLError`
+
+ """
- """
- @__api_check(True)
- def remove_streams (self, stream_id_list, ports = None):
ports = ports if ports is not None else self.get_acquired_ports()
ports = self._validate_port_list(ports)
@@ -1273,34 +1434,6 @@ class STLClient(object):
- """
- start traffic on port(s)
-
- :parameters:
- ports : list
- ports to execute command
-
- mult : str
- multiplier in a form of pps, bps, or line util in %
- examples: "5kpps", "10gbps", "85%", "32mbps"
-
- force : bool
- imply stopping the port of active and also
- forces a profile that exceeds the L1 BW
-
- duration : int
- limit the run for time in seconds
- -1 means unlimited
-
- total : bool
- should the B/W be divided by the ports
- or duplicated for each
-
-
- :raises:
- + :exc:`STLError`
-
- """
@__api_check(True)
def start (self,
ports = None,
@@ -1308,6 +1441,34 @@ class STLClient(object):
force = False,
duration = -1,
total = False):
+ """
+ start traffic on port(s)
+
+ :parameters:
+ ports : list
+ ports to execute command
+
+ mult : str
+ multiplier in a form of pps, bps, or line util in %
+ examples: "5kpps", "10gbps", "85%", "32mbps"
+
+ force : bool
+ imply stopping the port of active and also
+ forces a profile that exceeds the L1 BW
+
+ duration : int
+ limit the run for time in seconds
+ -1 means unlimited
+
+ total : bool
+ should the B/W be divided by the ports
+ or duplicated for each
+
+
+ :raises:
+ + :exc:`STLError`
+
+ """
ports = ports if ports is not None else self.get_acquired_ports()
@@ -1355,19 +1516,19 @@ class STLClient(object):
- """
- stop port(s)
+ @__api_check(True)
+ def stop (self, ports = None):
+ """
+ stop port(s)
- :parameters:
- ports : list
- ports to execute the command
+ :parameters:
+ ports : list
+ ports to execute the command
- :raises:
- + :exc:`STLError`
+ :raises:
+ + :exc:`STLError`
- """
- @__api_check(True)
- def stop (self, ports = None):
+ """
ports = ports if ports is not None else self.get_active_ports()
ports = self._validate_port_list(ports)
@@ -1383,32 +1544,33 @@ class STLClient(object):
raise STLError(rc)
- """
- update traffic on port(s)
+ @__api_check(True)
+ def update (self, ports = None, mult = "1", total = False, force = False):
+ """
+ update traffic on port(s)
- :parameters:
- ports : list
- ports to execute command
+ :parameters:
+ ports : list
+ ports to execute command
- mult : str
- multiplier in a form of pps, bps, or line util in %
- and also with +/-
- examples: "5kpps+", "10gbps-", "85%", "32mbps", "20%+"
+ mult : str
+ multiplier in a form of pps, bps, or line util in %
+ and also with +/-
+ examples: "5kpps+", "10gbps-", "85%", "32mbps", "20%+"
- force : bool
- forces a profile that exceeds the L1 BW
+ force : bool
+ forces a profile that exceeds the L1 BW
- total : bool
- should the B/W be divided by the ports
- or duplicated for each
-
+ total : bool
+ should the B/W be divided by the ports
+ or duplicated for each
- :raises:
- + :exc:`STLError`
- """
- @__api_check(True)
- def update (self, ports = None, mult = "1", total = False, force = False):
+ :raises:
+ + :exc:`STLError`
+
+ """
+
ports = ports if ports is not None else self.get_active_ports()
ports = self._validate_port_list(ports)
@@ -1436,19 +1598,20 @@ class STLClient(object):
- """
- pause traffic on port(s)
+ @__api_check(True)
+ def pause (self, ports = None):
+ """
+ pause traffic on port(s). works only for ports that are active and all streams are in cont mode
- :parameters:
- ports : list
- ports to execute command
+ :parameters:
+ ports : list
+ ports to execute command
- :raises:
- + :exc:`STLError`
+ :raises:
+ + :exc:`STLError`
+
+ """
- """
- @__api_check(True)
- def pause (self, ports = None):
ports = ports if ports is not None else self.get_transmitting_ports()
ports = self._validate_port_list(ports)
@@ -1460,19 +1623,20 @@ class STLClient(object):
if not rc:
raise STLError(rc)
- """
- resume traffic on port(s)
+ @__api_check(True)
+ def resume (self, ports = None):
+ """
+ resume traffic on port(s)
- :parameters:
- ports : list
- ports to execute command
+ :parameters:
+ ports : list
+ ports to execute command
- :raises:
- + :exc:`STLError`
+ :raises:
+ + :exc:`STLError`
+
+ """
- """
- @__api_check(True)
- def resume (self, ports = None):
ports = ports if ports is not None else self.get_paused_ports()
ports = self._validate_port_list(ports)
@@ -1486,31 +1650,32 @@ class STLClient(object):
raise STLError(rc)
- """
- validate port(s) configuration
+ @__api_check(True)
+ def validate (self, ports = None, mult = "1", duration = "-1", total = False):
+ """
+ validate port(s) configuration
+
+ :parameters:
+ ports : list
+ ports to execute command
- :parameters:
- ports : list
- ports to execute command
+ mult : str
+ multiplier in a form of pps, bps, or line util in %
+ examples: "5kpps", "10gbps", "85%", "32mbps"
- mult : str
- multiplier in a form of pps, bps, or line util in %
- examples: "5kpps", "10gbps", "85%", "32mbps"
+ duration : int
+ limit the run for time in seconds
+ -1 means unlimited
- duration : int
- limit the run for time in seconds
- -1 means unlimited
+ total : bool
+ should the B/W be divided by the ports
+ or duplicated for each
- total : bool
- should the B/W be divided by the ports
- or duplicated for each
+ :raises:
+ + :exc:`STLError`
- :raises:
- + :exc:`STLError`
+ """
- """
- @__api_check(True)
- def validate (self, ports = None, mult = "1", duration = "-1", total = False):
ports = ports if ports is not None else self.get_acquired_ports()
ports = self._validate_port_list(ports)
@@ -1537,22 +1702,25 @@ class STLClient(object):
self.ports[port].print_profile(mult_obj, duration)
- """
- clear stats on port(s)
+ @__api_check(False)
+ def clear_stats (self, ports = None, clear_global = True, clear_flow_stats = True):
+ """
+ clear stats on port(s)
- :parameters:
- ports : list
- ports to execute command
-
- clear_global : bool
- clear the global stats
+ :parameters:
+ ports : list
+ ports to execute command
- :raises:
- + :exc:`STLError`
+ clear_global : bool
+ clear the global stats
- """
- @__api_check(False)
- def clear_stats (self, ports = None, clear_global = True, clear_flow_stats = True):
+ clear_flow_stats : bool
+ clear the flow stats
+
+ :raises:
+ + :exc:`STLError`
+
+ """
ports = ports if ports is not None else self.get_all_ports()
ports = self._validate_port_list(ports)
@@ -1568,25 +1736,49 @@ class STLClient(object):
+ @__api_check(True)
+ def is_traffic_active (self, ports = None):
+ """
+ retrun if specify port(s) has traffic
+ :parameters:
+ ports : list
+ ports to execute command
- """
- block until specify port(s) traffic has ended
- :parameters:
- ports : list
- ports to execute command
-
- timeout : int
- timeout in seconds
+ :raises:
+ + :exc:`STLTimeoutError` - in case timeout has expired
+ + :exe:'STLError'
+
+ """
+
+ ports = ports if ports is not None else self.get_acquired_ports()
+ ports = self._validate_port_list(ports)
+
+
+ expr = time.time() + timeout
+
+ return set(self.get_active_ports()).intersection(ports)
+
- :raises:
- + :exc:`STLTimeoutError` - in case timeout has expired
- + :exe:'STLError'
- """
@__api_check(True)
def wait_on_traffic (self, ports = None, timeout = 60):
+ """
+ block until specify port(s) traffic has ended
+
+ :parameters:
+ ports : list
+ ports to execute command
+
+ timeout : int
+ timeout in seconds
+
+ :raises:
+ + :exc:`STLTimeoutError` - in case timeout has expired
+ + :exe:'STLError'
+
+ """
ports = ports if ports is not None else self.get_acquired_ports()
ports = self._validate_port_list(ports)
@@ -1601,19 +1793,18 @@ class STLClient(object):
raise STLTimeoutError(timeout)
- #
- """
- set port(s) attributes
+ @__api_check(True)
+ def set_port_attr (self, ports = None, promiscuous = None):
+ """
+ set port(s) attributes
- :parameters:
- promiscuous - set this to True or False
+ :parameters:
+ promiscuous - set this to True or False
- :raises:
- None
+ :raises:
+ None
- """
- @__api_check(True)
- def set_port_attr (self, ports = None, promiscuous = None):
+ """
ports = ports if ports is not None else self.get_acquired_ports()
ports = self._validate_port_list(ports)
@@ -1637,17 +1828,17 @@ class STLClient(object):
if not rc:
raise STLError(rc)
- """
- clear all events
+ def clear_events (self):
+ """
+ clear all events
- :parameters:
- None
+ :parameters:
+ None
- :raises:
- None
+ :raises:
+ None
- """
- def clear_events (self):
+ """
self.event_handler.clear_events()
@@ -1657,6 +1848,7 @@ class STLClient(object):
# console decorator
def __console(f):
+ @wraps(f)
def wrap(*args):
client = args[0]
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py
index 14c04a52..eac12ebb 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py
@@ -527,7 +527,14 @@ def check_for_int (val):
class CTRexVmDescFlowVar(CTRexVmDescBase):
+ """
+ flow var instruction
+ """
+
def __init__(self, name, init_value=None, min_value=0, max_value=255, size=4, step=1,op="inc"):
+ """
+
+ """
super(CTRexVmDescFlowVar, self).__init__()
self.name = name;
assert type(name)==str, 'type of name is not str'
@@ -666,20 +673,66 @@ class CTRexVmDescTupleGen(CTRexVmDescBase):
################################################################################################
class CScapyTRexPktBuilder(CTrexPktBuilderInterface):
-
"""
- This class defines the TRex API of building a packet using scapy package.
- Using this class the user can also define how TRex will handle the packet by specifying the VM setting.
- pkt could be Scapy pkt or pcap file name
-
- When path_relative_to_profile is True load pcap file from path relative to the profile
+ This class defines the TRex API of building a packet and Field engine using scapy package.
+ Using this class the user can also define how TRex will handle the packet by specifying the Field engine setting.
+ pkt could be Scapy pkt or pcap file name
+ When path_relative_to_profile is a True load pcap file from a path relative to the profile
"""
+
def __init__(self, pkt = None, pkt_buffer = None, vm = None, path_relative_to_profile = False, build_raw = False, remove_fcs = True):
"""
Instantiate a CTRexPktBuilder object
:parameters:
- None
+
+ pkt : Scapy or pcap file filename
+ a scapy packet
+
+ pkt_buffer : string
+ a packet as buffer
+
+ vm : list
+ a list of instructions to manipolate packet fields
+
+ path_relative_to_profile : bool
+ in case pkt is pcap file, do we want to load it relative to profile file
+
+ build_raw : bool
+ Do we want to build scapy in case buffer was given. good for cases we want offset to be taken from scapy
+
+ remove_fcs : bool
+ in case of buffer do we want to remove fcs
+
+ for Example::
+
+ # packet is scapy
+ STLPktBuilder( pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/(10*'x')
+
+ # packet is taken from pcap file relative to python
+ STLPktBuilder(pkt ="stl/yaml/udp_64B_no_crc.pcap")
+
+ # packet is taken from pcap file relative to profile file
+ STLPktBuilder(pkt ="stl/yaml/udp_64B_no_crc.pcap",
+ path_relative_to_profile = True)
+
+
+ vm = CTRexScRaw( [ STLVmTupleGen ( ip_min="16.0.0.1", ip_max="16.0.0.2",
+ port_min=1025, port_max=65535,
+ name="tuple"), # define tuple gen
+
+ STLVmWrFlowVar (fv_name="tuple.ip", pkt_offset= "IP.src" ), # write ip to packet IP.src
+ STLVmFixIpv4(offset = "IP"), # fix checksum
+ STLVmWrFlowVar (fv_name="tuple.port", pkt_offset= "UDP.sport" ) #write udp.port
+ ]
+ );
+
+ base_pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)
+ pad = max(0, size - len(base_pkt)) * 'x'
+
+ STLPktBuilder(pkt = base_pkt/pad,
+ vm= vm)
+
"""
super(CScapyTRexPktBuilder, self).__init__()
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
index eba9c580..2a99be8d 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
@@ -17,7 +17,35 @@ import copy
# base class for TX mode
class STLTXMode(object):
+ """ mode rate speed """
+
def __init__ (self, pps = None, bps_L1 = None, bps_L2 = None, percentage = None):
+ """
+ Speed could be in packet per second (pps) or L2/L1 bps or port precent
+ only one of them is valid.
+ you can enter pps =10000 oe bps_L1=10
+
+ :parameters:
+ pps : float
+ packet per second
+
+ bps_L1 : float
+ bit per second L1 (with IPG)
+
+ bps_L2 : float
+ bit per second L2 (Ethernet-FCS)
+
+ percentage : float
+ link interface precent 0-100 e.g. 10 is 10%% of the port link setup
+
+ For example::
+ mode = STLTXCont(pps = 10)
+ mode = STLTXCont(bps_L1 = 10000000) #10mbps L1
+ mode = STLTXCont(bps_L2 = 10000000) #10mbps L2
+ mode = STLTXCont(percentage = 10) #10%
+
+ """
+
args = [pps, bps_L1, bps_L2, percentage]
# default
@@ -62,11 +90,21 @@ class STLTXMode(object):
# continuous mode
class STLTXCont(STLTXMode):
+ """ continuous mode """
def __init__ (self, **kwargs):
+ """
+ continuous mode
+
+ see :class:`trex_stl_lib.trex_stl_streams.STLTXMode` for rate
+ For example::
+ mode = STLTXCont(pps = 10)
+
+ """
super(STLTXCont, self).__init__(**kwargs)
+
self.fields['type'] = 'continuous'
@staticmethod
@@ -75,8 +113,23 @@ class STLTXCont(STLTXMode):
# single burst mode
class STLTXSingleBurst(STLTXMode):
+ """ Single burst mode """
def __init__ (self, total_pkts = 1, **kwargs):
+ """
+ single burst mode
+
+ :parameters:
+ total_pkts : int
+ how many packets for this burst
+
+ see :class:`trex_stl_lib.trex_stl_streams.STLTXMode` for rate
+
+ For example::
+ mode = STLTXSingleBurst( pps = 10, total_pkts = 1)
+
+ """
+
if not isinstance(total_pkts, int):
raise STLArgumentError('total_pkts', total_pkts)
@@ -92,12 +145,34 @@ class STLTXSingleBurst(STLTXMode):
# multi burst mode
class STLTXMultiBurst(STLTXMode):
+ """ Multi burst mode """
def __init__ (self,
pkts_per_burst = 1,
ibg = 0.0, # usec not SEC
count = 1,
**kwargs):
+ """
+ Multi burst mode
+
+ :parameters:
+
+ pkts_per_burst: int
+ how many packets per burst
+
+ ibg : float
+ inter burst gap in usec 1000,000.0 is 1 sec
+
+ count : int
+ how many bursts
+
+ see :class:`trex_stl_lib.trex_stl_streams.STLTXMode` for rate
+
+ For example::
+ mode = STLTXMultiBurst(pps = 10, pkts_per_burst = 1,count 10, ibg=10.0)
+
+ """
+
if not isinstance(pkts_per_burst, int):
raise STLArgumentError('pkts_per_burst', pkts_per_burst)
@@ -142,6 +217,19 @@ class STLFlowStats(object):
return {'enabled' : False}
class STLStream(object):
+ """ One stream object, include mode, Field Engine mode packet template and Rx stats
+
+ For example::
+ base_pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)
+ pad = max(0, size - len(base_pkt)) * 'x'
+
+ STLStream( isg = 10.0, # star in delay
+ name ='S0',
+ packet = STLPktBuilder(pkt = base_pkt/pad),
+ mode = STLTXSingleBurst( pps = 10, total_pkts = 1),
+ next = 'S1'), # point to next stream
+
+ """
def __init__ (self,
name = None,
@@ -158,6 +246,58 @@ class STLStream(object):
mac_src_override_by_pkt=None,
mac_dst_override_mode=None #see STLStreamDstMAC_xx
):
+ """
+ Stream object
+
+ :parameters:
+
+ name : string
+ The name of the stream. Needed if this stream is dependent on another stream and another stream need to refer to this stream by its name.
+
+ packet : STLPktBuilder
+ The template packet and field engine program e.g. packet = STLPktBuilder(pkt = base_pkt/pad)
+
+ mode : STLTXCont or STLTXSingleBurst or STLTXMultiBurst
+
+ enabled : bool
+ if the stream is enabled.
+
+ self_start : bool
+ In case it is False another stream will activate it
+
+ isg : float
+ Inter stream gap in usec. time to wait until stream will send the first packet
+
+ flow_stats : STLFlowStats
+ Per stream statistic object see STLFlowStats
+
+ next : string
+ The name of the stream to activate
+
+ stream_id :
+ for HLTAPI usage
+
+ action_count : uint16_t
+ In case there is a next stream how many loops until stopping. Default is zero, which mean unlimited
+
+ random_seed: uint16_t
+ If given the seed for this stream will be this value. Good in case you need a deterministic random value
+
+ mac_src_override_by_pkt : bool
+ Template packet will set src MAC
+
+ mac_dst_override_mode=None : STLStreamDstMAC_xx
+ Template packet will set dst MAC
+
+
+ :return:
+ None
+
+ :raises:
+ None
+
+ """
+
# type checking
validate_type('mode', mode, STLTXMode)
@@ -254,23 +394,31 @@ class STLStream(object):
return s
def to_json (self):
+ """
+ return json format
+ """
return dict(self.fields)
def get_id (self):
+ """ Get the stream id after resolution """
return self.id
def get_name (self):
+ """ Get the stream name """
return self.name
def get_next (self):
+ """ Get next stream object """
return self.next
def get_pkt (self):
+ """ Get packet as string """
return self.pkt
def get_pkt_len (self, count_crc = True):
+ """ Get packet number of bytes """
pkt_len = len(self.get_pkt())
if count_crc:
pkt_len += 4
@@ -279,6 +427,7 @@ class STLStream(object):
def get_pkt_type (self):
+ """ Get packet description for example IP:UDP """
if self.packet_desc == None:
self.packet_desc = CScapyTRexPktBuilder.pkt_layers_desc_from_buffer(self.get_pkt())
@@ -289,6 +438,7 @@ class STLStream(object):
@staticmethod
def get_rate_from_field (rate_json):
+ """ Get rate from json """
t = rate_json['type']
v = rate_json['value']
@@ -305,6 +455,7 @@ class STLStream(object):
return self.get_rate_from_field(self.fields['mode']['rate'])
def to_pkt_dump (self):
+ """ print packet description from scapy """
if self.name:
print "Stream Name: ",self.name
scapy_b = self.scapy_pkt_builder;
@@ -316,6 +467,7 @@ class STLStream(object):
def to_yaml (self):
+ """ convert to YAML """
y = {}
if self.name:
@@ -337,6 +489,7 @@ class STLStream(object):
# returns the Python code (text) to build this stream, inside the code it will be in variable "stream"
def to_code (self):
+ """ convert to Python code as profile """
packet = Ether(self.pkt)
packet.hide_defaults()
payload = packet.getlayer('Raw')
@@ -436,6 +589,7 @@ class STLStream(object):
return r'\x{0:02x}'.format(ord(match.group()))
def dump_to_yaml (self, yaml_file = None):
+ """ print as yaml """
yaml_dump = yaml.dump([self.to_yaml()], default_flow_style = False)
# write to file if provided
@@ -583,7 +737,45 @@ class YAMLLoader(object):
# profile class
class STLProfile(object):
+ """ Describe a list of streams
+
+ For example::
+
+ profile = STLProfile( [ STLStream( isg = 10.0, # star in delay
+ name ='S0',
+ packet = STLPktBuilder(pkt = base_pkt/pad),
+ mode = STLTXSingleBurst( pps = 10, total_pkts = self.burst_size),
+ next = 'S1'), # point to next stream
+
+ STLStream( self_start = False, # stream is disabled enable trow S0
+ name ='S1',
+ packet = STLPktBuilder(pkt = base_pkt1/pad),
+ mode = STLTXSingleBurst( pps = 10, total_pkts = self.burst_size),
+ next = 'S2' ),
+
+ STLStream( self_start = False, # stream is disabled enable trow S0
+ name ='S2',
+ packet = STLPktBuilder(pkt = base_pkt2/pad),
+ mode = STLTXSingleBurst( pps = 10, total_pkts = self.burst_size )
+ )
+ ]).get_streams()
+
+
+
+ """
+
def __init__ (self, streams = None):
+ """
+
+ :parameters:
+
+ streams : list of STLStream
+ a list of stream objects
+
+
+ """
+
+
if streams == None:
streams = []
@@ -597,6 +789,7 @@ class STLProfile(object):
def get_streams (self):
+ """ Get the list of stream"""
return self.streams
def __str__ (self):
@@ -605,6 +798,8 @@ class STLProfile(object):
@staticmethod
def load_yaml (yaml_file):
+ """ load from YAML file a profile with number of streams"""
+
# check filename
if not os.path.isfile(yaml_file):
raise STLError("file '{0}' does not exists".format(yaml_file))
@@ -617,6 +812,8 @@ class STLProfile(object):
@staticmethod
def load_py (python_file):
+ """ load from Python profile """
+
# check filename
if not os.path.isfile(python_file):
raise STLError("file '{0}' does not exists".format(python_file))
@@ -648,6 +845,30 @@ class STLProfile(object):
# loop_count = 0 means loop forever
@staticmethod
def load_pcap (pcap_file, ipg_usec = None, speedup = 1.0, loop_count = 1, vm = None):
+ """ Convert a pcap file with a number of packets to a list of connected streams
+
+ packet1->packet2->packet3 etc
+
+ :parameters:
+
+ pcap_file : string
+ The name of the pcap file
+
+ ipg_usec : float
+ The inter packet gap in usec. in case of None IPG is taken from pcap file
+
+ speedup : float
+ By which factor to get IPG smaller so we will send pcap file in speedup
+
+ loop_count : uint16_t
+ how many loops to repeat the pcap file
+
+ vm : list
+ A list of Field engine instructions
+
+ :return: STLProfile
+
+ """
# check filename
if not os.path.isfile(pcap_file):
@@ -696,6 +917,16 @@ class STLProfile(object):
@staticmethod
def load (filename):
+ """ load a profile by its type supported type are
+ * py
+ * yaml
+ * pcap file that converted to profile automaticly
+
+ :parameters:
+ filename : string as filename
+
+ """
+
x = os.path.basename(filename).split('.')
suffix = x[1] if (len(x) == 2) else None
@@ -714,6 +945,7 @@ class STLProfile(object):
return profile
def dump_as_pkt (self):
+ """ dump the profile as scapy packet. in case it is raw convert to scapy and dump it"""
cnt=0;
for stream in self.streams:
print "======================="
@@ -723,6 +955,7 @@ class STLProfile(object):
stream.to_pkt_dump()
def dump_to_yaml (self, yaml_file = None):
+ """ convert it to yaml """
yaml_list = [stream.to_yaml() for stream in self.streams]
yaml_str = yaml.dump(yaml_list, default_flow_style = False)
@@ -734,6 +967,7 @@ class STLProfile(object):
return yaml_str
def dump_to_code (self, profile_file = None):
+ """ convert it to Python native profile. yeah this is cool """
profile_dump = '''# !!! Auto-generated code !!!
from trex_stl_lib.api import *