Config file: Add ability to mask links
To avoid adding yet another section to the config file, and since link operating mode and masks are related, I suggest we set masks in the link_settings
section by adding a mask
field alongside mode
- e.g:
link_settings:
# 1st entry: Settings for A -> B
- from: {board: A}
to: {board: B}
mode: [csp, 156, 162, idle1]
# 2nd entry: Mask links from B -> C
- from: {board: B}
to: {board: C}
mode: [csp, 54, 54, idle1]
mask: True
# 3rd entry: Unmask linkX
- id: linkX
mask: False
By default, all links would be unmasked. Entries can now either specify a mode, specify a mask, or specify both.
Implementation
The link settings are represented by the LinkModeManager
class in src/swatch/config.py
, and this section of the config file is parsed by the _parse_link_settings_section
function from the same file. Looking through these, I suggest extending LinkModeManager
as follows:
- Constructor:
- Add new
mask_by_default
argument, and corresponding member data -
mask_by_default
should never beNone
- should beFalse
if there's no default entry inlink_settings
or ifmask
is not set in the default entry.
- Add new
-
add_rule
method:- Add new
mask
argument. - If either
mask
ormode
is not specified in thatlink_settings
entry, set thatadd_rule
argument toNone
- Add new
- Add
get_mask
/is_masked
method, in analogy toget_mode
- In this case though, since
mask_by_default
can't beNone
, you shouldn't ever need to raise an exception.
- In this case though, since
- Add
get_masked_inputs
andget_masked_outputs
, returning maps of processor objects to lists of indices of the masked ports- Move the first few lines of the
System.mask_links
method here - to automatically mask unconnected input/output ports.
- Move the first few lines of the
I think it'll then make sense to change System.mask_links
to simply:
def mask_links(self, link_manager, *, leases):
rx_ports_to_mask = link_manager.get_masked_inputs()
tx_ports_to_mask = link_manager.get_masked_outputs()
for proc in self.connected_processors:
proc.mask_input_ports(port_indices=rx_ports_to_mask[proc], lease=leases[proc])
proc.mask_output_ports(port_indices=tx_ports_to_mask[proc], lease=leases[proc])
... and in main_link_test
add extra rules to the link manager if the --mask
and --mask-all-except
flags are used - e.g:
if mask_all_except:
link_mode_mgr.add_rule(id_regex='.*', mask=True)
# Then, looping over all '--mask' flags
link_mode_mgr.add_rule(id_regex=mask_flag_value, mask=not mask_all_except)
The implementation of the board-manager mask-links
command (in src/swatch/cli/board_manager/system.py) will also need to be updated at the same time - and may come in handy for testing changes (e.g. if board-manager show system
is run afterwards to check that the correct links are being masked)