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:
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.
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.
20 TODO: Review env and constant names, make them matching if possible.
27 def get_str_from_env(env_var_names, default_value):
28 """Attempt to read string from environment variable, return that or default.
30 If environment variable exists, but is empty (and default is not),
31 empty string is returned.
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.
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.
45 prefixes = (u"FDIO_CSIT_", u"CSIT_", u"")
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)
56 def get_int_from_env(env_var_names, default_value):
57 """Attempt to read int from environment variable, return that or default.
59 String value is read, default is returned also if conversion fails.
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.
68 env_str = get_str_from_env(env_var_names, u"")
75 def get_float_from_env(env_var_names, default_value):
76 """Attempt to read float from environment variable, return that or default.
78 String value is read, default is returned also if conversion fails.
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.
87 env_str = get_str_from_env(env_var_names, u"")
94 def get_pessimistic_bool_from_env(env_var_names):
95 """Attempt to read bool from environment variable, assume False by default.
97 Conversion is lenient and pessimistic, only few strings are considered true.
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.
104 env_str = get_str_from_env(env_var_names, u"").lower()
105 return bool(env_str in (u"true", u"yes", u"y", u"1"))
108 def get_optimistic_bool_from_env(env_var_names):
109 """Attempt to read bool from environment variable, assume True by default.
111 Conversion is lenient and optimistic, only few strings are considered false.
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.
118 env_str = get_str_from_env(env_var_names, u"").lower()
119 return bool(env_str not in (u"false", u"no", u"n", u"0"))
123 """Constants used in CSIT.
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.
130 # OpenVPP testing directory location at topology nodes
131 REMOTE_FW_DIR = u"/tmp/openvpp-testing"
133 # shell scripts location
134 RESOURCES_LIB_SH = u"resources/libraries/bash"
136 # Python API provider location
137 RESOURCES_PAPI_PROVIDER = u"resources/tools/papi/vpp_papi_provider.py"
139 # vat templates location
140 RESOURCES_TPL_VAT = u"resources/templates/vat"
142 # Kubernetes templates location
143 RESOURCES_TPL_K8S = u"resources/templates/kubernetes"
145 # KernelVM templates location
146 RESOURCES_TPL_VM = u"resources/templates/vm"
148 # Container templates location
149 RESOURCES_TPL_CONTAINER = u"resources/templates/container"
151 # HTTP Server www root directory
152 RESOURCES_TP_WRK_WWW = u"resources/traffic_profiles/wrk/www"
154 # OpenVPP VAT binary name
155 VAT_BIN_NAME = u"vpp_api_test"
157 # VPP service unit name
160 # Number of system CPU cores.
163 # Number of vswitch main thread CPU cores.
167 QEMU_BIN_PATH = u"/usr/bin"
169 # QEMU VM kernel image path
170 QEMU_VM_KERNEL = u"/opt/boot/vmlinuz"
172 # QEMU VM kernel initrd path
173 QEMU_VM_KERNEL_INITRD = u"/opt/boot/initrd.img"
175 # QEMU VM nested image path
176 QEMU_VM_IMAGE = u"/var/lib/vm/vhost-nested.img"
179 QEMU_VM_DPDK = u"/opt/dpdk-19.02"
181 # Docker container SUT image
182 DOCKER_SUT_IMAGE_UBUNTU = u"snergster/csit-sut:latest"
184 # Docker container arm SUT image
185 DOCKER_SUT_IMAGE_UBUNTU_ARM = u"snergster/csit-arm-sut:latest"
187 # TRex install directory
188 TREX_INSTALL_DIR = u"/opt/trex-core-2.61"
190 # Sysctl kernel.core_pattern
191 KERNEL_CORE_PATTERN = u"/tmp/%p-%u-%g-%s-%t-%h-%e.core"
193 # Core dump directory
194 CORE_DUMP_DIR = u"/tmp"
196 # Equivalent to ~0 used in vpp code
197 BITWISE_NON_ZERO = 0xffffffff
199 # Default path to VPP API socket.
200 SOCKSVR_PATH = u"/run/vpp/api.sock"
202 # Number of trials to execute in MRR test.
203 PERF_TRIAL_MULTIPLICITY = get_int_from_env(u"PERF_TRIAL_MULTIPLICITY", 10)
205 # Duration of one trial in MRR test.
206 PERF_TRIAL_DURATION = get_float_from_env(u"PERF_TRIAL_DURATION", 1.0)
208 # UUID string of DUT1 /tmp volume created outside of the
209 # DUT1 docker in case of vpp-device test. ${EMPTY} value means that
210 # /tmp directory is inside the DUT1 docker.
211 DUT1_UUID = get_str_from_env(u"DUT1_UUID", u"")
213 # Default path to VPP API Stats socket.
214 SOCKSTAT_PATH = u"/run/vpp/stats.sock"
216 # Global "kill switch" for CRC checking during runtime.
217 FAIL_ON_CRC_MISMATCH = get_pessimistic_bool_from_env(
218 u"FAIL_ON_CRC_MISMATCH"
221 # Mapping from NIC name to its bps limit.
222 NIC_NAME_TO_BPS_LIMIT = {
223 u"Cisco-VIC-1227": 10000000000,
224 u"Cisco-VIC-1385": 24500000000,
225 u"Intel-X520-DA2": 10000000000,
226 u"Intel-X553": 10000000000,
227 u"Intel-X710": 10000000000,
228 u"Intel-XL710": 24500000000,
229 u"Intel-XXV710": 24500000000,
230 u"Mellanox-CX556A": 100000000000,
231 u"virtual": 100000000,
234 # Mapping from NIC name to its pps limit.
235 NIC_NAME_TO_PPS_LIMIT = {
236 u"Cisco-VIC-1227": 14880952,
237 u"Cisco-VIC-1385": 18750000,
238 u"Intel-X520-DA2": 14880952,
239 u"Intel-X553": 14880952,
240 u"Intel-X710": 14880952,
241 u"Intel-XL710": 18750000,
242 u"Intel-XXV710": 18750000,
243 u"Mellanox-CX556A": 60000000, # 148809523,
244 u"virtual": 14880952,
247 # Suite file names use codes for NICs.
249 u"Cisco-VIC-1227": u"10ge2p1vic1227",
250 u"Cisco-VIC-1385": u"40ge2p1vic1385",
251 u"Intel-X520-DA2": u"10ge2p1x520",
252 u"Intel-X553": u"10ge2p1x553",
253 u"Intel-X710": u"10ge2p1x710",
254 u"Intel-XL710": u"40ge2p1xl710",
255 u"Intel-XXV710": u"25ge2p1xxv710",
256 u"Mellanox-CX556A": u"100ge2p1cx556a",
259 # TODO CSIT-1481: Crypto HW should be read from topology file instead.
260 NIC_NAME_TO_CRYPTO_HW = {
261 u"Intel-X553": u"HW_C3xxx",
262 u"Intel-X710": u"HW_DH895xcc",
263 u"Intel-XL710": u"HW_DH895xcc",
266 PERF_TYPE_TO_KEYWORD = {
267 u"mrr": u"Traffic should pass with maximum rate",
268 u"ndrpdr": u"Find NDR and PDR intervals using optimized search",
269 u"soak": u"Find critical load using PLRsearch",
272 PERF_TYPE_TO_SUITE_DOC_VER = {
273 u"mrr": u'''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 u"ndrpdr": u'''ication:* 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 u"soak": u'''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.\\''',
289 PERF_TYPE_TO_TEMPLATE_DOC_VER = {
290 u"mrr": u'''Measure MaxReceivedRate for ${frame_size}B frames\\
291 | | ... | using burst trials throughput test.\\''',
292 u"ndrpdr": u"Measure NDR and PDR values using MLRsearch algorithm.\\",
293 u"soak": u"Estimate critical rate using PLRsearch algorithm.\\",