diff options
Diffstat (limited to 'scripts/automation/trex_control_plane/doc_stl')
10 files changed, 1383 insertions, 0 deletions
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/_templates/layout.html b/scripts/automation/trex_control_plane/doc_stl/_templates/layout.html new file mode 100644 index 00000000..8c1c709c --- /dev/null +++ b/scripts/automation/trex_control_plane/doc_stl/_templates/layout.html @@ -0,0 +1,17 @@ +{% extends "!layout.html" %} + +{% block footer %} +{{ super() }} +<script> + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + ga('create', 'UA-75220362-1', 'auto'); + ga('send', 'pageview'); + +</script> +{% endblock %} + + 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 100755 index 00000000..953c5c84 --- /dev/null +++ b/scripts/automation/trex_control_plane/doc_stl/api/client_code.rst @@ -0,0 +1,260 @@ + +Client Module +================== + +The TRex Client provides access to the TRex server. + +**Client and interfaces** + +Multiple users can interact with one TRex server. Each user "owns" a different set of interfaces. +The protocol is JSON-RPC2 over ZMQ transport. + +In addition to the Python API, a console-based API interface is also available. + +Python-like example:: + + c.start(ports = [0, 1], mult = "5mpps", duration = 10) + + c.start(ports = [0, 1], mult = "5mpps", duration = 10, core_mask = [0x1,0xe] ) + + c.start(ports = [0, 1], mult = "5mpps", duration = 10, core_mask = core_mask=STLClient.CORE_MASK_PIN ) + +Console-like example:: + + c.start_line (" -f stl/udp_1pkt_simple.py -m 10mpps --port 0 1 ") + + + +Example 1 - Typical Python API:: + + c = STLClient(username = "itay",server = "10.0.0.10", verbose_level = LoggerApi.VERBOSE_HIGH) + + try: + # connect to server + c.connect() + + # prepare our ports (my machine has 0 <--> 1 with static route) + c.reset(ports = [0, 1]) + + # add both streams to ports + c.add_streams(s1, ports = [0]) + + # clear the stats before injecting + c.clear_stats() + + c.start(ports = [0, 1], mult = "5mpps", duration = 10) + + # block until done + c.wait_on_traffic(ports = [0, 1]) + + # check for any warnings + if c.get_warnings(): + # handle warnings here + pass + + finally: + c.disconnect() + + +STLClient class +--------------- + +.. autoclass:: trex_stl_lib.trex_stl_client.STLClient + :members: + :member-order: bysource + + +STLClient snippet +----------------- + + +.. code-block:: python + + # Example 1: Minimal example of client interacting with the TRex server + + c = STLClient() + + try: + # connect to server + c.connect() + + # prepare our ports (my machine has 0 <--> 1 with static route) + c.reset(ports = [0, 1]) + + # add both streams to ports + c.add_streams(s1, ports = [0]) + + # clear the stats before injecting + c.clear_stats() + + c.start(ports = [0, 1], mult = "5mpps", duration = 10) + + # block until done + c.wait_on_traffic(ports = [0, 1]) + + # check for any warnings + if c.get_warnings(): + # handle warnings here + pass + + finally: + c.disconnect() + + + +.. code-block:: python + + # Example 2: Client can execute other functions while the TRex server is generating traffic + + + c = STLClient() + try: + #connect to server + c.connect() + + #.. + + c.start(ports = [0, 1], mult = "5mpps", duration = 10) + + # block until done + while True : + # do somthing else + os.sleep(1) # sleep for 1 sec + # check if the port is still active + if c.is_traffic_active(ports = [0, 1])==False + break; + + finally: + c.disconnect() + + + +.. code-block:: python + + # Example 3: Console-like API interface + + + def simple (): + + # create client + #verbose_level = LoggerApi.VERBOSE_HIGH # set to see JSON-RPC commands + c = STLClient(verbose_level = LoggerApi.VERBOSE_REGULAR) + passed = True + + try: + # connect to server + c.connect() + + my_ports=[0,1] + + # prepare our ports + c.reset(ports = my_ports) + + print (" is connected {0}".format(c.is_connected())) + + print (" number of ports {0}".format(c.get_port_count())) + print (" acquired_ports {0}".format(c.get_acquired_ports())) + # port stats + print c.get_stats(my_ports) + + # port info, mac-addr info, speed + print c.get_port_info(my_ports) + + c.ping() + + print("start") + # start traffic on port 0,1 each 10mpps + c.start_line (" -f ../../../../stl/udp_1pkt_simple.py -m 10mpps --port 0 1 ") + time.sleep(2); + c.pause_line("--port 0 1"); + time.sleep(2); + c.resume_line("--port 0 1"); + time.sleep(2); + c.update_line("--port 0 1 -m 5mpps"); # reduce to 5 mpps + time.sleep(2); + c.stop_line("--port 0 1"); # stop both ports + + except STLError as e: + passed = False + print e + + finally: + c.disconnect() + + +Example 4: Load profile from a file:: + + def simple (): + + # create client + #verbose_level = LoggerApi.VERBOSE_HIGH + c = STLClient(verbose_level = LoggerApi.VERBOSE_REGULAR) + passed = True + + try: + # connect to server + c.connect() + + my_ports=[0,1] + + # prepare our ports + c.reset(ports = my_ports) + + profile_file = "../../../../stl/udp_1pkt_simple.py" # a traffic profile file + + try: # load a profile + profile = STLProfile.load(profile_file) + except STLError as e: + print format_text("\nError while loading profile '{0}'\n".format(profile_file), 'bold') + print e.brief() + "\n" + return + + print profile.dump_to_yaml() # print it as YAML + + c.remove_all_streams(my_ports) # remove all streams + + + c.add_streams(profile.get_streams(), ports = my_ports) # add them + + c.start(ports = [0, 1], mult = "5mpps", duration = 10) # start for 10 sec + + # block until done + c.wait_on_traffic(ports = [0, 1]) # wait + + + finally: + c.disconnect() + + +.. code-block:: python + + # Example 5: pin cores to ports + + c = STLClient() + + try: + # connect to server + c.connect() + + # prepare our ports (my machine has 0 <--> 1 with static route) + c.reset(ports = [0, 1]) + + # add both streams to ports + c.add_streams(s1, ports = [0]) + + # clear the stats before injecting + c.clear_stats() + + c.start(ports = [0, 1], mult = "5mpps", duration = 10, core_mask = [0x1,0x2]) # pin core to ports for better performance + + # block until done + c.wait_on_traffic(ports = [0, 1]) + + # check for any warnings + if c.get_warnings(): + # handle warnings here + pass + + finally: + c.disconnect() + diff --git a/scripts/automation/trex_control_plane/doc_stl/api/field_engine.rst b/scripts/automation/trex_control_plane/doc_stl/api/field_engine.rst new file mode 100755 index 00000000..cac2f5ab --- /dev/null +++ b/scripts/automation/trex_control_plane/doc_stl/api/field_engine.rst @@ -0,0 +1,254 @@ + +Field Engine modules +======================= + +The Field Engine (FE) has limited number of instructions/operations to support most use cases. +There is a plan to add LuaJIT to be more flexible at the cost of performance. +The FE can allocate stream variables in a stream context, write a stream variable to a packet offset, change packet size, and so on. + +*Examples of Field Engine uses:* + +* Change ipv4.tos 1-10 +* Change packet size to a random value in the range 64 to 9K +* Create a range of flows (change src_ip, dest_ip, src_port, dest_port) +* Update IPv4 checksum + + +The following snippet creates a range of 64 bytes packets :: + + # split the range of IP to cores + # + class STLS1(object): + + def __init__ (self): + self.fsize =64; + + def create_stream (self): + # create a base packet and pad it to size + size = self.fsize - 4; # no FCS + + 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' + + vm = STLScVmRaw( [ STLVmFlowVar ( "ip_src", + min_value="10.0.0.1", + max_value="10.0.0.255", + size=4, + step=1, + op="inc"), + STLVmWrFlowVar (fv_name="ip_src", + pkt_offset= "IP.src" ), # write ip to packet IP.src + STLVmFixIpv4(offset = "IP") # fix checksum + ], + split_by_field = "ip_src", + cache_size =255 # cache the packets, much better performance + ); + + pkt = STLPktBuilder(pkt = base_pkt/pad, + vm = vm) + stream = STLStream(packet = pkt, + mode = STLTXCont()) + #print(stream.to_code()) + return stream + + + def get_streams (self, direction = 0, **kwargs): + # create 1 stream + return [ self.create_stream() ] + + +The following snippet creates a SYN attack:: + + # create attack from random src_ip from 16.0.0.0-18.0.0.254 and random src_port 1025-65000 + # attack 48.0.0.1 server + + def create_stream (self): + + + # TCP SYN + base_pkt = Ether()/IP(dst="48.0.0.1")/TCP(dport=80,flags="S") + + + # vm + vm = STLScVmRaw( [ STLVmFlowVar(name="ip_src", + min_value="16.0.0.0", + max_value="18.0.0.254", + size=4, op="random"), + + STLVmFlowVar(name="src_port", + min_value=1025, + max_value=65000, + size=2, op="random"), + + STLVmWrFlowVar(fv_name="ip_src", pkt_offset= "IP.src" ), + + STLVmFixIpv4(offset = "IP"), # fix checksum + + STLVmWrFlowVar(fv_name="src_port", + pkt_offset= "TCP.sport") # fix udp len + + ] + ) + + pkt = STLPktBuilder(pkt = base_pkt, + vm = vm) + + return STLStream(packet = pkt, + random_seed = 0x1234,# can be remove. will give the same random value any run + mode = STLTXCont()) + + + + +STLScVmRaw class +---------------- + +Aggregate raw instructions objects + +.. autoclass:: trex_stl_lib.trex_stl_packet_builder_scapy.STLScVmRaw + :members: + :member-order: bysource + + +STLVmFlowVar +------------ + +.. autoclass:: trex_stl_lib.trex_stl_packet_builder_scapy.STLVmFlowVar + :members: + :member-order: bysource + +STLVmWrFlowVar +--------------- + +.. autoclass:: trex_stl_lib.trex_stl_packet_builder_scapy.STLVmWrFlowVar + :members: + :member-order: bysource + + +STLVmWrMaskFlowVar +------------------ + +.. autoclass:: trex_stl_lib.trex_stl_packet_builder_scapy.STLVmWrMaskFlowVar + :members: + :member-order: bysource + +STLVmFixChecksumHw +-------------------- + +.. autoclass:: trex_stl_lib.trex_stl_packet_builder_scapy.STLVmFixChecksumHw + :members: + :member-order: bysource + + +STLVmFixIpv4 +------------------ + +.. autoclass:: trex_stl_lib.trex_stl_packet_builder_scapy.STLVmFixIpv4 + :members: + :member-order: bysource + + +STLVmTrimPktSize +------------------ + +.. autoclass:: trex_stl_lib.trex_stl_packet_builder_scapy.STLVmTrimPktSize + :members: + :member-order: bysource + +STLVmTupleGen +------------------ + +.. autoclass:: trex_stl_lib.trex_stl_packet_builder_scapy.STLVmTupleGen + :members: + :member-order: bysource + +STLVmFlowVarRepetableRandom +---------------------------- + +.. autoclass:: trex_stl_lib.trex_stl_packet_builder_scapy.STLVmFlowVarRepetableRandom + :members: + :member-order: bysource + + + + +Field Engine snippet +-------------------- + +.. code-block:: python + + # FE Example1 + + + 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' + + vm = STLScVmRaw( [ STLVmTupleGen ( ip_min="16.0.0.1", ip_max="16.0.0.2", + port_min=1025, port_max=65535, + name="tuple"), # define tuple gen + + # write ip to packet IP.src + STLVmWrFlowVar (fv_name="tuple.ip", pkt_offset= "IP.src" ), + + STLVmFixIpv4(offset = "IP"), # fix checksum + STLVmWrFlowVar (fv_name="tuple.port", pkt_offset= "UDP.sport" ) #write udp.port + ] + ); + + pkt = STLPktBuilder(pkt = base_pkt/pad, + vm = vm) + + +.. code-block:: python + + # FE Example2 + + + #range of source mac-addr + + 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' + + vm = STLScVmRaw( [ STLVmFlowVar(name="mac_src", + min_value=1, + max_value=30, + size=2, op="dec",step=1), + STLVmWrMaskFlowVar(fv_name="mac_src", + pkt_offset= 11, + pkt_cast_size=1, + mask=0xff) + ] + ) + + +.. code-block:: python + + # FE Example3 + + + #IP dest would have 10 random values betwean 48.0.0.1 48.0.0.255 + + base_pkt = Ether()/IP(src=src_ip,dst=dst_ip)/UDP(dport=12,sport=1025) + + pad = max(0, size - len(base_pkt)) * 'x' + + vm = STLScVmRaw( [ STLVmFlowVar ( "ip_src", min_value="10.0.0.1", + max_value="10.0.0.255", size=4, step=1,op="inc"), + STLVmFlowVarRepetableRandom ( "ip_dst", + min_value="48.0.0.1", + max_value="48.0.0.255", + size=4, + limit=10, seed=0x1235), + + STLVmWrFlowVar (fv_name="ip_src", pkt_offset= "IP.src" ), # write ip to packet IP.src + STLVmWrFlowVar (fv_name="ip_dst", pkt_offset= "IP.dst" ), # write ip to packet IP.dst + + STLVmFixIpv4(offset = "IP") # fix checksum + ] + ,split_by_field = "ip_src" # split to cores base on the tuple generator + ,cache_size = cache_size # the cache size + ); + + 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 100755 index 00000000..a3c8ad5a --- /dev/null +++ b/scripts/automation/trex_control_plane/doc_stl/api/index.rst @@ -0,0 +1,37 @@ + +TRex Stateless API Reference +============================ + +**Client: STLClient** + +.. toctree:: + :maxdepth: 4 + + client_code + +**Traffic profile STLProfile,STLStream** + +.. toctree:: + :maxdepth: 4 + + profile_code + + +**Packet builder** + +.. toctree:: + :maxdepth: 4 + + scapy_builder + + +**Field Engine** + +.. toctree:: + :maxdepth: 4 + + field_engine + + + + diff --git a/scripts/automation/trex_control_plane/doc_stl/api/profile_code.rst b/scripts/automation/trex_control_plane/doc_stl/api/profile_code.rst new file mode 100755 index 00000000..8a0d7a2a --- /dev/null +++ b/scripts/automation/trex_control_plane/doc_stl/api/profile_code.rst @@ -0,0 +1,140 @@ + +Traffic profile modules +======================= + +The TRex STLProfile traffic profile includes a number of streams. The profile is a ``program`` of related streams. +Each stream can trigger another stream. Each stream can be named. For a full set of examples, see Manual_. + +.. _Manual: ../trex_stateless.html + + +Example:: + + def create_stream (self): + + # create a base packet and pad it to size + size = self.fsize - 4; # no FCS + base_pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025) + base_pkt1 = Ether()/IP(src="16.0.0.2",dst="48.0.0.1")/UDP(dport=12,sport=1025) + base_pkt2 = Ether()/IP(src="16.0.0.3",dst="48.0.0.1")/UDP(dport=12,sport=1025) + pad = max(0, size - len(base_pkt)) * 'x' + + + return STLProfile( [ STLStream( isg = 1.0, # star in delay in usec + packet = STLPktBuilder(pkt = base_pkt/pad), + mode = STLTXCont( pps = 10), + ), + + STLStream( isg = 2.0, + packet = STLPktBuilder(pkt = base_pkt1/pad), + mode = STLTXCont( pps = 20), + ), + + STLStream( isg = 3.0, + packet = STLPktBuilder(pkt = base_pkt2/pad), + mode = STLTXCont( pps = 30) + + ) + ]).get_streams() + + +STLProfile class +---------------- + +.. autoclass:: trex_stl_lib.trex_stl_streams.STLProfile + :members: + :member-order: bysource + +STLStream +--------- + +.. autoclass:: trex_stl_lib.trex_stl_streams.STLStream + :members: + :member-order: bysource + + +STLStream modes +---------------- + +.. autoclass:: trex_stl_lib.trex_stl_streams.STLTXMode + :members: + :member-order: bysource + +.. autoclass:: trex_stl_lib.trex_stl_streams.STLTXCont + :members: + :member-order: bysource + +.. autoclass:: trex_stl_lib.trex_stl_streams.STLTXSingleBurst + :members: + :member-order: bysource + +.. autoclass:: trex_stl_lib.trex_stl_streams.STLTXMultiBurst + :members: + :member-order: bysource + +.. autoclass:: trex_stl_lib.trex_stl_streams.STLFlowStats + :members: + :member-order: bysource + +.. autoclass:: trex_stl_lib.trex_stl_streams.STLFlowLatencyStats + :members: + :member-order: bysource + + + + +STLProfile snippet +------------------ + + +.. code-block:: python + + # STLProfile Example1 + + + size = self.fsize - 4; # no FCS + base_pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025) + base_pkt1 = Ether()/IP(src="16.0.0.2",dst="48.0.0.1")/UDP(dport=12,sport=1025) + base_pkt2 = Ether()/IP(src="16.0.0.3",dst="48.0.0.1")/UDP(dport=12,sport=1025) + pad = max(0, size - len(base_pkt)) * 'x' + + + return STLProfile( [ STLStream( isg = 10.0, # star in delay + name ='S0', + packet = STLPktBuilder(pkt = base_pkt/pad), + mode = STLTXSingleBurst( pps = 10, total_pkts = 10), + 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 = 20), + 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 = 30 ) + ) + ]).get_streams() + + +.. code-block:: python + + # STLProfile Example2 + + + class STLS1(object): + + def get_streams (self, direction = 0): + return [STLStream(packet = STLPktBuilder(pkt ="stl/yaml/udp_64B_no_crc.pcap"), + mode = STLTXCont(pps=1000), + flow_stats = STLFlowStats(pg_id = 7)), + + STLStream(packet = STLPktBuilder(pkt ="stl/yaml/udp_594B_no_crc.pcap"), + mode = STLTXCont(pps=5000), + flow_stats = STLFlowStats(pg_id = 12)) + ] + + + diff --git a/scripts/automation/trex_control_plane/doc_stl/api/scapy_builder.rst b/scripts/automation/trex_control_plane/doc_stl/api/scapy_builder.rst new file mode 100755 index 00000000..2c5790bf --- /dev/null +++ b/scripts/automation/trex_control_plane/doc_stl/api/scapy_builder.rst @@ -0,0 +1,44 @@ + +Packet builder modules +======================= + +The packet builder module is used for building a template packet for a stream, and creating a Field Engine program to change fields in the packet. + +**Examples:** + +* Build a IP/UDP/DNS packet with a src_ip range of 10.0.0.1 to 10.0.0.255 +* Build IP/UDP packets in IMIX sizes + + +For example, this snippet creates a SYN attack:: + + # create attack from random src_ip from 16.0.0.0-18.0.0.254 and random src_port 1025-65000 + # attack 48.0.0.1 server + + def create_stream (self): + + + # TCP SYN + base_pkt = Ether()/IP(dst="48.0.0.1")/TCP(dport=80,flags="S") + + pkt = STLPktBuilder(pkt = base_pkt) + + return STLStream(packet = pkt, #<<<<< set packet builder inside the stream + mode = STLTXCont()) + + + + +STLPktBuilder class +-------------------- + +Aggregate a raw instructions objects + +.. autoclass:: trex_stl_lib.trex_stl_packet_builder_scapy.STLPktBuilder + :members: + :member-order: bysource + + + + + 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..c8788ca7 --- /dev/null +++ b/scripts/automation/trex_control_plane/doc_stl/conf.py @@ -0,0 +1,328 @@ +# -*- 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 +import functools + +def no_op_wraps(func): + """Replaces functools.wraps in order to undo wrapping. + + Can be used to preserve the decorated function's signature + in the documentation generated by Sphinx. + + """ + def wrapper(decorator): + return func + return wrapper + +functools.wraps = no_op_wraps + + + +# 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 = '2.0' + +# 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") + 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..8a2fc4b0 --- /dev/null +++ b/scripts/automation/trex_control_plane/doc_stl/index.rst @@ -0,0 +1,101 @@ +.. TRex Stateless Python API documentation + 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** + +How to Install +=============== +.. toctree:: + :maxdepth: 2 + +| TRex package contains trex_client.tar.gz +| Put it at any place you like, preferably same place as your scripts. +| (If it's not at same place as your scripts, you will need to ensure trex_client directory is in sys.path) + +Un-pack it using command:: + + tar -xzf trex_client.tar.gz + +How to use +================== + +| The client assumes server is running. +| After un-tarring the client package, you can verify basic tests in examples directory out of the box: + +.. code-block:: bash + + cd trex_client/stl/examples + python stl_imix.py -s <server address> + +You can verify that the traffic was sent and arrives properly if you see something like this::: + + Mapped ports to sides [0, 2] <--> [1, 3] + Injecting [0, 2] <--> [1, 3] on total rate of '30%' for 10 seconds + + Packets injected from [0, 2]: 473,856 + Packets injected from [1, 3]: 473,856 + + packets lost from [0, 2] --> [0, 2]: 0 pkts + packets lost from [1, 3] --> [1, 3]: 0 pkts + + Test has passed :-) + + +Also, in the stl folder there are directories with profiles that define streams and the console (with which you can easily send the profiles) + +How to pyATS +================== + +.. sectionauthor:: David Shen + +pyATS Compatibility + +TRex supports both Python2 and Python3 pyATS. + +* Install python2/python3 pyats + /auto/pyats/bin/pyats-install --python2 + /auto/pyats/bin/pyats-install --python3 + +* setenv TREX_PATH to the trex stateless lib path + setenv TREX_PATH <your path>/automation/trex_control_plane/stl + +* In the script or job file, add the TREX_PATH to sys.path:: + + import sys, os; sys.path.append(os.environ['TREX_PATH']) + +* Source trex stateless libs in scripts:: + + from trex_stl_lib.api import * + from scapy.contrib.mpls import * + from trex_stl_lib.trex_stl_hltapi import * + +If using trex_client package, import syntax is:: + + from trex_client.stl.api import * + + +API Reference +============== +.. toctree:: + :maxdepth: 2 + + api/index + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + + +.. rubric:: Footnotes + |