From 01b071222d99bea31e2846e95963c475262dd114 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 2 Nov 2016 10:40:09 -0700 Subject: Dump routes (VPP-500) Change-Id: I86e7382395a8b6471a0deaf57163718d41b71b83 Signed-off-by: Steven --- vnet/vnet/fib/fib_entry.c | 10 ++++++++++ vnet/vnet/fib/fib_entry.h | 2 ++ vnet/vnet/fib/fib_path.c | 43 +++++++++++++++++++++++++++++++++++++++++++ vnet/vnet/fib/fib_path.h | 5 +++-- vnet/vnet/fib/fib_types.h | 9 +++++++++ 5 files changed, 67 insertions(+), 2 deletions(-) (limited to 'vnet') diff --git a/vnet/vnet/fib/fib_entry.c b/vnet/vnet/fib/fib_entry.c index 4080b762..da2656e3 100644 --- a/vnet/vnet/fib/fib_entry.c +++ b/vnet/vnet/fib/fib_entry.c @@ -1478,6 +1478,16 @@ fib_entry_module_init (void) fib_node_register_type (FIB_NODE_TYPE_ENTRY, &fib_entry_vft); } +void +fib_entry_encode (fib_node_index_t fib_entry_index, + fib_route_path_encode_t **api_rpaths) +{ + fib_entry_t *fib_entry; + + fib_entry = fib_entry_get(fib_entry_index); + fib_path_list_walk(fib_entry->fe_parent, fib_path_encode, api_rpaths); +} + void fib_entry_get_prefix (fib_node_index_t fib_entry_index, fib_prefix_t *pfx) diff --git a/vnet/vnet/fib/fib_entry.h b/vnet/vnet/fib/fib_entry.h index 39b2083e..d62a9404 100644 --- a/vnet/vnet/fib/fib_entry.h +++ b/vnet/vnet/fib/fib_entry.h @@ -497,6 +497,8 @@ extern u32 fib_entry_get_resolving_interface_for_source( fib_node_index_t fib_entry_index, fib_source_t source); +extern void fib_entry_encode(fib_node_index_t fib_entry_index, + fib_route_path_encode_t **api_rpaths); extern void fib_entry_get_prefix(fib_node_index_t fib_entry_index, fib_prefix_t *pfx); extern u32 fib_entry_get_fib_index(fib_node_index_t fib_entry_index); diff --git a/vnet/vnet/fib/fib_path.c b/vnet/vnet/fib/fib_path.c index 9fe653dc..98669317 100644 --- a/vnet/vnet/fib/fib_path.c +++ b/vnet/vnet/fib/fib_path.c @@ -1818,6 +1818,49 @@ fib_path_is_looped (fib_node_index_t path_index) return (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP); } +int +fib_path_encode (fib_node_index_t path_list_index, + fib_node_index_t path_index, + void *ctx) +{ + fib_route_path_encode_t **api_rpaths = ctx; + fib_route_path_encode_t *api_rpath; + fib_path_t *path; + + path = fib_path_get(path_index); + if (!path) + return (0); + vec_add2(*api_rpaths, api_rpath, 1); + api_rpath->rpath.frp_weight = path->fp_weight; + api_rpath->rpath.frp_proto = path->fp_nh_proto; + api_rpath->rpath.frp_sw_if_index = ~0; + api_rpath->dpo = path->exclusive.fp_ex_dpo; + switch (path->fp_type) + { + case FIB_PATH_TYPE_RECEIVE: + api_rpath->rpath.frp_addr = path->receive.fp_addr; + api_rpath->rpath.frp_sw_if_index = path->receive.fp_interface; + break; + case FIB_PATH_TYPE_ATTACHED: + api_rpath->rpath.frp_sw_if_index = path->attached.fp_interface; + break; + case FIB_PATH_TYPE_ATTACHED_NEXT_HOP: + api_rpath->rpath.frp_sw_if_index = path->attached_next_hop.fp_interface; + api_rpath->rpath.frp_addr = path->attached_next_hop.fp_nh; + break; + case FIB_PATH_TYPE_SPECIAL: + break; + case FIB_PATH_TYPE_DEAG: + break; + case FIB_PATH_TYPE_RECURSIVE: + api_rpath->rpath.frp_addr = path->recursive.fp_nh; + break; + default: + break; + } + return (1); +} + void fib_path_module_init (void) { diff --git a/vnet/vnet/fib/fib_path.h b/vnet/vnet/fib/fib_path.h index 2c141a41..4151c578 100644 --- a/vnet/vnet/fib/fib_path.h +++ b/vnet/vnet/fib/fib_path.h @@ -150,7 +150,8 @@ extern u32 fib_path_get_resolving_interface(fib_node_index_t fib_entry_index); extern int fib_path_get_weight(fib_node_index_t path_index); extern void fib_path_module_init(void); - -extern void fib_path_module_init(void); +extern int fib_path_encode(fib_node_index_t path_list_index, + fib_node_index_t path_index, + void *ctx); #endif diff --git a/vnet/vnet/fib/fib_types.h b/vnet/vnet/fib/fib_types.h index 1e70a2a9..83123a51 100644 --- a/vnet/vnet/fib/fib_types.h +++ b/vnet/vnet/fib/fib_types.h @@ -316,4 +316,13 @@ typedef struct fib_route_path_t_ { mpls_label_t frp_label; } fib_route_path_t; +/** + * @brief + * A representation of a fib path for fib_path_encode to convey the information to the caller + */ +typedef struct fib_route_path_encode_t_ { + fib_route_path_t rpath; + dpo_id_t dpo; +} fib_route_path_encode_t; + #endif -- cgit 1.2.3-korg