fib: format deleted LB
[vpp.git] / src / vnet / dpo / load_balance.h
index 1799653..eee073f 100644 (file)
@@ -36,6 +36,7 @@
 #include <vnet/ip/lookup.h>
 #include <vnet/dpo/dpo.h>
 #include <vnet/fib/fib_types.h>
+#include <vnet/fib/fib_entry.h>
 
 /**
  * Load-balance main
@@ -48,6 +49,12 @@ typedef struct load_balance_main_t_
 
 extern load_balance_main_t load_balance_main;
 
+/**
+ * The maximum number of buckets that a load-balance object can have
+ * This must not overflow the lb_n_buckets field
+ */
+#define LB_MAX_BUCKETS 8192
+
 /**
  * The number of buckets that a load-balance object can have and still
  * fit in one cache-line
@@ -75,12 +82,40 @@ typedef struct load_balance_path_t_ {
     u32 path_weight;
 } load_balance_path_t;
 
+/**
+ * Flags controlling load-balance creation and modification
+ */
+typedef enum load_balance_attr_t_ {
+    LOAD_BALANCE_ATTR_USES_MAP = 0,
+    LOAD_BALANCE_ATTR_STICKY = 1,
+} load_balance_attr_t;
+
+#define LOAD_BALANCE_ATTR_NAMES  {                  \
+    [LOAD_BALANCE_ATTR_USES_MAP] = "uses-map",      \
+    [LOAD_BALANCE_ATTR_STICKY] = "sticky",          \
+}
+
+#define FOR_EACH_LOAD_BALANCE_ATTR(_attr)                       \
+    for (_attr = 0; _attr <= LOAD_BALANCE_ATTR_STICKY; _attr++)
+
+typedef enum load_balance_flags_t_ {
+    LOAD_BALANCE_FLAG_NONE = 0,
+    LOAD_BALANCE_FLAG_USES_MAP = (1 << 0),
+    LOAD_BALANCE_FLAG_STICKY = (1 << 1),
+} __attribute__((packed)) load_balance_flags_t;
+
 /**
  * The FIB DPO provieds;
  *  - load-balancing over the next DPOs in the chain/graph
  *  - per-route counters
  */
 typedef struct load_balance_t_ {
+    /**
+     * required for pool_get_aligned.
+     *  memebers used in the switch path come first!
+     */
+    CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
+
     /**
      * number of buckets in the load-balance. always a power of 2.
      */
@@ -98,6 +133,16 @@ typedef struct load_balance_t_ {
      */
     dpo_proto_t lb_proto;
 
+    /**
+     * Flags concenring the LB's creation and modification
+     */
+    load_balance_flags_t lb_flags;
+
+    /**
+     * Flags from the load-balance's associated fib_entry_t
+     */
+    fib_entry_flag_t lb_fib_entry_flags;
+
     /**
      * The number of locks, which is approximately the number of users,
      * of this load-balance.
@@ -136,7 +181,11 @@ typedef struct load_balance_t_ {
 } load_balance_t;
 
 STATIC_ASSERT(sizeof(load_balance_t) <= CLIB_CACHE_LINE_BYTES,
-             "A load_balance object size exceeds one cachline");
+             "A load_balance object size exceeds one cacheline");
+STATIC_ASSERT (LB_MAX_BUCKETS <= CLIB_U16_MAX,
+              "Too many buckets for load_balance object");
+STATIC_ASSERT (LB_MAX_BUCKETS && !(LB_MAX_BUCKETS & (LB_MAX_BUCKETS - 1)),
+              "LB_MAX_BUCKETS must be a power of 2");
 
 /**
  * Flags controlling load-balance formatting/display
@@ -146,17 +195,10 @@ typedef enum load_balance_format_flags_t_ {
     LOAD_BALANCE_FORMAT_DETAIL = (1 << 0),
 } load_balance_format_flags_t;
 
-/**
- * Flags controlling load-balance creation and modification
- */
-typedef enum load_balance_flags_t_ {
-    LOAD_BALANCE_FLAG_NONE = 0,
-    LOAD_BALANCE_FLAG_USES_MAP = (1 << 0),
-} load_balance_flags_t;
-
 extern index_t load_balance_create(u32 num_buckets,
                                   dpo_proto_t lb_proto,
                                   flow_hash_config_t fhc);
+extern flow_hash_config_t load_balance_get_default_flow_hash(dpo_proto_t lb_proto);
 extern void load_balance_multipath_update(
     const dpo_id_t *dpo,
     const load_balance_path_t * raw_next_hops,
@@ -167,6 +209,8 @@ extern void load_balance_set_bucket(index_t lbi,
                                    const dpo_id_t *next);
 extern void load_balance_set_urpf(index_t lbi,
                                  index_t urpf);
+extern void load_balance_set_fib_entry_flags(index_t lbi,
+                                             fib_entry_flag_t flags);
 extern index_t load_balance_get_urpf(index_t lbi);
 
 extern u8* format_load_balance(u8 * s, va_list * args);
@@ -174,6 +218,7 @@ extern u8* format_load_balance(u8 * s, va_list * args);
 extern const dpo_id_t *load_balance_get_bucket(index_t lbi,
                                               u32 bucket);
 extern int load_balance_is_drop(const dpo_id_t *dpo);
+extern u16 load_balance_n_buckets(index_t lbi);
 
 extern f64 load_balance_get_multipath_tolerance(void);
 
@@ -187,6 +232,14 @@ load_balance_get (index_t lbi)
     return (pool_elt_at_index(load_balance_pool, lbi));
 }
 
+static inline load_balance_t *
+load_balance_get_or_null (index_t lbi)
+{
+  if (pool_is_free_index (load_balance_pool, lbi))
+    return 0;
+  return (pool_elt_at_index (load_balance_pool, lbi));
+}
+
 #define LB_HAS_INLINE_BUCKETS(_lb)             \
     ((_lb)->lb_n_buckets <= LB_NUM_INLINE_BUCKETS)