summaryrefslogtreecommitdiffstats
path: root/src/vnet/mfib
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2017-01-26 01:18:23 -0800
committerFlorin Coras <florin.coras@gmail.com>2017-02-20 09:54:49 +0000
commit5a8123bda0261158457e38bfb4922aa5961389ff (patch)
treedf221814e21d30ea5d63620504c73e64371a5780 /src/vnet/mfib
parent90c55724b583434957cf83555a084770f2efdd7a (diff)
Python test IP and MPLS objects conform to infra.
Add IP[46] MFIB dump. Change-Id: I4a2821f65e67a5416b291e4912c84f64989883b8 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/mfib')
-rw-r--r--src/vnet/mfib/ip4_mfib.c23
-rw-r--r--src/vnet/mfib/ip4_mfib.h11
-rw-r--r--src/vnet/mfib/ip6_mfib.c50
-rw-r--r--src/vnet/mfib/ip6_mfib.h11
-rw-r--r--src/vnet/mfib/mfib_entry.c8
-rw-r--r--src/vnet/mfib/mfib_entry.h3
-rw-r--r--src/vnet/mfib/mfib_table.c19
-rw-r--r--src/vnet/mfib/mfib_table.h16
8 files changed, 129 insertions, 12 deletions
diff --git a/src/vnet/mfib/ip4_mfib.c b/src/vnet/mfib/ip4_mfib.c
index 3e7bdd81bbf..164cafa118b 100644
--- a/src/vnet/mfib/ip4_mfib.c
+++ b/src/vnet/mfib/ip4_mfib.c
@@ -279,6 +279,29 @@ ip4_mfib_table_entry_remove (ip4_mfib_t *mfib,
mfib->fib_entry_by_dst_address[len] = hash;
}
+void
+ip4_mfib_table_walk (ip4_mfib_t *mfib,
+ mfib_table_walk_fn_t fn,
+ void *ctx)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_LEN (mfib->fib_entry_by_dst_address); i++)
+ {
+ uword * hash = mfib->fib_entry_by_dst_address[i];
+
+ if (NULL != hash)
+ {
+ hash_pair_t * p;
+
+ hash_foreach_pair (p, hash,
+ ({
+ fn(p->value[0], ctx);
+ }));
+ }
+ }
+}
+
static void
ip4_mfib_table_show_all (ip4_mfib_t *mfib,
vlib_main_t * vm)
diff --git a/src/vnet/mfib/ip4_mfib.h b/src/vnet/mfib/ip4_mfib.h
index 6fc74a368bd..ea682651767 100644
--- a/src/vnet/mfib/ip4_mfib.h
+++ b/src/vnet/mfib/ip4_mfib.h
@@ -90,6 +90,15 @@ u32 ip4_mfib_index_from_table_id (u32 table_id)
extern u32 ip4_mfib_table_get_index_for_sw_if_index(u32 sw_if_index);
+/**
+ * @brief Walk the IP4 mfib table.
+ *
+ * @param mfib the table to walk
+ * @param fn The function to invoke on each entry visited
+ * @param ctx A context passed in the visit function
+ */
+extern void ip4_mfib_table_walk (ip4_mfib_t *mfib,
+ mfib_table_walk_fn_t fn,
+ void *ctx);
#endif
-
diff --git a/src/vnet/mfib/ip6_mfib.c b/src/vnet/mfib/ip6_mfib.c
index 0c2e4c7b796..8f3dae8d7b5 100644
--- a/src/vnet/mfib/ip6_mfib.c
+++ b/src/vnet/mfib/ip6_mfib.c
@@ -483,20 +483,16 @@ ip6_mfib_table_show_one (ip6_mfib_t *mfib,
}
typedef struct ip6_mfib_show_ctx_t_ {
- u32 fib_index;
fib_node_index_t *entries;
} ip6_mfib_show_ctx_t;
static int
-ip6_mfib_table_collect_entries (struct radix_node *rn, void *arg)
+ip6_mfib_table_collect_entries (fib_node_index_t mfei, void *arg)
{
ip6_mfib_show_ctx_t *ctx = arg;
- ip6_mfib_node_t *i6mn;
-
- i6mn = (ip6_mfib_node_t*) rn;
- vec_add1(ctx->entries, i6mn->i6mn_entry);
+ vec_add1(ctx->entries, mfei);
return (0);
}
@@ -507,13 +503,12 @@ ip6_mfib_table_show_all (ip6_mfib_t *mfib,
{
fib_node_index_t *mfib_entry_index;
ip6_mfib_show_ctx_t ctx = {
- .fib_index = mfib->index,
.entries = NULL,
};
- rn_walktree(mfib->rhead,
- ip6_mfib_table_collect_entries,
- &ctx);
+ ip6_mfib_table_walk(mfib,
+ ip6_mfib_table_collect_entries,
+ &ctx);
vec_sort_with_function(ctx.entries, mfib_entry_cmp_for_sort);
@@ -528,6 +523,41 @@ ip6_mfib_table_show_all (ip6_mfib_t *mfib,
vec_free(ctx.entries);
}
+typedef struct ip6_mfib_radix_walk_ctx_t_
+{
+ mfib_table_walk_fn_t user_fn;
+ void *user_ctx;
+} ip6_mfib_radix_walk_ctx_t;
+
+static int
+ip6_mfib_table_radix_walk (struct radix_node *rn,
+ void *arg)
+{
+ ip6_mfib_radix_walk_ctx_t *ctx = arg;
+ ip6_mfib_node_t *i6mn;
+
+ i6mn = (ip6_mfib_node_t*) rn;
+
+ ctx->user_fn(i6mn->i6mn_entry, ctx->user_ctx);
+
+ return (0);
+}
+
+void
+ip6_mfib_table_walk (ip6_mfib_t *mfib,
+ mfib_table_walk_fn_t fn,
+ void *ctx)
+{
+ ip6_mfib_radix_walk_ctx_t rn_ctx = {
+ .user_fn = fn,
+ .user_ctx = ctx,
+ };
+
+ rn_walktree(mfib->rhead,
+ ip6_mfib_table_radix_walk,
+ &rn_ctx);
+}
+
static clib_error_t *
ip6_show_mfib (vlib_main_t * vm,
unformat_input_t * input,
diff --git a/src/vnet/mfib/ip6_mfib.h b/src/vnet/mfib/ip6_mfib.h
index d91af46dc93..adaa7ec24fe 100644
--- a/src/vnet/mfib/ip6_mfib.h
+++ b/src/vnet/mfib/ip6_mfib.h
@@ -105,5 +105,16 @@ extern fib_node_index_t ip6_mfib_table_lookup2(const ip6_mfib_t *mfib,
const ip6_address_t *src,
const ip6_address_t *grp);
+/**
+ * @brief Walk the IP6 mfib table.
+ *
+ * @param mfib the table to walk
+ * @param fn The function to invoke on each entry visited
+ * @param ctx A context passed in the visit function
+ */
+extern void ip6_mfib_table_walk (ip6_mfib_t *mfib,
+ mfib_table_walk_fn_t fn,
+ void *ctx);
+
#endif
diff --git a/src/vnet/mfib/mfib_entry.c b/src/vnet/mfib/mfib_entry.c
index acbe90bb109..1947360ad14 100644
--- a/src/vnet/mfib/mfib_entry.c
+++ b/src/vnet/mfib/mfib_entry.c
@@ -1050,9 +1050,15 @@ mfib_entry_encode (fib_node_index_t mfib_entry_index,
mfib_entry_t *mfib_entry;
mfib_entry = mfib_entry_get(mfib_entry_index);
- fib_path_list_walk(mfib_entry->mfe_parent, fib_path_encode, api_rpaths);
+ if (FIB_NODE_INDEX_INVALID != mfib_entry->mfe_parent)
+ {
+ fib_path_list_walk(mfib_entry->mfe_parent,
+ fib_path_encode,
+ api_rpaths);
+ }
}
+
void
mfib_entry_get_prefix (fib_node_index_t mfib_entry_index,
mfib_prefix_t *pfx)
diff --git a/src/vnet/mfib/mfib_entry.h b/src/vnet/mfib/mfib_entry.h
index 36fc73e1670..dc8f49aad1a 100644
--- a/src/vnet/mfib/mfib_entry.h
+++ b/src/vnet/mfib/mfib_entry.h
@@ -130,6 +130,9 @@ extern void mfib_entry_contribute_forwarding(
fib_forward_chain_type_t type,
dpo_id_t *dpo);
+extern void mfib_entry_encode(fib_node_index_t fib_entry_index,
+ fib_route_path_encode_t **api_rpaths);
+
extern void mfib_entry_module_init(void);
diff --git a/src/vnet/mfib/mfib_table.c b/src/vnet/mfib/mfib_table.c
index b4e855ff071..3b4bd985893 100644
--- a/src/vnet/mfib/mfib_table.c
+++ b/src/vnet/mfib/mfib_table.c
@@ -489,6 +489,25 @@ mfib_table_lock (u32 fib_index,
mfib_table->mft_locks++;
}
+void
+mfib_table_walk (u32 fib_index,
+ fib_protocol_t proto,
+ mfib_table_walk_fn_t fn,
+ void *ctx)
+{
+ switch (proto)
+ {
+ case FIB_PROTOCOL_IP4:
+ ip4_mfib_table_walk(ip4_mfib_get(fib_index), fn, ctx);
+ break;
+ case FIB_PROTOCOL_IP6:
+ ip6_mfib_table_walk(ip6_mfib_get(fib_index), fn, ctx);
+ break;
+ case FIB_PROTOCOL_MPLS:
+ break;
+ }
+}
+
u8*
format_mfib_table_name (u8* s, va_list ap)
{
diff --git a/src/vnet/mfib/mfib_table.h b/src/vnet/mfib/mfib_table.h
index 4c51b70fd72..95239f7cb17 100644
--- a/src/vnet/mfib/mfib_table.h
+++ b/src/vnet/mfib/mfib_table.h
@@ -360,4 +360,20 @@ extern u32 mfib_table_get_num_entries(u32 fib_index,
extern mfib_table_t *mfib_table_get(fib_node_index_t index,
fib_protocol_t proto);
+/**
+ * @brief Call back function when walking entries in a FIB table
+ */
+typedef int (*mfib_table_walk_fn_t)(fib_node_index_t fei,
+ void *ctx);
+
+/**
+ * @brief Walk all entries in a FIB table
+ * N.B: This is NOT safe to deletes. If you need to delete, walk the whole
+ * table and store elements in a vector, then delete the elements
+ */
+extern void mfib_table_walk(u32 fib_index,
+ fib_protocol_t proto,
+ mfib_table_walk_fn_t fn,
+ void *ctx);
+
#endif