Skip to content

Commit

Permalink
Revert set_flow_entry_attr params for flow SAI backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyzhai committed Sep 9, 2024
1 parent 68c7deb commit a3b9cf2
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 246 deletions.
322 changes: 182 additions & 140 deletions dash-pipeline/SAI/specs/dash_flow.yaml

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions dash-pipeline/SAI/specs/sai_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,30 @@ enums:
name: DST_MAC
description: ''
value: '2'
- !!python/object:utils.sai_spec.sai_enum.SaiEnum
name: sai_dash_flow_sync_state_t
description: ''
members:
- !!python/object:utils.sai_spec.sai_enum_member.SaiEnumMember
name: FLOW_MISS
description: ''
value: '0'
- !!python/object:utils.sai_spec.sai_enum_member.SaiEnumMember
name: FLOW_CREATED
description: ''
value: '1'
- !!python/object:utils.sai_spec.sai_enum_member.SaiEnumMember
name: FLOW_SYNCED
description: ''
value: '2'
- !!python/object:utils.sai_spec.sai_enum_member.SaiEnumMember
name: FLOW_PENDING_DELETE
description: ''
value: '3'
- !!python/object:utils.sai_spec.sai_enum_member.SaiEnumMember
name: FLOW_PENDING_RESIMULATION
description: ''
value: '4'
port_extenstion: !!python/object:utils.sai_spec.sai_api_extension.SaiApiExtension
attributes: []
stats:
Expand Down
21 changes: 17 additions & 4 deletions dash-pipeline/bmv2/dash_headers.p4
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum bit<16> dash_encapsulation_t {

header encap_data_t {
bit<24> vni;
bit<24> dest_vnet_vni;
bit<8> reserved;
IPv4Address underlay_sip;
IPv4Address underlay_dip;
EthernetAddress underlay_smac;
Expand Down Expand Up @@ -153,6 +153,19 @@ header ipv6_t {
const bit<16> IPV6_HDR_SIZE=320/8;


// Flow sync state
enum bit<8> dash_flow_sync_state_t {
FLOW_MISS = 0, // Flow not created yet
FLOW_CREATED = 1, // Flow is created but not synched or waiting for ack
FLOW_SYNCED = 2, // Flow has been synched to its peer
FLOW_PENDING_DELETE = 3, // Flow is pending deletion, waiting for ack
FLOW_PENDING_RESIMULATION = 4 // Flow is marked as pending resimulation
}

enum bit<32> dash_flow_action_t {
NONE = 0
}

enum bit<16> dash_flow_enabled_key_t {
ENI_MAC = (1 << 0),
VNI = (1 << 1),
Expand Down Expand Up @@ -214,10 +227,10 @@ const bit<16> FLOW_KEY_HDR_SIZE=flow_key_t.minSizeInBytes();
header flow_data_t {
bit<7> reserved;
bit<1> is_unidirectional;
bit<32> version;
dash_flow_sync_state_t sync_state;
dash_direction_t direction;
bit<16> tunnel_id;
bit<32> routing_actions;
bit<32> version;
dash_flow_action_t actions;
dash_meter_class_t meter_class;
}
const bit<16> FLOW_DATA_HDR_SIZE=flow_data_t.minSizeInBytes();
Expand Down
29 changes: 15 additions & 14 deletions dash-pipeline/bmv2/dash_metadata.p4
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@ enum bit<8> dash_ha_state_t {
SWITCHING_TO_STANDALONE = 12
};

// Flow state
enum bit<8> dash_flow_state_t {
FLOW_MISS = 0, // Flow not created yet
FLOW_CREATED = 1, // Flow is created but not synched or waiting for ack
FLOW_SYNCED = 2, // Flow has been synched to its peer
FLOW_PENDING_DELETE = 3, // Flow is pending deletion, waiting for ack
FLOW_PENDING_RESIMULATION = 4 // Flow is marked as pending resimulation
};

struct ha_data_t {
// HA scope settings
bit<16> ha_scope_id;
Expand All @@ -140,18 +131,24 @@ struct ha_data_t {
bit<16> dp_channel_dst_port;
bit<16> dp_channel_src_port_min;
bit<16> dp_channel_src_port_max;

// HA packet/flow state
dash_flow_state_t ha_flow_state;
}

#ifdef TARGET_DPDK_PNA
// redefine encap_data_t -> meta_encap_data_t
// redefine overlay_rewrite_data_t -> meta_overlay_rewrite_data_t
// header in struct is not well supported for target dpdk-pna
struct meta_flow_data_t {
bit<7> reserved;
bit<1> is_unidirectional;
dash_flow_sync_state_t sync_state;
dash_direction_t direction;
bit<32> version;
dash_flow_action_t actions;
dash_meter_class_t meter_class;
}
struct meta_encap_data_t {
bit<24> vni;
bit<24> dest_vnet_vni;
bit<8> reserved;
IPv4Address underlay_sip;
IPv4Address underlay_dip;
EthernetAddress underlay_smac;
Expand Down Expand Up @@ -214,8 +211,12 @@ struct metadata_t {

// Flow data
conntrack_data_t conntrack_data;
#ifdef TARGET_DPDK_PNA
meta_flow_data_t flow_data;
#else
flow_data_t flow_data;
#endif // TARGET_DPDK_PNA
flow_table_data_t flow_table;
dash_flow_state_t flow_state;
bit<16> bulk_get_session_id;
bit<16> bulk_get_session_filter_id;
bool flow_enabled;
Expand Down
9 changes: 4 additions & 5 deletions dash-pipeline/bmv2/dash_parser.p4
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,16 @@ parser dash_parser(
// Flow delete, extract flow_data ...
packet.extract(hd.flow_data);

if (hd.flow_data.routing_actions != 0) {
if (hd.flow_data.actions != 0) {
packet.extract(hd.flow_overlay_data);
}

if (hd.flow_data.routing_actions & dash_routing_actions_t.STATIC_ENCAP != 0) {
if (hd.flow_data.actions & dash_routing_actions_t.STATIC_ENCAP != 0) {
packet.extract(hd.flow_encap_data);
}

if (hd.flow_data.tunnel_id != 0) {
packet.extract(hd.flow_tunnel_data);
}
// FIXME: assume no tunnel data
// packet.extract(hd.flow_tunnel_data);
}

transition parse_customer_ethernet;
Expand Down
3 changes: 2 additions & 1 deletion dash-pipeline/bmv2/dash_pipeline.p4
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ control dash_ingress(

#ifndef TARGET_DPDK_PNA
meta.rx_encap.setValid();
meta.flow_data.setValid();
meta.encap_data.setValid();
meta.tunnel_data.setValid();
meta.overlay_data.setValid();
Expand Down Expand Up @@ -268,7 +269,7 @@ control dash_ingress(
ha_stage.apply(hdr, meta);

if (!meta.flow_enabled ||
(meta.flow_state == dash_flow_state_t.FLOW_MISS &&
(meta.flow_data.sync_state == dash_flow_sync_state_t.FLOW_MISS &&
hdr.packet_meta.packet_source == dash_packet_source_t.EXTERNAL))
{
dash_match_stage.apply(hdr, meta);
Expand Down
145 changes: 72 additions & 73 deletions dash-pipeline/bmv2/stages/conntrack_lookup.p4
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ action conntrack_set_meta_from_dash_header(in headers_t hdr, out metadata_t meta
{
/* basic metadata */
meta.direction = hdr.flow_data.direction;
meta.dash_tunnel_id = hdr.flow_data.tunnel_id;
meta.routing_actions = hdr.flow_data.routing_actions;
meta.dash_tunnel_id = 0;
meta.routing_actions = (bit<32>)hdr.flow_data.actions;
meta.meter_class = hdr.flow_data.meter_class;

/* encapsulation metadata */
#ifdef TARGET_DPDK_PNA
meta.encap_data.vni = hdr.flow_encap_data.vni;
meta.encap_data.dest_vnet_vni = hdr.flow_encap_data.dest_vnet_vni;
meta.encap_data.underlay_sip = hdr.flow_encap_data.underlay_sip;
meta.encap_data.underlay_dip = hdr.flow_encap_data.underlay_dip;
meta.encap_data.underlay_smac = hdr.flow_encap_data.underlay_smac;
Expand All @@ -27,7 +26,6 @@ action conntrack_set_meta_from_dash_header(in headers_t hdr, out metadata_t meta
/* tunnel metadata */
#ifdef TARGET_DPDK_PNA
meta.tunnel_data.vni = hdr.flow_tunnel_data.vni;
meta.tunnel_data.dest_vnet_vni = hdr.flow_tunnel_data.dest_vnet_vni;
meta.tunnel_data.underlay_sip = hdr.flow_tunnel_data.underlay_sip;
meta.tunnel_data.underlay_dip = hdr.flow_tunnel_data.underlay_dip;
meta.tunnel_data.underlay_smac = hdr.flow_tunnel_data.underlay_smac;
Expand Down Expand Up @@ -71,16 +69,14 @@ control conntrack_build_dash_header(inout headers_t hdr, in metadata_t meta,
hdr.flow_data.is_unidirectional = 0;
hdr.flow_data.version = 0;
hdr.flow_data.direction = meta.direction;
hdr.flow_data.tunnel_id = meta.dash_tunnel_id;
hdr.flow_data.routing_actions = meta.routing_actions;
hdr.flow_data.actions = (dash_flow_action_t)meta.routing_actions;
hdr.flow_data.meter_class = meta.meter_class;
length = length + FLOW_DATA_HDR_SIZE;

if (meta.routing_actions & dash_routing_actions_t.STATIC_ENCAP != 0) {
#ifdef TARGET_DPDK_PNA
hdr.flow_encap_data.setValid();
hdr.flow_encap_data.vni = meta.encap_data.vni;
hdr.flow_encap_data.dest_vnet_vni = meta.encap_data.dest_vnet_vni;
hdr.flow_encap_data.underlay_sip = meta.encap_data.underlay_sip;
hdr.flow_encap_data.underlay_dip = meta.encap_data.underlay_dip;
hdr.flow_encap_data.underlay_smac = meta.encap_data.underlay_smac;
Expand All @@ -96,7 +92,6 @@ control conntrack_build_dash_header(inout headers_t hdr, in metadata_t meta,
#ifdef TARGET_DPDK_PNA
hdr.flow_tunnel_data.setValid();
hdr.flow_tunnel_data.vni = meta.tunnel_data.vni;
hdr.flow_tunnel_data.dest_vnet_vni = meta.tunnel_data.dest_vnet_vni;
hdr.flow_tunnel_data.underlay_sip = meta.tunnel_data.underlay_sip;
hdr.flow_tunnel_data.underlay_dip = meta.tunnel_data.underlay_dip;
hdr.flow_tunnel_data.underlay_smac = meta.tunnel_data.underlay_smac;
Expand Down Expand Up @@ -178,11 +173,11 @@ control conntrack_flow_created_handle(inout headers_t hdr, inout metadata_t meta
control conntrack_flow_handle(inout headers_t hdr, inout metadata_t meta)
{
apply {
switch (meta.flow_state) {
dash_flow_state_t.FLOW_MISS: {
switch (meta.flow_data.sync_state) {
dash_flow_sync_state_t.FLOW_MISS: {
conntrack_flow_miss_handle.apply(hdr, meta);
}
dash_flow_state_t.FLOW_CREATED: {
dash_flow_sync_state_t.FLOW_CREATED: {
conntrack_flow_created_handle.apply(hdr, meta);
}
}
Expand Down Expand Up @@ -225,87 +220,91 @@ control conntrack_lookup_stage(inout headers_t hdr, inout metadata_t meta) {
//
action set_flow_entry_attr(
/* Flow basic metadata */
bit<1> is_unidirectional,
dash_flow_state_t state,
bit<32> version,
@SaiVal[type="sai_dash_direction_t"] dash_direction_t dash_direction,
bit<16> tunnel_id,
bit<32> routing_actions,
@SaiVal[type="sai_dash_flow_action_t"] dash_flow_action_t dash_flow_action,
bit<32> meter_class,
bit<1> is_unidirectional_flow,
@SaiVal[type="sai_dash_flow_sync_state_t"] dash_flow_sync_state_t dash_flow_sync_state,

/* Reverse flow key */
EthernetAddress reverse_flow_eni_mac,
bit<16> reverse_flow_vnet_id,
bit<8> reverse_flow_ip_proto,
IPv4ORv6Address reverse_flow_src_ip,
IPv4ORv6Address reverse_flow_dst_ip,
bit<16> reverse_flow_src_port,
bit<16> reverse_flow_dst_port,

/* Flow encap related attributes */
bit<24> encap_data_vni,
bit<24> encap_data_dest_vnet_vni,
IPv4Address encap_data_underlay_sip,
IPv4Address encap_data_underlay_dip,
EthernetAddress encap_data_underlay_smac,
EthernetAddress encap_data_underlay_dmac,
@SaiVal[type="sai_dash_encapsulation_t"] dash_encapsulation_t encap_data_dash_encapsulation,

/* Flow tunnel related attributes */
bit<24> tunnel_data_vni,
bit<24> tunnel_data_dest_vnet_vni,
IPv4Address tunnel_data_underlay_sip,
IPv4Address tunnel_data_underlay_dip,
EthernetAddress tunnel_data_underlay_smac,
EthernetAddress tunnel_data_underlay_dmac,
@SaiVal[type="sai_dash_encapsulation_t"] dash_encapsulation_t tunnel_data_dash_encapsulation,
bit<24> underlay0_vnet_id,
IPv4Address underlay0_sip,
IPv4Address underlay0_dip,
EthernetAddress underlay0_smac,
EthernetAddress underlay0_dmac,
@SaiVal[type="sai_dash_encapsulation_t"] dash_encapsulation_t underlay0_dash_encapsulation,

bit<24> underlay1_vnet_id,
IPv4Address underlay1_sip,
IPv4Address underlay1_dip,
EthernetAddress underlay1_smac,
EthernetAddress underlay1_dmac,
@SaiVal[type="sai_dash_encapsulation_t"] dash_encapsulation_t underlay1_dash_encapsulation,

/* Flow overlay rewrite related attributes */
bit<1> overlay_data_is_ipv6,
EthernetAddress overlay_data_dst_mac,
IPv4ORv6Address overlay_data_sip,
IPv4ORv6Address overlay_data_dip,
IPv6Address overlay_data_sip_mask,
IPv6Address overlay_data_dip_mask,

/* Extra flow metadata, unused */
EthernetAddress dst_mac,
IPv4ORv6Address sip,
IPv4ORv6Address dip,
IPv6Address sip_mask,
IPv6Address dip_mask,
@SaiVal[name = "ip_is_v6"]bit<1> is_ipv6,

/* Extra flow metadata */
@SaiVal[type="sai_u8_list_t"] bit<16> vendor_metadata,
@SaiVal[type="sai_u8_list_t"] bit<16> flow_data_pb)
{
meta.flow_state = state;
// TODO check FLOW_SYNCED in ha
// Do state FSM later
if (state != dash_flow_state_t.FLOW_CREATED) {
return;
}

/* Set basic metadata */
/* Set Flow basic metadata */
meta.flow_data.version = version;
meta.flow_data.direction = dash_direction;
meta.flow_data.actions = dash_flow_action;
meta.flow_data.meter_class = meter_class;
meta.flow_data.is_unidirectional= is_unidirectional_flow;
meta.flow_data.sync_state = dash_flow_sync_state;

/* Also set basic metadata */
meta.direction = dash_direction;
meta.dash_tunnel_id = tunnel_id;
meta.routing_actions = routing_actions;
meta.routing_actions = (bit<32>)dash_flow_action;
meta.meter_class = meter_class;

/* Reverse flow key is not used by now */
;

/* Set encapsulation metadata */
meta.encap_data.vni = encap_data_vni;
meta.encap_data.dest_vnet_vni = encap_data_dest_vnet_vni;
meta.encap_data.underlay_sip = encap_data_underlay_sip;
meta.encap_data.underlay_dip = encap_data_underlay_dip;
meta.encap_data.underlay_smac = encap_data_underlay_smac;
meta.encap_data.underlay_dmac = encap_data_underlay_dmac;
meta.encap_data.dash_encapsulation = encap_data_dash_encapsulation;


/* Set tunnel metadata */
meta.tunnel_data.vni = tunnel_data_vni;
meta.tunnel_data.dest_vnet_vni = tunnel_data_dest_vnet_vni;
meta.tunnel_data.underlay_sip = tunnel_data_underlay_sip;
meta.tunnel_data.underlay_dip = tunnel_data_underlay_dip;
meta.tunnel_data.underlay_smac = tunnel_data_underlay_smac;
meta.tunnel_data.underlay_dmac = tunnel_data_underlay_dmac;
meta.tunnel_data.dash_encapsulation = tunnel_data_dash_encapsulation;
meta.encap_data.vni = underlay0_vnet_id;
meta.encap_data.underlay_sip = underlay0_sip;
meta.encap_data.underlay_dip = underlay0_dip;
meta.encap_data.dash_encapsulation = underlay0_dash_encapsulation;
meta.encap_data.underlay_smac = underlay0_smac;
meta.encap_data.underlay_dmac = underlay0_dmac;

meta.tunnel_data.vni = underlay1_vnet_id;
meta.tunnel_data.underlay_sip = underlay1_sip;
meta.tunnel_data.underlay_dip = underlay1_dip;
meta.tunnel_data.dash_encapsulation = underlay1_dash_encapsulation;
meta.tunnel_data.underlay_smac = underlay1_smac;
meta.tunnel_data.underlay_dmac = underlay1_dmac;

/* Set overlay rewrite metadata */
meta.overlay_data.is_ipv6 = overlay_data_is_ipv6;
meta.overlay_data.dmac = overlay_data_dst_mac;
meta.overlay_data.sip = overlay_data_sip;
meta.overlay_data.dip = overlay_data_dip;
meta.overlay_data.sip_mask = overlay_data_sip_mask;
meta.overlay_data.dip_mask = overlay_data_dip_mask;
meta.overlay_data.dmac = dst_mac;
meta.overlay_data.sip = sip;
meta.overlay_data.dip = dip;
meta.overlay_data.sip_mask = sip_mask;
meta.overlay_data.dip_mask = dip_mask;
meta.overlay_data.is_ipv6 = is_ipv6;
}

action flow_miss() {
meta.flow_state = dash_flow_state_t.FLOW_MISS;
meta.flow_data.sync_state = dash_flow_sync_state_t.FLOW_MISS;
}

@SaiTable[name = "flow", api = "dash_flow", order = 1, enable_bulk_get_api = "true", enable_bulk_get_server = "true"]
Expand Down
Loading

0 comments on commit a3b9cf2

Please sign in to comment.