DOCA Flow Tune Server
This guide provides an overview and configuration instructions for DOCA Flow Tune Server API.
DOCA Flow Tune Server (TS), DOCA Flow subcomponent, exposes an API to collect predefined internal key performance indicators (KPIs) and pipeline visualization of a running DOCA Flow application.
Supported port KPIs:
Total add operations across all queues
Total update operations across all queues
Total remove operations across all queues
Pending operations number across all queues
Number of
NO_WAITflag operations across all queuesNumber of shared resources and counters
Number of pipes
Supported application KPIs:
Number of ports
Number of queues
Queues depth
Pipeline information is saved to a JSON file to simplify its structure. Visualization is supported for the following DOCA Flow pipes:
Basic
Control
Each pipe contains the following fields:
Type
Name
Domain
Is root
Match
Match mask
FWD
FWD miss
Supported entry information:
Basic
FWD
Control
FWD
Match
Match mask
Priority
DOCA Flow Tune Server API is available only by using the DOCA Flow and DOCA Flow Tune Server trace libraries.
For more detailed information, refer to section "DOCA Flow Debug and Trace" under DOCA Flow.
For more detailed information on DOCA Flow API, refer to NVIDIA DOCA Library APIs.
The following subsections provide additional details about the library API.
3.1 enum doca_flow_tune_server_kpi_type
DOCA Flow TS KPI flags.
Flag | Description |
| Retrieve port number |
| Retrieve queue number |
| Retrieve queue depth |
| Retrieve shared resource and counter numbers |
| Retrieve number of pipes per port |
| Retrieve entry add operations per port |
| Retrieve entry update operations per port |
| Retrieve entry remove operations per port |
| Retrieve entry pending operations per port |
| Retrieve entry |
3.2 struct doca_flow_tune_server_shared_resources_kpi_res
Holds the number of each shared resources and counters per port.
Field | Description |
| Number of meters |
| Number of counters |
| Number of RSS |
| Number of mirrors |
| Number of PSP |
| Number of encap |
| Number of decap |
3.3 struct doca_flow_tune_server_kpi_res
Holds the KPI result.
This structure is required when calling doca_flow_tune_server_get_kpi or doca_flow_tune_server_get_port_kpi.
Field | Description |
| KPI result type |
| Shared resource result values |
| Result value |
3.4 doca_flow_tune_server_cfg_create
Creates DOCA Flow Tune Server configuration structure.
doca_error_t doca_flow_tune_server_cfg_create(struct doca_flow_tune_server **cfg);
3.5 doca_flow_tune_server_cfg_set_bind_path
Adds local path to the configuration struct on which the DOCA Flow Tune Server AF_UNIX socket binds.
doca_error_t doca_flow_tune_server_cfg_set_bind_path(struct doca_flow_tune_server *cfg, const char *path, size_t path_len);
3.6 doca_flow_tune_server_cfg_destroy
Destroys DOCA Flow Tune Server configuration structure.
doca_error_t doca_flow_tune_server_cfg_destroy(struct doca_flow_tune_server *cfg);
3.7 doca_flow_tune_server_init
Initializes DOCA Flow Tune Server internal structures.
doca_error_t doca_flow_tune_server_init(void);
3.8 doca_flow_tune_server_destroy
Destroys DOCA Flow Tune Server internal structures.
void doca_flow_tune_server_destroy(void);
3.9 doca_flow_tune_server_query_pipe_line
Queries and dumps pipeline info for all ports to a JSON file pointed by fp.
doca_error_t doca_flow_tune_server_query_pipe_line(FILE *fp);
3.10 doca_flow_tune_server_get_port_ids
Retrieves ports identification numbers.
doca_error_t doca_flow_tune_server_get_port_ids(uint16_t *port_id_arr, uint16_t port_id_arr_len, uint16_t *nr_ports);
3.11 doca_flow_tune_server_get_kpi
Retrieves application scope KPI.
doca_error_t doca_flow_tune_server_get_kpi(enum doca_flow_tune_server_kpi_type kpi_type,
struct doca_flow_tune_server_kpi_res *res)
3.12 doca_flow_tune_server_get_port_kpi
Retrieves port scope KPI.
doca_error_t doca_flow_tune_server_get_port_kpi(uint16_t port_id,
enum doca_flow_tune_server_kpi_type kpi_type,
struct doca_flow_tune_server_kpi_res *res);
This section describes DOCA Flow Tune Server samples.
The samples illustrate how to use the library API to retrieve KPIs or save pipeline information into a JSON file.
All the DOCA samples described in this section are governed under the BSD-3 software license agreement.
4.1 Running the Samples
Refer to the following documents:
NVIDIA DOCA Installation Guide for Linux for details on how to install BlueField-related software.
NVIDIA DOCA Troubleshooting Guide for any issue you may encounter with the installation, compilation, or execution of DOCA samples.
To build a given sample:
cd /opt/mellanox/doca/samples/doca_flow/flow_tune_server_dump_pipeline meson /tmp/build ninja -C /tmp/build
InfoThe binary
doca_flow_tune_server_dump_pipelineis created under/tmp/build/samples/.Sample (e.g.,
doca_flow_tune_server_dump_pipeline) usage:Usage: doca_<sample_name> [DOCA Flags] [Program Flags] DOCA Flags: -h, --help Print a help synopsis -v, --version Print program version information -l, --log-level Set the (numeric) log level
forthe program <10=DISABLE,20=CRITICAL,30=ERROR,40=WARNING,50=INFO,60=DEBUG,70=TRACE> --sdk-log-level Set the SDK (numeric) log levelforthe program <10=DISABLE,20=CRITICAL,30=ERROR,40=WARNING,50=INFO,60=DEBUG,70=TRACE> -j, --json <path> Parse all command flags from an input json fileFor additional information per sample, use the
-hoption:/tmp/build/samples/<sample_name> -h
The following is a CLI example for running the samples:
/tmp/build/doca_<sample_name> -a auxiliary:mlx5_core.sf.2,dv_flow_en=2 -a auxiliary:mlx5_core.sf.3,dv_flow_en=2 -- -l 60
4.2 Samples
4.2.1 Flow Tune Server KPI
This sample illustrates how to use DOCA Flow Tune Server API to retrieve KPIs.
The sample logic includes:
Initializing DOCA Flow by indicating
mode_args="vnf,hws"in thedoca_flow_cfgstruct.Starting a single DOCA Flow port.
Creating a server configuration struct using the
doca_flow_tune_server_cfg_createfunction.Initializing DOCA Flow server using the
doca_flow_tune_server_initfunction. This must be done after calling thedoca_flow_port_startfunction (or theinit_doca_flow_portshelper function).Querying existing port IDs using the
doca_flow_tune_server_get_port_idsfunction.Querying application level KPIs using
doca_flow_tune_server_get_kpifunction. The following KPI are read:Number of queues
Queue depth
KPIs per port on which the basic pipe is created:
Add operation entries.
Adding 20 entries followed by a second call to query entries add operations.
Reference:
/opt/mellanox/doca/samples/doca_flow/flow_tune_server_kpi/flow_tune_server_kpi_sample.c/opt/mellanox/doca/samples/doca_flow/flow_tune_server_kpi/flow_tune_server_kpi_main.c/opt/mellanox/doca/samples/doca_flow/flow_tune_server_kpi/meson.build
4.2.2 Flow Tune Server Dump Pipeline
This sample illustrates how to use DOCA Flow Tune Server API to dump pipeline information into a JSON file.
The sample logic includes:
Initializing DOCA Flow by indicating
mode_args="vnf,hws"in thedoca_flow_cfgstruct.Starting two DOCA Flow ports.
Creating server configuration struct using the
doca_flow_tune_server_cfg_createfunction.Initializing DOCA Flow server using
doca_flow_tune_server_initfunction.NoteThis must be done after calling
init_foca_flow_portsfunction.Opening a file called
sample_pipeline.jsonfor writing.For each port:
Creating a pipe to drop all traffic.
Creating a pipe to hairpin traffic from port 0 to port 1
Creating FWD pipe to forward traffic based on 5-tuple.
Adding two entries to FWD pipe, each entry with different 5-tuple.
Creating a control pipe and adding the FWD pipe as an entry.
Dumping the pipeline information into a file.
Reference:
/opt/mellanox/doca/samples/doca_flow/flow_tune_server_dump_pipeline/flow_tune_server_dump_pipeline_sample.c/opt/mellanox/doca/samples/doca_flow/flow_tune_server_dump_pipeline/flow_tune_server_dump_pipeline_main.c/opt/mellanox/doca/samples/doca_flow/flow_tune_server_dump_pipeline/meson.build
Once a DOCA Flow application pipeline has been exported to a JSON file, it is easy to visualize it using tools such as Mermaid.
Save the following Python script locally to a file named
doca-flow-viz.py(or similar). This script converts a given JSON file produced by DOCA Flow TS to a Mermaid diagram embedded in a markdown document.#!/usr/bin/python3## Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED.## This software product is a proprietary product of NVIDIA CORPORATION &# AFFILIATES (the "Company") and all right, title, and interest in and to the# software product, including all associated intellectual property rights, are# and shall remain exclusively with the Company.## This software product is governed by the End User License Agreement# provided with the software product.#importglobimportjsonimportsysimportos.pathclassMermaidConfig:def__init__(self):self.prefix_pipe_name_with_port_id=Falseself.show_match_criteria=Falseself.show_actions=FalseclassMermaidFormatter:def__init__(self, cfg):self.cfg=cfgself.syntax=''self.prefix_pipe_name_with_port_id=cfg.prefix_pipe_name_with_port_iddefformat(self, data):self.prefix_pipe_name_with_port_id=self.cfg.prefix_pipe_name_with_port_idandlen(data.get('ports', [])) >0ifnot'ports'indata: port_id=data.get('port_id',0) data={'ports': [ {'port_id': port_id,'pipes': data['pipes'] } ] }self.syntax=''self.append('```mermaid')self.append('graph LR')self.declare_terminal_states(data)forportindata['ports']:self.process_port(port)self.append('```')returnself.syntaxdefappend(self, text, endline="\n"):self.syntax+=text+endlinedefdeclare_terminal_states(self, data): all_fwd_types=self.get_all_fwd_types(data)if'drop'inall_fwd_types:self.append(' drop[[drop]]')if'rss'inall_fwd_types:self.append(' RSS[[RSS]]')defget_all_fwd_types(self, data):# Gather all 'fwd' and 'fwd_miss' types from pipes and 'fwd' types from entriesall_fwd_types={ fwd_typeforportindata.get('ports', [])forpipeinport.get('pipes', [])fortagin['fwd','fwd_miss']# Process both 'fwd' and 'fwd_miss' for each pipeforfwd_typein[pipe.get(tag, {}).get('type',None)]# Extract the 'type'iffwd_type } | { fwd_typeforportindata.get('ports', [])forpipeinport.get('pipes', [])fortagin['fwd']forentryinpipe.get('entries', [])# Process all entries in each pipeforfwd_typein[entry.get(tag, {}).get('type',None)]iffwd_type }returnall_fwd_typesdefprocess_port(self, port): port_id=port['port_id'] pipe_names=self.resolve_pipe_names(port)self.declare_pipes(port, pipe_names)forpipeinport.get('pipes', []):self.process_pipe(pipe, port_id)defresolve_pipe_names(self, port): pipe_names={} port_id=port['port_id']forpipeinport.get('pipes', []):id=pipe['pipe_id'] name=pipe['attributes'].get('name', f"pipe_{id}")ifself.prefix_pipe_name_with_port_id: name=f"p{port_id}.{name}"pipe_names[id]=namereturnpipe_namesdefdeclare_pipes(self, port, pipe_names): port_id=port['port_id']forpipeinport.get('pipes', []):id=pipe['pipe_id'] name=pipe_names[id]self.declare_pipe(port_id, pipe, name)defdeclare_pipe(self, port_id, pipe, pipe_name):id=pipe['pipe_id'] attr="\n(root)"ifself.pipe_is_root(pipe)else""ifself.cfg.show_match_criteriaandnotself.pipe_is_ctrl(pipe): fields_matched=self.pipe_match_criteria(pipe,'match') attr+=f"\nmatch: {fields_matched}"self.append(f' p{port_id}.pipe_{id}{{{{"{pipe_name}{attr}"}}}}')defpipe_match_criteria(self, pipe, key: ['match','match_mask']):return"\n".join(self.extract_match_criteria_paths(None, pipe.get(key, {})))or'None'defextract_match_criteria_paths(self, prefix, match):fork,vinmatch.items():ifisinstance(v,dict): new_prefix=f"{prefix}.{k}"ifprefixelsekforxinself.extract_match_criteria_paths(new_prefix, v):yieldxelse:# ignore v, the match valueyieldf"{prefix}.{k}"ifprefixelsekdefpipe_is_ctrl(self, pipe):returnpipe['attributes']['type']=='control'defpipe_is_root(self, pipe):returnpipe['attributes'].get('is_root',False)defprocess_pipe(self, pipe, port_id): pipe_id=f"pipe_{pipe['pipe_id']}"is_ctrl=self.pipe_is_ctrl(pipe)self.declare_fwd(port_id, pipe_id,'-->',self.get_fwd_target(pipe.get('fwd', {}), port_id))self.declare_fwd(port_id, pipe_id,'-.->',self.get_fwd_target(pipe.get('fwd_miss', {}), port_id))forentryinpipe.get('entries', []): fields_matched=self.pipe_match_criteria(entry,'match')ifis_ctrlelseNonefields_matched=f'|"{fields_matched}"|'iffields_matchedelse''self.declare_fwd(port_id, pipe_id, f'-->{fields_matched}',self.get_fwd_target(entry.get('fwd', {}), port_id))ifself.pipe_is_root(pipe):self.declare_fwd(port_id,None,'-->', f"p{port_id}.{pipe_id}")defget_fwd_target(self, fwd, port_id): fwd_type=fwd.get('type',None)ifnotfwd_type:returnNoneiffwd_type=='changeable':returnNoneeliffwd_type=='pipe': pipe_id=fwd.get('pipe_id', fwd.get('value',None)) target=f"p{port_id}.pipe_{pipe_id}"eliffwd_type=='port': port_id=fwd.get('port_id', fwd.get('value',None)) target=f"p{port_id}.egress"else: target=f"{fwd_type}"returntargetdefdeclare_fwd(self, port_id, pipe_id, arrow, target):iftarget: src=f"p{port_id}.{pipe_id}"ifpipe_idelsef"p{port_id}.ingress"self.append(f" {src} {arrow} {target}")defjson_to_md(infile, outfile, cfg): formatter=MermaidFormatter(cfg) data=json.load(infile) mermaid_syntax=formatter.format(data) outfile.write(mermaid_syntax)defjson_dir_to_md_inplace(dir, cfg):forinfileinglob.glob(dir+'/**/*.json', recursive=True): outfile=os.path.splitext(infile)[0]+'.md'print(f"{infile} --> {outfile}") json_to_md(open(infile,'r'),open(outfile,'w'), cfg)defmain()->int: cfg=MermaidConfig() cfg.show_match_criteria=Trueiflen(sys.argv)==2andos.path.isdir(sys.argv[1]): json_dir_to_md_inplace(sys.argv[1], cfg)else: infile=open(sys.argv[1],'r')iflen(sys.argv) >1elsesys.stdin outfile=open(sys.argv[2],'w')iflen(sys.argv) >2elsesys.stdout json_to_md(infile, outfile, cfg)if__name__=='__main__': sys.exit(main())The resulting Markdown can be viewed in several ways, including:
Microsoft Visual Studio Code (using an available Mermaid plugin, such as this one)
In the GitHub and GitLab built-in Markdown renderer (after committing the output to a Git repo)
By pasting only the Flowchart content into the Online FlowChart and Diagram Editor
The Python script can be invoked as follows:
python3 doca-flow-viz.py sample_pipeline.json sample_pipeline.md
In the case of the
flow_tune_server_dump_pipelinesample, the script produces the following diagram: