nat: static mappings in flow hash
[vpp.git] / src / plugins / nat / lib / lib.h
index 04bad5c..cea9ed7 100644 (file)
@@ -54,19 +54,6 @@ typedef enum
 #undef _
 } nat_error_t;
 
-#define foreach_nat_protocol   \
-  _ (OTHER, 0, other, "other") \
-  _ (UDP, 1, udp, "udp")       \
-  _ (TCP, 2, tcp, "tcp")       \
-  _ (ICMP, 3, icmp, "icmp")
-
-typedef enum
-{
-#define _(N, i, n, s) NAT_PROTOCOL_##N = i,
-  foreach_nat_protocol
-#undef _
-} nat_protocol_t;
-
 /* default protocol timeouts */
 #define NAT_UDP_TIMEOUT 300
 #define NAT_TCP_TRANSITORY_TIMEOUT 240
@@ -95,7 +82,25 @@ nat_reset_timeouts (nat_timeouts_t * timeouts)
   timeouts->icmp = NAT_ICMP_TIMEOUT;
 }
 
-// TODO: move common formating definitions here
+static_always_inline u32
+nat_calc_bihash_buckets (u32 n_elts)
+{
+  n_elts = n_elts / 2.5;
+  u64 lower_pow2 = 1;
+  while (lower_pow2 * 2 < n_elts)
+    {
+      lower_pow2 = 2 * lower_pow2;
+    }
+  u64 upper_pow2 = 2 * lower_pow2;
+  if ((upper_pow2 - n_elts) < (n_elts - lower_pow2))
+    {
+      if (upper_pow2 <= UINT32_MAX)
+       {
+         return upper_pow2;
+       }
+    }
+  return lower_pow2;
+}
 
 #endif /* included_nat_lib_h__ */
 /*