Skip CRC checking by default
[csit.git] / resources / libraries / python / Constants.py
1 # Copyright (c) 2019 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 Here, "constant" means a value that keeps its value since initialization.
17 However, the value does not need to be hardcoded here,
18 some values are affected by environment variables.
19
20 TODO: Review env and constant names, make them matching if possible.
21 """
22
23
24 import os
25
26
27 def get_str_from_env(env_var_names, default_value):
28     """Attempt to read string from environment variable, return that or default.
29
30     If environment variable exists, but is empty (and default is not),
31     empty string is returned.
32
33     Several environment variable names are examined, as CSIT currently supports
34     a mix of naming convensions.
35     Here "several" means there are hardcoded prefixes to try,
36     and env_var_names itself can be single name, or a list or a tuple of names.
37
38     :param env_var_names: Base names of environment variable to attempt to read.
39     :param default_value: Value to return if the env var does not exist.
40     :type env_var_names: str, or list of str, or tuple of str
41     :type default_value: str
42     :returns: The value read, or default value.
43     :rtype: str
44     """
45     prefixes = ("FDIO_CSIT_", "CSIT_", "")
46     if not isinstance(env_var_names, (list, tuple)):
47         env_var_names = [env_var_names]
48     for name in env_var_names:
49         for prefix in prefixes:
50             value = os.environ.get(prefix + name, None)
51             if value is not None:
52                 return value
53     return default_value
54
55
56 def get_int_from_env(env_var_names, default_value):
57     """Attempt to read int from environment variable, return that or default.
58
59     String value is read, default is returned also if conversion fails.
60
61     :param env_var_names: Base names of environment variable to attempt to read.
62     :param default_value: Value to return if read or conversion fails.
63     :type env_var_names: str, or list of str, or tuple of str
64     :type default_value: int
65     :returns: The value read, or default value.
66     :rtype: int
67     """
68     env_str = get_str_from_env(env_var_names, "")
69     try:
70         return int(env_str)
71     except ValueError:
72         return default_value
73
74
75 def get_float_from_env(env_var_names, default_value):
76     """Attempt to read float from environment variable, return that or default.
77
78     String value is read, default is returned also if conversion fails.
79
80     :param env_var_names: Base names of environment variable to attempt to read.
81     :param default_value: Value to return if read or conversion fails.
82     :type env_var_names: str, or list of str, or tuple of str
83     :type default_value: float
84     :returns: The value read, or default value.
85     :rtype: float
86     """
87     env_str = get_str_from_env(env_var_names, "")
88     try:
89         return float(env_str)
90     except ValueError:
91         return default_value
92
93
94 def get_pessimistic_bool_from_env(env_var_names):
95     """Attempt to read bool from environment variable, assume False by default.
96
97     Conversion is lenient and pessimistic, only few strings are considered true.
98
99     :param env_var_names: Base names of environment variable to attempt to read.
100     :type env_var_names: str, or list of str, or tuple of str
101     :returns: The value read, or False.
102     :rtype: bool
103     """
104     env_str = get_str_from_env(env_var_names, "").lower()
105     return True if env_str in ("true", "yes", "y", "1") else False
106
107
108 def get_optimistic_bool_from_env(env_var_names):
109     """Attempt to read bool from environment variable, assume True by default.
110
111     Conversion is lenient and optimistic, only few strings are considered false.
112
113     :param env_var_names: Base names of environment variable to attempt to read.
114     :type env_var_names: str, or list of str, or tuple of str
115     :returns: The value read, or True.
116     :rtype: bool
117     """
118     env_str = get_str_from_env(env_var_names, "").lower()
119     return False if env_str in ("false", "no", "n", "0") else True
120
121
122 class Constants(object):
123     """Constants used in CSIT.
124
125     TODO: Yaml files are easier for humans to edit.
126     Figure out how to set the attributes by parsing a file
127     that works regardless of current working directory.
128     """
129
130     # OpenVPP testing directory location at topology nodes
131     REMOTE_FW_DIR = '/tmp/openvpp-testing'
132
133     # shell scripts location
134     RESOURCES_LIB_SH = 'resources/libraries/bash'
135
136     # Python API provider location
137     RESOURCES_PAPI_PROVIDER = 'resources/tools/papi/vpp_papi_provider.py'
138
139     # vat templates location
140     RESOURCES_TPL_VAT = 'resources/templates/vat'
141
142     # Kubernetes templates location
143     RESOURCES_TPL_K8S = 'resources/templates/kubernetes'
144
145     # KernelVM templates location
146     RESOURCES_TPL_VM = 'resources/templates/vm'
147
148     # Container templates location
149     RESOURCES_TPL_CONTAINER = 'resources/templates/container'
150
151     # HTTP Server www root directory
152     RESOURCES_TP_WRK_WWW = 'resources/traffic_profiles/wrk/www'
153
154     # OpenVPP VAT binary name
155     VAT_BIN_NAME = 'vpp_api_test'
156
157     # VPP service unit name
158     VPP_UNIT = '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 = '/usr/bin'
168
169     # QEMU VM kernel image path
170     QEMU_VM_KERNEL = '/opt/boot/vmlinuz'
171
172     # QEMU VM kernel initrd path
173     QEMU_VM_KERNEL_INITRD = '/opt/boot/initrd.img'
174
175     # QEMU VM nested image path
176     QEMU_VM_IMAGE = '/var/lib/vm/vhost-nested.img'
177
178     # QEMU VM DPDK path
179     QEMU_VM_DPDK = '/opt/dpdk-19.02'
180
181     # Docker container SUT image
182     DOCKER_SUT_IMAGE_UBUNTU = 'snergster/csit-sut:latest'
183
184     # Docker container arm SUT image
185     DOCKER_SUT_IMAGE_UBUNTU_ARM = 'snergster/csit-arm-sut:latest'
186
187     # TRex install directory
188     TREX_INSTALL_DIR = '/opt/trex-core-2.61'
189
190     # Honeycomb directory location at topology nodes:
191     REMOTE_HC_DIR = '/opt/honeycomb'
192
193     # Honeycomb persistence files location
194     REMOTE_HC_PERSIST = '/var/lib/honeycomb/persist'
195
196     # Honeycomb log file location
197     REMOTE_HC_LOG = '/var/log/honeycomb/honeycomb.log'
198
199     # Honeycomb templates location
200     RESOURCES_TPL_HC = 'resources/templates/honeycomb'
201
202     # ODL Client Restconf listener port
203     ODL_PORT = 8181
204
205     # Sysctl kernel.core_pattern
206     KERNEL_CORE_PATTERN = '/tmp/%p-%u-%g-%s-%t-%h-%e.core'
207
208     # Core dump directory
209     CORE_DUMP_DIR = '/tmp'
210
211     # Equivalent to ~0 used in vpp code
212     BITWISE_NON_ZERO = 0xffffffff
213
214     # Default path to VPP API socket.
215     SOCKSVR_PATH = "/run/vpp/api.sock"
216
217     # Number of trials to execute in MRR test.
218     PERF_TRIAL_MULTIPLICITY = get_int_from_env("PERF_TRIAL_MULTIPLICITY", 10)
219
220     # Duration of one trial in MRR test.
221     PERF_TRIAL_DURATION = get_float_from_env("PERF_TRIAL_DURATION", 1.0)
222
223     # UUID string of DUT1 /tmp volume created outside of the
224     # DUT1 docker in case of vpp-device test. ${EMPTY} value means that
225     #  /tmp directory is inside the DUT1 docker.
226     DUT1_UUID = get_str_from_env("DUT1_UUID", "")
227
228     # Default path to VPP API Stats socket.
229     SOCKSTAT_PATH = "/run/vpp/stats.sock"
230
231     # Global "kill switch" for CRC checking during runtime.
232     FAIL_ON_CRC_MISMATCH = get_pessimistic_bool_from_env("FAIL_ON_CRC_MISMATCH")
233
234     # Mapping from NIC name to its bps limit.
235     # TODO: Implement logic to lower limits to TG NIC or software. Or PCI.
236     NIC_NAME_TO_LIMIT = {
237         # TODO: Explain why ~40Gbps NICs are using ~25Gbps limit.
238         "Cisco-VIC-1227": 10000000000,
239         "Cisco-VIC-1385": 24500000000,
240         "Intel-X520-DA2": 10000000000,
241         "Intel-X553": 10000000000,
242         "Intel-X710": 10000000000,
243         "Intel-XL710": 24500000000,
244         "Intel-XXV710": 24500000000,
245         "virtual": 100000000,
246     }
247
248     # Suite file names use somewhat more rich (less readable) codes for NICs.
249     NIC_NAME_TO_CODE = {
250         "Cisco-VIC-1227": "10ge2p1vic1227",
251         "Cisco-VIC-1385": "40ge2p1vic1385",
252         "Intel-X520-DA2": "10ge2p1x520",
253         "Intel-X553": "10ge2p1x553",
254         "Intel-X710": "10ge2p1x710",
255         "Intel-XL710": "40ge2p1xl710",
256         "Intel-XXV710": "25ge2p1xxv710",
257     }
258
259     # TODO CSIT-1481: Crypto HW should be read from topology file instead.
260     NIC_NAME_TO_CRYPTO_HW = {
261         "Intel-X553": "HW_C3xxx",
262         "Intel-X710": "HW_DH895xcc",
263         "Intel-XL710": "HW_DH895xcc",
264     }
265
266     PERF_TYPE_TO_KEYWORD = {
267         "mrr": "Traffic should pass with maximum rate",
268         "ndrpdr": "Find NDR and PDR intervals using optimized search",
269         "soak": "Find critical load using PLRsearch",
270     }
271
272     PERF_TYPE_TO_SUITE_DOC_VER = {
273         "mrr" : '''fication:* In MaxReceivedRate tests TG sends traffic\\
274 | ... | at line rate and reports total received packets over trial period.\\''',
275         # TODO: Figure out how to include the full "*[Ver] TG verification:*"
276         # while keeping this readable and without breaking line length limit.
277         "ndrpdr": '''fication:* TG finds and reports throughput NDR (Non Drop\\
278 | ... | Rate) with zero packet loss tolerance and throughput PDR (Partial Drop\\
279 | ... | Rate) with non-zero packet loss tolerance (LT) expressed in percentage\\
280 | ... | of packets transmitted. NDR and PDR are discovered for different\\
281 | ... | Ethernet L2 frame sizes using MLRsearch library.\\''',
282         "soak": '''fication:* TG sends traffic at dynamically computed\\
283 | ... | rate as PLRsearch algorithm gathers data and improves its estimate\\
284 | ... | of a rate at which a prescribed small fraction of packets\\
285 | ... | would be lost. After set time, the serarch stops\\
286 | ... | and the algorithm reports its current estimate.\\''',
287     }
288
289     PERF_TYPE_TO_TEMPLATE_DOC_VER = {
290         "mrr": '''Measure MaxReceivedRate for ${frame_size}B frames\\
291 | | ... | using burst trials throughput test.\\''',
292         "ndrpdr": '''Measure NDR and PDR values using MLRsearch algorithm.\\''',
293         "soak": '''Estimate critical rate using PLRsearch algorithm.\\''',
294     }