Skip to content

Commit

Permalink
Added vrf implementation in worker
Browse files Browse the repository at this point in the history
  • Loading branch information
stal76 committed Dec 22, 2024
1 parent 22de5cc commit a180c58
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 22 deletions.
120 changes: 100 additions & 20 deletions dataplane/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,19 +963,19 @@ inline void cWorker::handlePackets()
tsc_deltas->write(tsc_start, stack_size, tsc_deltas->balancer_icmp_forward_handle, base_values.balancer_icmp_forward_handle);
}

stack_size = route_stack4.mbufsCount;
stack_size = route_stack4.mbufsCount + vrf_route_stack4.mbufsCount;
route_handle4();
tsc_deltas->write(tsc_start, stack_size, tsc_deltas->route_handle4, base_values.route_handle4);

stack_size = route_stack6.mbufsCount;
stack_size = route_stack6.mbufsCount + vrf_route_stack6.mbufsCount;
route_handle6();
tsc_deltas->write(tsc_start, stack_size, tsc_deltas->route_handle6, base_values.route_handle6);

stack_size = route_tunnel_stack4.mbufsCount;
stack_size = route_tunnel_stack4.mbufsCount + vrf_route_tunnel_stack4.mbufsCount;
route_tunnel_handle4();
tsc_deltas->write(tsc_start, stack_size, tsc_deltas->route_tunnel_handle4, base_values.route_tunnel_handle4);

stack_size = route_tunnel_stack6.mbufsCount;
stack_size = route_tunnel_stack6.mbufsCount + vrf_route_tunnel_stack6.mbufsCount;
route_tunnel_handle6();
tsc_deltas->write(tsc_start, stack_size, tsc_deltas->route_tunnel_handle6, base_values.route_tunnel_handle6);

Expand Down Expand Up @@ -2099,11 +2099,25 @@ inline void cWorker::route_entry(rte_mbuf* mbuf)

if (metadata->network_headerType == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
{
route_stack4.insert(mbuf);
if (metadata->vrfId == 0)
{
route_stack4.insert(mbuf);
}
else
{
vrf_route_stack4.insert(mbuf);
}
}
else if (metadata->network_headerType == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
{
route_stack6.insert(mbuf);
if (metadata->vrfId == 0)
{
route_stack6.insert(mbuf);
}
else
{
vrf_route_stack6.insert(mbuf);
}
}
else
{
Expand All @@ -2120,10 +2134,14 @@ inline void cWorker::route_handle4()
{
const auto& base = bases[localBaseId & 1];

if (unlikely(route_stack4.mbufsCount == 0))
unsigned int countVrf0 = route_stack4.mbufsCount;
unsigned int countVrfOther = vrf_route_stack4.mbufsCount;
if (unlikely(countVrf0 + countVrfOther == 0))
{
return;
}
route_stack4.copy_from(vrf_route_stack4);
vrf_route_stack4.clear();

for (unsigned int mbuf_i = 0;
mbuf_i < route_stack4.mbufsCount;
Expand All @@ -2133,12 +2151,21 @@ inline void cWorker::route_handle4()
dataplane::metadata* metadata = YADECAP_METADATA(mbuf);
rte_ipv4_hdr* ipv4Header = rte_pktmbuf_mtod_offset(mbuf, rte_ipv4_hdr*, metadata->network_headerOffset);

route_ipv4_keys[mbuf_i] = ipv4Header->dst_addr;
route_keys.ipv4[mbuf_i] = ipv4Header->dst_addr;
route_keys.vrfs[mbuf_i] = metadata->vrfId;

calcHash(mbuf);
}

base.globalBase->route_lpm4->lookup(route_ipv4_keys, route_ipv4_values, route_stack4.mbufsCount);
if (countVrf0 != 0)
{
base.globalBase->route_lpm4->lookup(route_keys.ipv4, route_ipv4_values, countVrf0);
}
if (countVrfOther != 0)
{
base.globalBase->vrf_route_lpm4.Lookup(route_keys.ipv4 + countVrf0, route_keys.vrfs + countVrf0, route_ipv4_values + countVrf0, countVrfOther);
}

for (unsigned int mbuf_i = 0;
mbuf_i < route_stack4.mbufsCount;
mbuf_i++)
Expand Down Expand Up @@ -2248,10 +2275,14 @@ inline void cWorker::route_handle6()
{
const auto& base = bases[localBaseId & 1];

if (unlikely(route_stack6.mbufsCount == 0))
unsigned int countVrf0 = route_stack6.mbufsCount;
unsigned int countVrfOther = vrf_route_stack6.mbufsCount;
if (unlikely(countVrf0 + countVrfOther == 0))
{
return;
}
route_stack6.copy_from(vrf_route_stack6);
vrf_route_stack6.clear();

for (unsigned int mbuf_i = 0;
mbuf_i < route_stack6.mbufsCount;
Expand All @@ -2261,12 +2292,21 @@ inline void cWorker::route_handle6()
dataplane::metadata* metadata = YADECAP_METADATA(mbuf);
rte_ipv6_hdr* ipv6Header = rte_pktmbuf_mtod_offset(mbuf, rte_ipv6_hdr*, metadata->network_headerOffset);

rte_memcpy(route_ipv6_keys[mbuf_i].bytes, ipv6Header->dst_addr, 16);
rte_memcpy(route_keys.ipv6[mbuf_i].bytes, ipv6Header->dst_addr, 16);
route_keys.vrfs[mbuf_i] = metadata->vrfId;

calcHash(mbuf);
}

base.globalBase->route_lpm6->lookup(route_ipv6_keys, route_ipv6_values, route_stack6.mbufsCount);
if (countVrf0 != 0)
{
base.globalBase->route_lpm6->lookup(route_keys.ipv6, route_ipv6_values, countVrf0);
}
if (countVrfOther != 0)
{
base.globalBase->vrf_route_lpm6.Lookup(route_keys.ipv6 + countVrf0, route_keys.vrfs + countVrf0, route_ipv6_values + countVrf0, countVrfOther);
}

for (unsigned int mbuf_i = 0;
mbuf_i < route_stack6.mbufsCount;
mbuf_i++)
Expand Down Expand Up @@ -2440,11 +2480,25 @@ inline void cWorker::route_tunnel_entry(rte_mbuf* mbuf)

if (metadata->network_headerType == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
{
route_tunnel_stack4.insert(mbuf);
if (metadata->vrfId == 0)
{
route_tunnel_stack4.insert(mbuf);
}
else
{
vrf_route_tunnel_stack4.insert(mbuf);
}
}
else if (metadata->network_headerType == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
{
route_tunnel_stack6.insert(mbuf);
if (metadata->vrfId == 0)
{
route_tunnel_stack6.insert(mbuf);
}
else
{
vrf_route_tunnel_stack6.insert(mbuf);
}
}
else
{
Expand All @@ -2456,10 +2510,14 @@ inline void cWorker::route_tunnel_handle4()
{
const auto& base = bases[localBaseId & 1];

if (unlikely(route_tunnel_stack4.mbufsCount == 0))
unsigned int countVrf0 = route_tunnel_stack4.mbufsCount;
unsigned int countVrfOther = vrf_route_tunnel_stack4.mbufsCount;
if (unlikely(countVrf0 + countVrfOther == 0))
{
return;
}
route_tunnel_stack4.copy_from(vrf_route_tunnel_stack4);
vrf_route_tunnel_stack4.clear();

for (unsigned int mbuf_i = 0;
mbuf_i < route_tunnel_stack4.mbufsCount;
Expand All @@ -2469,13 +2527,22 @@ inline void cWorker::route_tunnel_handle4()
dataplane::metadata* metadata = YADECAP_METADATA(mbuf);
rte_ipv4_hdr* ipv4Header = rte_pktmbuf_mtod_offset(mbuf, rte_ipv4_hdr*, metadata->network_headerOffset);

route_ipv4_keys[mbuf_i] = ipv4Header->dst_addr;
route_keys.ipv4[mbuf_i] = ipv4Header->dst_addr;
route_keys.vrfs[mbuf_i] = metadata->vrfId;

calcHash(mbuf);
metadata->hash = rte_hash_crc(&metadata->flowLabel, 4, metadata->hash);
}

base.globalBase->route_tunnel_lpm4->lookup(route_ipv4_keys, route_ipv4_values, route_tunnel_stack4.mbufsCount);
if (countVrf0 != 0)
{
base.globalBase->route_tunnel_lpm4->lookup(route_keys.ipv4, route_ipv4_values, countVrf0);
}
if (countVrfOther != 0)
{
base.globalBase->vrf_route_tunnel_lpm4.Lookup(route_keys.ipv4 + countVrf0, route_keys.vrfs + countVrf0, route_ipv4_values + countVrf0, countVrfOther);
}

for (unsigned int mbuf_i = 0;
mbuf_i < route_tunnel_stack4.mbufsCount;
mbuf_i++)
Expand Down Expand Up @@ -2587,10 +2654,14 @@ inline void cWorker::route_tunnel_handle6()
{
const auto& base = bases[localBaseId & 1];

if (unlikely(route_tunnel_stack6.mbufsCount == 0))
unsigned int countVrf0 = route_tunnel_stack6.mbufsCount;
unsigned int countVrfOther = vrf_route_tunnel_stack6.mbufsCount;
if (unlikely(countVrf0 + countVrfOther == 0))
{
return;
}
route_tunnel_stack6.copy_from(vrf_route_tunnel_stack6);
vrf_route_tunnel_stack6.clear();

for (unsigned int mbuf_i = 0;
mbuf_i < route_tunnel_stack6.mbufsCount;
Expand All @@ -2600,13 +2671,22 @@ inline void cWorker::route_tunnel_handle6()
dataplane::metadata* metadata = YADECAP_METADATA(mbuf);
rte_ipv6_hdr* ipv6Header = rte_pktmbuf_mtod_offset(mbuf, rte_ipv6_hdr*, metadata->network_headerOffset);

rte_memcpy(route_ipv6_keys[mbuf_i].bytes, ipv6Header->dst_addr, 16);
rte_memcpy(route_keys.ipv6[mbuf_i].bytes, ipv6Header->dst_addr, 16);
route_keys.vrfs[mbuf_i] = metadata->vrfId;

calcHash(mbuf);
metadata->hash = rte_hash_crc(&metadata->flowLabel, 4, metadata->hash);
}

base.globalBase->route_tunnel_lpm6->lookup(route_ipv6_keys, route_ipv6_values, route_tunnel_stack6.mbufsCount);
if (countVrf0 != 0)
{
base.globalBase->route_tunnel_lpm6->lookup(route_keys.ipv6, route_ipv6_values, countVrf0);
}
if (countVrfOther != 0)
{
base.globalBase->vrf_route_tunnel_lpm6.Lookup(route_keys.ipv6 + countVrf0, route_keys.vrfs + countVrf0, route_ipv6_values + countVrf0, countVrfOther);
}

for (unsigned int mbuf_i = 0;
mbuf_i < route_tunnel_stack6.mbufsCount;
mbuf_i++)
Expand Down
17 changes: 15 additions & 2 deletions dataplane/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class tStack
mbufsCount = 0;
}

inline void copy_from(tStack& other)
{
insert(other.mbufs, other.mbufsCount);
}

public:
unsigned int mbufsCount{};
rte_mbuf* mbufs[TSize];
Expand Down Expand Up @@ -271,9 +276,13 @@ class cWorker

union
{
uint32_t route_ipv4_keys[CONFIG_YADECAP_MBUFS_BURST_SIZE];
struct
{
uint32_t ipv4[CONFIG_YADECAP_MBUFS_BURST_SIZE];
ipv6_address_t ipv6[CONFIG_YADECAP_MBUFS_BURST_SIZE];
tVrfId vrfs[CONFIG_YADECAP_MBUFS_BURST_SIZE];
} route_keys;
dataplane::globalBase::tun64mapping_key_t tun64_keys[CONFIG_YADECAP_MBUFS_BURST_SIZE];
ipv6_address_t route_ipv6_keys[CONFIG_YADECAP_MBUFS_BURST_SIZE];
dataplane::globalBase::nat64stateful_lan_key nat64stateful_lan_keys[CONFIG_YADECAP_MBUFS_BURST_SIZE];
dataplane::globalBase::nat64stateful_wan_key nat64stateful_wan_keys[CONFIG_YADECAP_MBUFS_BURST_SIZE];
dataplane::globalBase::balancer_state_key_t balancer_keys[CONFIG_YADECAP_MBUFS_BURST_SIZE];
Expand Down Expand Up @@ -320,6 +329,10 @@ class cWorker
worker::tStack<> route_stack6;
worker::tStack<> route_tunnel_stack4;
worker::tStack<> route_tunnel_stack6;
worker::tStack<> vrf_route_stack4;
worker::tStack<> vrf_route_stack6;
worker::tStack<> vrf_route_tunnel_stack4;
worker::tStack<> vrf_route_tunnel_stack6;
worker::tStack<> nat64stateful_lan_stack;
worker::tStack<> nat64stateful_wan_stack;
worker::tStack<> nat64stateless_ingress_stack;
Expand Down

0 comments on commit a180c58

Please sign in to comment.