Skip to content

Commit

Permalink
api: add MTL_FLAG_RX_UDP_PORT_ONLY (#546)
Browse files Browse the repository at this point in the history
To exclusively use port only for flow, the application must ensure that
all RX streams have unique UDP port numbers.

Signed-off-by: Frank Du <[email protected]>
  • Loading branch information
frankdjx authored Oct 24, 2023
1 parent 1772538 commit 85bdcdf
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 31 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ If you find value in our project, please consider giving it a star. Your support
#### 1.1.1 ST2110 features

* Narrow and wide pacing. Please see [compliance](doc/compliance.md) page for the ST2110 narrow report on our software solution.
* ST2110-10, ST2110-20, ST2110-21, ST2110-30, ST2110-40, ST2110-22, ST2022-7
* ST2110-10, ST2110-20, ST2110-21, ST2110-30, ST2110-40, ST2022-7
* 1080p, 720p, 4k, 8k and other
* FPS: 120, 119.88, 100, 60, 59.94, 50, 30, 29.97, 25, 24, 23.98
* All video formats listed in ST2110-20, including YUV 4:2:2 10-bit and others, are supported.
* CSC support status: [status](doc/convert.md)
* ST2110-22 with encoder/decoder [plugin](doc/plugin.md) interface.
* ST2022-6 by RTP passthrough interface.

### 1.2 Architecture
Expand Down
5 changes: 5 additions & 0 deletions app/src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ enum st_args_cmd {
ST_ARG_SHARED_TX_QUEUES,
ST_ARG_SHARED_RX_QUEUES,
ST_ARG_RX_USE_CNI,
ST_ARG_RX_UDP_PORT_ONLY,
ST_ARG_VIRTIO_USER,
ST_ARG_VIDEO_SHA_CHECK,
ST_ARG_MAX,
Expand Down Expand Up @@ -227,6 +228,7 @@ static struct option st_app_args_options[] = {
{"shared_tx_queues", no_argument, 0, ST_ARG_SHARED_TX_QUEUES},
{"shared_rx_queues", no_argument, 0, ST_ARG_SHARED_RX_QUEUES},
{"rx_use_cni", no_argument, 0, ST_ARG_RX_USE_CNI},
{"rx_udp_port_only", no_argument, 0, ST_ARG_RX_UDP_PORT_ONLY},
{"virtio_user", no_argument, 0, ST_ARG_VIRTIO_USER},
{"video_sha_check", no_argument, 0, ST_ARG_VIDEO_SHA_CHECK},

Expand Down Expand Up @@ -690,6 +692,9 @@ int st_app_parse_args(struct st_app_context* ctx, struct mtl_init_params* p, int
case ST_ARG_RX_USE_CNI:
p->flags |= MTL_FLAG_RX_USE_CNI;
break;
case ST_ARG_RX_UDP_PORT_ONLY:
p->flags |= MTL_FLAG_RX_UDP_PORT_ONLY;
break;
case ST_ARG_VIRTIO_USER:
p->flags |= MTL_FLAG_VIRTIO_USER;
break;
Expand Down
2 changes: 1 addition & 1 deletion config/4k_rx_1port_1v.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"interfaces": [
{
"name": "0000:af:00.1",
"name": "0000:af:01.1",
"ip": "192.168.84.189"
}
],
Expand Down
2 changes: 1 addition & 1 deletion config/4k_tx_1port_1v.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"interfaces": [
{
"name": "0000:af:00.0",
"name": "0000:af:01.0",
"ip": "192.168.84.188"
}
],
Expand Down
2 changes: 1 addition & 1 deletion config/8k_rx_1port_1v.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"interfaces": [
{
"name": "0000:af:00.1",
"name": "0000:af:01.1",
"ip": "192.168.84.189"
}
],
Expand Down
2 changes: 1 addition & 1 deletion config/8k_tx_1port_1v.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"interfaces": [
{
"name": "0000:af:00.0",
"name": "0000:af:01.0",
"ip": "192.168.84.188"
}
],
Expand Down
2 changes: 1 addition & 1 deletion config/test_rx_1port_1v.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"interfaces": [
{
"name": "0000:af:00.1",
"name": "0000:af:01.1",
"ip": "192.168.84.189"
}
],
Expand Down
2 changes: 1 addition & 1 deletion config/test_rx_1port_1v_1a_1anc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"interfaces": [
{
"name": "0000:af:00.1",
"name": "0000:af:01.1",
"ip": "192.168.68.189"
}
],
Expand Down
4 changes: 2 additions & 2 deletions config/test_rx_2port_1v_1a.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"interfaces": [
{
"name": "0000:4b:00.0",
"name": "0000:af:01.0",
"ip": "192.168.88.189"
},
{
"name": "0000:4b:00.1",
"name": "0000:af:01.1",
"ip": "192.168.88.199"
}
],
Expand Down
4 changes: 2 additions & 2 deletions config/test_rx_2port_1v_1a_1anc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"user_timestamp": "1111111",
"interfaces": [
{
"name": "0000:4b:00.0",
"name": "0000:af:01.0",
"driver": "uio",
"ip": "192.168.88.189"
},
{
"name": "0000:4b:00.1",
"name": "0000:af:01.1",
"driver": "uio",
"ip": "192.168.88.199"
}
Expand Down
4 changes: 2 additions & 2 deletions config/test_rx_st20p.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"interfaces": [
{
"name": "0000:4b:00.0",
"name": "0000:af:01.0",
"ip": "192.168.96.1"
},
{
"name": "0000:4b:00.1",
"name": "0000:af:01.1",
"ip": "192.168.96.2"
}
],
Expand Down
4 changes: 2 additions & 2 deletions config/test_rx_st22p.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"interfaces": [
{
"name": "0000:4b:00.0",
"name": "0000:af:01.0",
"ip": "192.168.96.1"
},
{
"name": "0000:4b:00.1",
"name": "0000:af:01.1",
"ip": "192.168.96.2"
}
],
Expand Down
2 changes: 1 addition & 1 deletion config/test_tx_1port_1v.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"interfaces": [
{
"name": "0000:af:00.0",
"name": "0000:af:01.0",
"ip": "192.168.84.188"
}
],
Expand Down
2 changes: 1 addition & 1 deletion config/test_tx_1port_1v_1a_1anc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"interfaces": [
{
"name": "0000:af:00.0",
"name": "0000:af:01.0",
"ip": "192.168.68.188"
}
],
Expand Down
2 changes: 1 addition & 1 deletion config/test_tx_1port_1v_2dest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"interfaces": [
{
"name": "0000:4b:00.0",
"name": "0000:af:01.0",
"ip": "192.168.96.188"
}
],
Expand Down
2 changes: 1 addition & 1 deletion config/test_tx_2port_1v_1a.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"interfaces": [
{
"name": "0000:af:00.0",
"name": "0000:af:01.0",
"ip": "192.168.88.188"
},
{
Expand Down
4 changes: 2 additions & 2 deletions config/test_tx_2port_1v_1a_1anc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"interfaces": [
{
"name": "0000:af:00.0",
"name": "0000:af:01.0",
"ip": "192.168.88.188"
},
{
"name": "0000:af:00.1",
"name": "0000:af:01.1",
"driver": "uio",
"ip": "192.168.88.198"
}
Expand Down
4 changes: 2 additions & 2 deletions config/test_tx_2port_1v_1a_1anc_50fps.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"interfaces": [
{
"name": "0000:af:00.0",
"name": "0000:af:01.0",
"ip": "192.168.88.188"
},
{
"name": "0000:af:00.1",
"name": "0000:af:01.1",
"ip": "192.168.88.198"
}
],
Expand Down
4 changes: 2 additions & 2 deletions config/test_tx_2port_1v_1a_1anc_rtp.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"interfaces": [
{
"name": "0000:af:00.0",
"name": "0000:af:01.0",
"ip": "192.168.88.188"
},
{
"name": "0000:af:00.1",
"name": "0000:af:01.1",
"ip": "192.168.88.198"
}
],
Expand Down
6 changes: 6 additions & 0 deletions include/mtl_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ enum st21_tx_pacing_way {
* Use CNI based queue for RX.
*/
#define MTL_FLAG_RX_USE_CNI (MTL_BIT64(45))
/**
* Flag bit in flags of struct mtl_init_params, debug usage only.
* To exclusively use port only for flow, the application must ensure that all RX streams
* have unique UDP port numbers.
*/
#define MTL_FLAG_RX_UDP_PORT_ONLY (MTL_BIT64(46))

/**
* The structure describing how to init af_xdp interface.
Expand Down
22 changes: 17 additions & 5 deletions lib/src/mt_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static struct rte_flow* rte_rx_flow_create(struct mt_interface* inf, uint16_t q,
bool has_port_flow = true;

uint16_t port_id = inf->port_id;
enum mtl_port port = inf->port;

memset(&error, 0, sizeof(error));

Expand All @@ -100,6 +101,13 @@ static struct rte_flow* rte_rx_flow_create(struct mt_interface* inf, uint16_t q,
/* no port flow requested */
if (flow->flags & MT_RXQ_FLOW_F_NO_PORT) has_port_flow = false;

if (mt_get_user_params(inf->parent)->flags & MTL_FLAG_RX_UDP_PORT_ONLY) {
if (has_ip_flow) {
info("%s(%d), no ip flow as MTL_FLAG_RX_UDP_PORT_ONLY is set\n", __func__, port);
has_ip_flow = false;
}
}

/* only raw flow can be applied on the hdr split queue */
if (mt_if_hdr_split_pool(inf, q)) {
return rte_rx_flow_create_raw(inf, q, flow);
Expand Down Expand Up @@ -162,7 +170,7 @@ static struct rte_flow* rte_rx_flow_create(struct mt_interface* inf, uint16_t q,

ret = rte_flow_validate(port_id, &attr, pattern, action, &error);
if (ret < 0) {
err("%s(%d), rte_flow_validate fail %d for queue %d, %s\n", __func__, port_id, ret, q,
err("%s(%d), rte_flow_validate fail %d for queue %d, %s\n", __func__, port, ret, q,
mt_string_safe(error.message));
return NULL;
}
Expand All @@ -171,14 +179,18 @@ static struct rte_flow* rte_rx_flow_create(struct mt_interface* inf, uint16_t q,
r_flow = rte_flow_create(port_id, &attr, pattern, action, &error);
mt_pthread_mutex_unlock(&inf->vf_cmd_mutex);
if (!r_flow) {
err("%s(%d), rte_flow_create fail for queue %d, %s\n", __func__, port_id, q,
err("%s(%d), rte_flow_create fail for queue %d, %s\n", __func__, port, q,
mt_string_safe(error.message));
return NULL;
}

uint8_t* ip = flow->dip_addr;
info("%s(%d), queue %u succ, ip %u.%u.%u.%u port %u\n", __func__, inf->port, q, ip[0],
ip[1], ip[2], ip[3], flow->dst_port);
if (has_ip_flow) {
uint8_t* ip = flow->dip_addr;
info("%s(%d), queue %u succ, ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0],
ip[1], ip[2], ip[3], flow->dst_port);
} else {
info("%s(%d), queue %u succ, port %u\n", __func__, port, q, flow->dst_port);
}
return r_flow;
}

Expand Down
13 changes: 12 additions & 1 deletion lib/src/mt_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ int mt_socket_add_flow(struct mtl_main_impl* impl, enum mtl_port port, uint16_t
int flow_id = -1;
uint8_t start_queue = mt_afxdp_start_queue(impl, port);
const char* if_name = mt_kernel_if_name(impl, port);
bool has_ip_flow = true;

if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) {
err("%s(%d), sys_queue not supported\n", __func__, port);
Expand All @@ -400,7 +401,17 @@ int mt_socket_add_flow(struct mtl_main_impl* impl, enum mtl_port port, uint16_t
return -EIO;
}

if (flow->flags & MT_RXQ_FLOW_F_NO_IP) {
/* no ip flow requested */
if (flow->flags & MT_RXQ_FLOW_F_NO_IP) has_ip_flow = false;

if (mt_get_user_params(impl)->flags & MTL_FLAG_RX_UDP_PORT_ONLY) {
if (has_ip_flow) {
info("%s(%d), no ip flow as MTL_FLAG_RX_UDP_PORT_ONLY is set\n", __func__, port);
has_ip_flow = false;
}
}

if (!has_ip_flow) {
snprintf(cmd, sizeof(cmd), "ethtool -N %s flow-type udp4 dst-port %u action %u",
if_name, flow->dst_port, queue_id + start_queue);
} else if (mt_is_multicast_ip(flow->dip_addr)) {
Expand Down

0 comments on commit 85bdcdf

Please sign in to comment.