aboutsummaryrefslogtreecommitdiffstats
path: root/resources/traffic_profiles/trex/trex-sl-3n-ethip4-ip4dst100000.py
blob: 3b27e9a9e024e7913cf28778a2437fc79a77dce2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch
# Copyright (c) 2017 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Stream profile for T-rex traffic generator.

Stream profile:
 - Two streams sent in directions 0 --> 1 and 1 --> 0 at the same time.
 - Packet: ETH / IP /
 - Direction 0 --> 1:
   - Source IP address range:      10.0.0.1
   - Destination IP address range: 20.0.0.0 - 20.1.134.159
 - Direction 1 --> 0:
   - Source IP address range:      20.0.0.1
   - Destination IP address range: 10.0.0.0 - 10.1.134.159
"""

from trex_stl_lib.api import *
from profile_trex_stateless_base_class import TrafficStreamsBaseClass


class TrafficStreams(TrafficStreamsBaseClass):
    """Stream profile."""

    def __init__(self):
        """Initialization and setting of streams' parameters."""

        super(TrafficStreamsBaseClass, self).__init__()

        # IPs used in packet headers.
        self.p1_src_start_ip = '10.0.0.1'
        self.p1_dst_start_ip = '20.0.0.0'
        self.p1_dst_end_ip = '20.1.134.159'

        self.p2_src_start_ip = '20.0.0.1'
        self.p2_dst_start_ip = '10.0.0.0'
        self.p2_dst_end_ip = '10.1.134.159'

    def define_packets(self):
        """Defines the packets to be sent from the traffic generator.

        Packet definition: | ETH | IP |

        :returns: Packets to be sent from the traffic generator.
        :rtype: tuple
        """

        # Direction 0 --> 1
        base_pkt_a = (Ether() /
                      IP(src=self.p1_src_start_ip,
                         dst=self.p1_dst_start_ip,
                         proto=61))
        # Direction 1 --> 0
        base_pkt_b = (Ether() /
                      IP(src=self.p2_src_start_ip,
                         dst=self.p2_dst_start_ip,
                         proto=61))

        # Direction 0 --> 1
        vm1 = STLScVmRaw([STLVmFlowVar(name="dst",
                                       min_value=self.p1_dst_start_ip,
                                       max_value=self.p1_dst_end_ip,
                                       size=4, op="inc"),
                          STLVmWrFlowVar(fv_name="dst", pkt_offset="IP.dst"),
                          STLVmFixIpv4(offset="IP")],
                         split_by_field="dst")
        # Direction 1 --> 0
        vm2 = STLScVmRaw([STLVmFlowVar(name="dst",
                                       min_value=self.p2_dst_start_ip,
                                       max_value=self.p2_dst_end_ip,
                                       size=4, op="inc"),
                          STLVmWrFlowVar(fv_name="dst", pkt_offset="IP.dst"),
                          STLVmFixIpv4(offset="IP")],
                         split_by_field="dst")

        return base_pkt_a, base_pkt_b, vm1, vm2


def register():
    """Register this traffic profile to T-rex.

    Do not change this function.

    :return: Traffic streams.
    :rtype: Object
    """
    return TrafficStreams()
an> dpkg-query --show $$i >/dev/null 2>&1 || inst="$$inst $$i"; \ done; \ if [ "$$inst" ]; then \ sudo apt-get update; \ sudo apt-get $(CONFIRM) $(FORCE) install $$inst; \ fi @if [ ! -s /usr/lib/graphviz/config6a ]; then \ echo "Rebuilding system Graphviz configuration."; \ sudo dot -c; \ fi else ifneq ("$(wildcard /etc/redhat-release)","") @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS) else ifeq ($(OS_ID),darwin) @set -e; \ for bin in $(DOC_MAC_BIN_DEPENDS); do \ which -s $${bin} || (\ echo "Program '$${bin}' not found, please install it."; \ false; \ ); \ done @set -e; \ for py in $(DOC_MAC_PY_DEPENDS); do \ python -c "import $${py}" >/dev/null 2>&1 || (\ echo "Python package '$${py}' not found, please install it."; \ false; \ ); \ done else ifeq ($(OS_ID),opensuse) @sudo zypper install $(CONFIRM) $(DOC_SUSE_RPM_DEPENDS) else $(error "Building documentation currently works only on Ubuntu, CentOS, MacOS and OpenSUSE systems.") endif @touch $@ .PHONY: bootstrap-doxygen bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok .DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep $(BR)/.doxygen-siphon.dep: Makefile \ $(addprefix,$(WSROOT),$(DOXY_INPUT)) @echo "Building siphon dependencies..." @rm -f "$@"; for input in $(DOXY_INPUT); do \ [ -e "$(WS_ROOT)/$$input" ] && \ find "$(WS_ROOT)/$$input" -type f \ \( -name '*.[ch]' -or -name '*.dox' \) -print \ | grep -v -E '^$(WS_ROOT)/$(DOXY_EXCLUDE_REGEXP)' \ | sed -e "s/^/\$$(SIPHON_FILES): /" \ >> $@; \ done # Include the source -> siphon dependencies -include $(BR)/.doxygen-siphon.dep # Generate .siphon files that contain fragments of source file that # relate to the siphons we support. .NOTPARALLEL: $(SIPHON_FILES) $(SIPHON_FILES): $(BR)/.doxygen-bootstrap.ok \ $(DOXY_DIR)/siphon-generate \ $(addprefix,$(WSROOT),$(DOXY_INPUT)) \ $(wildcard $(DOXY_DIR)/siphon/*.py) @echo "Validating source tree..." @set -e; for input in $(DOXY_INPUT); do \ if [ ! -e "$(WS_ROOT)/$$input" ]; then \ echo "ERROR: Input path '$$input' does not exist." >&2; \ exit 1; \ fi; \ done @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)" @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)" @touch $(SIPHON_INPUT)/files @echo "Collating source file list for siphoning..." @for input in $(DOXY_INPUT); do \ cd "$(WS_ROOT)"; \ find "$$input" -type f \ \( -name '*.[ch]' -or -name '*.dox' \) -print \ | grep -v -E '^src/examples/' \ | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \ >> $(SIPHON_INPUT)/files; \ done @echo "Generating siphons..." @set -e; \ cd "$(WS_ROOT)"; \ $(DOXY_DIR)/siphon-generate \ --output="$(SIPHON_INPUT)" \ "@$(SIPHON_INPUT)/files" # Evaluate this to build a siphon doc output target for each desired # output type: # $(eval $(call siphon-process,file_extension,output_type_name)) define siphon-process $(SIPHON_OUTPUT)/%.$(1): $(SIPHON_INPUT)/%.siphon \ $(DOXY_DIR)/siphon-process \ $(wildcard $(DOXY_DIR)/siphon/*.py) \ $(wildcard $(DOXY_DIR)/siphon_templates/$(2)/*/*.$(1)) @echo "Processing siphon for $(2) from $$(notdir $$<)..." @set -e; \ cd "$(WS_ROOT)"; \ $(DOXY_DIR)/siphon-process \ --type=$$(basename $$(notdir $$<)) \ --format=$(2) \ --output="$$@" \ "$$<" endef # Process the .siphon source fragments and render them into doxygen flavored # markdown documentation .DELETE_ON_ERROR: $(SIPHON_DOCS) $(eval $(call siphon-process,md,markdown)) # Process the .siphon source fragments and render them into a list of cli # commands. .DELETE_ON_ERROR: $(SIPHON_ITEMLIST) $(eval $(call siphon-process,itemlist,itemlist)) # This target can be used just to generate the siphoned things .PHONY: doxygen-siphon doxygen-siphon: $(SIPHON_DOCS) $(SIPHON_ITEMLIST) # Generate the doxygen docs .PHONY: doxygen doxygen: $(SIPHON_DOCS) @mkdir -p "$(DOXY_OUTPUT)" @echo "Running Doxygen..." set -e; cd "$(WS_ROOT)"; \ ROOT="$(WS_ROOT)" \ BUILD_ROOT="$(BR)" \ INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \ INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \ EXCLUDE="$(DOXY_EXCLUDE)" \ HTML=YES \ VERSION="`git describe --tags --dirty`" \ doxygen $(DOXY_DIR)/doxygen.cfg .PHONY: wipe-doxygen wipe-doxygen: @rm -rf $(BR)/docs @rm -rf $(BR)/.doxygen-siphon.dep @rm -rf $(BR)/.doxygen-bootstrap.ok @rm -rf $(DOXY_DIR)/siphon/__pycache__ .PHONY: clean clean: wipe-doxygen