Skip to content

Commit

Permalink
switch: Add support to direct-tx
Browse files Browse the repository at this point in the history
  • Loading branch information
acassen committed Apr 15, 2024
1 parent 8de4150 commit 5795266
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/bpf/gtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ struct gtp_rt_rule {
#define GTP_RT_FL_UDP_LEARNING (1 << 3)

/* FIXME: How can we fetch cpu_num in BPF context ? */
const volatile int nr_cpus = 32;
//const volatile int nr_cpus = 32;
const volatile int nr_cpus = 16;

struct rt_percpu_ctx {
/* ingress */
Expand Down
14 changes: 14 additions & 0 deletions src/gtp_switch_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ DEFUN(no_gtp_switch,
return CMD_SUCCESS;
}

DEFUN(gtp_switch_direct_tx,
gtp_switch_direct_tx_cmd,
"direct-tx",
"xmit packet to the same interface it was received on\n")
{
gtp_switch_t *ctx = vty->index;

__set_bit(GTP_FL_DIRECT_TX_BIT, &ctx->flags);
return CMD_SUCCESS;
}

DEFUN(gtpc_switch_tunnel_endpoint,
gtpc_switch_tunnel_endpoint_cmd,
"gtpc-tunnel-endpoint (A.B.C.D|X:X:X:X) port <1024-65535> [listener-count [INTEGER]]",
Expand Down Expand Up @@ -492,6 +503,8 @@ gtp_config_write(vty_t *vty)
list_for_each_entry(ctx, l, next) {
vty_out(vty, "gtp-switch %s%s", ctx->name, VTY_NEWLINE);
srv = &ctx->gtpc;
if (__test_bit(GTP_FL_DIRECT_TX_BIT, &srv->flags))
vty_out(vty, " direct-tx");
if (__test_bit(GTP_FL_CTL_BIT, &srv->flags)) {
vty_out(vty, " gtpc-tunnel-endpoint %s port %d"
, inet_sockaddrtos(&srv->addr)
Expand Down Expand Up @@ -558,6 +571,7 @@ gtp_switch_vty_init(void)
install_element(CONFIG_NODE, &no_gtp_switch_cmd);

install_default(GTP_SWITCH_NODE);
install_element(GTP_SWITCH_NODE, &gtp_switch_direct_tx_cmd);
install_element(GTP_SWITCH_NODE, &gtpc_switch_tunnel_endpoint_cmd);
install_element(GTP_SWITCH_NODE, &gtpu_switch_tunnel_endpoint_cmd);
install_element(GTP_SWITCH_NODE, &gtpc_force_pgw_selection_cmd);
Expand Down
28 changes: 27 additions & 1 deletion src/gtp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,30 @@ DEFUN(show_xdp_forwarding_iptnl,
return CMD_SUCCESS;
}

DEFUN(show_xdp_forwarding_mac_learning,
show_xdp_forwarding_mac_learning_cmd,
"show xdp forwarding mac-learning",
SHOW_STR
"GTP XDP Forwarding MAC Address Learning\n")
{
int err;

if (!__test_bit(GTP_FL_GTP_FORWARD_LOADED_BIT, &daemon_data->flags)) {
vty_out(vty, "%% XDP GTP-U is not configured. Ignoring%s"
, VTY_NEWLINE);
return CMD_WARNING;
}

err = gtp_xdp_fwd_mac_learning_vty(vty);
if (err) {
vty_out(vty, "%% Error displaying XDP ruleset%s"
, VTY_NEWLINE);
return CMD_WARNING;
}

return CMD_SUCCESS;
}

DEFUN(show_xdp_routing,
show_xdp_routing_cmd,
"show xdp routing",
Expand Down Expand Up @@ -607,7 +631,7 @@ DEFUN(show_xdp_routing_mac_learning,
show_xdp_routing_mac_learning_cmd,
"show xdp routing mac-learning",
SHOW_STR
"GTP XDP Routing IPIP MAC Address Learning\n")
"GTP XDP Routing MAC Address Learning\n")
{
int err;

Expand Down Expand Up @@ -842,6 +866,7 @@ gtp_vty_init(void)
/* Install show commands */
install_element(VIEW_NODE, &show_xdp_forwarding_cmd);
install_element(VIEW_NODE, &show_xdp_forwarding_iptnl_cmd);
install_element(VIEW_NODE, &show_xdp_forwarding_mac_learning_cmd);
install_element(VIEW_NODE, &show_xdp_routing_cmd);
install_element(VIEW_NODE, &show_xdp_routing_iptnl_cmd);
install_element(VIEW_NODE, &show_xdp_routing_mac_learning_cmd);
Expand All @@ -850,6 +875,7 @@ gtp_vty_init(void)
install_element(VIEW_NODE, &gtp_send_echo_request_extended_cmd);
install_element(ENABLE_NODE, &show_xdp_forwarding_cmd);
install_element(ENABLE_NODE, &show_xdp_forwarding_iptnl_cmd);
install_element(ENABLE_NODE, &show_xdp_forwarding_mac_learning_cmd);
install_element(ENABLE_NODE, &show_xdp_routing_cmd);
install_element(ENABLE_NODE, &show_xdp_routing_iptnl_cmd);
install_element(ENABLE_NODE, &show_xdp_routing_mac_learning_cmd);
Expand Down
6 changes: 6 additions & 0 deletions src/gtp_xdp_fwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,15 @@ static void
gtp_xdp_teid_rule_set(struct gtp_teid_rule *r, gtp_teid_t *t)
{
unsigned int nr_cpus = bpf_num_possible_cpus();
gtp_session_t *s = t->session;
gtp_server_t *w_srv = s->w->srv;
gtp_switch_t *sw = w_srv->ctx;
__u8 flags = __test_bit(GTP_TEID_FL_INGRESS, &t->flags) ? GTP_FWD_FL_INGRESS : GTP_FWD_FL_EGRESS;
int i;

if (__test_bit(GTP_FL_DIRECT_TX_BIT, &sw->flags))
flags |= GTP_FWD_FL_DIRECT_TX;

for (i = 0; i < nr_cpus; i++) {
r[i].vteid = t->vid;
r[i].teid = t->id;
Expand Down
1 change: 1 addition & 0 deletions src/include/gtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum gtp_flags {
GTP_FL_UPF_BIT,
GTP_FL_FORCE_PGW_BIT,
GTP_FL_IPTNL_BIT,
GTP_FL_DIRECT_TX_BIT,
};

/* default values */
Expand Down
1 change: 1 addition & 0 deletions src/include/gtp_xdp_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ extern int gtp_xdp_fwd_teid_vty(vty_t *, __be32);
extern int gtp_xdp_fwd_vty(vty_t *);
extern int gtp_xdp_fwd_iptnl_action(int, gtp_iptnl_t *);
extern int gtp_xdp_fwd_iptnl_vty(vty_t *);
extern int gtp_xdp_fwd_mac_learning_vty(vty_t *);

#endif

0 comments on commit 5795266

Please sign in to comment.