T-Rex: 2.82, core pin, 8 workers
[csit.git] / resources / libraries / python / Constants.py
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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """Constants used in CSIT.
15
16 "Constant" means a value that keeps its value since initialization. The value
17 does not need to be hard coded here, but can be read from environment variables.
18 """
19
20
21 import os
22
23
24 def get_str_from_env(env_var_names, default_value):
25     """Attempt to read string from environment variable, return that or default.
26
27     If environment variable exists, but is empty (and default is not),
28     empty string is returned.
29
30     Several environment variable names are examined, as CSIT currently supports
31     a mix of naming conventions.
32     Here "several" means there are hard coded prefixes to try,
33     and env_var_names itself can be single name, or a list or a tuple of names.
34
35     :param env_var_names: Base names of environment variable to attempt to read.
36     :param default_value: Value to return if the env var does not exist.
37     :type env_var_names: str, or list of str, or tuple of str
38     :type default_value: str
39     :returns: The value read, or default value.
40     :rtype: str
41     """
42     prefixes = (u"FDIO_CSIT_", u"CSIT_", u"")
43     if not isinstance(env_var_names, (list, tuple)):
44         env_var_names = [env_var_names]
45     for name in env_var_names:
46         for prefix in prefixes:
47             value = os.environ.get(prefix + name, None)
48             if value is not None:
49                 return value
50     return default_value
51
52
53 def get_int_from_env(env_var_names, default_value):
54     """Attempt to read int from environment variable, return that or default.
55
56     String value is read, default is returned also if conversion fails.
57
58     :param env_var_names: Base names of environment variable to attempt to read.
59     :param default_value: Value to return if read or conversion fails.
60     :type env_var_names: str, or list of str, or tuple of str
61     :type default_value: int
62     :returns: The value read, or default value.
63     :rtype: int
64     """
65     env_str = get_str_from_env(env_var_names, u"")
66     try:
67         return int(env_str)
68     except ValueError:
69         return default_value
70
71
72 def get_float_from_env(env_var_names, default_value):
73     """Attempt to read float from environment variable, return that or default.
74
75     String value is read, default is returned also if conversion fails.
76
77     :param env_var_names: Base names of environment variable to attempt to read.
78     :param default_value: Value to return if read or conversion fails.
79     :type env_var_names: str, or list of str, or tuple of str
80     :type default_value: float
81     :returns: The value read, or default value.
82     :rtype: float
83     """
84     env_str = get_str_from_env(env_var_names, u"")
85     try:
86         return float(env_str)
87     except ValueError:
88         return default_value
89
90
91 def get_pessimistic_bool_from_env(env_var_names):
92     """Attempt to read bool from environment variable, assume False by default.
93
94     Conversion is lenient and pessimistic, only few strings are considered true.
95
96     :param env_var_names: Base names of environment variable to attempt to read.
97     :type env_var_names: str, or list of str, or tuple of str
98     :returns: The value read, or False.
99     :rtype: bool
100     """
101     env_str = get_str_from_env(env_var_names, u"").lower()
102     return bool(env_str in (u"true", u"yes", u"y", u"1"))
103
104
105 def get_optimistic_bool_from_env(env_var_names):
106     """Attempt to read bool from environment variable, assume True by default.
107
108     Conversion is lenient and optimistic, only few strings are considered false.
109
110     :param env_var_names: Base names of environment variable to attempt to read.
111     :type env_var_names: str, or list of str, or tuple of str
112     :returns: The value read, or True.
113     :rtype: bool
114     """
115     env_str = get_str_from_env(env_var_names, u"").lower()
116     return bool(env_str not in (u"false", u"no", u"n", u"0"))
117
118
119 class Constants:
120     """Constants used in CSIT.
121
122     TODO: Yaml files are easier for humans to edit.
123     Figure out how to set the attributes by parsing a file
124     that works regardless of current working directory.
125     """
126
127     # OpenVPP testing directory location at topology nodes
128     REMOTE_FW_DIR = u"/tmp/openvpp-testing"
129
130     # shell scripts location
131     RESOURCES_LIB_SH = u"resources/libraries/bash"
132
133     # Python API provider location
134     RESOURCES_PAPI_PROVIDER = u"resources/tools/papi/vpp_papi_provider.py"
135
136     # vat templates location
137     RESOURCES_TPL_VAT = u"resources/templates/vat"
138
139     # Kubernetes templates location
140     RESOURCES_TPL_K8S = u"resources/templates/kubernetes"
141
142     # KernelVM templates location
143     RESOURCES_TPL_VM = u"resources/templates/vm"
144
145     # Container templates location
146     RESOURCES_TPL_CONTAINER = u"resources/templates/container"
147
148     # VPP Communications Library templates location
149     RESOURCES_TPL_VCL = u"resources/templates/vcl"
150
151     # VPP Communications Library LD_PRELOAD library
152     VCL_LDPRELOAD_LIBRARY = u"/usr/lib/x86_64-linux-gnu/libvcl_ldpreload.so"
153
154     # OpenVPP VAT binary name
155     VAT_BIN_NAME = u"vpp_api_test"
156
157     # VPP service unit name
158     VPP_UNIT = u"vpp"
159
160     # Number of system CPU cores.
161     CPU_CNT_SYSTEM = 1
162
163     # Number of vswitch main thread CPU cores.
164     CPU_CNT_MAIN = 1
165
166     # QEMU binary path
167     QEMU_BIN_PATH = u"/usr/bin"
168
169     # QEMU VM kernel image path
170     QEMU_VM_KERNEL = u"/opt/boot/vmlinuz"
171
172     # QEMU VM kernel initrd path
173     QEMU_VM_KERNEL_INITRD = u"/opt/boot/initrd.img"
174
175     # QEMU VM nested image path
176     QEMU_VM_IMAGE = u"/var/lib/vm/image.iso"
177
178     # QEMU VM DPDK path
179     QEMU_VM_DPDK = u"/opt/dpdk-20.02"
180
181     # Docker container SUT image
182     DOCKER_SUT_IMAGE_UBUNTU = u"snergster/csit-sut:latest"
183
184     # Docker container arm SUT image
185     DOCKER_SUT_IMAGE_UBUNTU_ARM = u"snergster/csit-arm-sut:latest"
186
187     # TRex install directory
188     TREX_INSTALL_DIR = u"/opt/trex-core-2.82"
189
190     # TODO: Find the right way how to use it in trex profiles
191     # TRex pcap files directory
192     TREX_PCAP_DIR = f"{TREX_INSTALL_DIR}/scripts/avl"
193
194     # TRex limit memory.
195     TREX_LIMIT_MEMORY = get_int_from_env(u"TREX_LIMIT_MEMORY", 8192)
196
197     # TRex number of cores
198     TREX_CORE_COUNT = get_int_from_env(u"TREX_CORE_COUNT", 8)
199
200     # Trex force start regardless ports state
201     TREX_SEND_FORCE = get_pessimistic_bool_from_env(u"TREX_SEND_FORCE")
202
203     # TRex extra commandline arguments
204     TREX_EXTRA_CMDLINE = get_str_from_env(
205         u"TREX_EXTRA_CMDLINE", u"--mbuf-factor 32")
206
207     # graph node variant value
208     GRAPH_NODE_VARIANT = get_str_from_env(
209         u"GRAPH_NODE_VARIANT", u"")
210
211     # Sysctl kernel.core_pattern
212     KERNEL_CORE_PATTERN = u"/tmp/%p-%u-%g-%s-%t-%h-%e.core"
213
214     # Core dump directory
215     CORE_DUMP_DIR = u"/tmp"
216
217     # Perf stat events (comma separated).
218     PERF_STAT_EVENTS = u"L1-icache-load-misses"
219
220     # Equivalent to ~0 used in vpp code
221     BITWISE_NON_ZERO = 0xffffffff
222
223     # Default path to VPP API socket.
224     SOCKSVR_PATH = u"/run/vpp/api.sock"
225
226     # Number of trials to execute in MRR test.
227     PERF_TRIAL_MULTIPLICITY = get_int_from_env(u"PERF_TRIAL_MULTIPLICITY", 10)
228
229     # Duration of one trial in MRR test.
230     PERF_TRIAL_DURATION = get_float_from_env(u"PERF_TRIAL_DURATION", 1.0)
231
232     # Duration of one latency-specific trial in NDRPDR test.
233     PERF_TRIAL_LATENCY_DURATION = get_float_from_env(
234         u"PERF_TRIAL_LATENCY_DURATION", 5.0)
235
236     # Extended debug (incl. vpp packet trace, linux perf stat, ...).
237     # Full list is available as suite variable (__init__.robot) or is
238     # override by test.
239     EXTENDED_DEBUG = get_pessimistic_bool_from_env(u"EXTENDED_DEBUG")
240
241     # UUID string of DUT1 /tmp volume created outside of the
242     # DUT1 docker in case of vpp-device test. ${EMPTY} value means that
243     #  /tmp directory is inside the DUT1 docker.
244     DUT1_UUID = get_str_from_env(u"DUT1_UUID", u"")
245
246     # Default path to VPP API Stats socket.
247     SOCKSTAT_PATH = u"/run/vpp/stats.sock"
248
249     # Global "kill switch" for CRC checking during runtime.
250     FAIL_ON_CRC_MISMATCH = get_pessimistic_bool_from_env(
251         u"FAIL_ON_CRC_MISMATCH"
252     )
253
254     # Default IP4 prefix length (if not defined in topology file)
255     DEFAULT_IP4_PREFIX_LENGTH = u"24"
256
257     # Maximum number of interfaces in a data path
258     DATAPATH_INTERFACES_MAX = 100
259
260     # Mapping from NIC name to its bps limit.
261     NIC_NAME_TO_BPS_LIMIT = {
262         u"Cisco-VIC-1227": 10000000000,
263         u"Cisco-VIC-1385": 24500000000,
264         u"Intel-X520-DA2": 10000000000,
265         u"Intel-X553": 10000000000,
266         u"Intel-X710": 10000000000,
267         u"Intel-XL710": 24500000000,
268         u"Intel-XXV710": 24500000000,
269         u"Intel-E810CQ": 100000000000,
270         u"Mellanox-CX556A": 100000000000,
271         u"Amazon-Nitro-50G": 10000000000,
272         u"virtual": 100000000,
273     }
274
275     # Mapping from NIC name to its pps limit.
276     NIC_NAME_TO_PPS_LIMIT = {
277         u"Cisco-VIC-1227": 14880952,
278         u"Cisco-VIC-1385": 18750000,
279         u"Intel-X520-DA2": 14880952,
280         u"Intel-X553": 14880952,
281         u"Intel-X710": 14880952,
282         u"Intel-XL710": 18750000,
283         u"Intel-XXV710": 18750000,
284         u"Intel-E810CQ": 58500000,
285         u"Mellanox-CX556A": 60000000, # 148809523,
286         u"Amazon-Nitro-50G": 1500000,
287         u"virtual": 14880952,
288     }
289
290     # Suite file names use codes for NICs.
291     NIC_NAME_TO_CODE = {
292         u"Cisco-VIC-1227": u"10ge2p1vic1227",
293         u"Cisco-VIC-1385": u"40ge2p1vic1385",
294         u"Intel-X520-DA2": u"10ge2p1x520",
295         u"Intel-X553": u"10ge2p1x553",
296         u"Intel-X710": u"10ge2p1x710",
297         u"Intel-XL710": u"40ge2p1xl710",
298         u"Intel-XXV710": u"25ge2p1xxv710",
299         u"Intel-E810CQ": u"100ge2p1e810cq",
300         u"Amazon-Nitro-50G": u"50ge1p1ENA",
301         u"Mellanox-CX556A": u"100ge2p1cx556a",
302     }
303
304     # Not each driver is supported by each NIC.
305     NIC_NAME_TO_DRIVER = {
306         u"Cisco-VIC-1227": [u"vfio-pci"],
307         u"Cisco-VIC-1385": [u"vfio-pci"],
308         u"Intel-X520-DA2": [u"vfio-pci"],
309         u"Intel-X553": [u"vfio-pci"],
310         u"Intel-X710": [u"vfio-pci", u"avf"],
311         u"Intel-XL710": [u"vfio-pci", u"avf"],
312         u"Intel-XXV710": [u"vfio-pci", u"avf"],
313         u"Intel-E810CQ": [u"vfio-pci", u"avf"],
314         u"Amazon-Nitro-50G": [u"vfio-pci"],
315         u"Mellanox-CX556A": [u"rdma-core"],
316     }
317
318     # Each driver needs different prugin to work.
319     NIC_DRIVER_TO_PLUGINS = {
320         u"vfio-pci": u"dpdk_plugin.so",
321         u"avf": u"avf_plugin.so",
322         u"rdma-core": u"rdma_plugin.so",
323     }
324
325     # Tags to differentiate tests for different NIC driver.
326     NIC_DRIVER_TO_TAG = {
327         u"vfio-pci": u"DRV_VFIO_PCI",
328         u"avf": u"DRV_AVF",
329         u"rdma-core": u"DRV_RDMA_CORE",
330     }
331
332     # Suite names have to be different, add prefix.
333     NIC_DRIVER_TO_SUITE_PREFIX = {
334         u"vfio-pci": u"",
335         u"avf": u"avf-",
336         u"rdma-core": u"rdma-",
337     }
338
339     # Number of virtual functions of physical nic.
340     NIC_DRIVER_TO_VFS = {
341         u"vfio-pci": u"nic_vfs}= | 0",
342         u"avf": u"nic_vfs}= | 1",
343         u"rdma-core": u"nic_vfs}= | 0",
344     }
345
346     # Not each driver is supported by each NIC.
347     DPDK_NIC_NAME_TO_DRIVER = {
348         u"Cisco-VIC-1227": [u"vfio-pci"],
349         u"Cisco-VIC-1385": [u"vfio-pci"],
350         u"Intel-X520-DA2": [u"vfio-pci"],
351         u"Intel-X553": [u"vfio-pci"],
352         u"Intel-X710": [u"vfio-pci"],
353         u"Intel-XL710": [u"vfio-pci"],
354         u"Intel-XXV710": [u"vfio-pci"],
355         u"Intel-E810CQ": [u"vfio-pci"],
356         u"Amazon-Nitro-50G": [u"vfio-pci"],
357         u"Mellanox-CX556A": [u"mlx5_core"],
358     }
359
360     # Tags to differentiate tests for different NIC driver.
361     DPDK_NIC_DRIVER_TO_TAG = {
362         u"vfio-pci": u"DRV_VFIO_PCI",
363         u"mlx5_core": u"DRV_MLX5_CORE",
364     }
365
366     # Suite names have to be different, add prefix.
367     DPDK_NIC_DRIVER_TO_SUITE_PREFIX = {
368         u"vfio-pci": u"",
369         u"mlx5_core": u"mlx5-",
370     }
371
372     # Some identifiers constructed from suite names
373     # have to be independent of NIC driver used.
374     # In order to remove or reject the NIC driver part,
375     # it is useful to have a list of such prefixes precomputed.
376     FORBIDDEN_SUITE_PREFIX_LIST = [
377         prefix for prefix in NIC_DRIVER_TO_SUITE_PREFIX.values() if prefix
378     ]
379     FORBIDDEN_SUITE_PREFIX_LIST += [
380         prefix for prefix in DPDK_NIC_DRIVER_TO_SUITE_PREFIX.values() if prefix
381     ]
382
383     # TODO CSIT-1481: Crypto HW should be read from topology file instead.
384     NIC_NAME_TO_CRYPTO_HW = {
385         u"Intel-X553": u"HW_C3xxx",
386         u"Intel-X710": u"HW_DH895xcc",
387         u"Intel-XL710": u"HW_DH895xcc",
388     }
389
390     PERF_TYPE_TO_KEYWORD = {
391         u"mrr": u"Traffic should pass with maximum rate",
392         u"ndrpdr": u"Find NDR and PDR intervals using optimized search",
393         u"soak": u"Find critical load using PLRsearch",
394     }
395
396     PERF_TYPE_TO_SUITE_DOC_VER = {
397         u"mrr": u'''fication:* In MaxReceivedRate tests TG sends traffic\\
398 | ... | at line rate and reports total received packets over trial period.\\''',
399         # TODO: Figure out how to include the full "*[Ver] TG verification:*"
400         # while keeping this readable and without breaking line length limit.
401         u"ndrpdr": u'''ication:* TG finds and reports throughput NDR (Non Drop\\
402 | ... | Rate) with zero packet loss tolerance and throughput PDR (Partial Drop\\
403 | ... | Rate) with non-zero packet loss tolerance (LT) expressed in percentage\\
404 | ... | of packets transmitted. NDR and PDR are discovered for different\\
405 | ... | Ethernet L2 frame sizes using MLRsearch library.\\''',
406         u"soak": u'''fication:* TG sends traffic at dynamically computed\\
407 | ... | rate as PLRsearch algorithm gathers data and improves its estimate\\
408 | ... | of a rate at which a prescribed small fraction of packets\\
409 | ... | would be lost. After set time, the serarch stops\\
410 | ... | and the algorithm reports its current estimate.\\''',
411     }
412
413     PERF_TYPE_TO_TEMPLATE_DOC_VER = {
414         u"mrr": u'''Measure MaxReceivedRate for ${frame_size}B frames\\
415 | | ... | using burst trials throughput test.\\''',
416         u"ndrpdr": u"Measure NDR and PDR values using MLRsearch algorithm.\\",
417         u"soak": u"Estimate critical rate using PLRsearch algorithm.\\",
418     }