Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * mpls_fib.h: The Label/MPLS FIB |
| 3 | * |
| 4 | * Copyright (c) 2012 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | /** |
| 18 | * An MPLS_FIB table; |
| 19 | * |
| 20 | * The entries in the table are programmed wtih one or more MOIs. These MOIs |
| 21 | * may result in different forwarding actions for end-of-stack (EOS) and non-EOS |
| 22 | * packets. Whether the two actions are the same more often than they are |
| 23 | * different, or vice versa, is a function of the deployment in which the router |
| 24 | * is used and thus not predictable. |
| 25 | * The desgin choice to make with an MPLS_FIB table is: |
| 26 | * 1 - 20 bit key: label only. |
| 27 | * When the EOS and non-EOS actions differ the result is a 'EOS-choice' object. |
| 28 | * 2 - 21 bit key: label and EOS-bit. |
| 29 | * The result is then the specific action based on EOS-bit. |
| 30 | * |
| 31 | * 20 bit key: |
| 32 | * Advantages: |
| 33 | * - lower memory overhead, since there are few DB entries. |
| 34 | * Disadvantages: |
| 35 | * - slower DP performance in the case the chains differ, as more objects are |
| 36 | * encounterd in the switch path |
| 37 | * |
| 38 | * 21 bit key: |
| 39 | * Advantages: |
| 40 | * - faster DP performance |
| 41 | * Disadvantages |
| 42 | * - increased memory footprint. |
| 43 | * |
| 44 | * Switching between schemes based on observed/measured action similarity is not |
| 45 | * considered on the grounds of complexity and flip-flopping. |
| 46 | * |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 47 | * VPP mantra - favour performance over memory. We choose a 21 bit key. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 48 | */ |
| 49 | |
| 50 | #include <vnet/fib/fib_table.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 51 | #include <vnet/fib/mpls_fib.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 52 | #include <vnet/dpo/load_balance.h> |
| 53 | #include <vnet/dpo/drop_dpo.h> |
| 54 | #include <vnet/dpo/punt_dpo.h> |
| 55 | #include <vnet/dpo/lookup_dpo.h> |
| 56 | #include <vnet/mpls/mpls.h> |
| 57 | |
| 58 | /** |
| 59 | * All lookups in an MPLS_FIB table must result in a DPO of type load-balance. |
| 60 | * This is the default result which links to drop |
| 61 | */ |
| 62 | static index_t mpls_fib_drop_dpo_index = INDEX_INVALID; |
| 63 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 64 | static inline u32 |
| 65 | mpls_fib_entry_mk_key (mpls_label_t label, |
| 66 | mpls_eos_bit_t eos) |
| 67 | { |
| 68 | ASSERT(eos <= 1); |
| 69 | return (label << 1 | eos); |
| 70 | } |
| 71 | |
| 72 | u32 |
| 73 | mpls_fib_index_from_table_id (u32 table_id) |
| 74 | { |
| 75 | mpls_main_t *mm = &mpls_main; |
| 76 | uword * p; |
| 77 | |
| 78 | p = hash_get (mm->fib_index_by_table_id, table_id); |
| 79 | if (!p) |
| 80 | return FIB_NODE_INDEX_INVALID; |
| 81 | |
| 82 | return p[0]; |
| 83 | } |
| 84 | |
| 85 | static u32 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 86 | mpls_fib_create_with_table_id (u32 table_id, |
| 87 | fib_source_t src) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 88 | { |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 89 | dpo_id_t dpo = DPO_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 90 | fib_table_t *fib_table; |
| 91 | mpls_eos_bit_t eos; |
| 92 | mpls_fib_t *mf; |
| 93 | int i; |
| 94 | |
Dave Barach | eb987d3 | 2018-05-03 08:26:39 -0400 | [diff] [blame] | 95 | pool_get(mpls_main.fibs, fib_table); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 96 | pool_get_aligned(mpls_main.mpls_fibs, mf, CLIB_CACHE_LINE_BYTES); |
| 97 | |
| 98 | ASSERT((fib_table - mpls_main.fibs) == |
| 99 | (mf - mpls_main.mpls_fibs)); |
| 100 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 101 | clib_memset(fib_table, 0, sizeof(*fib_table)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 102 | |
| 103 | fib_table->ft_proto = FIB_PROTOCOL_MPLS; |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 104 | fib_table->ft_index = (fib_table - mpls_main.fibs); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 105 | |
| 106 | hash_set (mpls_main.fib_index_by_table_id, table_id, fib_table->ft_index); |
| 107 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 108 | fib_table->ft_table_id = table_id; |
| 109 | fib_table->ft_flow_hash_config = MPLS_FLOW_HASH_DEFAULT; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 110 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 111 | fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_MPLS, src); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 112 | |
| 113 | if (INDEX_INVALID == mpls_fib_drop_dpo_index) |
| 114 | { |
| 115 | mpls_fib_drop_dpo_index = load_balance_create(1, DPO_PROTO_MPLS, 0); |
| 116 | load_balance_set_bucket(mpls_fib_drop_dpo_index, |
| 117 | 0, |
| 118 | drop_dpo_get(DPO_PROTO_MPLS)); |
| 119 | } |
| 120 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 121 | mf->mf_entries = hash_create(0, sizeof(fib_node_index_t)); |
| 122 | for (i = 0; i < MPLS_FIB_DB_SIZE; i++) |
| 123 | { |
| 124 | /* |
| 125 | * initialise each DPO in the data-path lookup table |
| 126 | * to be the special MPLS drop |
| 127 | */ |
| 128 | mf->mf_lbs[i] = mpls_fib_drop_dpo_index; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * non-default forwarding for the special labels. |
| 133 | */ |
| 134 | fib_prefix_t prefix = { |
| 135 | .fp_proto = FIB_PROTOCOL_MPLS, |
| 136 | .fp_payload_proto = DPO_PROTO_MPLS, |
| 137 | }; |
| 138 | |
| 139 | /* |
| 140 | * PUNT the router alert, both EOS and non-eos |
| 141 | */ |
| 142 | prefix.fp_label = MPLS_IETF_ROUTER_ALERT_LABEL; |
| 143 | FOR_EACH_MPLS_EOS_BIT(eos) |
| 144 | { |
| 145 | prefix.fp_eos = eos; |
| 146 | fib_table_entry_special_dpo_add(fib_table->ft_index, |
| 147 | &prefix, |
| 148 | FIB_SOURCE_SPECIAL, |
| 149 | FIB_ENTRY_FLAG_EXCLUSIVE, |
| 150 | punt_dpo_get(DPO_PROTO_MPLS)); |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * IPv4 explicit NULL EOS lookup in the interface's IPv4 table |
| 155 | */ |
| 156 | prefix.fp_label = MPLS_IETF_IPV4_EXPLICIT_NULL_LABEL; |
| 157 | prefix.fp_payload_proto = DPO_PROTO_IP4; |
| 158 | prefix.fp_eos = MPLS_EOS; |
| 159 | |
| 160 | lookup_dpo_add_or_lock_w_fib_index(0, // unused |
| 161 | DPO_PROTO_IP4, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 162 | LOOKUP_UNICAST, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 163 | LOOKUP_INPUT_DST_ADDR, |
| 164 | LOOKUP_TABLE_FROM_INPUT_INTERFACE, |
| 165 | &dpo); |
| 166 | fib_table_entry_special_dpo_add(fib_table->ft_index, |
| 167 | &prefix, |
| 168 | FIB_SOURCE_SPECIAL, |
| 169 | FIB_ENTRY_FLAG_EXCLUSIVE, |
| 170 | &dpo); |
| 171 | |
| 172 | prefix.fp_payload_proto = DPO_PROTO_MPLS; |
| 173 | prefix.fp_eos = MPLS_NON_EOS; |
| 174 | |
| 175 | lookup_dpo_add_or_lock_w_fib_index(0, //unsued |
| 176 | DPO_PROTO_MPLS, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 177 | LOOKUP_UNICAST, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 178 | LOOKUP_INPUT_DST_ADDR, |
| 179 | LOOKUP_TABLE_FROM_INPUT_INTERFACE, |
| 180 | &dpo); |
| 181 | fib_table_entry_special_dpo_add(fib_table->ft_index, |
| 182 | &prefix, |
| 183 | FIB_SOURCE_SPECIAL, |
| 184 | FIB_ENTRY_FLAG_EXCLUSIVE, |
| 185 | &dpo); |
| 186 | |
| 187 | /* |
| 188 | * IPv6 explicit NULL EOS lookup in the interface's IPv6 table |
| 189 | */ |
| 190 | prefix.fp_label = MPLS_IETF_IPV6_EXPLICIT_NULL_LABEL; |
| 191 | prefix.fp_payload_proto = DPO_PROTO_IP6; |
| 192 | prefix.fp_eos = MPLS_EOS; |
| 193 | |
| 194 | lookup_dpo_add_or_lock_w_fib_index(0, //unused |
| 195 | DPO_PROTO_IP6, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 196 | LOOKUP_UNICAST, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 197 | LOOKUP_INPUT_DST_ADDR, |
| 198 | LOOKUP_TABLE_FROM_INPUT_INTERFACE, |
| 199 | &dpo); |
| 200 | fib_table_entry_special_dpo_add(fib_table->ft_index, |
| 201 | &prefix, |
| 202 | FIB_SOURCE_SPECIAL, |
| 203 | FIB_ENTRY_FLAG_EXCLUSIVE, |
| 204 | &dpo); |
| 205 | |
| 206 | prefix.fp_payload_proto = DPO_PROTO_MPLS; |
| 207 | prefix.fp_eos = MPLS_NON_EOS; |
| 208 | lookup_dpo_add_or_lock_w_fib_index(0, // unsued |
| 209 | DPO_PROTO_MPLS, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 210 | LOOKUP_UNICAST, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 211 | LOOKUP_INPUT_DST_ADDR, |
| 212 | LOOKUP_TABLE_FROM_INPUT_INTERFACE, |
| 213 | &dpo); |
| 214 | fib_table_entry_special_dpo_add(fib_table->ft_index, |
| 215 | &prefix, |
| 216 | FIB_SOURCE_SPECIAL, |
| 217 | FIB_ENTRY_FLAG_EXCLUSIVE, |
| 218 | &dpo); |
| 219 | |
| 220 | return (fib_table->ft_index); |
| 221 | } |
| 222 | |
| 223 | u32 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 224 | mpls_fib_table_find_or_create_and_lock (u32 table_id, |
| 225 | fib_source_t src) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 226 | { |
| 227 | u32 index; |
| 228 | |
| 229 | index = mpls_fib_index_from_table_id(table_id); |
| 230 | if (~0 == index) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 231 | return mpls_fib_create_with_table_id(table_id, src); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 232 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 233 | fib_table_lock(index, FIB_PROTOCOL_MPLS, src); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 234 | |
| 235 | return (index); |
| 236 | } |
| 237 | u32 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 238 | mpls_fib_table_create_and_lock (fib_source_t src) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 239 | { |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 240 | return (mpls_fib_create_with_table_id(~0, src)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | void |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 244 | mpls_fib_table_destroy (u32 fib_index) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 245 | { |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 246 | fib_table_t *fib_table = pool_elt_at_index(mpls_main.fibs, fib_index); |
| 247 | mpls_fib_t *mf = pool_elt_at_index(mpls_main.mpls_fibs, fib_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 248 | fib_prefix_t prefix = { |
| 249 | .fp_proto = FIB_PROTOCOL_MPLS, |
| 250 | }; |
| 251 | mpls_label_t special_labels[] = { |
| 252 | MPLS_IETF_ROUTER_ALERT_LABEL, |
| 253 | MPLS_IETF_IPV6_EXPLICIT_NULL_LABEL, |
| 254 | MPLS_IETF_IPV4_EXPLICIT_NULL_LABEL, |
| 255 | }; |
| 256 | mpls_eos_bit_t eos; |
| 257 | u32 ii; |
| 258 | |
| 259 | for (ii = 0; ii < ARRAY_LEN(special_labels); ii++) |
| 260 | { |
| 261 | FOR_EACH_MPLS_EOS_BIT(eos) |
| 262 | { |
| 263 | prefix.fp_label = special_labels[ii]; |
| 264 | prefix.fp_eos = eos; |
| 265 | |
| 266 | fib_table_entry_delete(fib_table->ft_index, |
| 267 | &prefix, |
| 268 | FIB_SOURCE_SPECIAL); |
| 269 | } |
| 270 | } |
| 271 | if (~0 != fib_table->ft_table_id) |
| 272 | { |
| 273 | hash_unset(mpls_main.fib_index_by_table_id, |
| 274 | fib_table->ft_table_id); |
| 275 | } |
Neale Ranns | bcc6aa4 | 2017-02-24 01:34:14 -0800 | [diff] [blame] | 276 | hash_free(mf->mf_entries); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 277 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 278 | pool_put(mpls_main.mpls_fibs, mf); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 279 | pool_put(mpls_main.fibs, fib_table); |
| 280 | } |
| 281 | |
| 282 | fib_node_index_t |
| 283 | mpls_fib_table_lookup (const mpls_fib_t *mf, |
| 284 | mpls_label_t label, |
| 285 | mpls_eos_bit_t eos) |
| 286 | { |
| 287 | uword *p; |
| 288 | |
| 289 | p = hash_get(mf->mf_entries, mpls_fib_entry_mk_key(label, eos)); |
| 290 | |
| 291 | if (NULL == p) |
| 292 | return FIB_NODE_INDEX_INVALID; |
| 293 | |
| 294 | return p[0]; |
| 295 | } |
| 296 | |
| 297 | void |
| 298 | mpls_fib_table_entry_insert (mpls_fib_t *mf, |
| 299 | mpls_label_t label, |
| 300 | mpls_eos_bit_t eos, |
| 301 | fib_node_index_t lfei) |
| 302 | { |
| 303 | hash_set(mf->mf_entries, mpls_fib_entry_mk_key(label, eos), lfei); |
| 304 | } |
| 305 | |
| 306 | void |
| 307 | mpls_fib_table_entry_remove (mpls_fib_t *mf, |
| 308 | mpls_label_t label, |
| 309 | mpls_eos_bit_t eos) |
| 310 | { |
| 311 | hash_unset(mf->mf_entries, mpls_fib_entry_mk_key(label, eos)); |
| 312 | } |
| 313 | |
| 314 | void |
| 315 | mpls_fib_forwarding_table_update (mpls_fib_t *mf, |
| 316 | mpls_label_t label, |
| 317 | mpls_eos_bit_t eos, |
| 318 | const dpo_id_t *dpo) |
| 319 | { |
| 320 | mpls_label_t key; |
| 321 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 322 | ASSERT((DPO_LOAD_BALANCE == dpo->dpoi_type) || |
| 323 | (DPO_REPLICATE == dpo->dpoi_type)); |
| 324 | if (CLIB_DEBUG > 0) |
| 325 | { |
| 326 | if (DPO_REPLICATE == dpo->dpoi_type) |
| 327 | ASSERT(dpo->dpoi_index & MPLS_IS_REPLICATE); |
| 328 | if (DPO_LOAD_BALANCE == dpo->dpoi_type) |
| 329 | ASSERT(!(dpo->dpoi_index & MPLS_IS_REPLICATE)); |
| 330 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 331 | key = mpls_fib_entry_mk_key(label, eos); |
| 332 | |
| 333 | mf->mf_lbs[key] = dpo->dpoi_index; |
| 334 | } |
| 335 | |
| 336 | void |
| 337 | mpls_fib_forwarding_table_reset (mpls_fib_t *mf, |
| 338 | mpls_label_t label, |
| 339 | mpls_eos_bit_t eos) |
| 340 | { |
| 341 | mpls_label_t key; |
| 342 | |
| 343 | key = mpls_fib_entry_mk_key(label, eos); |
| 344 | |
| 345 | mf->mf_lbs[key] = mpls_fib_drop_dpo_index; |
| 346 | } |
| 347 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 348 | void |
| 349 | mpls_fib_table_walk (mpls_fib_t *mpls_fib, |
| 350 | fib_table_walk_fn_t fn, |
| 351 | void *ctx) |
| 352 | { |
| 353 | fib_node_index_t lfei; |
| 354 | mpls_label_t key; |
| 355 | |
| 356 | hash_foreach(key, lfei, mpls_fib->mf_entries, |
| 357 | ({ |
| 358 | fn(lfei, ctx); |
| 359 | })); |
| 360 | } |
| 361 | |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 362 | u8 * |
| 363 | format_mpls_fib_table_memory (u8 * s, va_list * args) |
| 364 | { |
| 365 | u64 n_tables, mem; |
| 366 | |
| 367 | n_tables = pool_elts(mpls_main.fibs); |
| 368 | mem = n_tables * sizeof(mpls_fib_t); |
| 369 | s = format(s, "%=30s %=6ld %=8ld\n", "MPLS", n_tables, mem); |
| 370 | |
| 371 | return (s); |
| 372 | } |
| 373 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 374 | static void |
| 375 | mpls_fib_table_show_all (const mpls_fib_t *mpls_fib, |
| 376 | vlib_main_t * vm) |
| 377 | { |
| 378 | fib_node_index_t lfei, *lfeip, *lfeis = NULL; |
| 379 | mpls_label_t key; |
| 380 | |
| 381 | hash_foreach(key, lfei, mpls_fib->mf_entries, |
| 382 | ({ |
| 383 | vec_add1(lfeis, lfei); |
| 384 | })); |
| 385 | |
| 386 | vec_sort_with_function(lfeis, fib_entry_cmp_for_sort); |
| 387 | |
| 388 | vec_foreach(lfeip, lfeis) |
| 389 | { |
| 390 | vlib_cli_output (vm, "%U", |
| 391 | format_fib_entry, *lfeip, |
| 392 | FIB_ENTRY_FORMAT_DETAIL); |
| 393 | } |
| 394 | vec_free(lfeis); |
| 395 | } |
| 396 | |
| 397 | static void |
| 398 | mpls_fib_table_show_one (const mpls_fib_t *mpls_fib, |
| 399 | mpls_label_t label, |
| 400 | vlib_main_t * vm) |
| 401 | { |
| 402 | fib_node_index_t lfei; |
| 403 | mpls_eos_bit_t eos; |
| 404 | |
| 405 | FOR_EACH_MPLS_EOS_BIT(eos) |
| 406 | { |
| 407 | lfei = mpls_fib_table_lookup(mpls_fib, label, eos); |
| 408 | |
| 409 | if (FIB_NODE_INDEX_INVALID != lfei) |
| 410 | { |
| 411 | vlib_cli_output (vm, "%U", |
| 412 | format_fib_entry, lfei, FIB_ENTRY_FORMAT_DETAIL); |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | static clib_error_t * |
| 418 | mpls_fib_show (vlib_main_t * vm, |
| 419 | unformat_input_t * input, |
| 420 | vlib_cli_command_t * cmd) |
| 421 | { |
| 422 | fib_table_t * fib_table; |
| 423 | mpls_label_t label; |
| 424 | int table_id; |
| 425 | |
| 426 | table_id = -1; |
| 427 | label = MPLS_LABEL_INVALID; |
| 428 | |
| 429 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 430 | { |
| 431 | /* if (unformat (input, "brief") || unformat (input, "summary") */ |
| 432 | /* || unformat (input, "sum")) */ |
| 433 | /* verbose = 0; */ |
| 434 | |
| 435 | if (unformat (input, "%d", &label)) |
| 436 | continue; |
| 437 | else if (unformat (input, "table %d", &table_id)) |
| 438 | ; |
| 439 | else |
| 440 | break; |
| 441 | } |
| 442 | |
| 443 | pool_foreach (fib_table, mpls_main.fibs, |
| 444 | ({ |
| 445 | if (table_id >= 0 && table_id != fib_table->ft_table_id) |
| 446 | continue; |
| 447 | |
| 448 | vlib_cli_output (vm, "%v, fib_index %d", |
| 449 | fib_table->ft_desc, mpls_main.fibs - fib_table); |
| 450 | |
| 451 | if (MPLS_LABEL_INVALID == label) |
| 452 | { |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 453 | mpls_fib_table_show_all(mpls_fib_get(fib_table->ft_index), vm); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 454 | } |
| 455 | else |
| 456 | { |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 457 | mpls_fib_table_show_one(mpls_fib_get(fib_table->ft_index), label, vm); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 458 | } |
| 459 | })); |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | VLIB_CLI_COMMAND (mpls_fib_show_command, static) = { |
| 465 | .path = "show mpls fib", |
| 466 | .short_help = "show mpls fib [summary] [table <n>]", |
| 467 | .function = mpls_fib_show, |
| 468 | }; |