Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 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/vnet.h> |
| 17 | |
| 18 | #include <vnet/mfib/mfib_itf.h> |
| 19 | #include <vnet/mfib/mfib_signal.h> |
| 20 | |
| 21 | mfib_itf_t *mfib_itf_pool; |
| 22 | |
| 23 | index_t |
| 24 | mfib_itf_create (u32 sw_if_index, |
| 25 | mfib_itf_flags_t mfi_flags) |
| 26 | { |
| 27 | mfib_itf_t *mfib_itf; |
| 28 | |
| 29 | pool_get_aligned(mfib_itf_pool, mfib_itf, |
| 30 | CLIB_CACHE_LINE_BYTES); |
| 31 | |
| 32 | mfib_itf->mfi_sw_if_index = sw_if_index; |
| 33 | mfib_itf->mfi_flags = mfi_flags; |
| 34 | mfib_itf->mfi_si = INDEX_INVALID; |
| 35 | |
| 36 | return (mfib_itf - mfib_itf_pool); |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | mfib_itf_delete (mfib_itf_t *mfi) |
| 41 | { |
| 42 | mfib_signal_remove_itf(mfi); |
| 43 | pool_put(mfib_itf_pool, mfi); |
| 44 | } |
| 45 | |
| 46 | u8 * |
| 47 | format_mfib_itf (u8 * s, va_list * args) |
| 48 | { |
| 49 | mfib_itf_t *mfib_itf; |
| 50 | vnet_main_t *vnm; |
| 51 | index_t mfi; |
| 52 | |
| 53 | mfi = va_arg (*args, index_t); |
| 54 | |
| 55 | vnm = vnet_get_main(); |
| 56 | mfib_itf = mfib_itf_get(mfi); |
| 57 | |
| 58 | if (~0 != mfib_itf->mfi_sw_if_index) |
| 59 | { |
| 60 | return (format(s, " %U: %U", |
| 61 | format_vnet_sw_interface_name, |
| 62 | vnm, |
| 63 | vnet_get_sw_interface(vnm, |
| 64 | mfib_itf->mfi_sw_if_index), |
| 65 | format_mfib_itf_flags, mfib_itf->mfi_flags)); |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | return (format(s, " local: %U", |
| 70 | format_mfib_itf_flags, mfib_itf->mfi_flags)); |
| 71 | } |
| 72 | return (s); |
| 73 | } |
| 74 | |
| 75 | static clib_error_t * |
| 76 | show_mfib_itf_command (vlib_main_t * vm, |
| 77 | unformat_input_t * input, |
| 78 | vlib_cli_command_t * cmd) |
| 79 | { |
| 80 | index_t mfii; |
| 81 | |
| 82 | if (unformat (input, "%d", &mfii)) |
| 83 | { |
| 84 | /* |
| 85 | * show one in detail |
| 86 | */ |
| 87 | if (!pool_is_free_index(mfib_itf_pool, mfii)) |
| 88 | { |
| 89 | vlib_cli_output (vm, "%d@%U", |
| 90 | mfii, |
| 91 | format_mfib_itf, mfii); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | vlib_cli_output (vm, "itf %d invalid", mfii); |
| 96 | } |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | /* |
| 101 | * show all |
| 102 | */ |
| 103 | vlib_cli_output (vm, "mFIB interfaces::"); |
| 104 | pool_foreach_index(mfii, mfib_itf_pool, |
| 105 | ({ |
| 106 | vlib_cli_output (vm, "%d@%U", |
| 107 | mfii, |
| 108 | format_mfib_itf, mfii); |
| 109 | })); |
| 110 | } |
| 111 | |
| 112 | return (NULL); |
| 113 | } |
| 114 | |
Neale Ranns | c756c1c | 2017-02-08 09:11:57 -0800 | [diff] [blame^] | 115 | /*? |
| 116 | * This commnad displays an MFIB interface, or all interfaces, indexed by their unique |
| 117 | * numerical indentifier. |
| 118 | ?*/ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 119 | VLIB_CLI_COMMAND (show_mfib_itf, static) = { |
| 120 | .path = "show mfib interface", |
| 121 | .function = show_mfib_itf_command, |
| 122 | .short_help = "show mfib interface", |
| 123 | }; |