DOCA Flow Connection Tracking
This guide provides an overview and configuration instructions for the DOCA Flow Connection Tracking (CT) API.
The DOCA Flow Connection Tracking (CT) module is a 5-tuple table designed to efficiently track network connections using hardware resources. It supports the following key features:
Track zone and 5-tuple sessions – Track and manage network connections based on a 5-tuple (source IP, destination IP, source port, destination port, and protocol) along with zone-based separation
Zone-based virtual tables – Enable logical isolation using zones
Aging support – Remove idle connections automatically using configurable timeouts
Connection metadata – Set and manage metadata for tracked connections
Bidirectional packet handling – Manage traffic in both directions of a connection
High connection rate – Efficiently handle a high rate of connections per second (CPS)
The CT module makes it simple and efficient to track connections by leveraging hardware resources.
The DOCA Flow CT Pipe is designed to handle non-encapsulated TCP and UDP packets. It supports two primary actions:
Forward to next pipe – For packets that match a known 6-tuple connection (5-tuple + zone)
Miss to next pipe – For packets without a matching connection entry
The application is responsible for handling packets based on these outcomes.
The DOCA Flow CT API consists of four major components:
CT module manipulation – Configure and manage resources within the CT module
CT connection entry manipulation – Add, remove, or update connection entries efficiently
Callbacks – Handle asynchronous processing results for connection entries
Pipe and entry statistics – Monitor connection tracking performance using pipe-level and entry-level statistics
These components provide flexible control over connection tracking and monitoring, allowing applications to adapt to various network scenarios effectively.

Aging
Aging time refers to the maximum duration (in seconds) a session can remain active without detecting any packets. If no packets are observed within this period, the session is terminated.
To support aging, a dedicated aging thread is launched. This thread polls and checks counters for all active connections, ensuring that stale sessions are removed efficiently.
When aging is enabled, either the counter
flag or a non-zero timeout
must be set for at least one connection entry to trigger session expiration.
Managed Mode
In Managed Mode, the application is responsible for:
Managing worker threads
Parsing and handling connection lifecycles
This mode utilizes DOCA Flow CT management APIs for creating and destroying connections.
The CT aging module automatically notifies the application of aged-out connections by invoking callbacks.
Connection Rules and Management
Users have the flexibility to create connection rules with different patterns, metadata (meta), or counters which can be applied separately for each packet direction.
Users must manually define the appropriate meta and mask values for matching (
match
) and modifying (
modify
) packets.
To create rules in stages:
Create one rule for a connection using the standard API.
Add a second rule for the opposite packet direction using the
doca_flow_ct_entry_add_dir()
API.

Processing CT Entries
DOCA Flow provides specialized APIs to process CT entries using a dedicated queue:
doca_flow_entries_process
– Processes pipe entries in the queuedoca_flow_aging_handle
– Handles the aging of pipe entries
Some APIs, such as CT entry status queries and pipe miss queries, are not supported in Managed Mode.
DPU
To enable DOCA Flow CT on the DPU, perform the following on the Arm:
Enable
iommu.passthrough
in Linux boot commands ( or disable SMMU from the DPU BIOS):Run:
sudo vim /etc/
default
/grubSet
GRUB_CMDLINE_LINUX="iommu.passthrough=1"
.Run:
sudo update-grub sudo reboot
Configure DPU firmware with
LAG_RESOURCE_ALLOCATION=1
:sudo mlxconfig -d <device-id> s LAG_RESOURCE_ALLOCATION=
1
InfoRetrieve
device-id
from the output of themst status -v
command. If, under the MST tab, the value is N/A, run themst start
command.Update
/etc/mellanox/mlnx-bf.conf
as follows:ALLOW_SHARED_RQ=
"no"
Perform power cycle on the host and Arm sides.
If working with a single port, set the DPU into e-switch mode:
sudo devlink dev eswitch set pci/<pcie-address> mode switchdev sudo devlink dev param set pci/<pcie-address> name esw_multiport value
false
cmode runtimeInfoRetrieve
pcie-address
from the output of themst status -v
command.If working with two PF ports, set the DPU into multi-port e-switch mode (for the 2 PCIe devices):
sudo devlink dev param set pci/<pcie-address> name esw_multiport value
true
cmode runtimeInfoRetrieve
pcie-address
from the output of themst status -v
command.Define huge pages (see DOCA Flow prerequisites).
ConnectX
To enable DOCA Flow CT on the NVIDIA® ConnectX®, perform the following:
Configure firmware with
LAG_RESOURCE_ALLOCATION=1
:sudo mlxconfig -d <device-id> s LAG_RESOURCE_ALLOCATION=
1
InfoRetrieve
device-id
from the output of themst status -v
command. If, under the MST tab, the value is N/A, run themst start
command.Perform power cycle.
If working with a single port:
sudo devlink dev eswitch set pci/<pcie-address> mode switchdev sudo devlink dev param set pci/<pcie-address> name esw_multiport value
false
cmode runtimeInfoRetrieve
pcie-address
from the output of themst status -v
command.If working with two PF ports:
sudo devlink dev eswitch set pci/<pcie-address0> mode switchdev sudo devlink dev eswitch set pci/<pcie-address1> mode switchdev sudo devlink dev param set pci/<pcie-address0> name esw_multiport value
true
cmode runtime sudo devlink dev param set pci/<pcie-address1> name esw_multiport valuetrue
cmode runtimeInfoRetrieve
pcie-address
from the output of themst status -v
command.Define huge pages (see DOCA Flow prerequisites).
DOCA Flow CT supports actions based on meta and NAT operations. Each action can be defined as either shared or non-shared.
Action descriptors are not supported.
Shared Actions
Actions that can be shared between entries. Shared actions are predefined and reused in multiple entries.
The user gets a handle per shared action created and uses this handle as a reference to the action where required.
It is user responsibility to track shared actions and to remove them when they become irrelevant.
Shared actions are defined using a control queue (see struct doca_flow_ct_cfg).
Non-shared Actions
Actions provided with their data during entry create/update.
These actions are completely managed by DOCA Flow CT and cannot be reused in multiple flows (i.e., NAT operations).
Action Sets in Pipe Creation
When creating a DOCA Flow CT pipe, users must define action sets, just as they would for any other pipe.
Fields in the CT pipe must be marked as CHANGEABLE
during pipe creation. This allows the actual criteria for these fields to be specified later during entry creation.
Only actions related to meta and NAT, as defined in struct doca_flow_ct_actions , are supported.
During entry creation or update, different actions can be specified for each direction, allowing variations in action content and/or action type.
Feature Enable
To enable user actions, configure the following parameters:
User action templates during DOCA Flow CT pipe creation
Maximum number of user actions (
nb_user_actions
on DOCA Flow CT init)
Using Actions in Managed Mode
Init
Configure the following parameters on doca_flow_ct_init()
:
nb_ctrl_queues
– number of control queues for defining shared actionsnb_user_actions
– maximum number of user actions. Must align to 64. Both shared control queues and non-shared control queues cache action IDs to speed up ID allocation. Each queue may cache a maximum of 1024 IDs. Users must configure the expected number of actions + total queues * 1024. This number cannot exceed the number of actions hardware supports.
Create DOCA Flow CT Pipe
Configure actions sets on doca_flow_pipe_create()
.
Create Shared Actions
Use doca_flow_ct_actions_add_shared()
with one of the control queues.
Shared actions can be added at any time before use.
Add Entry
Entry can be created in one of the following ways:
Using an action handle of a predefined shared action
Using action data, which is specific to the flow, not sharable (e.g., for NAT operations)
The entry can have different actions and/or different action types per direction.
Remove Entry
Non-shared actions associated with an entry are implicitly destroyed by DOCA Flow CT.
Shared actions are not destroyed. They can be used by the user until they decide to remove them.
Update Entry
Entry actions can be updated per direction. All combinations of shared/non-shared actions are applicable (e.g., update from shared to non-shared).
DOCA Flow CT allows using a different forward pipe per flow direction.
DOCA Flow CT supports the forward pipe in two levels:
Pipe level – a single forward pipe defined during DOCA Flow CT pipe creation and used for all entries
Entry level – forward pipe defined during entry create
DOCA Flow CT operates in one of the two levels
DOCA CT forward in entry level has the following characteristics:
Supports only
DOCA_FLOW_FWD_PIPE
(up to 4 different forward pipes)Supports forward pipe per flow direction (both directions can have same/different forward pipe)
Must set forward pipes on each entry create (no default forward pipe)
Turn on the feature:
Create DOCA Flow CT pipe with forward type =
DOCA_FLOW_FWD_PIPE
andnext_pipe
=NULL
.Call to
doca_flow_ct_fwd_register
to register forward pipes and getfwd_handles
in return.
Using Changeable Forward in Managed Mode
Initialize DOCA Flow CT (
doca_flow_ct_init
).Register forward pipes (
doca_flow_ct_fwd_register
).Define pipes that can be used for forward
Create DOCA Flow CT pipe (
doca_flow_pipe_create
) w ith definition of possible forward pipes.Add entry (
doca_flow_ct_add_entry
).Set origin and/or reply
fwd_handles
returned fromdoca_flow_ct_fwd_register
.
Update forward for entry direction (
doca_flow_ct_update_entry
).NoteUpdating forward handle requires setting all other parameters with their previous values.
For the library API reference, refer to DOCA Flow and CT API documentation in the DOCA Library APIs.
The pkg-config (*.pc
file) for the Flow CT library is included in DOCA's regular definitions :doca
.
The following sections provide additional details about the library API.
enum doca_flow_ct_flags
DOCA Flow CT configuration optional flags.
Flag | Description |
| Enable internal pipe counters for packet tracking purposes. Call |
| Enable worker thread internal debug counter periodical dump. |
| Disable aging |
| Allow Tunnel or non-tunnel in different direction. |
| Disable counter and aging to save aging thread CPU cycles |
| The user must check TCP SYN flags and UDP in CT miss flow to identify ADD type packets. |
| Hint traffic comes from uplink wire and forwards to uplink wire. Note
If this flag is set, the direction info must be |
| Apply the connection duplication filter for UDP connections only |
enum doca_flow_ct doca_flow_ct_entry_flags
DOCA Flow CT Entry optional flags.
Flag | Description |
| Entry is not buffered; send to hardware immediately |
| Apply flags to origin direction |
| Apply flags to reply direction |
|
Origin direction is IPv6; origin match union in struct |
|
Reply direction is IPv6; reply match union in struct |
| Apply counter to origin direction |
| Apply counter to reply direction |
| Counter is shared for both direction (origin and reply) |
| Enable flow log on entry removed |
|
Allocate on entry not found when calling |
| Enable duplication filter on origin direction |
| Enable duplication filter on reply direction |
enum doca_flow_ct_rule_opr
Options for handling flows in autonomous mode with shared actions. The decision is taken on the first flow packet.
Operation | Description |
| Flow should be defined in the CT pipe using the required shared actions handles |
| Flow should not be defined in the CT pipe. The packet should be dropped. |
| Flow should not be defined in the CT pipe. The packet should be transmitted. |
struct direction_cfg
Managed mode configuration for origin or reply direction.
Field | Description |
| 5-tuple match pattern applies to packet inner layer |
| Mask to indicate meta field and bits to match |
| Mask to indicate meta field and bits to modify on connection packet match |
doca_flow_ct_cfg
DOCA Flow CT configuration manipulation:
struct doca_flow_ct_cfg *ct_cfg;
ret = doca_flow_ct_cfg_create(&ct_cfg);
doca_flow_ct_cfg_set_flags(ct_cfg, flags);
doca_flow_ct_cfg_set_queues(ct_cfg, n_queues);
doca_flow_ct_cfg_set_connections(ct_cfg, n_v4, n_v6, n_max);
...
ret = doca_flow_ct_init(ct_cfg);
final
:
ret = doca_flow_ct_cfg_destroy(ct_cfg);
Where:
Field | Description |
doca_flow_ct_cfg_create(struct doca_flow_ct_cfg **cfg) | Create CT configuration |
doca_flow_ct_cfg_destroy(struct doca_flow_ct_cfg *cfg) | Destroy CT configuration |
doca_flow_ct_cfg_set_flags(struct doca_flow_ct_cfg *cfg, uint32_t flags) |
Set CT flags; see |
doca_flow_ct_cfg_set_queues(struct doca_flow_ct_cfg *cfg, uint32_t n_queues) | Set number of hardware queues to manipulate connections |
doca_flow_ct_cfg_set_queue_depth(struct doca_flow_ct_cfg *cfg, uint32_t queue_depth); | Set queue depth; default to 512 rules |
doca_flow_ct_cfg_set_ctrl_queues(struct doca_flow_ct_cfg *cfg, uint32_t n_ctrl_queues) | Number of CT control queues used for defining shared actions |
doca_flow_ct_cfg_set_user_actions(struct doca_flow_ct_cfg *cfg, uint32_t n_user_actions) | Maximum number of user actions supported (shared and non-shared). Minimum value is 1K * ( |
doca_flow_ct_cfg_set_connections(struct doca_flow_ct_cfg *cfg, | Maximum number of IPv4, IPv6, and total CT connections |
doca_flow_ct_cfg_set_max_connections_per_zone(struct doca_flow_ct_cfg *cfg, | Max CT connection per zone |
doca_flow_ct_cfg_set_counter_asymmetric(struct doca_flow_ct_cfg *cfg, uint32_t n_counter_asymmetric) | Max connections with an asymmetric counter; non-shared counter |
doca_flow_ct_cfg_set_entry_private_data_size(struct doca_flow_ct_cfg *cfg, uint32_t entry_priv_data_size) | User private data size to allocate per connection |
doca_flow_ct_cfg_set_entry_finalize_cb(struct doca_flow_ct_cfg *cfg, | Entry finalize callback to query connection final stats |
doca_flow_ct_cfg_set_status_update_cb(struct doca_flow_ct_cfg *cfg, | Status update callback to notify on counter changes |
doca_flow_ct_cfg_set_aging_core(struct doca_flow_ct_cfg *cfg, uint32_t aging_core) | CPU core ID for CT aging thread to bind. |
doca_flow_ct_cfg_set_aging_query_delay(struct doca_flow_ct_cfg *cfg, uint32_t aging_query_delay_s) | CT aging query delay for new created connections |
doca_flow_ct_cfg_set_aging_plugin_ops(struct doca_flow_ct_cfg *cfg, | User-defined aging logic callback functions. Fallback to default aging logic |
doca_flow_ct_cfg_set_dup_filter_size(struct doca_flow_ct_cfg *cfg, uint32_t dup_filter_sz) | Number of connections to cache in the duplication filter |
doca_flow_ct_cfg_set_direction(struct doca_flow_ct_cfg *cfg, | Configuration origin and reply direction |
struct doca_flow_ct_actions
This structure is used in the following cases:
For defining shared actions. In this case, action data is provided by the user. The action handle is returned by DOCA Flow CT.
For defining an entry with actions. The structure can be filled with two options:
With action handle of a previously created shared action
With non-shared action data
DOCA Flow CT action structure.
enum
doca_flow_resource_type resource_type;
union {
/* Used when creating an entry with a shared action. */
uint32_t action_handle;
/* Used when creating an entry with non-shared action or when creating a shared action. */
struct {
uint32_t action_idx;
struct doca_flow_meta meta;
struct doca_flow_header_l4_port l4_port;
union {
struct doca_flow_ct_ip4 ip4;
struct doca_flow_ct_ip6 ip6;
};
} data;
};
Where:
Field | Description |
| Shared/non-shared action |
| Shared action handle |
| Actions template index |
| Modify meta values |
| UDP or TCP source and destination port |
| Source and destination IPv4 addresses |
| Source and destination IPv6 addresses |
The value in
meta
,
l4_port
,
ip4
, and
ip6
should start from bit0
, the least significant bit, regardless of which bits are set in mask. For example, action_val.meta.u32[0] = DOCA_HTOBE32(0x12)
, action_mask.meta.u32[0] = DOCA_HTOBE32(0x0000FF00)
sets bits 15-8 to 0x12
.
This section describes DOCA Flow CT samples based on the DOCA Flow CT pipe.
The samples illustrate how to use the library API to manage TCP/UDP connections.
All the DOCA samples described in this section are governed under the BSD-3 software license agreement.
Running the Samples
Refer to the following documents:
DOCA Installation Guide for Linux for details on how to install BlueField-related software.
NVIDIA BlueField Platform Software Troubleshooting Guide for any issue you may encounter with the installation, compilation, or execution of DOCA samples.
To build a given sample, run the following command. If you downloaded the sample from GitHub, update the path in the first line to reflect the location of the sample file:
cd /opt/mellanox/doca/samples/doca_flow/flow_ct_udp meson /tmp/build ninja -C /tmp/build
InfoThe binary
doca_flow_ct_udp
is created under/tmp/build/samples/
.Sample (e.g.,
doca_flow_ct_udp
) 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
for
the program <10
=DISABLE,20
=CRITICAL,30
=ERROR,40
=WARNING,50
=INFO,60
=DEBUG,70
=TRACE> --sdk-log-level Set the SDK (numeric) log levelfor
the 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 file Program Flags: -p, --pci_addr <PCI-ADDRESS> PCIe device addressFor additional information per sample, use the
-h
option:/tmp/build/samples/<sample_name> -h
The following is a CLI example for running the samples when port 08:00.0
is configured (multi-port e-switch) as manager port:
/tmp/build/samples/doca_<sample_name> -- -r pci/08
:00.0
,pf0vf0 -l 60
The following is a CLI example for running the samples when port 08:00.0
is configured (multi-port e-switch) as manager port and 08:00.1
is configured as the representor of the second uplink:
/tmp/build/samples/doca_<sample_name> -- -r pci/08
:00.1
-l 60
To avoid the test being impacted by unexpected packets, it only accepts packets like the following examples:
IPv4 destination address is
1.1.1.1
IPv6 destination address is
0101:0101:0101:0101:0101:0101:0101:0101