feat(telemetry): Rework
[csit.git] / resources / libraries / python / Constants.py
1 # Copyright (c) 2022 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     # Version for CSIT data model. See docs/model/.
123     MODEL_VERSION = u"1.0.1"
124
125     # Global off-switch in case JSON export is large or slow.
126     EXPORT_JSON = get_optimistic_bool_from_env(u"EXPORT_JSON")
127
128     # OpenVPP testing directory location at topology nodes
129     REMOTE_FW_DIR = u"/tmp/openvpp-testing"
130
131     # shell scripts location
132     RESOURCES_LIB_SH = u"resources/libraries/bash"
133
134     # python scripts location
135     RESOURCES_LIB_PY = u"resources/libraries/python"
136
137     # shell scripts location
138     RESOURCES_TOOLS = u"resources/tools"
139
140     # Python API provider location
141     RESOURCES_PAPI_PROVIDER = u"resources/tools/papi/vpp_papi_provider.py"
142
143     # Templates location
144     RESOURCES_TPL = u"resources/templates"
145
146     # vat templates location
147     RESOURCES_TPL_VAT = u"resources/templates/vat"
148
149     # Kubernetes templates location
150     RESOURCES_TPL_K8S = u"resources/templates/kubernetes"
151
152     # Container templates location
153     RESOURCES_TPL_CONTAINER = u"resources/templates/container"
154
155     # VPP Communications Library templates location
156     RESOURCES_TPL_VCL = u"resources/templates/vcl"
157
158     # VPP Communications Library templates location
159     RESOURCES_TPL_TELEMETRY = u"resources/templates/telemetry"
160
161     # VPP Communications Library LD_PRELOAD library
162     VCL_LDPRELOAD_LIBRARY = u"/usr/lib/x86_64-linux-gnu/libvcl_ldpreload.so"
163
164     # OpenVPP VAT binary name
165     VAT_BIN_NAME = u"vpp_api_test"
166
167     # VPP service unit name
168     VPP_UNIT = u"vpp"
169
170     # Number of system CPU cores.
171     CPU_CNT_SYSTEM = 1
172
173     # Number of vswitch main thread CPU cores.
174     CPU_CNT_MAIN = 1
175
176     # QEMU binary path
177     QEMU_BIN_PATH = u"/usr/bin"
178
179     # QEMU VM kernel image path
180     QEMU_VM_KERNEL = u"/opt/boot/vmlinuz"
181
182     # QEMU VM kernel initrd path
183     QEMU_VM_KERNEL_INITRD = u"/opt/boot/initrd.img"
184
185     # QEMU VM nested image path
186     QEMU_VM_IMAGE = u"/var/lib/vm/image.iso"
187
188     # QEMU VM DPDK path
189     QEMU_VM_DPDK = u"/opt/dpdk-22.03"
190
191     # Docker container SUT image
192     DOCKER_SUT_IMAGE_UBUNTU = u"csit_sut-ubuntu2004:local"
193
194     # Docker container arm SUT image
195     DOCKER_SUT_IMAGE_UBUNTU_ARM = u"csit_sut-ubuntu2004:local"
196
197     # TRex install directory
198     TREX_INSTALL_DIR = u"/opt/trex-core-2.97"
199
200     # TRex pcap files directory
201     TREX_PCAP_DIR = f"{TREX_INSTALL_DIR}/scripts/avl"
202
203     # TRex limit memory.
204     TREX_LIMIT_MEMORY = get_int_from_env(u"TREX_LIMIT_MEMORY", 8192)
205
206     # TRex number of cores
207     TREX_CORE_COUNT = get_int_from_env(u"TREX_CORE_COUNT", 16)
208
209     # TRex set number of RX/TX descriptors
210     # Set to 0 to use default values
211     TREX_TX_DESCRIPTORS_COUNT = get_int_from_env(
212         u"TREX_TX_DESCRIPTORS_COUNT", 0
213     )
214     TREX_RX_DESCRIPTORS_COUNT = get_int_from_env(
215         u"TREX_RX_DESCRIPTORS_COUNT", 0
216     )
217
218     # Trex force start regardless ports state
219     TREX_SEND_FORCE = get_pessimistic_bool_from_env(u"TREX_SEND_FORCE")
220
221     # TRex extra commandline arguments
222     TREX_EXTRA_CMDLINE = get_str_from_env(
223         u"TREX_EXTRA_CMDLINE", u"--mbuf-factor 32")
224
225     # Graph node variant value
226     GRAPH_NODE_VARIANT = get_str_from_env(u"GRAPH_NODE_VARIANT", u"")
227
228     # Default memory page size in case multiple configured in system
229     DEFAULT_HUGEPAGE_SIZE = get_str_from_env(u"DEFAULT_HUGEPAGE_SIZE", u"2M")
230
231     # Sysctl kernel.core_pattern
232     KERNEL_CORE_PATTERN = u"/tmp/%p-%u-%g-%s-%t-%h-%e.core"
233
234     # Core dump directory
235     CORE_DUMP_DIR = u"/tmp"
236
237     # Perf stat events (comma separated).
238     PERF_STAT_EVENTS = get_str_from_env(
239         u"PERF_STAT_EVENTS",
240         u"cpu-clock,context-switches,cpu-migrations,page-faults,"
241         u"cycles,instructions,branches,branch-misses,L1-icache-load-misses")
242
243     # Equivalent to ~0 used in vpp code
244     BITWISE_NON_ZERO = 0xffffffff
245
246     # Default path to VPP API socket.
247     SOCKSVR_PATH = u"/run/vpp/api.sock"
248
249     # Default path to VPP CLI socket.
250     SOCKCLI_PATH = u"/run/vpp/cli.sock"
251
252     # Default path to VPP API Stats socket.
253     SOCKSTAT_PATH = u"/run/vpp/stats.sock"
254
255     # Number of trials to execute in MRR test.
256     PERF_TRIAL_MULTIPLICITY = get_int_from_env(u"PERF_TRIAL_MULTIPLICITY", 10)
257
258     # Duration [s] of one trial in MRR test.
259     PERF_TRIAL_DURATION = get_float_from_env(u"PERF_TRIAL_DURATION", 1.0)
260
261     # Whether to use latency streams in main search trials.
262     PERF_USE_LATENCY = get_pessimistic_bool_from_env(u"PERF_USE_LATENCY")
263
264     # Duration of one latency-specific trial in NDRPDR test.
265     PERF_TRIAL_LATENCY_DURATION = get_float_from_env(
266         u"PERF_TRIAL_LATENCY_DURATION", 5.0)
267
268     # For some testbeds TG takes longer than usual to start sending traffic.
269     # This constant [s] allows longer wait, without affecting
270     # the approximate duration. For example, use 0.098 for AWS.
271     PERF_TRIAL_STL_DELAY = get_float_from_env(u"PERF_TRIAL_STL_DELAY", 0.0)
272
273     # ASTF usually needs a different value for the delay.
274     PERF_TRIAL_ASTF_DELAY = get_float_from_env(
275         u"PERF_TRIAL_ASTF_DELAY", 0.112
276     )
277
278     # Number of data frames in TPUT transaction, used both by TCP and UDP.
279     # The value should be 33 to keep historic continuity for UDP TPUT tests,
280     # but we are limited by TRex window of 48 KiB, so for 9000B tests
281     # it means we can send only 5 full data frames in a burst.
282     # https://github.com/cisco-system-traffic-generator/
283     # trex-core/blob/v2.88/src/44bsd/tcp_var.h#L896-L903
284     ASTF_N_DATA_FRAMES = get_int_from_env(u"ASTF_N_DATA_FRAMES", 5)
285
286     # Extended debug (incl. vpp packet trace, linux perf stat, ...).
287     # Full list is available as suite variable (__init__.robot) or is
288     # override by test.
289     EXTENDED_DEBUG = get_pessimistic_bool_from_env(u"EXTENDED_DEBUG")
290
291     # UUID string of DUT1 /tmp volume created outside of the
292     # DUT1 docker in case of vpp-device test. ${EMPTY} value means that
293     #  /tmp directory is inside the DUT1 docker.
294     DUT1_UUID = get_str_from_env(u"DUT1_UUID", u"")
295
296     # Global "kill switch" for CRC checking during runtime.
297     FAIL_ON_CRC_MISMATCH = get_pessimistic_bool_from_env(
298         u"FAIL_ON_CRC_MISMATCH"
299     )
300
301     # Default IP4 prefix length (if not defined in topology file)
302     DEFAULT_IP4_PREFIX_LENGTH = u"24"
303
304     # Maximum number of interfaces in a data path
305     DATAPATH_INTERFACES_MAX = 100
306
307     # Mapping from NIC name to its bps limit.
308     NIC_NAME_TO_BPS_LIMIT = {
309         u"Intel-X520-DA2": 10000000000,
310         u"Intel-X553": 10000000000,
311         u"Intel-X710": 10000000000,
312         u"Intel-XL710": 24500000000,
313         u"Intel-XXV710": 24500000000,
314         u"Intel-E810XXV": 24500000000,
315         u"Intel-E810CQ": 100000000000,
316         u"Mellanox-CX556A": 100000000000,
317         u"Amazon-Nitro-50G": 10000000000,
318         u"virtual": 100000000,
319     }
320
321     # Mapping from NIC name to its pps limit.
322     NIC_NAME_TO_PPS_LIMIT = {
323         u"Intel-X520-DA2": 14880952,
324         u"Intel-X553": 14880952,
325         u"Intel-X710": 14880952,
326         u"Intel-XL710": 18750000,
327         u"Intel-XXV710": 18750000,
328         u"Intel-E810XXV": 29000000,
329         u"Intel-E810CQ": 58500000,
330         u"Mellanox-CX556A": 148809523,
331         u"Amazon-Nitro-50G": 1200000,
332         u"virtual": 14880952,
333     }
334
335     # Suite file names use codes for NICs.
336     NIC_NAME_TO_CODE = {
337         u"Intel-X520-DA2": u"10ge2p1x520",
338         u"Intel-X553": u"10ge2p1x553",
339         u"Intel-X710": u"10ge2p1x710",
340         u"Intel-XL710": u"40ge2p1xl710",
341         u"Intel-XXV710": u"25ge2p1xxv710",
342         u"Intel-E810XXV": u"25ge2p1e810xxv",
343         u"Intel-E810CQ": u"100ge2p1e810cq",
344         u"Amazon-Nitro-50G": u"50ge1p1ena",
345         u"Mellanox-CX556A": u"100ge2p1cx556a",
346     }
347
348     # Shortened lowercase NIC model name, useful for presentation.
349     NIC_CODE_TO_SHORT_NAME = {
350         u"10ge2p1x520": u"x520",
351         u"10ge2p1x553": u"x553",
352         u"10ge2p1x710": u"x710",
353         u"40ge2p1xl710": u"xl710",
354         u"25ge2p1xxv710": u"xxv710",
355         u"25ge2p1e810xxv": u"e810xxv",
356         u"100ge2p1e810cq": u"e810cq",
357         u"50ge1p1ena": u"ena",
358         u"100ge2p1cx556a": u"cx556a",
359     }
360
361     # Not each driver is supported by each NIC.
362     NIC_NAME_TO_DRIVER = {
363         u"Intel-X520-DA2": [u"vfio-pci", u"af_xdp"],
364         u"Intel-X553": [u"vfio-pci", u"af_xdp"],
365         u"Intel-X710": [u"vfio-pci", u"avf", u"af_xdp"],
366         u"Intel-XL710": [u"vfio-pci", u"avf", u"af_xdp"],
367         u"Intel-XXV710": [u"vfio-pci", u"avf", u"af_xdp"],
368         u"Intel-E810XXV": [u"vfio-pci", u"avf", u"af_xdp"],
369         u"Intel-E810CQ": [u"vfio-pci", u"avf", u"af_xdp"],
370         u"Amazon-Nitro-50G": [u"vfio-pci"],
371         u"Mellanox-CX556A": [u"rdma-core", u"af_xdp"],
372     }
373
374     # Each driver needs different prugin to work.
375     NIC_DRIVER_TO_PLUGINS = {
376         u"vfio-pci": u"dpdk_plugin.so",
377         u"avf": u"avf_plugin.so",
378         u"rdma-core": u"rdma_plugin.so",
379         u"af_xdp": u"af_xdp_plugin.so",
380     }
381
382     # Tags to differentiate tests for different NIC driver.
383     NIC_DRIVER_TO_TAG = {
384         u"vfio-pci": u"DRV_VFIO_PCI",
385         u"avf": u"DRV_AVF",
386         u"rdma-core": u"DRV_RDMA_CORE",
387         u"af_xdp": u"DRV_AF_XDP",
388     }
389
390     # Suite names have to be different, add prefix.
391     NIC_DRIVER_TO_SUITE_PREFIX = {
392         u"vfio-pci": u"",
393         u"avf": u"avf-",
394         u"rdma-core": u"rdma-",
395         u"af_xdp": u"af-xdp-",
396     }
397
398     # Number of virtual functions of physical nic.
399     NIC_DRIVER_TO_VFS = {
400         u"vfio-pci": u"nic_vfs}= | 0",
401         u"avf": u"nic_vfs}= | 1",
402         u"rdma-core": u"nic_vfs}= | 0",
403         u"af_xdp": u"nic_vfs}= | 0",
404     }
405
406     # Not each driver is supported by each NIC.
407     DPDK_NIC_NAME_TO_DRIVER = {
408         u"Intel-X520-DA2": [u"vfio-pci"],
409         u"Intel-X553": [u"vfio-pci"],
410         u"Intel-X710": [u"vfio-pci"],
411         u"Intel-XL710": [u"vfio-pci"],
412         u"Intel-XXV710": [u"vfio-pci"],
413         u"Intel-E810XXV": [u"vfio-pci"],
414         u"Intel-E810CQ": [u"vfio-pci"],
415         u"Amazon-Nitro-50G": [u"vfio-pci"],
416         u"Mellanox-CX556A": [u"mlx5_core"],
417     }
418
419     # Tags to differentiate tests for different NIC driver.
420     DPDK_NIC_DRIVER_TO_TAG = {
421         u"vfio-pci": u"DRV_VFIO_PCI",
422         u"mlx5_core": u"DRV_MLX5_CORE",
423     }
424
425     # Suite names have to be different, add prefix.
426     DPDK_NIC_DRIVER_TO_SUITE_PREFIX = {
427         u"vfio-pci": u"",
428         u"mlx5_core": u"mlx5-",
429     }
430
431     # Some identifiers constructed from suite names
432     # have to be independent of NIC driver used.
433     # In order to remove or reject the NIC driver part,
434     # it is useful to have a list of such prefixes precomputed.
435     FORBIDDEN_SUITE_PREFIX_LIST = [
436         prefix for prefix in NIC_DRIVER_TO_SUITE_PREFIX.values() if prefix
437     ]
438     FORBIDDEN_SUITE_PREFIX_LIST += [
439         prefix for prefix in DPDK_NIC_DRIVER_TO_SUITE_PREFIX.values() if prefix
440     ]
441
442     # TODO CSIT-1481: Crypto HW should be read from topology file instead.
443     NIC_NAME_TO_CRYPTO_HW = {
444         u"Intel-X553": u"HW_C3xxx",
445         u"Intel-X710": u"HW_DH895xcc",
446         u"Intel-XL710": u"HW_DH895xcc",
447     }
448
449     DEVICE_TYPE_TO_KEYWORD = {
450         u"scapy": None
451     }
452
453     PERF_TYPE_TO_KEYWORD = {
454         u"mrr": u"Traffic should pass with maximum rate",
455         u"ndrpdr": u"Find NDR and PDR intervals using optimized search",
456         u"soak": u"Find critical load using PLRsearch",
457     }
458
459     PERF_TYPE_TO_SUITE_DOC_VER = {
460         u"mrr": u'''fication:** In MaxReceivedRate tests TG sends traffic at \\
461 | ... | line rate and reports total received packets over trial period. \\''',
462         u"ndrpdr": u'''rification:** TG finds and reports throughput NDR (Non \\
463 | ... | Drop Rate) with zero packet loss tolerance and throughput PDR \\
464 | ... | (Partial Drop Rate) with non-zero packet loss tolerance (LT) \\
465 | ... | expressed in percentage of packets transmitted. NDR and PDR are \\
466 | ... | discovered for different Ethernet L2 frame sizes using MLRsearch \\
467 | ... | library.''',
468         u"soak": u'''rification:** TG sends traffic at dynamically computed \\
469 | ... | rate as PLRsearch algorithm gathers data and improves its estimate \\
470 | ... | of a rate at which a prescribed small fraction of packets \\
471 | ... | would be lost. After set time, the serarch stops \\
472 | ... | and the algorithm reports its current estimate. \\''',
473     }
474
475     PERF_TYPE_TO_TEMPLATE_DOC_VER = {
476         u"mrr": u'''Measure MaxReceivedRate for ${frame_size}B frames \\
477 | | ... | using burst trials throughput test. \\''',
478         u"ndrpdr": u"Measure NDR and PDR values using MLRsearch algorithm.",
479         u"soak": u"Estimate critical rate using PLRsearch algorithm. \\",
480     }