From: Vijayabhaskar Katamreddy Date: Thu, 14 Dec 2017 21:20:50 +0000 (-0800) Subject: Adding a format function for bihash init routine to format the key, value, when verbo... X-Git-Tag: v18.04-rc1~450 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=fb8e61cd93178f56a1fc91d438e8b2eec46f1522;p=vpp.git Adding a format function for bihash init routine to format the key, value, when verbose option is used Change-Id: Ib63ead4525332f897b8a1d8a4cf5a0eb1da1e7f3 Signed-off-by: Vijayabhaskar Katamreddy --- diff --git a/src/vppinfra/bihash_template.c b/src/vppinfra/bihash_template.c index 56c410b5a51..3f25b02d5df 100644 --- a/src/vppinfra/bihash_template.c +++ b/src/vppinfra/bihash_template.c @@ -41,6 +41,14 @@ void BV (clib_bihash_init) BV (clib_bihash_reset_cache) (h->buckets + i); clib_mem_set_heap (oldheap); + + h->fmt_fn = NULL; +} + +void BV (clib_bihash_set_kvp_format_fn) (BVT (clib_bihash) * h, + format_function_t * fmt_fn) +{ + h->fmt_fn = fmt_fn; } void BV (clib_bihash_free) (BVT (clib_bihash) * h) @@ -566,9 +574,18 @@ u8 *BV (format_bihash) (u8 * s, va_list * args) } if (verbose) { - s = format (s, " %d: %U\n", - j * BIHASH_KVP_PER_PAGE + k, - BV (format_bihash_kvp), &(v->kvp[k])); + if (h->fmt_fn) + { + s = format (s, " %d: %U\n", + j * BIHASH_KVP_PER_PAGE + k, + h->fmt_fn, &(v->kvp[k])); + } + else + { + s = format (s, " %d: %U\n", + j * BIHASH_KVP_PER_PAGE + k, + BV (format_bihash_kvp), &(v->kvp[k])); + } } active_elements++; } diff --git a/src/vppinfra/bihash_template.h b/src/vppinfra/bihash_template.h index ea1b6f7b86f..9df418b5d7d 100644 --- a/src/vppinfra/bihash_template.h +++ b/src/vppinfra/bihash_template.h @@ -91,6 +91,11 @@ typedef struct BVT (clib_bihash_value) ** freelists; void *mheap; + /** + * A custom format function to print the Key and Value of bihash_key instead of default hexdump + */ + format_function_t *fmt_fn; + } BVT (clib_bihash); @@ -240,6 +245,9 @@ static inline uword BV (clib_bihash_get_offset) (BVT (clib_bihash) * h, void BV (clib_bihash_init) (BVT (clib_bihash) * h, char *name, u32 nbuckets, uword memory_size); +void BV (clib_bihash_set_kvp_format_fn) (BVT (clib_bihash) * h, + format_function_t * fmt_fn); + void BV (clib_bihash_free) (BVT (clib_bihash) * h); int BV (clib_bihash_add_del) (BVT (clib_bihash) * h,