API: DSCP Tagging

Link-Inline™ Software User Guide

Platform
Napatech SmartNIC
Content Type
User Guide
Capture Software Version
Link-Inline™ Software 3.2

DSCP (differentiated services field code point) tagging is enabled using the RTE_FLOW_ACTION_TYPE_MODIFY_FIELD action type. Use this DPDK API example to configure the SmartNIC for DSCP tagging.

Modifying the DSCP field

This example creates a flow rule to modify the DSCP field in IPv4 header of received frames matching specific IP addresses and UDP port numbers.
/*Create group 1 exact match 5-tuple to retransmit and DSCP tagging offloaded IPv4 UDP packets.*/
struct rte_flow_attr attr = { .group = 1, .ingress = 1 };

struct rte_flow_item_ipv4 ipv4 = { .hdr = {
  .src_addr = RTE_BE32(RTE_IPV4(20, 10, 10, 2)), .dst_addr = RTE_BE32(RTE_IPV4(20, 10, 11, 23)) }};
struct rte_flow_item_udp udp = { .hdr = {
  .src_port = RTE_BE16(0x1000), .dst_port = RTE_BE16(0x1001) }};
struct rte_flow_item pattern[] = {
  [0] = { .type = RTE_FLOW_ITEM_TYPE_IPV4, .spec = &ipv4, .mask = &rte_flow_item_ipv4_mask },
  [1] = { .type = RTE_FLOW_ITEM_TYPE_UDP, .spec = &udp, .mask = &rte_flow_item_udp_mask }};

struct rte_flow_action_modify_field modify_field_dscp = {
  .operation = RTE_FLOW_MODIFY_SET,
  .dst = { .field = RTE_FLOW_FIELD_IPV4_DSCP },
  .src = { .field = RTE_FLOW_FIELD_VALUE, .value[0] = 0x2 },
  .width = 1 };
struct rte_flow_action_port_id port_id = { .id = 1 };
struct rte_flow_action action[] = {
  [0] = { .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD, .conf = &modify_field_dscp },
  [1] = { .type = RTE_FLOW_ACTION_TYPE_PORT_ID, .conf = &port_id },
  [2] = { .type = RTE_FLOW_ACTION_TYPE_END }};

struct rte_flow_error error;
struct rte_flow *flow = rte_flow_create(PORT_ID, &attr, pattern, action, &error);
if (!flow) {
  /* Error handling */
}

The flow rule includes a group ID of 1 and specifies that the rule applies to ingress traffic. The pattern array specifies the pattern to match on received frames, which includes an IPv4 header and a UDP header.

The action array specifies the action to modify the DSCP field and transmit the frame on port 1. The first action modifies the DSCP field using the modify_field_dscp configuration structure, which sets the field to the value 0x2.

Note: The DSCP field in the IPv6 header can be modified using RTE_FLOW_FIELD_IPV6_DSCP in the rte_flow_action_modify_data structure.
Note: A flow rule with group 0 must be created before the flow rule in this API example is created. This step has been omitted in this example for brevity.