Revert "fix(jobspec): Delete ipsec nfv density tests"
[csit.git] / resources / libraries / python / VppConfigGenerator.py
1 # Copyright (c) 2024 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 """VPP Configuration File Generator library."""
15
16 import re
17
18 from resources.libraries.python.Constants import Constants
19 from resources.libraries.python.ssh import exec_cmd_no_error
20 from resources.libraries.python.topology import NodeType
21 from resources.libraries.python.topology import Topology
22 from resources.libraries.python.VPPUtil import VPPUtil
23
24 __all__ = ["VppConfigGenerator", "VppInitConfig"]
25
26
27 def pci_dev_check(pci_dev):
28     """Check if provided PCI address is in correct format.
29
30     :param pci_dev: PCI address (expected format: xxxx:xx:xx.x).
31     :type pci_dev: str
32     :returns: True if PCI address is in correct format.
33     :rtype: bool
34     :raises ValueError: If PCI address is in incorrect format.
35     """
36     pattern = re.compile(
37         r"^[0-9A-Fa-f]{4}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}\.[0-9A-Fa-f]$"
38     )
39     if not re.match(pattern, pci_dev):
40         raise ValueError(
41             f"PCI address {pci_dev} is not in valid format xxxx:xx:xx.x"
42         )
43     return True
44
45
46 class VppConfigGenerator:
47     """VPP Configuration File Generator."""
48
49     def __init__(self):
50         """Initialize library."""
51         # VPP Node to apply configuration on
52         self._node = ""
53         # Topology node key
54         self._node_key = ""
55         # VPP Configuration
56         self._nodeconfig = dict()
57         # Serialized VPP Configuration
58         self._vpp_config = ""
59         # VPP Service name
60         self._vpp_service_name = "vpp"
61         # VPP Startup config location
62         self._vpp_startup_conf = "/etc/vpp/startup.conf"
63
64     def set_node(self, node, node_key=None):
65         """Set DUT node.
66
67         :param node: Node to store configuration on.
68         :param node_key: Topology node key.
69         :type node: dict
70         :type node_key: str
71         :raises RuntimeError: If Node type is not DUT.
72         """
73         if node["type"] != NodeType.DUT:
74             raise RuntimeError(
75                 "Startup config can only be applied to DUTnode."
76             )
77         self._node = node
78         self._node_key = node_key
79
80     def get_config_str(self):
81         """Get dumped startup configuration in VPP config format.
82
83         :returns: Startup configuration in VPP config format.
84         :rtype: str
85         """
86         self.dump_config(self._nodeconfig)
87         return self._vpp_config
88
89     def add_config_item(self, config, value, path):
90         """Add startup configuration item.
91
92         :param config: Startup configuration of node.
93         :param value: Value to insert.
94         :param path: Path where to insert item.
95         :type config: dict
96         :type value: str
97         :type path: list
98         """
99         if len(path) == 1:
100             config[path[0]] = value
101             return
102         if path[0] not in config:
103             config[path[0]] = dict()
104         elif isinstance(config[path[0]], str):
105             config[path[0]] = dict() if config[path[0]] == "" \
106                 else {config[path[0]]: ""}
107         self.add_config_item(config[path[0]], value, path[1:])
108
109     def dump_config(self, obj, level=-1):
110         """Dump the startup configuration in VPP config format.
111
112         :param obj: Python Object to print.
113         :param level: Nested level for indentation.
114         :type obj: Obj
115         :type level: int
116         :returns: nothing
117         """
118         indent = "  "
119         if level >= 0:
120             self._vpp_config += f"{level * indent}{{\n"
121         if isinstance(obj, dict):
122             for key, val in obj.items():
123                 if hasattr(val, u"__iter__") and not isinstance(val, str):
124                     self._vpp_config += f"{(level + 1) * indent}{key}\n"
125                     self.dump_config(val, level + 1)
126                 else:
127                     self._vpp_config += f"{(level + 1) * indent}{key} {val}\n"
128         else:
129             for val in obj:
130                 self._vpp_config += f"{(level + 1) * indent}{val}\n"
131         if level >= 0:
132             self._vpp_config += f"{level * indent}}}\n"
133
134     def add_unix_log(self, value="/var/log/vpp/vpp.log"):
135         """Add UNIX log configuration.
136
137         :param value: Log file.
138         :type value: str
139         """
140         path = ["unix", "log"]
141         self.add_config_item(self._nodeconfig, value, path)
142
143     def add_unix_cli_listen(self, value="/run/vpp/cli.sock"):
144         """Add UNIX cli-listen configuration.
145
146         :param value: CLI listen address and port or path to CLI socket.
147         :type value: str
148         """
149         path = ["unix", "cli-listen"]
150         self.add_config_item(self._nodeconfig, value, path)
151
152     def add_unix_cli_no_pager(self):
153         """Add UNIX cli-no-pager configuration."""
154         path = ["unix", "cli-no-pager"]
155         self.add_config_item(self._nodeconfig, "", path)
156
157     def add_unix_gid(self, value="vpp"):
158         """Add UNIX gid configuration.
159
160         :param value: Gid.
161         :type value: str
162         """
163         path = ["unix", "gid"]
164         self.add_config_item(self._nodeconfig, value, path)
165
166     def add_unix_nodaemon(self):
167         """Add UNIX nodaemon configuration."""
168         path = ["unix", "nodaemon"]
169         self.add_config_item(self._nodeconfig, "", path)
170
171     def add_unix_coredump(self):
172         """Add UNIX full-coredump configuration."""
173         path = ["unix", "full-coredump"]
174         self.add_config_item(self._nodeconfig, "", path)
175
176     def add_unix_exec(self, value):
177         """Add UNIX exec configuration."""
178         path = ["unix", "exec"]
179         self.add_config_item(self._nodeconfig, value, path)
180
181     def add_socksvr(self, socket=Constants.SOCKSVR_PATH):
182         """Add socksvr configuration."""
183         path = ["socksvr", "socket-name"]
184         self.add_config_item(self._nodeconfig, socket, path)
185
186     def add_graph_node_variant(self, variant=Constants.GRAPH_NODE_VARIANT):
187         """Add default graph node variant.
188
189         :param value: Graph node variant default value.
190         :type value: str
191         """
192         if variant == "":
193             return
194         variant_list = ["hsw", "skx", "icl"]
195         if variant not in variant_list:
196             raise ValueError("Invalid graph node variant value")
197         path = ["node", "default", "variant"]
198         self.add_config_item(self._nodeconfig, variant, path)
199
200     def add_api_segment_gid(self, value="vpp"):
201         """Add api-segment gid configuration.
202
203         :param value: Gid.
204         :type value: str
205         """
206         path = ["api-segment", "gid"]
207         self.add_config_item(self._nodeconfig, value, path)
208
209     def add_api_segment_global_size(self, value):
210         """Add api-segment global-size configuration.
211
212         :param value: Global size.
213         :type value: str
214         """
215         path = ["api-segment", "global-size"]
216         self.add_config_item(self._nodeconfig, value, path)
217
218     def add_api_segment_prefix(self, value="vpp"):
219         """Add api-segment prefix configuration.
220
221         :param value: Gid.
222         :type value: str
223         """
224         path = ["api-segment", "prefix"]
225         self.add_config_item(self._nodeconfig, value, path)
226
227     def add_api_segment_api_size(self, value):
228         """Add api-segment api-size configuration.
229
230         :param value: API size.
231         :type value: str
232         """
233         path = ["api-segment", "api-size"]
234         self.add_config_item(self._nodeconfig, value, path)
235
236     def add_buffers_per_numa(self, value):
237         """Increase number of buffers allocated.
238
239         :param value: Number of buffers allocated.
240         :type value: int
241         """
242         path = ["buffers", "buffers-per-numa"]
243         self.add_config_item(self._nodeconfig, value, path)
244
245     def add_buffers_default_data_size(self, value):
246         """Increase buffers data-size allocated.
247
248         :param value: Buffers data-size allocated.
249         :type value: int
250         """
251         path = ["buffers", "default data-size"]
252         self.add_config_item(self._nodeconfig, value, path)
253
254     def add_dpdk_dev(self, *devices):
255         """Add DPDK PCI device configuration.
256
257         :param devices: PCI device(s) (format xxxx:xx:xx.x)
258         :type devices: tuple
259         """
260         for device in devices:
261             if pci_dev_check(device):
262                 path = ["dpdk", f"dev {device}"]
263                 self.add_config_item(self._nodeconfig, "", path)
264
265     def add_dpdk_cryptodev(self, count, num_rx_queues=1):
266         """Add DPDK Crypto PCI device configuration.
267
268         :param count: Number of HW crypto devices to add.
269         :param num_rx_queues: Number of RX queues per QAT interface.
270         :type count: int
271         :type num_rx_queues: int
272         """
273         cryptodevs = Topology.get_cryptodev(self._node)
274         for device in cryptodevs.values():
275             for i in range(int(count/len(cryptodevs))):
276                 numvfs = device["numvfs"]
277                 computed = f"{(i+1)//numvfs}.{(i+1)%numvfs}"
278                 addr = re.sub(r"\d.\d$", computed, device["pci_address"])
279                 path = ["dpdk", f"dev {addr}", "num-rx-queues"]
280                 self.add_config_item(self._nodeconfig, num_rx_queues, path)
281         self.add_dpdk_uio_driver("vfio-pci")
282
283     def add_dpdk_sw_cryptodev(self, sw_pmd_type, socket_id, count):
284         """Add DPDK SW Crypto device configuration.
285
286         :param sw_pmd_type: Type of SW crypto device PMD to add.
287         :param socket_id: Socket ID.
288         :param count: Number of SW crypto devices to add.
289         :type sw_pmd_type: str
290         :type socket_id: int
291         :type count: int
292         """
293         for _ in range(count):
294             cryptodev_config = f"vdev cryptodev_{sw_pmd_type}_pmd," \
295                 f"socket_id={str(socket_id)}"
296             path = ["dpdk", cryptodev_config]
297             self.add_config_item(self._nodeconfig, "", path)
298
299     def add_dpdk_dev_default_rxq(self, value):
300         """Add DPDK dev default rxq configuration.
301
302         :param value: Default number of rxqs.
303         :type value: str
304         """
305         path = ["dpdk", "dev default", "num-rx-queues"]
306         self.add_config_item(self._nodeconfig, value, path)
307
308     def add_dpdk_dev_default_txq(self, value):
309         """Add DPDK dev default txq configuration.
310
311         :param value: Default number of txqs.
312         :type value: str
313         """
314         path = ["dpdk", "dev default", "num-tx-queues"]
315         self.add_config_item(self._nodeconfig, value, path)
316
317     def add_dpdk_dev_default_rxd(self, value):
318         """Add DPDK dev default rxd configuration.
319
320         :param value: Default number of rxds.
321         :type value: str
322         """
323         path = ["dpdk", "dev default", "num-rx-desc"]
324         self.add_config_item(self._nodeconfig, value, path)
325
326     def add_dpdk_dev_default_txd(self, value):
327         """Add DPDK dev default txd configuration.
328
329         :param value: Default number of txds.
330         :type value: str
331         """
332         path = ["dpdk", "dev default", "num-tx-desc"]
333         self.add_config_item(self._nodeconfig, value, path)
334
335     def add_dpdk_log_level(self, value):
336         """Add DPDK log-level configuration.
337
338         :param value: Log level.
339         :type value: str
340         """
341         path = ["dpdk", "log-level"]
342         self.add_config_item(self._nodeconfig, value, path)
343
344     def add_dpdk_no_pci(self):
345         """Add DPDK no-pci."""
346         path = ["dpdk", "no-pci"]
347         self.add_config_item(self._nodeconfig, "", path)
348
349     def add_dpdk_uio_driver(self, value=None):
350         """Add DPDK uio-driver configuration.
351
352         :param value: DPDK uio-driver configuration. By default, driver will be
353             loaded automatically from Topology file, still leaving option
354             to manually override by parameter.
355         :type value: str
356         """
357         if value is None:
358             value = Topology.get_uio_driver(self._node)
359         path = ["dpdk", "uio-driver"]
360         self.add_config_item(self._nodeconfig, value, path)
361
362     def add_dpdk_max_simd_bitwidth(self, variant=Constants.GRAPH_NODE_VARIANT):
363         """Add DPDK max-simd-bitwidth configuration.
364
365         :param value: Graph node variant default value.
366         :type value: str
367         """
368         if variant == "icl":
369             value = 512
370         elif variant in ["skx", "hsw"]:
371             value = 256
372         else:
373             return
374
375         path = ["dpdk", "max-simd-bitwidth"]
376         self.add_config_item(self._nodeconfig, value, path)
377
378     def add_cpu_main_core(self, value):
379         """Add CPU main core configuration.
380
381         :param value: Main core option.
382         :type value: str
383         """
384         path = ["cpu", "main-core"]
385         self.add_config_item(self._nodeconfig, value, path)
386
387     def add_cpu_corelist_workers(self, value):
388         """Add CPU corelist-workers configuration.
389
390         :param value: Corelist-workers option.
391         :type value: str
392         """
393         path = ["cpu", "corelist-workers"]
394         self.add_config_item(self._nodeconfig, value, path)
395
396     def add_main_heap_size(self, value):
397         """Add Main Heap Size configuration.
398
399         :param value: Amount of heap.
400         :type value: str
401         """
402         path = ["memory", "main-heap-size"]
403         self.add_config_item(self._nodeconfig, value, path)
404
405     def add_main_heap_page_size(self, value):
406         """Add Main Heap Page Size configuration.
407
408         :param value: Heap page size.
409         :type value: str
410         """
411         path = ["memory", "main-heap-page-size"]
412         self.add_config_item(self._nodeconfig, value, path)
413
414     def add_default_hugepage_size(self, value=Constants.DEFAULT_HUGEPAGE_SIZE):
415         """Add Default Hugepage Size configuration.
416
417         :param value: Hugepage size.
418         :type value: str
419         """
420         path = ["memory", "default-hugepage-size"]
421         self.add_config_item(self._nodeconfig, value, path)
422
423     def add_api_trace(self):
424         """Add API trace configuration."""
425         path = ["api-trace", "on"]
426         self.add_config_item(self._nodeconfig, "", path)
427
428     def add_ip6_hash_buckets(self, value):
429         """Add IP6 hash buckets configuration.
430
431         :param value: Number of IP6 hash buckets.
432         :type value: str
433         """
434         path = ["ip6", "hash-buckets"]
435         self.add_config_item(self._nodeconfig, value, path)
436
437     def add_ip6_heap_size(self, value):
438         """Add IP6 heap-size configuration.
439
440         :param value: IP6 Heapsize amount.
441         :type value: str
442         """
443         path = ["ip6", "heap-size"]
444         self.add_config_item(self._nodeconfig, value, path)
445
446     def add_ipsec_spd_flow_cache_ipv4_inbound(self, value):
447         """Add IPsec spd flow cache for IP4 inbound.
448
449         :param value: "on" to enable spd flow cache.
450         :type value: str
451         """
452         path = ["ipsec", "ipv4-inbound-spd-flow-cache"]
453         self.add_config_item(self._nodeconfig, value, path)
454
455     def add_ipsec_spd_flow_cache_ipv4_outbound(self, value):
456         """Add IPsec spd flow cache for IP4 outbound.
457
458         :param value: "on" to enable spd flow cache.
459         :type value: str
460         """
461         path = ["ipsec", "ipv4-outbound-spd-flow-cache"]
462         self.add_config_item(self._nodeconfig, value, path)
463
464     def add_ipsec_spd_fast_path_ipv4_inbound(self, value):
465         """Add IPsec spd fast path for IP4 inbound.
466
467         :param value: "on" to enable spd fast path.
468         :type value: str
469         """
470         path = [u"ipsec", u"ipv4-inbound-spd-fast-path"]
471         self.add_config_item(self._nodeconfig, value, path)
472
473     def add_ipsec_spd_fast_path_ipv4_outbound(self, value):
474         """Add IPsec spd fast path for IP4 outbound.
475
476         :param value: "on" to enable spd fast path.
477         :type value: str
478         """
479         path = ["ipsec", "ipv4-outbound-spd-fast-path"]
480         self.add_config_item(self._nodeconfig, value, path)
481
482     def add_ipsec_spd_fast_path_num_buckets(self, value):
483         """Add num buckets for IPsec spd fast path.
484
485         :param value: Number of buckets.
486         :type value: int
487         """
488         path = ["ipsec", "spd-fast-path-num-buckets"]
489         self.add_config_item(self._nodeconfig, value, path)
490
491     def add_statseg_size(self, value):
492         """Add Stats Heap Size configuration.
493
494         :param value: Stats heapsize amount.
495         :type value: str
496         """
497         path = ["statseg", "size"]
498         self.add_config_item(self._nodeconfig, value, path)
499
500     def add_statseg_page_size(self, value):
501         """Add Stats Heap Page Size configuration.
502
503         :param value: Stats heapsize amount.
504         :type value: str
505         """
506         path = ["statseg", "page-size"]
507         self.add_config_item(self._nodeconfig, value, path)
508
509     def add_statseg_per_node_counters(self, value):
510         """Add stats per-node-counters configuration.
511
512         :param value: "on" to switch the counters on.
513         :type value: str
514         """
515         path = ["statseg", "per-node-counters"]
516         self.add_config_item(self._nodeconfig, value, path)
517
518     def add_plugin(self, state, *plugins):
519         """Add plugin section for specific plugin(s).
520
521         :param state: State of plugin [enable|disable].
522         :param plugins: Plugin(s) to disable.
523         :type state: str
524         :type plugins: list
525         """
526         for plugin in plugins:
527             path = ["plugins", f"plugin {plugin}", state]
528             self.add_config_item(self._nodeconfig, " ", path)
529
530     def add_dpdk_no_multi_seg(self):
531         """Add DPDK no-multi-seg configuration."""
532         path = ["dpdk", "no-multi-seg"]
533         self.add_config_item(self._nodeconfig, "", path)
534
535     def add_dpdk_no_tx_checksum_offload(self):
536         """Add DPDK no-tx-checksum-offload configuration."""
537         path = ["dpdk", "no-tx-checksum-offload"]
538         self.add_config_item(self._nodeconfig, "", path)
539
540     def add_nat(self, value="deterministic"):
541         """Add NAT mode configuration.
542
543         :param value: NAT mode.
544         :type value: str
545         """
546         path = ["nat", value]
547         self.add_config_item(self._nodeconfig, "", path)
548
549     def add_nat_max_translations_per_thread(self, value):
550         """Add NAT max. translations per thread number configuration.
551
552         :param value: NAT mode.
553         :type value: str
554         """
555         path = ["nat", "max translations per thread"]
556         self.add_config_item(self._nodeconfig, value, path)
557
558     def add_nsim_poll_main_thread(self):
559         """Add NSIM poll-main-thread configuration."""
560         path = ["nsim", "poll-main-thread"]
561         self.add_config_item(self._nodeconfig, "", path)
562
563     def add_tcp_congestion_control_algorithm(self, value="cubic"):
564         """Add TCP congestion control algorithm.
565
566         :param value: The congestion control algorithm to use. Example: cubic
567         :type value: str
568         """
569         path = ["tcp", "cc-algo"]
570         self.add_config_item(self._nodeconfig, value, path)
571
572     def add_tcp_preallocated_connections(self, value):
573         """Add TCP pre-allocated connections.
574
575         :param value: The number of pre-allocated connections.
576         :type value: int
577         """
578         path = ["tcp", "preallocated-connections"]
579         self.add_config_item(self._nodeconfig, value, path)
580
581     def add_tcp_preallocated_half_open_connections(self, value):
582         """Add TCP pre-allocated half open connections.
583
584         :param value: The number of pre-allocated half open connections.
585         :type value: int
586         """
587         path = ["tcp", "preallocated-half-open-connections"]
588         self.add_config_item(self._nodeconfig, value, path)
589
590     def add_session_enable(self):
591         """Add session enable."""
592         path = ["session", "enable"]
593         self.add_config_item(self._nodeconfig, "", path)
594
595     def add_session_app_socket_api(self):
596         """Use session app socket api."""
597         path = ["session", "use-app-socket-api"]
598         self.add_config_item(self._nodeconfig, "", path)
599
600     def add_session_event_queues_memfd_segment(self):
601         """Add session event queue memfd segment."""
602         path = ["session", "evt_qs_memfd_seg"]
603         self.add_config_item(self._nodeconfig, "", path)
604
605     def add_session_event_queue_length(self, value):
606         """Add session event queue length.
607
608         :param value: Session event queue length.
609         :type value: int
610         """
611         path = ["session", "event-queue-length"]
612         self.add_config_item(self._nodeconfig, value, path)
613
614     def add_session_event_queues_segment_size(self, value):
615         """Add session event queue length.
616
617         :param value: Session event queue segment size.
618         :type value: str
619         """
620         path = ["session", "evt_qs_seg_size"]
621         self.add_config_item(self._nodeconfig, value, path)
622
623     def add_session_preallocated_sessions(self, value):
624         """Add the number of pre-allocated sessions.
625
626         :param value: Number of pre-allocated sessions.
627         :type value: int
628         """
629         path = ["session", "preallocated-sessions"]
630         self.add_config_item(self._nodeconfig, value, path)
631
632     def add_session_v4_session_table_buckets(self, value):
633         """Add number of v4 session table buckets to the config.
634
635         :param value: Number of v4 session table buckets.
636         :type value: int
637         """
638         path = ["session", "v4-session-table-buckets"]
639         self.add_config_item(self._nodeconfig, value, path)
640
641     def add_session_v4_session_table_memory(self, value):
642         """Add the size of v4 session table memory.
643
644         :param value: Size of v4 session table memory.
645         :type value: str
646         """
647         path = ["session", "v4-session-table-memory"]
648         self.add_config_item(self._nodeconfig, value, path)
649
650     def add_session_v4_halfopen_table_buckets(self, value):
651         """Add the number of v4 halfopen table buckets.
652
653         :param value: Number of v4 halfopen table buckets.
654         :type value: int
655         """
656         path = ["session", "v4-halfopen-table-buckets"]
657         self.add_config_item(self._nodeconfig, value, path)
658
659     def add_session_v4_halfopen_table_memory(self, value):
660         """Add the size of v4 halfopen table memory.
661
662         :param value: Size of v4 halfopen table memory.
663         :type value: str
664         """
665         path = ["session", "v4-halfopen-table-memory"]
666         self.add_config_item(self._nodeconfig, value, path)
667
668     def add_session_local_endpoints_table_buckets(self, value):
669         """Add the number of local endpoints table buckets.
670
671         :param value: Number of local endpoints table buckets.
672         :type value: int
673         """
674         path = ["session", "local-endpoints-table-buckets"]
675         self.add_config_item(self._nodeconfig, value, path)
676
677     def add_session_local_endpoints_table_memory(self, value):
678         """Add the size of local endpoints table memory.
679
680         :param value: Size of local endpoints table memory.
681         :type value: str
682         """
683         path = ["session", "local-endpoints-table-memory"]
684         self.add_config_item(self._nodeconfig, value, path)
685
686     def add_dma_dev(self, devices):
687         """Add DMA devices configuration.
688
689         :param devices: DMA devices or work queues.
690         :type devices: list
691         """
692         for device in devices:
693             path = ["dsa", f"dev {device}"]
694             self.add_config_item(self._nodeconfig, "", path)
695
696     def add_logging_default_syslog_log_level(self, value="debug"):
697         """Add default logging level for syslog.
698
699         :param value: Log level.
700         :type value: str
701         """
702         path = ["logging", "default-syslog-log-level"]
703         self.add_config_item(self._nodeconfig, value, path)
704
705     def write_config(self, filename=None):
706         """Generate and write VPP startup configuration to file.
707
708         Use data from calls to this class to form a startup.conf file and
709         replace /etc/vpp/startup.conf with it on topology node.
710
711         :param filename: Startup configuration file name.
712         :type filename: str
713         """
714         self.dump_config(self._nodeconfig)
715
716         if filename is None:
717             filename = self._vpp_startup_conf
718
719         cmd = f"echo \"{self._vpp_config}\" | sudo tee {filename}"
720         exec_cmd_no_error(
721             self._node, cmd, message="Writing config file failed!"
722         )
723
724     def apply_config(self, filename=None, verify_vpp=True):
725         """Generate and write VPP startup configuration to file and restart VPP.
726
727         Use data from calls to this class to form a startup.conf file and
728         replace /etc/vpp/startup.conf with it on topology node.
729
730         :param filename: Startup configuration file name.
731         :param verify_vpp: Verify VPP is running after restart.
732         :type filename: str
733         :type verify_vpp: bool
734         """
735         self.write_config(filename=filename)
736
737         VPPUtil.restart_vpp_service(self._node, self._node_key)
738         if verify_vpp:
739             VPPUtil.verify_vpp(self._node)
740
741
742 class VppInitConfig:
743     """VPP Initial Configuration."""
744     @staticmethod
745     def init_vpp_startup_configuration_on_all_duts(nodes):
746         """Apply initial VPP startup configuration on all DUTs.
747
748         :param nodes: Nodes in the topology.
749         :type nodes: dict
750         """
751         huge_size = Constants.DEFAULT_HUGEPAGE_SIZE
752         for node in nodes.values():
753             if node["type"] == NodeType.DUT:
754                 vpp_config = VppConfigGenerator()
755                 vpp_config.set_node(node)
756                 vpp_config.add_unix_log()
757                 vpp_config.add_unix_cli_listen()
758                 vpp_config.add_unix_cli_no_pager()
759                 vpp_config.add_unix_gid()
760                 vpp_config.add_unix_coredump()
761                 vpp_config.add_socksvr(socket=Constants.SOCKSVR_PATH)
762                 vpp_config.add_main_heap_size("2G")
763                 vpp_config.add_main_heap_page_size(huge_size)
764                 vpp_config.add_default_hugepage_size(huge_size)
765                 vpp_config.add_statseg_size("2G")
766                 vpp_config.add_statseg_page_size(huge_size)
767                 vpp_config.add_statseg_per_node_counters("on")
768                 vpp_config.add_plugin("disable", "default")
769                 vpp_config.add_plugin("enable", "dpdk_plugin.so")
770                 vpp_config.add_dpdk_dev(
771                     *[node["interfaces"][interface].get("pci_address") \
772                         for interface in node["interfaces"]]
773                 )
774                 vpp_config.add_ip6_hash_buckets(2000000)
775                 vpp_config.add_ip6_heap_size("4G")
776                 vpp_config.apply_config()