Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove flow type enum #427

Merged
merged 5 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/sys_design/dpservice_dataplane.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions include/dp_mbuf_dyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ extern "C" {

struct dp_flow {
struct {
uint16_t flow_type : 2; // local,outgoing,incoming
uint16_t public_flow : 1;
uint16_t overlay_type: 1; // supported overlay type
uint16_t overlay_type : 1; // supported overlay type
uint16_t nat : 3;
uint16_t offload_ipv6 : 1; // tmp solution to set if we should offload ipv6 pkts
uint16_t dir : 2; // store the direction of each packet
Expand Down Expand Up @@ -61,8 +60,8 @@ struct dp_flow {
uint8_t proto_id; //proto_id in outer ipv6 header
uint32_t dst_vni;
} tun_info;
uint8_t vnf_type;
uint8_t nxt_hop;
uint8_t vnf_type; // TODO(plague) enum?
uint8_t nxt_hop;
struct flow_value *conntrack;
#ifdef ENABLE_VIRTSVC
struct dp_virtsvc *virtsvc;
Expand Down
7 changes: 1 addition & 6 deletions include/dp_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ extern "C" {

#define VM_IFACE_ID_MAX_LEN 64

enum dp_port_type {
DP_PORT_PF,
DP_PORT_VF,
};

struct macip_entry {
struct rte_ether_addr own_mac;
struct rte_ether_addr neigh_mac;
Expand All @@ -43,7 +38,7 @@ struct vm_entry {
};

struct dp_port {
enum dp_port_type port_type;
bool is_pf;
uint16_t port_id;
char port_name[IF_NAMESIZE];
int socket_id;
Expand Down
4 changes: 0 additions & 4 deletions include/rte_flow/dp_rte_flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ extern "C"
#include "dp_lpm.h"
#include "dp_mbuf_dyn.h"

#define DP_FLOW_TYPE_LOCAL 1
#define DP_FLOW_TYPE_OUTGOING 2
#define DP_FLOW_TYPE_INCOMING 3

#define DP_FLOW_WEST_EAST 0
#define DP_FLOW_SOUTH_NORTH 1

Expand Down
19 changes: 9 additions & 10 deletions src/dp_cntrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,31 +93,30 @@ static __rte_always_inline void dp_cntrack_init_flow_offload_flags(struct flow_v

static __rte_always_inline void dp_cntrack_change_flow_offload_flags(struct rte_mbuf *m, struct flow_value *flow_val, struct dp_flow *df)
{
bool offload_check = false;
bool offload_other_pf = false;
struct dp_port *port = dp_get_port(m);

if (!offload_mode_enabled)
return;

if (df->flags.flow_type == DP_FLOW_TYPE_INCOMING) {
if (m->port == dp_get_pf0()->port_id)
offload_check = flow_val->incoming_flow_offloaded_flag.pf0;
if (port->is_pf) {
if (port == dp_get_pf0())
offload_other_pf = !flow_val->incoming_flow_offloaded_flag.pf0;
else
offload_check = flow_val->incoming_flow_offloaded_flag.pf1;
offload_other_pf = !flow_val->incoming_flow_offloaded_flag.pf1;
}

if (df->flags.dir == DP_FLOW_DIR_ORG) {
/* Despite the incoming flow is offloaded to one of the pf ports, pkts can arrive on another one */
/* So we need to check if the incoming flow is offloaded on the current port, */
/* if not, we do another offloading */
if (flow_val->offload_flags.orig == DP_FLOW_NON_OFFLOAD ||
(df->flags.flow_type == DP_FLOW_TYPE_INCOMING && !offload_check))
if (flow_val->offload_flags.orig == DP_FLOW_NON_OFFLOAD || offload_other_pf)
flow_val->offload_flags.orig = DP_FLOW_OFFLOAD_INSTALL;
else if (flow_val->offload_flags.orig == DP_FLOW_OFFLOAD_INSTALL)
flow_val->offload_flags.orig = DP_FLOW_OFFLOADED;

} else if (df->flags.dir == DP_FLOW_DIR_REPLY) {
if (flow_val->offload_flags.reply == DP_FLOW_NON_OFFLOAD ||
(df->flags.flow_type == DP_FLOW_TYPE_INCOMING && !offload_check))
if (flow_val->offload_flags.reply == DP_FLOW_NON_OFFLOAD || offload_other_pf)
flow_val->offload_flags.reply = DP_FLOW_OFFLOAD_INSTALL;
else if (flow_val->offload_flags.reply == DP_FLOW_OFFLOAD_INSTALL)
flow_val->offload_flags.reply = DP_FLOW_OFFLOADED;
Expand Down Expand Up @@ -170,7 +169,7 @@ static __rte_always_inline struct flow_value *flow_table_insert_entry(struct flo
/* This will be an uni-directional traffic, which does not expect its corresponding reverse traffic */
/* Details can be found in https://github.com/onmetal/net-dpservice/pull/341 */
if (offload_mode_enabled
&& (df->flags.flow_type != DP_FLOW_TYPE_INCOMING)
&& !port->is_pf
&& !DP_FAILED(dp_get_vnf_entry(&vnf_val, DP_VNF_TYPE_LB_ALIAS_PFX, port, DP_VNF_MATCH_ALL_PORT_ID))
)
flow_val->nf_info.nat_type = DP_FLOW_LB_TYPE_LOCAL_NEIGH_TRAFFIC;
Expand Down
4 changes: 2 additions & 2 deletions src/dp_firewall.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ enum dp_fwall_action dp_get_firewall_action(struct dp_flow *df,
struct dp_fwall_rule *rule;

/* Outgoing traffic to PF (VF Egress, PF Ingress), PF has no Ingress rules */
if (dst_port->port_type == DP_PORT_PF)
if (dst_port->is_pf)
return dp_get_egress_action(df, &src_port->vm.fwall_head);

/* Incoming from PF, PF has no Egress rules */
if (src_port->port_type == DP_PORT_PF)
if (src_port->is_pf)
egress_action = DP_FWALL_ACCEPT;
/* Incoming from VF. Check originating VF's Egress rules */
else
Expand Down
4 changes: 2 additions & 2 deletions src/dp_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static __rte_always_inline void dp_mark_vnf_type(struct dp_flow *df, const struc
struct snat_data *s_data;
struct dp_vnf_value vnf_val;

if (df->flags.flow_type == DP_FLOW_TYPE_INCOMING) {
if (port->is_pf) {
if (df->vnf_type == DP_VNF_TYPE_NAT || df->vnf_type == DP_VNF_TYPE_LB_ALIAS_PFX)
key->vnf = (uint8_t)df->vnf_type;
else
Expand Down Expand Up @@ -129,7 +129,7 @@ int dp_build_flow_key(struct flow_key *key /* out */, struct rte_mbuf *m /* in *

key->proto = df->l4_type;

if (df->flags.flow_type == DP_FLOW_TYPE_INCOMING)
if (port->is_pf)
key->vni = df->tun_info.dst_vni;
else
key->vni = port->vm.vni;
Expand Down
11 changes: 4 additions & 7 deletions src/dp_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,17 @@ static int dp_graph_init_nodes(void)

// some nodes need a direct Tx connection to all PF/VF ports, add them dynamically
snprintf(name, sizeof(name), "tx-%u", port_id);
switch (port->port_type) {
case DP_PORT_VF:
if (port->is_pf) {
if (DP_FAILED(ipip_encap_node_append_pf_tx(port_id, name)))
return DP_ERROR;
} else {
if (DP_FAILED(arp_node_append_vf_tx(port_id, name))
|| DP_FAILED(dhcp_node_append_vf_tx(port_id, name))
|| DP_FAILED(dhcpv6_node_append_vf_tx(port_id, name))
|| DP_FAILED(ipv6_nd_node_append_vf_tx(port_id, name))
|| DP_FAILED(firewall_node_append_vf_tx(port_id, name))
|| DP_FAILED(rx_periodic_node_append_vf_tx(port_id, name)))
return DP_ERROR;
break;
case DP_PORT_PF:
if (DP_FAILED(ipip_encap_node_append_pf_tx(port_id, name)))
return DP_ERROR;
break;
}
#ifdef ENABLE_VIRTSVC
// virtual services node is bi-directional
Expand Down
10 changes: 5 additions & 5 deletions src/dp_hairpin.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ static int setup_hairpin_rx_tx_queues(uint16_t port_id,

int dp_hairpin_setup(const struct dp_port *port)
{

uint16_t hairpin_queue_id = 0;
uint16_t peer_hairpin_queue_id = 0;

hairpin_queue_id = DP_NR_STD_RX_QUEUES;
if (port->port_type == DP_PORT_VF)
peer_hairpin_queue_id = DP_NR_RESERVED_TX_QUEUES - 1 + port->peer_pf_hairpin_tx_rx_queue_offset;
else
if (port->is_pf)
peer_hairpin_queue_id = DP_NR_STD_TX_QUEUES - 1 + port->peer_pf_hairpin_tx_rx_queue_offset;
else
peer_hairpin_queue_id = DP_NR_RESERVED_TX_QUEUES - 1 + port->peer_pf_hairpin_tx_rx_queue_offset;

if (DP_FAILED(setup_hairpin_rx_tx_queues(port->port_id,
port->peer_pf_port_id,
Expand All @@ -85,7 +84,7 @@ int dp_hairpin_setup(const struct dp_port *port)
}

// PF's hairpin queue is configured one by one
if (port->port_type == DP_PORT_VF) {
if (!port->is_pf) {
if (DP_FAILED(setup_hairpin_rx_tx_queues(port->peer_pf_port_id,
port->port_id,
peer_hairpin_queue_id,
Expand All @@ -95,6 +94,7 @@ int dp_hairpin_setup(const struct dp_port *port)
return DP_ERROR;
}
}

return DP_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dp_internal_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int dp_nat_get_used_ports_telemetry(struct rte_tel_data *dict)
int ret;

DP_FOREACH_PORT(ports, port) {
if (port->port_type != DP_PORT_VF || !port->allocated)
if (port->is_pf || !port->allocated)
continue;

ret = rte_tel_data_add_dict_u64(dict, port->vm.machineid, port->stats.nat_stats.used_port_cnt);
Expand Down
10 changes: 5 additions & 5 deletions src/dp_lpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int dp_add_route(const struct dp_port *port, uint32_t vni, uint32_t t_vni, uint3
// can only fail if node is NULL
rte_rib_set_nh(node, port->port_id);
/* This is an external route */
if (port->port_type == DP_PORT_PF) {
if (port->is_pf) {
route = rte_rib_get_ext(node);
route->vni = t_vni;
rte_memcpy(route->nh_ipv6, ip6, sizeof(route->nh_ipv6));
Expand Down Expand Up @@ -164,7 +164,7 @@ static int dp_list_route_entry(struct rte_rib_node *node,
if (unlikely(!dst_port))
return DP_GRPC_ERR_NO_VM;

if ((ext_routes && dst_port->port_type == DP_PORT_PF)
if ((ext_routes && dst_port->is_pf)
|| (!ext_routes && dst_port->port_id == port->port_id && !dp_route_in_dhcp_range(node, port))
) {
reply = dp_grpc_add_reply(responder);
Expand Down Expand Up @@ -240,7 +240,7 @@ int dp_add_route6(const struct dp_port *port, uint32_t vni, uint32_t t_vni, cons
// can only fail if node is NULL
rte_rib6_set_nh(node, port->port_id);
/* This is an external route */
if (port->port_type == DP_PORT_PF) {
if (port->is_pf) {
route = rte_rib6_get_ext(node);
route->vni = t_vni;
rte_memcpy(route->nh_ipv6, ext_ip6, sizeof(route->nh_ipv6));
Expand Down Expand Up @@ -302,7 +302,7 @@ const struct dp_port *dp_get_ip4_dst_port(const struct dp_port *port,
if (!dst_port)
return NULL;

if (dst_port->port_type == DP_PORT_PF)
if (dst_port->is_pf)
*route = *(struct vm_route *)rte_rib_get_ext(node);

if (DP_FAILED(rte_rib_get_ip(node, route_key)))
Expand Down Expand Up @@ -339,7 +339,7 @@ const struct dp_port *dp_get_ip6_dst_port(const struct dp_port *port,
if (!dst_port)
return NULL;

if (dst_port->port_type == DP_PORT_PF)
if (dst_port->is_pf)
*route = *(struct vm_route *)rte_rib6_get_ext(node);

return dst_port;
Expand Down
2 changes: 1 addition & 1 deletion src/dp_periodic_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void send_to_all_vfs(const struct rte_mbuf *pkt, uint16_t eth_type)
int ret;

DP_FOREACH_PORT(ports, port) {
if (port->port_type != DP_PORT_VF || !port->allocated)
if (port->is_pf || !port->allocated)
continue;

clone_buf = rte_pktmbuf_copy(pkt, dp_layer->rte_mempool, 0, UINT32_MAX);
Expand Down
Loading
Loading