Include allocated table memory in 'sh fib mem' output
[vpp.git] / src / vnet / fib / ip4_fib.c
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <vnet/fib/fib_table.h>
17 #include <vnet/fib/fib_entry.h>
18 #include <vnet/fib/ip4_fib.h>
19
20 /*
21  * A table of pefixes to be added to tables and the sources for them
22  */
23 typedef struct ip4_fib_table_special_prefix_t_ {
24     fib_prefix_t ift_prefix;
25     fib_source_t ift_source;
26     fib_entry_flag_t ift_flag;
27 } ip4_fib_table_special_prefix_t;
28
29 static const ip4_fib_table_special_prefix_t ip4_specials[] = {
30     {
31         /* 0.0.0.0/0*/
32         .ift_prefix = {
33             .fp_addr = {
34                 .ip4.data_u32 = 0,
35             },
36             .fp_len  = 0,
37             .fp_proto = FIB_PROTOCOL_IP4,
38         },
39         .ift_source = FIB_SOURCE_DEFAULT_ROUTE,
40         .ift_flag   = FIB_ENTRY_FLAG_DROP,
41     },
42     {
43         /* 0.0.0.0/32*/
44         .ift_prefix = {
45             .fp_addr = {
46                 .ip4.data_u32 = 0,
47             },
48             .fp_len  = 32,
49             .fp_proto = FIB_PROTOCOL_IP4,
50         },
51         .ift_source = FIB_SOURCE_DEFAULT_ROUTE,
52         .ift_flag   = FIB_ENTRY_FLAG_DROP,
53     },
54     {
55         /*
56          * 240.0.0.0/4
57          * drop class E
58          */
59         .ift_prefix = {
60             .fp_addr = {
61                 .ip4.data_u32 = 0xf0000000,
62             },
63             .fp_len   = 4,
64             .fp_proto = FIB_PROTOCOL_IP4,
65         },
66         .ift_source = FIB_SOURCE_SPECIAL,
67         .ift_flag   = FIB_ENTRY_FLAG_DROP,
68
69     },
70     {
71         /*
72          * 224.0.0.0/4
73          * drop all mcast
74          */
75         .ift_prefix = {
76             .fp_addr = {
77                 .ip4.data_u32 = 0xe0000000,
78             },
79             .fp_len   = 4,
80             .fp_proto = FIB_PROTOCOL_IP4,
81         },
82         .ift_source = FIB_SOURCE_SPECIAL,
83         .ift_flag    = FIB_ENTRY_FLAG_DROP,
84     },
85     {
86         /*
87          * 255.255.255.255/32
88          * drop, but we'll allow it to be usurped by the likes of DHCP
89          */
90         .ift_prefix = {
91             .fp_addr = {
92                 .ip4.data_u32 = 0xffffffff,
93             },
94             .fp_len   = 32,
95             .fp_proto = FIB_PROTOCOL_IP4,
96         },
97         .ift_source = FIB_SOURCE_DEFAULT_ROUTE,
98         .ift_flag   = FIB_ENTRY_FLAG_DROP,
99     }
100 };
101
102
103 static u32
104 ip4_create_fib_with_table_id (u32 table_id,
105                               fib_source_t src)
106 {
107     fib_table_t *fib_table;
108     ip4_fib_t *v4_fib;
109
110     pool_get_aligned(ip4_main.fibs, fib_table, CLIB_CACHE_LINE_BYTES);
111     memset(fib_table, 0, sizeof(*fib_table));
112
113     pool_get_aligned(ip4_main.v4_fibs, v4_fib, CLIB_CACHE_LINE_BYTES);
114
115     ASSERT((fib_table - ip4_main.fibs) ==
116            (v4_fib - ip4_main.v4_fibs));
117
118     fib_table->ft_proto = FIB_PROTOCOL_IP4;
119     fib_table->ft_index =
120         v4_fib->index =
121             (fib_table - ip4_main.fibs);
122
123     hash_set (ip4_main.fib_index_by_table_id, table_id, fib_table->ft_index);
124
125     fib_table->ft_table_id =
126         v4_fib->table_id =
127             table_id;
128     fib_table->ft_flow_hash_config = IP_FLOW_HASH_DEFAULT;
129     v4_fib->fwd_classify_table_index = ~0;
130     v4_fib->rev_classify_table_index = ~0;
131     
132     fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_IP4, src);
133
134     ip4_mtrie_init(&v4_fib->mtrie);
135
136     /*
137      * add the special entries into the new FIB
138      */
139     int ii;
140
141     for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++)
142     {
143         fib_prefix_t prefix = ip4_specials[ii].ift_prefix;
144
145         prefix.fp_addr.ip4.data_u32 =
146             clib_host_to_net_u32(prefix.fp_addr.ip4.data_u32);
147
148         fib_table_entry_special_add(fib_table->ft_index,
149                                     &prefix,
150                                     ip4_specials[ii].ift_source,
151                                     ip4_specials[ii].ift_flag);
152     }
153
154     return (fib_table->ft_index);
155 }
156
157 void
158 ip4_fib_table_destroy (u32 fib_index)
159 {
160     fib_table_t *fib_table = pool_elt_at_index(ip4_main.fibs, fib_index);
161     ip4_fib_t *v4_fib = pool_elt_at_index(ip4_main.v4_fibs, fib_index);
162     int ii;
163
164     /*
165      * remove all the specials we added when the table was created.
166      * In reverse order so the default route is last.
167      */
168     for (ii = ARRAY_LEN(ip4_specials) - 1; ii >= 0; ii--)
169     {
170         fib_prefix_t prefix = ip4_specials[ii].ift_prefix;
171
172         prefix.fp_addr.ip4.data_u32 =
173             clib_host_to_net_u32(prefix.fp_addr.ip4.data_u32);
174
175         fib_table_entry_special_remove(fib_table->ft_index,
176                                        &prefix,
177                                        ip4_specials[ii].ift_source);
178     }
179
180     /*
181      * validate no more routes.
182      */
183     ASSERT(0 == fib_table->ft_total_route_counts);
184     FOR_EACH_FIB_SOURCE(ii)
185     {
186         ASSERT(0 == fib_table->ft_src_route_counts[ii]);
187     }
188
189     if (~0 != fib_table->ft_table_id)
190     {
191         hash_unset (ip4_main.fib_index_by_table_id, fib_table->ft_table_id);
192     }
193
194     ip4_mtrie_free(&v4_fib->mtrie);
195
196     pool_put(ip4_main.v4_fibs, v4_fib);
197     pool_put(ip4_main.fibs, fib_table);
198 }
199
200
201 u32
202 ip4_fib_table_find_or_create_and_lock (u32 table_id,
203                                        fib_source_t src)
204 {
205     u32 index;
206
207     index = ip4_fib_index_from_table_id(table_id);
208     if (~0 == index)
209         return ip4_create_fib_with_table_id(table_id, src);
210
211     fib_table_lock(index, FIB_PROTOCOL_IP4, src);
212
213     return (index);
214 }
215
216 u32
217 ip4_fib_table_create_and_lock (fib_source_t src)
218 {
219     return (ip4_create_fib_with_table_id(~0, src));
220 }
221
222 u32
223 ip4_fib_table_get_index_for_sw_if_index (u32 sw_if_index)
224 {
225     if (sw_if_index >= vec_len(ip4_main.fib_index_by_sw_if_index))
226     {
227         /*
228          * This is the case for interfaces that are not yet mapped to
229          * a IP table
230          */
231         return (~0);
232     }
233     return (ip4_main.fib_index_by_sw_if_index[sw_if_index]);
234 }
235
236 /*
237  * ip4_fib_table_lookup_exact_match
238  *
239  * Exact match prefix lookup
240  */
241 fib_node_index_t
242 ip4_fib_table_lookup_exact_match (const ip4_fib_t *fib,
243                                   const ip4_address_t *addr,
244                                   u32 len)
245 {
246     uword * hash, * result;
247     u32 key;
248
249     hash = fib->fib_entry_by_dst_address[len];
250     key  = (addr->data_u32 & ip4_main.fib_masks[len]);
251
252     result = hash_get(hash, key);
253
254     if (NULL != result) {
255         return (result[0]);
256     }
257     return (FIB_NODE_INDEX_INVALID);
258 }
259
260 /*
261  * ip4_fib_table_lookup_adj
262  *
263  * Longest prefix match
264  */
265 index_t
266 ip4_fib_table_lookup_lb (ip4_fib_t *fib,
267                          const ip4_address_t *addr)
268 {
269     fib_node_index_t fei;
270
271     fei = ip4_fib_table_lookup(fib, addr, 32);
272
273     if (FIB_NODE_INDEX_INVALID != fei)
274     {
275         const dpo_id_t *dpo;
276
277         dpo = fib_entry_contribute_ip_forwarding(fei);
278
279         return (dpo->dpoi_index);
280     }
281     return (INDEX_INVALID);
282 }
283
284 /*
285  * ip4_fib_table_lookup
286  *
287  * Longest prefix match
288  */
289 fib_node_index_t
290 ip4_fib_table_lookup (const ip4_fib_t *fib,
291                       const ip4_address_t *addr,
292                       u32 len)
293 {
294     uword * hash, * result;
295     i32 mask_len;
296     u32 key;
297
298     for (mask_len = len; mask_len >= 0; mask_len--)
299     {
300         hash = fib->fib_entry_by_dst_address[mask_len];
301         key = (addr->data_u32 & ip4_main.fib_masks[mask_len]);
302
303         result = hash_get (hash, key);
304
305         if (NULL != result) {
306             return (result[0]);
307         }
308     }
309     return (FIB_NODE_INDEX_INVALID);
310 }
311
312 void
313 ip4_fib_table_entry_insert (ip4_fib_t *fib,
314                             const ip4_address_t *addr,
315                             u32 len,
316                             fib_node_index_t fib_entry_index)
317 {
318     uword * hash, * result;
319     u32 key;
320
321     key = (addr->data_u32 & ip4_main.fib_masks[len]);
322     hash = fib->fib_entry_by_dst_address[len];
323     result = hash_get (hash, key);
324
325     if (NULL == result) {
326         /*
327          * adding a new entry
328          */
329         if (NULL == hash) {
330             hash = hash_create (32 /* elts */, sizeof (uword));
331             hash_set_flags (hash, HASH_FLAG_NO_AUTO_SHRINK);
332         }
333         hash = hash_set(hash, key, fib_entry_index);
334         fib->fib_entry_by_dst_address[len] = hash;
335     }
336     else
337     {
338         ASSERT(0);
339     }
340 }
341
342 void
343 ip4_fib_table_entry_remove (ip4_fib_t *fib,
344                             const ip4_address_t *addr,
345                             u32 len)
346 {
347     uword * hash, * result;
348     u32 key;
349
350     key = (addr->data_u32 & ip4_main.fib_masks[len]);
351     hash = fib->fib_entry_by_dst_address[len];
352     result = hash_get (hash, key);
353
354     if (NULL == result)
355     {
356         /*
357          * removing a non-existant entry. i'll allow it.
358          */
359     }
360     else 
361     {
362         hash_unset(hash, key);
363     }
364
365     fib->fib_entry_by_dst_address[len] = hash;
366 }
367
368 void
369 ip4_fib_table_fwding_dpo_update (ip4_fib_t *fib,
370                                  const ip4_address_t *addr,
371                                  u32 len,
372                                  const dpo_id_t *dpo)
373 {
374     ip4_fib_mtrie_route_add(&fib->mtrie, addr, len, dpo->dpoi_index);
375 }
376
377 void
378 ip4_fib_table_fwding_dpo_remove (ip4_fib_t *fib,
379                                  const ip4_address_t *addr,
380                                  u32 len,
381                                  const dpo_id_t *dpo,
382                                  u32 cover_index)
383 {
384     fib_prefix_t cover_prefix = {
385         .fp_len = 0,
386     };
387     const dpo_id_t *cover_dpo;
388
389     /*
390      * We need to pass the MTRIE the LB index and address length of the
391      * covering prefix, so it can fill the plys with the correct replacement
392      * for the entry being removed
393      */
394     fib_entry_get_prefix(cover_index, &cover_prefix);
395     cover_dpo = fib_entry_contribute_ip_forwarding(cover_index);
396
397     ip4_fib_mtrie_route_del(&fib->mtrie,
398                             addr, len, dpo->dpoi_index,
399                             cover_prefix.fp_len,
400                             cover_dpo->dpoi_index);
401 }
402
403 void
404 ip4_fib_table_walk (ip4_fib_t *fib,
405                     fib_table_walk_fn_t fn,
406                     void *ctx)
407 {
408     int i;
409
410     for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
411     {
412         uword * hash = fib->fib_entry_by_dst_address[i];
413
414         if (NULL != hash)
415         {
416             hash_pair_t * p;
417
418             hash_foreach_pair (p, hash,
419             ({
420                 fn(p->value[0], ctx);
421             }));
422         }
423     }
424 }
425
426 /**
427  * Walk show context
428  */
429 typedef struct ip4_fib_show_walk_ctx_t_
430 {
431     fib_node_index_t *ifsw_indicies;
432 } ip4_fib_show_walk_ctx_t;
433
434 static int
435 ip4_fib_show_walk_cb (fib_node_index_t fib_entry_index,
436                       void *arg)
437 {
438     ip4_fib_show_walk_ctx_t *ctx = arg;
439
440     vec_add1(ctx->ifsw_indicies, fib_entry_index);
441
442     return (1);
443 }
444
445 static void
446 ip4_fib_table_show_all (ip4_fib_t *fib,
447                         vlib_main_t * vm)
448 {
449     ip4_fib_show_walk_ctx_t ctx = {
450         .ifsw_indicies = NULL,
451     };
452     fib_node_index_t *fib_entry_index;
453
454     ip4_fib_table_walk(fib, ip4_fib_show_walk_cb, &ctx);
455     vec_sort_with_function(ctx.ifsw_indicies,
456                            fib_entry_cmp_for_sort);
457
458     vec_foreach(fib_entry_index, ctx.ifsw_indicies)
459     {
460         vlib_cli_output(vm, "%U",
461                         format_fib_entry,
462                         *fib_entry_index,
463                         FIB_ENTRY_FORMAT_BRIEF);
464     }
465
466     vec_free(ctx.ifsw_indicies);
467 }
468
469 static void
470 ip4_fib_table_show_one (ip4_fib_t *fib,
471                         vlib_main_t * vm,
472                         ip4_address_t *address,
473                         u32 mask_len,
474                         int detail)
475 {    
476     vlib_cli_output(vm, "%U",
477                     format_fib_entry,
478                     ip4_fib_table_lookup(fib, address, mask_len),
479                     (detail ?
480                      FIB_ENTRY_FORMAT_DETAIL2 :
481                      FIB_ENTRY_FORMAT_DETAIL));
482 }
483
484 u8 *
485 format_ip4_fib_table_memory (u8 * s, va_list * args)
486 {
487     fib_table_t *fib_table;
488     u64 total_memory;
489
490     total_memory = 0;
491
492     pool_foreach (fib_table, ip4_main.fibs,
493     ({
494         ip4_fib_t *fib;
495         uword fib_size;
496         int i;
497
498         fib = pool_elt_at_index(ip4_main.v4_fibs, fib_table->ft_index);
499         fib_size = ip4_fib_mtrie_memory_usage(&fib->mtrie);
500
501         for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
502         {
503             uword * hash = fib->fib_entry_by_dst_address[i];
504
505             if (NULL != hash)
506             {
507                 fib_size += hash_bytes(hash);
508             }
509         }
510
511         total_memory += fib_size;
512     }));
513
514     s = format(s, "%=30s %=6d %=8ld\n",
515                "IPv4 unicast",
516                pool_elts(ip4_main.fibs), total_memory);
517
518     return (s);
519 }
520
521 static clib_error_t *
522 ip4_show_fib (vlib_main_t * vm,
523               unformat_input_t * input,
524               vlib_cli_command_t * cmd)
525 {
526     ip4_main_t * im4 = &ip4_main;
527     fib_table_t * fib_table;
528     u64 total_mtrie_memory, total_hash_memory;
529     int verbose, matching, mtrie, memory;
530     ip4_address_t matching_address;
531     u32 matching_mask = 32;
532     int i, table_id = -1, fib_index = ~0;
533     int detail = 0;
534
535     verbose = 1;
536     matching = mtrie = memory = 0;
537     total_hash_memory = total_mtrie_memory = 0;
538
539     while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
540     {
541         if (unformat (input, "brief") || unformat (input, "summary")
542             || unformat (input, "sum"))
543             verbose = 0;
544
545         else if (unformat (input, "detail") || unformat (input, "det"))
546             detail = 1;
547
548         else if (unformat (input, "mtrie"))
549             mtrie = 1;
550
551         else if (unformat (input, "mem") ||
552                  unformat (input, "memory"))
553             memory = 1;
554
555         else if (unformat (input, "%U/%d",
556                            unformat_ip4_address, &matching_address, &matching_mask))
557             matching = 1;
558
559         else if (unformat (input, "%U", unformat_ip4_address, &matching_address))
560             matching = 1;
561
562         else if (unformat (input, "table %d", &table_id))
563             ;
564         else if (unformat (input, "index %d", &fib_index))
565             ;
566         else
567             break;
568     }
569
570     pool_foreach (fib_table, im4->fibs,
571     ({
572         ip4_fib_t *fib = pool_elt_at_index(im4->v4_fibs, fib_table->ft_index);
573         fib_source_t source;
574         u8 *s = NULL;
575
576         if (table_id >= 0 && table_id != (int)fib->table_id)
577             continue;
578         if (fib_index != ~0 && fib_index != (int)fib->index)
579             continue;
580
581         if (memory)
582         {
583             uword mtrie_size, hash_size;
584
585             mtrie_size = ip4_fib_mtrie_memory_usage(&fib->mtrie);
586             hash_size = 0;
587
588             for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
589             {
590                 uword * hash = fib->fib_entry_by_dst_address[i];
591                 if (NULL != hash)
592                 {
593                     hash_size += hash_bytes(hash);
594                 }
595             }
596             if (verbose)
597                 vlib_cli_output (vm, "%U mtrie:%d hash:%d",
598                                  format_fib_table_name, fib->index,
599                                  FIB_PROTOCOL_IP4,
600                                  mtrie_size,
601                                  hash_size);
602             total_mtrie_memory += mtrie_size;
603             total_hash_memory += hash_size;
604             continue;
605         }
606
607         s = format(s, "%U, fib_index:%d, flow hash:[%U] locks:[",
608                    format_fib_table_name, fib->index,
609                    FIB_PROTOCOL_IP4,
610                    fib->index,
611                    format_ip_flow_hash_config,
612                    fib_table->ft_flow_hash_config);
613         FOR_EACH_FIB_SOURCE(source)
614         {
615             if (0 != fib_table->ft_locks[source])
616             {
617                 s = format(s, "%U:%d, ",
618                            format_fib_source, source,
619                            fib_table->ft_locks[source]);
620             }
621         }
622         s = format (s, "]");
623         vlib_cli_output (vm, "%v", s);
624         vec_free(s);
625
626         /* Show summary? */
627         if (mtrie)
628         {
629             vlib_cli_output (vm, "%U", format_ip4_fib_mtrie, &fib->mtrie, verbose);
630             continue;
631         }
632         if (! verbose)
633         {
634             vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count");
635             for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
636             {
637                 uword * hash = fib->fib_entry_by_dst_address[i];
638                 uword n_elts = hash_elts (hash);
639                 if (n_elts > 0)
640                     vlib_cli_output (vm, "%20d%16d", i, n_elts);
641             }
642             continue;
643         }
644
645         if (!matching)
646         {
647             ip4_fib_table_show_all(fib, vm);
648         }
649         else
650         {
651             ip4_fib_table_show_one(fib, vm, &matching_address,
652                                    matching_mask, detail);
653         }
654     }));
655
656     if (memory)
657         vlib_cli_output (vm, "totals: mtrie:%ld hash:%ld all:%ld",
658                          total_mtrie_memory,
659                          total_hash_memory,
660                          total_mtrie_memory + total_hash_memory);
661
662     return 0;
663 }
664
665 /*?
666  * This command displays the IPv4 FIB Tables (VRF Tables) and the route
667  * entries for each table.
668  *
669  * @note This command will run for a long time when the FIB tables are
670  * comprised of millions of entries. For those senarios, consider displaying
671  * a single table or summary mode.
672  *
673  * @cliexpar
674  * Example of how to display all the IPv4 FIB tables:
675  * @cliexstart{show ip fib}
676  * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
677  * 0.0.0.0/0
678  *   unicast-ip4-chain
679  *   [@0]: dpo-load-balance: [index:0 buckets:1 uRPF:0 to:[0:0]]
680  *     [0] [@0]: dpo-drop ip6
681  * 0.0.0.0/32
682  *   unicast-ip4-chain
683  *   [@0]: dpo-load-balance: [index:1 buckets:1 uRPF:1 to:[0:0]]
684  *     [0] [@0]: dpo-drop ip6
685  * 6.0.1.2/32
686  *   unicast-ip4-chain
687  *   [@0]: dpo-load-balance: [index:30 buckets:1 uRPF:29 to:[0:0]]
688  *     [0] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
689  * 7.0.0.1/32
690  *   unicast-ip4-chain
691  *   [@0]: dpo-load-balance: [index:31 buckets:4 uRPF:30 to:[0:0]]
692  *     [0] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
693  *     [1] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
694  *     [2] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
695  *     [3] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
696  * 224.0.0.0/8
697  *   unicast-ip4-chain
698  *   [@0]: dpo-load-balance: [index:3 buckets:1 uRPF:3 to:[0:0]]
699  *     [0] [@0]: dpo-drop ip6
700  * 240.0.0.0/8
701  *   unicast-ip4-chain
702  *   [@0]: dpo-load-balance: [index:2 buckets:1 uRPF:2 to:[0:0]]
703  *     [0] [@0]: dpo-drop ip6
704  * 255.255.255.255/32
705  *   unicast-ip4-chain
706  *   [@0]: dpo-load-balance: [index:4 buckets:1 uRPF:4 to:[0:0]]
707  *     [0] [@0]: dpo-drop ip6
708  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
709  * 0.0.0.0/0
710  *   unicast-ip4-chain
711  *   [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
712  *     [0] [@0]: dpo-drop ip6
713  * 0.0.0.0/32
714  *   unicast-ip4-chain
715  *   [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
716  *     [0] [@0]: dpo-drop ip6
717  * 172.16.1.0/24
718  *   unicast-ip4-chain
719  *   [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
720  *     [0] [@4]: ipv4-glean: af_packet0
721  * 172.16.1.1/32
722  *   unicast-ip4-chain
723  *   [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
724  *     [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
725  * 172.16.1.2/32
726  *   unicast-ip4-chain
727  *   [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
728  *     [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
729  * 172.16.2.0/24
730  *   unicast-ip4-chain
731  *   [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
732  *     [0] [@4]: ipv4-glean: af_packet1
733  * 172.16.2.1/32
734  *   unicast-ip4-chain
735  *   [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
736  *     [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
737  * 224.0.0.0/8
738  *   unicast-ip4-chain
739  *   [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
740  *     [0] [@0]: dpo-drop ip6
741  * 240.0.0.0/8
742  *   unicast-ip4-chain
743  *   [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
744  *     [0] [@0]: dpo-drop ip6
745  * 255.255.255.255/32
746  *   unicast-ip4-chain
747  *   [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
748  *     [0] [@0]: dpo-drop ip6
749  * @cliexend
750  * Example of how to display a single IPv4 FIB table:
751  * @cliexstart{show ip fib table 7}
752  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
753  * 0.0.0.0/0
754  *   unicast-ip4-chain
755  *   [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
756  *     [0] [@0]: dpo-drop ip6
757  * 0.0.0.0/32
758  *   unicast-ip4-chain
759  *   [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
760  *     [0] [@0]: dpo-drop ip6
761  * 172.16.1.0/24
762  *   unicast-ip4-chain
763  *   [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
764  *     [0] [@4]: ipv4-glean: af_packet0
765  * 172.16.1.1/32
766  *   unicast-ip4-chain
767  *   [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
768  *     [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
769  * 172.16.1.2/32
770  *   unicast-ip4-chain
771  *   [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
772  *     [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
773  * 172.16.2.0/24
774  *   unicast-ip4-chain
775  *   [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
776  *     [0] [@4]: ipv4-glean: af_packet1
777  * 172.16.2.1/32
778  *   unicast-ip4-chain
779  *   [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
780  *     [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
781  * 224.0.0.0/8
782  *   unicast-ip4-chain
783  *   [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
784  *     [0] [@0]: dpo-drop ip6
785  * 240.0.0.0/8
786  *   unicast-ip4-chain
787  *   [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
788  *     [0] [@0]: dpo-drop ip6
789  * 255.255.255.255/32
790  *   unicast-ip4-chain
791  *   [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
792  *     [0] [@0]: dpo-drop ip6
793  * @cliexend
794  * Example of how to display a summary of all IPv4 FIB tables:
795  * @cliexstart{show ip fib summary}
796  * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
797  *     Prefix length         Count
798  *                    0               1
799  *                    8               2
800  *                   32               4
801  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
802  *     Prefix length         Count
803  *                    0               1
804  *                    8               2
805  *                   24               2
806  *                   32               4
807  * @cliexend
808  ?*/
809 /* *INDENT-OFF* */
810 VLIB_CLI_COMMAND (ip4_show_fib_command, static) = {
811     .path = "show ip fib",
812     .short_help = "show ip fib [summary] [table <table-id>] [index <fib-id>] [<ip4-addr>[/<mask>]] [mtrie] [detail]",
813     .function = ip4_show_fib,
814 };
815 /* *INDENT-ON* */