Skip to content

Commit

Permalink
added test cases for lb relaying functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
byteocean authored and guvenc committed Aug 4, 2023
1 parent e749caf commit 2d63c7a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/dp_timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void dp_timers_free(void);
int dp_timers_add_stats(rte_timer_cb_t stats_cb);

uint64_t dp_timers_get_manage_interval_cycles(void);
uint8_t dp_timers_get_flow_aging_interval(void);
void dp_timers_signal_initialization(void);

#ifdef __cplusplus
Expand Down
14 changes: 8 additions & 6 deletions src/dp_cntrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
#include "dp_log.h"
#include "dp_vnf.h"
#include "rte_flow/dp_rte_flow.h"
#include "dp_conf.h"


static struct flow_key first_key = {0};
static struct flow_key second_key = {0};
static struct flow_key *prev_key = NULL, *curr_key = &first_key;
static struct flow_value *prev_flow_val = NULL;
static int flow_timeout = DP_FLOW_DEFAULT_TIMEOUT;
static uint64_t fast_path_timestamp = 0;
static uint64_t last_fast_path_timestamp, pkt_timestamp = 0;
static uint64_t fast_path_vars_timeout = 0;
static bool offload_mode_enabled = 0;

void dp_cntrack_init(void)
{
offload_mode_enabled = dp_conf_is_offload_enabled();
fast_path_vars_timeout = (DP_FLOW_DEFAULT_TIMEOUT - dp_timers_get_flow_aging_interval() - 1) * rte_get_timer_hz();
}

static __rte_always_inline void dp_cntrack_tcp_state(struct flow_value *flow_val, struct rte_tcp_hdr *tcp_hdr)
Expand Down Expand Up @@ -217,7 +218,6 @@ int dp_cntrack_handle(struct rte_node *node, struct rte_mbuf *m, struct dp_flow
struct flow_key *key = NULL;
bool same_key;
int ret;
uint64_t timer_hz = rte_get_timer_hz();

#ifdef ENABLE_PYTEST
flow_timeout = dp_conf_get_flow_timeout();
Expand All @@ -231,8 +231,10 @@ int dp_cntrack_handle(struct rte_node *node, struct rte_mbuf *m, struct dp_flow
if (unlikely(DP_FAILED(dp_build_flow_key(key, m))))
return DP_ERROR;

pkt_timestamp = rte_rdtsc();

// clean up temp vars in case a (same) flow expires and is removed from the flow table
if (rte_rdtsc() - fast_path_timestamp > (DP_FLOW_DEFAULT_TIMEOUT - 3) * timer_hz) {
if ((pkt_timestamp - last_fast_path_timestamp) > fast_path_vars_timeout) {
prev_key = NULL;
prev_flow_val = NULL;
}
Expand Down Expand Up @@ -272,8 +274,8 @@ int dp_cntrack_handle(struct rte_node *node, struct rte_mbuf *m, struct dp_flow
dp_set_flow_offload_flag(m, flow_val, df);
}

flow_val->timestamp = rte_rdtsc();
fast_path_timestamp = flow_val->timestamp;
flow_val->timestamp = pkt_timestamp;
last_fast_path_timestamp = pkt_timestamp;

if (df->l4_type == IPPROTO_TCP && !dp_get_pkt_mark(m)->flags.is_recirc) {
tcp_hdr = (struct rte_tcp_hdr *) (ipv4_hdr + 1);
Expand Down
5 changes: 5 additions & 0 deletions src/dp_timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ uint64_t dp_timers_get_manage_interval_cycles(void)
return dp_timer_manage_interval_cycles;
}

uint8_t dp_timers_get_flow_aging_interval(void)
{
return TIMER_FLOW_AGING_INTERVAL;
}

static inline int dp_timers_add(struct rte_timer *timer, int period, rte_timer_cb_t callback)
{
uint64_t cycles = period * rte_get_timer_hz();
Expand Down
24 changes: 24 additions & 0 deletions test/test_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,27 @@ def test_nat_to_lb_nat(request, prepare_ipv4, grpc_client, port_redundancy):
grpc_client.dellbtarget(lb_name, lb_vm1_ul_ipv6)
grpc_client.dellbprefix(VM1.name, lb_ip)
grpc_client.dellb(lb_name)

def send_bounce_pkt_to_pf(ipv6_lb):
bouce_pkt = (Ether(dst=ipv6_multicast_mac, src=PF0.mac, type=0x86DD) /
IPv6(dst=ipv6_lb, src=local_ul_ipv6, nh=4) /
IP(dst=lb_ip, src=public_ip) /
TCP(sport=8989, dport=80))
delayed_sendp(bouce_pkt, PF0.tap)

def test_external_lb_relay(prepare_ipv4, grpc_client):

lb_ul_ipv6 = grpc_client.createlb(lb_name, vni1, lb_ip, "tcp/80")
grpc_client.addlbtarget(lb_name, neigh_ul_ipv6)


threading.Thread(target=send_bounce_pkt_to_pf, args=(lb_ul_ipv6,)).start()
pkt = sniff_packet(PF0.tap, is_tcp_pkt, skip=1)

dst_ip = pkt[IPv6].dst
assert dst_ip == neigh_ul_ipv6, \
f"Wrong network-lb relayed packet (outer dst ipv6: {dst_ip})"


grpc_client.dellbtarget(lb_name, neigh_ul_ipv6)
grpc_client.dellb(lb_name)
37 changes: 37 additions & 0 deletions test/xtratest_flow_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,40 @@ def test_virtsvc_tcp_timeout(request, prepare_ipv4, fast_flow_timeout):
tester.client_port = 12350
tester.server_pkt_check = tcp_server_virtsvc_pkt_check_first_port
tester.request_rst()


def send_bounce_pkt_to_pf(ipv6_lb):
bouce_pkt = (Ether(dst=ipv6_multicast_mac, src=PF0.mac, type=0x86DD) /
IPv6(dst=ipv6_lb, src=local_ul_ipv6, nh=4) /
IP(dst=lb_ip, src=public_ip) /
TCP(sport=8989, dport=80))
delayed_sendp(bouce_pkt, PF0.tap)

def sniff_lb_pkt(dst_ipv6):
pkt = sniff_packet(PF0.tap, is_tcp_pkt, skip=1)
dst_ip = pkt[IPv6].dst
assert dst_ip == dst_ipv6, \
f"Wrong network-lb relayed packet (outer dst ipv6: {dst_ip})"

def test_external_lb_relay_timeout(prepare_ipv4, grpc_client, fast_flow_timeout):

if not fast_flow_timeout:
pytest.skip("Fast flow timeout needs to be enabled")

lb_ul_ipv6 = grpc_client.createlb(lb_name, vni1, lb_ip, "tcp/80")
grpc_client.addlbtarget(lb_name, neigh_ul_ipv6)

threading.Thread(target=send_bounce_pkt_to_pf, args=(lb_ul_ipv6,)).start()
sniff_lb_pkt(neigh_ul_ipv6)

age_out_flows()
threading.Thread(target=send_bounce_pkt_to_pf, args=(lb_ul_ipv6,)).start()
sniff_lb_pkt(neigh_ul_ipv6)

age_out_flows()
threading.Thread(target=send_bounce_pkt_to_pf, args=(lb_ul_ipv6,)).start()
sniff_lb_pkt(neigh_ul_ipv6)


grpc_client.dellbtarget(lb_name, neigh_ul_ipv6)
grpc_client.dellb(lb_name)

0 comments on commit 2d63c7a

Please sign in to comment.