Representing prefix lengths /0..32 with a 64-bit hardware bitmask + vEB binary search over prefix lengths (O(log W) = 5 hash probes) or a 2-level DIR-24-8 flat array achieves <20 ns LPM.
TL;DR30-second simplified summary▾
Use vEB predecessor/binary search on prefix lengths (Waldvogel's scheme: <=5 probes for IPv4) or L1-resident compressed summary bitmasks.
R & E — The 25-Nanosecond Line-Rate Budget.
32-Level Radix Trie vs. vEB Prefix-Length Search
At 40 million packets/sec on a single DPDK core, the entire LPM lookup budget is 25 ns. A single uncached DRAM fetch takes ~70 ns, which means a 32-level bitwise trie that walks 32 pointers can take 500–1,500 ns—dropping 95% of packets.
We must fit the hot decision metadata inside L1/L2 cache (32 KB – 256 KB) and cap worst-case hash/array probes at O(log W) = 5 for 32-bit IPv4 (log2(32) = 5).
H & D — Bit-Packed vEB LPM Engine in Python.
Sub-Microsecond LPM Forwarding Pipeline
- Problem
- How should a 40M pps software router perform Longest-Prefix Match across 1M BGP routes?
- Naive Solution
- Walk a 32-level binary radix trie bit-by-bit.
- Why It Fails
- Up to 32 dependent pointer chases cause DRAM stalls far exceeding the 25 ns/packet budget.
- Alternatives
- vEB / Binary Search on Prefix Lengths (O(log W) = 5 probes, scales to IPv6 /128 in 7 probes),DIR-24-8 Flat Table (1-2 array reads for IPv4, 64 MB RAM, fails for IPv6),32-level Radix Trie
- Engineering Decision
- Use DIR-24-8 for pure IPv4 when 64 MB L3/hugepage RAM is available, and vEB prefix-length search for IPv6 (/128 -> 7 probes) or memory-constrained eBPF maps.
- Trade-Offs
- vEB prefix-length search requires marker maintenance on BGP route updates, whereas DIR-24-8 requires 64 MB contiguous hugepages.
Why does vEB / binary search on prefix lengths scale seamlessly from IPv4 (/32) to IPv6 (/128)?
Waldvogel's binary search on prefix lengths (a direct application of vEB halving on W = 32 bits) stores a hash table for each prefix length L in 1..32, augmented with markers at midpoint lengths so a match at length 16 tells the engine whether a longer /24 prefix might exist:
from typing import Dict, Optional, Tuple
class VEBPrefixRouter:
"""O(log W) = 5-step Longest-Prefix Match for 32-bit IPv4 using prefix-length halving."""
def __init__(self) -> None:
self.tables: Dict[int, Dict[int, Tuple[int, bool]]] = {l: {} for l in range(33)}
self.default_hop: int = 0
def insert_route(self, ip_int: int, prefix_len: int, next_hop: int) -> None:
masked = ip_int & (((1 << prefix_len) - 1) << (32 - prefix_len)) if prefix_len > 0 else 0
self.tables[prefix_len][masked] = (next_hop, True)
# Populate binary-search markers on ancestor lengths (16, 24, 28, ...)
lo, hi = 0, 32
while lo < hi:
mid = (lo + hi + 1) // 2
if prefix_len > mid:
m_key = ip_int & (((1 << mid) - 1) << (32 - mid))
if m_key not in self.tables[mid]:
self.tables[mid][m_key] = (self.default_hop, False)
lo = mid
else:
hi = mid - 1
def lookup(self, ip_int: int) -> int:
best_hop = self.default_hop
lo, hi = 0, 32
while lo < hi:
mid = (lo + hi + 1) // 2
key = ip_int & (((1 << mid) - 1) << (32 - mid))
entry = self.tables[mid].get(key)
if entry is not None:
hop, is_real = entry
if is_real:
best_hop = hop
lo = mid
else:
hi = mid - 1
return best_hop
D — Lock-Free RCU BGP Route Updates.
RCU Route Table Swap
BGP churn can inject 10,000 route updates/sec. Forwarding cores read the active tables snapshot lock-free via Read-Copy-Update (RCU): a control-plane thread builds the new marker diff on a shadow copy and atomically swaps the pointer between packet bursts.