Skip to content

Commit

Permalink
Add flow idle-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyzhai committed Feb 25, 2025
1 parent 8012472 commit 8184676
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 21 deletions.
19 changes: 19 additions & 0 deletions dash-pipeline/SAI/specs/dash_eni.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,19 @@ sai_apis:
valid_only: null
is_vlan: false
deprecated: false
- !!python/object:utils.sai_spec.sai_attribute.SaiAttribute
name: SAI_ENI_ATTR_FLOW_TABLE_ID
description: Action parameter flow table id
type: sai_object_id_t
attr_value_field: u16
default: SAI_NULL_OBJECT_ID
isresourcetype: false
flags: CREATE_AND_SET
object_name: SAI_OBJECT_TYPE_FLOW_TABLE
allow_null: true
valid_only: null
is_vlan: false
deprecated: false
stats:
- !!python/object:utils.sai_spec.sai_attribute.SaiAttribute
name: SAI_ENI_STAT_RX_BYTES
Expand Down Expand Up @@ -1925,3 +1938,9 @@ sai_apis:
bitwidth: 1
ip_is_v6_field_id: 0
skipattr: null
SAI_ENI_ATTR_FLOW_TABLE_ID: !!python/object:utils.sai_spec.sai_api_p4_meta.SaiApiP4MetaActionParam
id: 43
field: u16
bitwidth: 16
ip_is_v6_field_id: 0
skipattr: null
1 change: 1 addition & 0 deletions dash-pipeline/bmv2/dash_headers.p4
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ header flow_data_t {
bit<32> version;
dash_flow_action_t actions;
dash_meter_class_t meter_class;
bit<32> idle_timeout;
}
const bit<16> FLOW_DATA_HDR_SIZE=flow_data_t.minSizeInBytes();

Expand Down
1 change: 1 addition & 0 deletions dash-pipeline/bmv2/dash_metadata.p4
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct meta_flow_data_t {
bit<32> version;
dash_flow_action_t actions;
dash_meter_class_t meter_class;
bit<32> idle_timeout;
}
struct meta_encap_data_t {
bit<24> vni;
Expand Down
5 changes: 4 additions & 1 deletion dash-pipeline/bmv2/dash_pipeline.p4
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ control dash_eni_stage(
@SaiVal[type="sai_object_id_t"] bit<16> outbound_routing_group_id,
bit<1> enable_reverse_tunnel_learning,
@SaiVal[type="sai_ip_address_t"] IPv4Address reverse_tunnel_sip,
bit<1> is_ha_flow_owner)
bit<1> is_ha_flow_owner,
@SaiVal[type="sai_object_id_t"] bit<16> flow_table_id)
{
meta.eni_data.cps = cps;
meta.eni_data.pps = pps;
Expand Down Expand Up @@ -112,6 +113,8 @@ control dash_eni_stage(

meta.ha.ha_scope_id = ha_scope_id;
meta.fast_path_icmp_flow_redirection_disabled = disable_fast_path_icmp_flow_redirection;

meta.flow_table.id = flow_table_id;
}

@SaiTable[name = "eni", api = "dash_eni", order=1, isobject="true"]
Expand Down
47 changes: 28 additions & 19 deletions dash-pipeline/bmv2/stages/conntrack_lookup.p4
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ control conntrack_build_dash_header(inout headers_t hdr, in metadata_t meta,
hdr.flow_data.direction = meta.direction;
hdr.flow_data.actions = (dash_flow_action_t)meta.routing_actions;
hdr.flow_data.meter_class = meta.meter_class;
hdr.flow_data.idle_timeout = meta.flow_data.idle_timeout;
length = length + FLOW_DATA_HDR_SIZE;

if (meta.routing_actions & dash_routing_actions_t.ENCAP_U0 != 0) {
Expand Down Expand Up @@ -386,48 +387,56 @@ control conntrack_lookup_stage(inout headers_t hdr, inout metadata_t meta) {
}
}

action set_flow_key()
action set_flow_key(bit<16> flow_enabled_key)
{
hdr.flow_key.setValid();
hdr.flow_key.is_ip_v6 = meta.is_overlay_ip_v6;
// TODO remove hardcode flow_enabled_key later
meta.flow_table.flow_enabled_key = dash_flow_enabled_key_t.ENI_MAC |
dash_flow_enabled_key_t.VNI |
dash_flow_enabled_key_t.PROTOCOL |
dash_flow_enabled_key_t.SRC_IP |
dash_flow_enabled_key_t.DST_IP |
dash_flow_enabled_key_t.SRC_PORT |
dash_flow_enabled_key_t.DST_PORT;

if (meta.flow_table.flow_enabled_key & dash_flow_enabled_key_t.ENI_MAC != 0) {

if (flow_enabled_key & dash_flow_enabled_key_t.ENI_MAC != 0) {
hdr.flow_key.eni_mac = meta.eni_addr;
}
if (meta.flow_table.flow_enabled_key & dash_flow_enabled_key_t.VNI != 0) {
if (flow_enabled_key & dash_flow_enabled_key_t.VNI != 0) {
hdr.flow_key.vnet_id = meta.vnet_id;
}
if (meta.flow_table.flow_enabled_key & dash_flow_enabled_key_t.PROTOCOL != 0) {
if (flow_enabled_key & dash_flow_enabled_key_t.PROTOCOL != 0) {
hdr.flow_key.ip_proto = meta.ip_protocol;
}
if (meta.flow_table.flow_enabled_key & dash_flow_enabled_key_t.SRC_IP != 0) {
if (flow_enabled_key & dash_flow_enabled_key_t.SRC_IP != 0) {
hdr.flow_key.src_ip = meta.src_ip_addr;
}
if (meta.flow_table.flow_enabled_key & dash_flow_enabled_key_t.DST_IP != 0) {
if (flow_enabled_key & dash_flow_enabled_key_t.DST_IP != 0) {
hdr.flow_key.dst_ip = meta.dst_ip_addr;
}

if (meta.flow_table.flow_enabled_key & dash_flow_enabled_key_t.SRC_PORT != 0) {
if (flow_enabled_key & dash_flow_enabled_key_t.SRC_PORT != 0) {
hdr.flow_key.src_port = meta.src_l4_port;
}

if (meta.flow_table.flow_enabled_key & dash_flow_enabled_key_t.DST_PORT != 0) {
if (flow_enabled_key & dash_flow_enabled_key_t.DST_PORT != 0) {
hdr.flow_key.dst_port = meta.dst_l4_port;
}
}

apply {
if (!hdr.flow_key.isValid()) {
flow_table.apply();
set_flow_key();
bit<16> flow_enabled_key;

if (flow_table.apply().hit) {
meta.flow_data.idle_timeout = meta.flow_table.flow_ttl_in_milliseconds;
flow_enabled_key = meta.flow_table.flow_enabled_key;
}
else {
// Enable all keys by default
flow_enabled_key = dash_flow_enabled_key_t.ENI_MAC |
dash_flow_enabled_key_t.VNI |
dash_flow_enabled_key_t.PROTOCOL |
dash_flow_enabled_key_t.SRC_IP |
dash_flow_enabled_key_t.DST_IP |
dash_flow_enabled_key_t.SRC_PORT |
dash_flow_enabled_key_t.DST_PORT;
}

set_flow_key(flow_enabled_key);
}

flow_entry.apply();
Expand Down
9 changes: 8 additions & 1 deletion dash-pipeline/dpapp/dash/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ dash_flow_create (dash_flow_table_t *flow_table, const dash_header_t *dh)

clib_memcpy_fast(&flow->flow_data, &dh->flow_data, sizeof(dh->flow_data));

if (flow->flow_data.idle_timeout != 0) {
flow->timeout = ntohl(flow->flow_data.idle_timeout)/1000;
if (flow->timeout > DASH_FLOW_MAX_TIMEOUT) {
flow->timeout = DASH_FLOW_MAX_TIMEOUT;
}
}

/* FIXME
* Assume overlay_data, u0_encap_data, u1_encap_data in order if exists
* Need to add their offset in generic.
Expand Down Expand Up @@ -209,7 +216,7 @@ dash_flow_table_init (dash_flow_table_t *flow_table)

TW (tw_timer_wheel_init) (&flow_table->flow_tw,
dash_flow_expired_timer_callback,
1.0 /* timer interval */, 1024);
1.0 /* timer interval */, DASH_FLOW_MAX_TIMEOUT);
}

int
Expand Down
3 changes: 3 additions & 0 deletions dash-pipeline/dpapp/dash/flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

/* Default timeout in seconds */
#define DASH_FLOW_TIMEOUT 30
/* Max timeout in seconds */
#define DASH_FLOW_MAX_TIMEOUT 1024

typedef enum _dash_packet_source_t {
EXTERNAL = 0, // Packets from external sources.
Expand Down Expand Up @@ -89,6 +91,7 @@ typedef struct flow_data {
u32 version;
u32 actions;
u32 meter_class;
u32 idle_timeout;
} __clib_packed flow_data_t;

typedef struct encap_data {
Expand Down
13 changes: 13 additions & 0 deletions test/test-cases/functional/ptf/saidashdpapp_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ def configureVnet(self):
max_resimulated_flow_per_second=0,
outbound_routing_group_id=self.outbound_routing_group)

self.flow_table = sai_thrift_create_flow_table(self.client,
max_flow_count=128,
dash_flow_enabled_key = SAI_DASH_FLOW_ENABLED_KEY_ENI_MAC
|SAI_DASH_FLOW_ENABLED_KEY_VNI
|SAI_DASH_FLOW_ENABLED_KEY_PROTOCOL
|SAI_DASH_FLOW_ENABLED_KEY_SRC_IP
|SAI_DASH_FLOW_ENABLED_KEY_DST_IP
|SAI_DASH_FLOW_ENABLED_KEY_SRC_PORT
|SAI_DASH_FLOW_ENABLED_KEY_DST_PORT,
flow_ttl_in_milliseconds=5000)
assert (self.flow_table != SAI_NULL_OBJECT_ID)
sai_thrift_set_eni_attribute(self.client, eni_oid = self.eni, flow_table_id=self.flow_table)

self.eam = sai_thrift_eni_ether_address_map_entry_t(switch_id=self.switch_id, address = self.eni_mac)
status = sai_thrift_create_eni_ether_address_map_entry(self.client,
eni_ether_address_map_entry=self.eam,
Expand Down

0 comments on commit 8184676

Please sign in to comment.