1 # Copyright (c) 2020 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Constants used in CSIT."""
20 def get_str_from_env(env_var_names, default_value):
21 """Attempt to read string from environment variable, return that or default.
23 If environment variable exists, but is empty (and default is not),
24 empty string is returned.
26 Several environment variable names are examined, as CSIT currently supports
27 a mix of naming conventions.
28 Here "several" means there are hard coded prefixes to try,
29 and env_var_names itself can be single name, or a list or a tuple of names.
31 :param env_var_names: Base names of environment variable to attempt to read.
32 :param default_value: Value to return if the env var does not exist.
33 :type env_var_names: str, or list of str, or tuple of str
34 :type default_value: str
35 :returns: The value read, or default value.
38 prefixes = ("FDIO_CSIT_", "CSIT_", "")
39 if not isinstance(env_var_names, (list, tuple)):
40 env_var_names = [env_var_names]
41 for name in env_var_names:
42 for prefix in prefixes:
43 value = os.environ.get(prefix + name, None)
49 def get_int_from_env(env_var_names, default_value):
50 """Attempt to read int from environment variable, return that or default.
52 String value is read, default is returned also if conversion fails.
54 :param env_var_names: Base names of environment variable to attempt to read.
55 :param default_value: Value to return if read or conversion fails.
56 :type env_var_names: str, or list of str, or tuple of str
57 :type default_value: int
58 :returns: The value read, or default value.
61 env_str = get_str_from_env(env_var_names, "")
68 def get_float_from_env(env_var_names, default_value):
69 """Attempt to read float from environment variable, return that or default.
71 String value is read, default is returned also if conversion fails.
73 :param env_var_names: Base names of environment variable to attempt to read.
74 :param default_value: Value to return if read or conversion fails.
75 :type env_var_names: str, or list of str, or tuple of str
76 :type default_value: float
77 :returns: The value read, or default value.
80 env_str = get_str_from_env(env_var_names, "")
87 def get_pessimistic_bool_from_env(env_var_names):
88 """Attempt to read bool from environment variable, assume False by default.
90 Conversion is lenient and pessimistic, only few strings are considered true.
92 :param env_var_names: Base names of environment variable to attempt to read.
93 :type env_var_names: str, or list of str, or tuple of str
94 :returns: The value read, or False.
97 env_str = get_str_from_env(env_var_names, "").lower()
98 return bool(env_str in ("true", "yes", "y", "1"))
101 def get_optimistic_bool_from_env(env_var_names):
102 """Attempt to read bool from environment variable, assume True by default.
104 Conversion is lenient and optimistic, only few strings are considered false.
106 :param env_var_names: Base names of environment variable to attempt to read.
107 :type env_var_names: str, or list of str, or tuple of str
108 :returns: The value read, or True.
111 env_str = get_str_from_env(env_var_names, "").lower()
112 return bool(env_str not in ("false", "no", "n", "0"))
115 class Constants(object):
116 """Constants used in CSIT.
118 TODO: Yaml files are easier for humans to edit.
119 Figure out how to set the attributes by parsing a file
120 that works regardless of current working directory.
123 # OpenVPP testing directory location at topology nodes
124 REMOTE_FW_DIR = '/tmp/openvpp-testing'
126 # shell scripts location
127 RESOURCES_LIB_SH = 'resources/libraries/bash'
129 # Python API provider location
130 RESOURCES_PAPI_PROVIDER = 'resources/tools/papi/vpp_papi_provider.py'
132 # vat templates location
133 RESOURCES_TPL_VAT = 'resources/templates/vat'
135 # Kubernetes templates location
136 RESOURCES_TPL_K8S = 'resources/templates/kubernetes'
138 # KernelVM templates location
139 RESOURCES_TPL_VM = 'resources/templates/vm'
141 # Container templates location
142 RESOURCES_TPL_CONTAINER = 'resources/templates/container'
144 # HTTP Server www root directory
145 RESOURCES_TP_WRK_WWW = 'resources/traffic_profiles/wrk/www'
147 # OpenVPP VAT binary name
148 VAT_BIN_NAME = 'vpp_api_test'
150 # VPP service unit name
153 # Number of system CPU cores.
156 # Number of vswitch main thread CPU cores.
160 QEMU_BIN_PATH = '/usr/bin'
162 # QEMU VM kernel image path
163 QEMU_VM_KERNEL = '/opt/boot/vmlinuz'
165 # QEMU VM kernel initrd path
166 QEMU_VM_KERNEL_INITRD = '/opt/boot/initrd.img'
168 # QEMU VM nested image path
169 QEMU_VM_IMAGE = '/var/lib/vm/vhost-nested.img'
172 QEMU_VM_DPDK = '/opt/dpdk-19.02'
174 # Docker container SUT image
175 DOCKER_SUT_IMAGE_UBUNTU = 'snergster/csit-sut:latest'
177 # Docker container arm SUT image
178 DOCKER_SUT_IMAGE_UBUNTU_ARM = 'snergster/csit-arm-sut:latest'
180 # TRex install version
181 TREX_INSTALL_VERSION = '2.54'
183 # TRex install directory
184 TREX_INSTALL_DIR = '/opt/trex-core-2.54'
186 # Honeycomb directory location at topology nodes:
187 REMOTE_HC_DIR = '/opt/honeycomb'
189 # Honeycomb persistence files location
190 REMOTE_HC_PERSIST = '/var/lib/honeycomb/persist'
192 # Honeycomb log file location
193 REMOTE_HC_LOG = '/var/log/honeycomb/honeycomb.log'
195 # Honeycomb templates location
196 RESOURCES_TPL_HC = 'resources/templates/honeycomb'
198 # ODL Client Restconf listener port
201 # Sysctl kernel.core_pattern
202 KERNEL_CORE_PATTERN = '/tmp/%p-%u-%g-%s-%t-%h-%e.core'
204 # Core dump directory
205 CORE_DUMP_DIR = '/tmp'
207 # Equivalent to ~0 used in vpp code
208 BITWISE_NON_ZERO = 0xffffffff
210 # Global "kill switch" for CRC checking during runtime.
211 FAIL_ON_CRC_MISMATCH = get_pessimistic_bool_from_env("FAIL_ON_CRC_MISMATCH")
213 # Mapping from NIC name to its bps limit.
214 # TODO: Implement logic to lower limits to TG NIC or software. Or PCI.
215 NIC_NAME_TO_LIMIT = {
216 # TODO: Explain why ~40Gbps NICs are using ~25Gbps limit.
217 "Cisco-VIC-1227": 10000000000,
218 "Cisco-VIC-1385": 24500000000,
219 "Intel-X520-DA2": 10000000000,
220 "Intel-X553": 10000000000,
221 "Intel-X710": 10000000000,
222 "Intel-XL710": 24500000000,
223 "Intel-XXV710": 24500000000,
224 "virtual": 100000000,
227 # Suite file names use somewhat more rich (less readable) codes for NICs.
229 "Cisco-VIC-1227": "10ge2p1vic1227",
230 "Cisco-VIC-1385": "40ge2p1vic1385",
231 "Intel-X520-DA2": "10ge2p1x520",
232 "Intel-X553": "10ge2p1x553",
233 "Intel-X710": "10ge2p1x710",
234 "Intel-XL710": "40ge2p1xl710",
235 "Intel-XXV710": "25ge2p1xxv710",
238 # TODO CSIT-1481: Crypto HW should be read from topology file instead.
239 NIC_NAME_TO_CRYPTO_HW = {
240 "Intel-X553": "HW_C3xxx",
241 "Intel-X710": "HW_DH895xcc",
242 "Intel-XL710": "HW_DH895xcc",
245 PERF_TYPE_TO_KEYWORD = {
246 "mrr": "Traffic should pass with maximum rate",
247 "ndrpdr": "Find NDR and PDR intervals using optimized search",
248 "soak": "Find critical load using PLRsearch",
251 PERF_TYPE_TO_SUITE_DOC_VER = {
252 "mrr" : '''fication:* In MaxReceivedRate tests TG sends traffic\\
253 | ... | at line rate and reports total received packets over trial period.\\''',
254 # TODO: Figure out how to include the full "*[Ver] TG verification:*"
255 # while keeping this readable and without breaking line length limit.
256 "ndrpdr": '''fication:* TG finds and reports throughput NDR (Non Drop\\
257 | ... | Rate) with zero packet loss tolerance and throughput PDR (Partial Drop\\
258 | ... | Rate) with non-zero packet loss tolerance (LT) expressed in percentage\\
259 | ... | of packets transmitted. NDR and PDR are discovered for different\\
260 | ... | Ethernet L2 frame sizes using MLRsearch library.\\''',
261 "soak": '''fication:* TG sends traffic at dynamically computed\\
262 | ... | rate as PLRsearch algorithm gathers data and improves its estimate\\
263 | ... | of a rate at which a prescribed small fraction of packets\\
264 | ... | would be lost. After set time, the serarch stops\\
265 | ... | and the algorithm reports its current estimate.\\''',
268 PERF_TYPE_TO_TEMPLATE_DOC_VER = {
269 "mrr": '''Measure MaxReceivedRate for ${frame_size}B frames\\
270 | | ... | using burst trials throughput test.\\''',
271 "ndrpdr": '''Measure NDR and PDR values using MLRsearch algorithm.\\''',
272 "soak": '''Estimate critical rate using PLRsearch algorithm.\\''',