DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dpdklibs_gen.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3import json
4import os
5import rich.traceback
6from rich.console import Console
7from os.path import exists, join
8from daqconf.core.system import System
9from daqconf.core.conf_utils import make_app_command_data
10from daqconf.core.metadata import write_metadata_file
11from daqconf.core.config_file import generate_cli_from_schema
12
13console = Console()
14
15# Set moo schema search path
16from dunedaq.env import get_moo_model_path
17import moo.io
18moo.io.default_load_path = get_moo_model_path()
19
20import click
21
22# Add -h as default help option
23CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
24@click.command(context_settings=CONTEXT_SETTINGS)
25@generate_cli_from_schema('dpdklibs/confgen.jsonnet', 'dpdklibs_gen')
26@click.argument('json_dir', type=click.Path())
27@click.option('--debug', default=False, is_flag=True, help="Switch to get a lot of printout and dot files")
28def cli(config, json_dir, debug):
29
30 if exists(json_dir):
31 raise RuntimeError(f"Directory {json_dir} already exists")
32
33 config_data = config[0]
34 config_file = config[1]
35
36 # Get our config objects
37 moo.otypes.load_types('dpdklibs/confgen.jsonnet')
38 import dunedaq.dpdklibs.confgen as confgen
39 moo.otypes.load_types('daqconf/confgen.jsonnet')
40 import dunedaq.daqconf.confgen as daqconfgen
41
42 boot = daqconfgen.boot(**config_data.boot)
43 dpdklibs = confgen.dpdklibs(**config_data.dpdklibs)
44
45 # Validate options
46 if dpdklibs.only_sender and dpdklibs.only_reader:
47 raise RuntimeError('Both options only_sender and only_reader can not be specified at the same time')
48
49 if dpdklibs.sender_boards % dpdklibs.sender_cores:
50 raise RuntimeError(f'sender_boards has to be divisible by sender_cores ({dpdklibs.sender_boards} is not divisible by {dpdklibs.sender_cores}')
51
52 enable_sender, enable_receiver = True, True
53 if dpdklibs.only_sender:
54 enable_receiver = False
55 if dpdklibs.only_reader:
56 enable_sender = False
57
58 console.log('Loading dpdklibs config generator')
59 from dpdklibs import sender_confgen
60 from dpdklibs import reader_confgen
61
62 the_system = System()
63
64 # add app
65 if enable_sender:
66 the_system.apps["dpdk-sender"] = sender_confgen.generate_dpdk_sender_app(
67 HOST=dpdklibs.host_sender,
68 NUMBER_OF_CORES=dpdklibs.sender_cores,
69 NUMBER_OF_IPS_PER_CORE=dpdklibs.sender_boards // dpdklibs.sender_cores,
70 TIME_TICK_DIFFERENCE=dpdklibs.sender_time_tick_difference,
71 )
72 if enable_receiver:
73 the_system.apps["dpdk-reader"] = reader_confgen.generate_dpdk_reader_app(
74 HOST=dpdklibs.host_reader,
75 EAL_ARGS=dpdklibs.eal_args,
76 )
77
78 # Arrange per-app command data into the format used by util.write_json_files()
79 app_command_datas = {
80 name : make_app_command_data(the_system, app, name)
81 for name,app in the_system.apps.items()
82 }
83
84 # Make boot.json config
85 from daqconf.core.conf_utils import make_system_command_datas, write_json_files
86
87 system_command_datas = make_system_command_datas(
88 boot,
89 the_system,
90 verbose=False
91 )
92
93 write_json_files(app_command_datas, system_command_datas, json_dir, verbose=True)
94
95 console.log(f"dpdklibs app config generated in {json_dir}")
96
97 write_metadata_file(json_dir, "dpdklibs_confgen", config_file)
98
99if __name__ == '__main__':
100 try:
101 cli(show_default=True, standalone_mode=True)
102 except Exception as e:
103 console.print_exception()
cli(config, json_dir, debug)