fib: doc nitfixes
[vpp.git] / src / vnet / fib / mpls_fib.c
index 19f9f3c..0ed2413 100644 (file)
@@ -22,7 +22,7 @@
  * packets. Whether the two actions are the same more often than they are
  * different, or vice versa, is a function of the deployment in which the router
  * is used and thus not predictable.
- * The desgin choice to make with an MPLS_FIB table is:
+ * The design choice to make with an MPLS_FIB table is:
  *  1 - 20 bit key: label only.
  *      When the EOS and non-EOS actions differ the result is a 'EOS-choice' object.
  *  2 - 21 bit key: label and EOS-bit.
@@ -33,7 +33,7 @@
  *    - lower memory overhead, since there are few DB entries.
  *   Disadvantages:
  *    - slower DP performance in the case the chains differ, as more objects are
- *      encounterd in the switch path
+ *      encountered in the switch path
  *
  * 21 bit key:
  *   Advantages:
  */
 static index_t mpls_fib_drop_dpo_index = INDEX_INVALID;
 
-/**
- * FIXME
- */
-#define MPLS_FLOW_HASH_DEFAULT 0
-
 static inline u32
 mpls_fib_entry_mk_key (mpls_label_t label,
                       mpls_eos_bit_t eos)
@@ -88,7 +83,8 @@ mpls_fib_index_from_table_id (u32 table_id)
 }
 
 static u32
-mpls_fib_create_with_table_id (u32 table_id)
+mpls_fib_create_with_table_id (u32 table_id,
+                               fib_source_t src)
 {
     dpo_id_t dpo = DPO_INVALID;
     fib_table_t *fib_table;
@@ -96,25 +92,23 @@ mpls_fib_create_with_table_id (u32 table_id)
     mpls_fib_t *mf;
     int i;
 
-    pool_get_aligned(mpls_main.fibs, fib_table, CLIB_CACHE_LINE_BYTES);
+    pool_get(mpls_main.fibs, fib_table);
     pool_get_aligned(mpls_main.mpls_fibs, mf, CLIB_CACHE_LINE_BYTES);
 
     ASSERT((fib_table - mpls_main.fibs) ==
            (mf - mpls_main.mpls_fibs));
 
-    memset(fib_table, 0, sizeof(*fib_table));
+    clib_memset(fib_table, 0, sizeof(*fib_table));
 
     fib_table->ft_proto = FIB_PROTOCOL_MPLS;
     fib_table->ft_index = (fib_table - mpls_main.fibs);
 
     hash_set (mpls_main.fib_index_by_table_id, table_id, fib_table->ft_index);
 
-    fib_table->ft_table_id =
-       table_id;
-    fib_table->ft_flow_hash_config = 
-       MPLS_FLOW_HASH_DEFAULT;
+    fib_table->ft_table_id = table_id;
+    fib_table->ft_flow_hash_config = MPLS_FLOW_HASH_DEFAULT;
     
-    fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_MPLS);
+    fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_MPLS, src);
 
     if (INDEX_INVALID == mpls_fib_drop_dpo_index)
     {
@@ -227,22 +221,23 @@ mpls_fib_create_with_table_id (u32 table_id)
 }
 
 u32
-mpls_fib_table_find_or_create_and_lock (u32 table_id)
+mpls_fib_table_find_or_create_and_lock (u32 table_id,
+                                        fib_source_t src)
 {
     u32 index;
 
     index = mpls_fib_index_from_table_id(table_id);
     if (~0 == index)
-       return mpls_fib_create_with_table_id(table_id);
+       return mpls_fib_create_with_table_id(table_id, src);
 
-    fib_table_lock(index, FIB_PROTOCOL_MPLS);
+    fib_table_lock(index, FIB_PROTOCOL_MPLS, src);
 
     return (index);
 }
 u32
-mpls_fib_table_create_and_lock (void)
+mpls_fib_table_create_and_lock (fib_source_t src)
 {
-    return (mpls_fib_create_with_table_id(~0));
+    return (mpls_fib_create_with_table_id(~0, src));
 }
 
 void
@@ -280,6 +275,7 @@ mpls_fib_table_destroy (u32 fib_index)
     }
     hash_free(mf->mf_entries);
 
+    vec_free(fib_table->ft_src_route_counts);
     pool_put(mpls_main.mpls_fibs, mf);
     pool_put(mpls_main.fibs, fib_table);
 }
@@ -350,13 +346,6 @@ mpls_fib_forwarding_table_reset (mpls_fib_t *mf,
     mf->mf_lbs[key] = mpls_fib_drop_dpo_index;
 }
 
-flow_hash_config_t
-mpls_fib_table_get_flow_hash_config (u32 fib_index)
-{
-    // FIXME.
-    return (0);
-}
-
 void
 mpls_fib_table_walk (mpls_fib_t *mpls_fib,
                      fib_table_walk_fn_t fn,
@@ -371,6 +360,18 @@ mpls_fib_table_walk (mpls_fib_t *mpls_fib,
     }));
 }
 
+u8 *
+format_mpls_fib_table_memory (u8 * s, va_list * args)
+{
+    u64 n_tables, mem;
+
+    n_tables = pool_elts(mpls_main.fibs);
+    mem = n_tables * sizeof(mpls_fib_t);
+    s = format(s, "%=30s %=6ld %=12ld\n", "MPLS", n_tables, mem);
+
+    return (s);
+}
+
 static void
 mpls_fib_table_show_all (const mpls_fib_t *mpls_fib,
                         vlib_main_t * vm)
@@ -440,13 +441,26 @@ mpls_fib_show (vlib_main_t * vm,
            break;
     }
 
-    pool_foreach (fib_table, mpls_main.fibs,
-    ({
+    pool_foreach (fib_table, mpls_main.fibs)
+     {
+        fib_source_t source;
+        u8 *s = NULL;
+
        if (table_id >= 0 && table_id != fib_table->ft_table_id)
            continue;
 
-       vlib_cli_output (vm, "%v, fib_index %d",
-                        fib_table->ft_desc, mpls_main.fibs - fib_table);
+       s = format (s, "%v, fib_index:%d locks:[",
+                    fib_table->ft_desc, mpls_main.fibs - fib_table);
+        vec_foreach_index(source, fib_table->ft_locks)
+        {
+            if (0 != fib_table->ft_locks[source])
+            {
+                s = format(s, "%U:%d, ",
+                           format_fib_source, source,
+                           fib_table->ft_locks[source]);
+            }
+        }
+        vlib_cli_output (vm, "%v]", s);
 
        if (MPLS_LABEL_INVALID == label)
        {
@@ -456,7 +470,7 @@ mpls_fib_show (vlib_main_t * vm,
        {
            mpls_fib_table_show_one(mpls_fib_get(fib_table->ft_index), label, vm);
        }
-    }));
+    }
 
     return 0;
 }