Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [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 | #include <vnet/mpls/mpls.h> |
| 18 | |
| 19 | #include <vnet/bier/bier_table.h> |
| 20 | #include <vnet/bier/bier_types.h> |
| 21 | #include <vnet/bier/bier_update.h> |
| 22 | |
| 23 | clib_error_t * |
| 24 | vnet_bier_table_cmd (vlib_main_t * vm, |
| 25 | unformat_input_t * input, |
| 26 | vlib_cli_command_t * cmd) |
| 27 | { |
| 28 | u32 hdr_len, local_label; |
| 29 | clib_error_t * error = 0; |
| 30 | bier_table_id_t bti = { |
| 31 | .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN, |
| 32 | }; |
| 33 | u32 is_add = 0; |
| 34 | |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 35 | local_label = MPLS_LABEL_INVALID; |
| 36 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 37 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { |
| 38 | if (unformat (input, "del")) { |
| 39 | is_add = 0; |
| 40 | } else if (unformat (input, "add")) { |
| 41 | is_add = 1; |
| 42 | } else if (unformat (input, "sd %d", &bti.bti_sub_domain)) { |
| 43 | } else if (unformat (input, "set %d", &bti.bti_set)) { |
| 44 | } else if (unformat (input, "bsl %d", &hdr_len)) { |
| 45 | } else if (unformat (input, "mpls %d", &local_label)) { |
| 46 | } else { |
| 47 | error = unformat_parse_error (input); |
| 48 | goto done; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len); |
| 53 | // FIXME |
| 54 | bti.bti_type = BIER_TABLE_MPLS_SPF; |
| 55 | |
| 56 | if (is_add) |
| 57 | { |
| 58 | bier_table_add_or_lock(&bti, local_label); |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | bier_table_unlock(&bti); |
| 63 | } |
| 64 | |
| 65 | done: |
| 66 | return (error); |
| 67 | } |
| 68 | |
| 69 | VLIB_CLI_COMMAND (bier_table_command) = { |
| 70 | .path = "bier table", |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 71 | .short_help = "bier table [add|del] sd <sub-domain> set <SET> bsl <bit-string-length> [mpls <label>]", |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 72 | .function = vnet_bier_table_cmd, |
| 73 | }; |
| 74 | |
| 75 | clib_error_t * |
| 76 | vnet_bier_route_cmd (vlib_main_t * vm, |
| 77 | unformat_input_t * input, |
| 78 | vlib_cli_command_t * cmd) |
| 79 | { |
| 80 | clib_error_t * error = NULL; |
Neale Ranns | 93149bb | 2017-11-15 10:44:07 -0800 | [diff] [blame] | 81 | fib_route_path_t *brps = NULL, brp = { |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 82 | .frp_flags = FIB_ROUTE_PATH_BIER_FMASK, |
| 83 | }; |
Neale Ranns | 70ed8ae | 2017-11-15 12:54:46 -0800 | [diff] [blame] | 84 | u32 hdr_len, payload_proto; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 85 | bier_table_id_t bti = { |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 86 | .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 87 | }; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 88 | bier_bp_t bp; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 89 | u32 add = 1; |
| 90 | |
Neale Ranns | 70ed8ae | 2017-11-15 12:54:46 -0800 | [diff] [blame] | 91 | payload_proto = DPO_PROTO_BIER; |
| 92 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 93 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { |
| 94 | if (unformat (input, "del")) { |
| 95 | add = 0; |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 96 | } else if (unformat (input, "add")) { |
| 97 | add = 1; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 98 | } else if (unformat (input, "sd %d", &bti.bti_sub_domain)) { |
| 99 | } else if (unformat (input, "set %d", &bti.bti_set)) { |
| 100 | } else if (unformat (input, "bsl %d", &hdr_len)) { |
| 101 | } else if (unformat (input, "bp %d", &bp)) { |
Neale Ranns | 70ed8ae | 2017-11-15 12:54:46 -0800 | [diff] [blame] | 102 | } else if (unformat (input, "via %U", |
| 103 | unformat_fib_route_path, |
| 104 | &brp, &payload_proto)) { |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 105 | } else { |
| 106 | error = unformat_parse_error (input); |
| 107 | goto done; |
| 108 | } |
| 109 | } |
| 110 | |
Neale Ranns | 93149bb | 2017-11-15 10:44:07 -0800 | [diff] [blame] | 111 | vec_add1(brps, brp); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 112 | bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len); |
| 113 | // FIXME |
| 114 | bti.bti_type = BIER_TABLE_MPLS_SPF; |
| 115 | |
| 116 | if (add) |
| 117 | { |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 118 | bier_table_route_path_add(&bti, bp, brps); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 119 | } |
| 120 | else |
| 121 | { |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 122 | bier_table_route_path_remove(&bti, bp, brps); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | done: |
Neale Ranns | 93149bb | 2017-11-15 10:44:07 -0800 | [diff] [blame] | 126 | vec_free(brps); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 127 | return (error); |
| 128 | } |
| 129 | |
| 130 | VLIB_CLI_COMMAND (bier_route_command) = { |
Neale Ranns | 6cfe643 | 2017-11-22 03:05:29 -0800 | [diff] [blame] | 131 | .path = "bier route", |
Vladislav Grishenko | dea806d | 2024-02-20 11:58:01 +0500 | [diff] [blame] | 132 | .short_help = |
| 133 | "bier route [add|del] sd <sud-domain> set <set> bsl <bit-string-length> " |
| 134 | "bp <bit-position> via [next-hop-address] [next-hop-interface] " |
| 135 | "[next-hop-table <value>] [weight <value>] [preference <value>] " |
| 136 | "[udp-encap-id <value>] [ip4-lookup-in-table <value>] " |
| 137 | "[ip6-lookup-in-table <value>] [mpls-lookup-in-table <value>] " |
| 138 | "[resolve-via-host] [resolve-via-connected] [rx-ip4|rx-ip6 <interface>] " |
| 139 | "[out-labels <value value value>]", |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 140 | .function = vnet_bier_route_cmd, |
| 141 | }; |
| 142 | |
| 143 | static clib_error_t * |
| 144 | show_bier_fib_command_fn (vlib_main_t * vm, |
| 145 | unformat_input_t * input, |
| 146 | vlib_cli_command_t * cmd) |
| 147 | { |
| 148 | bier_show_flags_t flags; |
| 149 | index_t bti, bei; |
| 150 | bier_bp_t bp; |
| 151 | |
| 152 | bp = BIER_BP_INVALID; |
| 153 | bti = bei = INDEX_INVALID; |
Neale Ranns | 93149bb | 2017-11-15 10:44:07 -0800 | [diff] [blame] | 154 | flags = BIER_SHOW_BRIEF; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 155 | |
| 156 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { |
| 157 | if (unformat (input, "%d %d", &bti, &bp)) |
| 158 | { |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 159 | flags = BIER_SHOW_DETAIL; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 160 | } |
| 161 | else if (unformat (input, "%d", &bti)) |
| 162 | { |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 163 | flags = BIER_SHOW_DETAIL; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 164 | } |
| 165 | else |
| 166 | { |
| 167 | break; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | if (INDEX_INVALID == bti) |
| 172 | { |
| 173 | bier_table_show_all(vm, flags); |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | if (!pool_is_free_index(bier_table_pool, bti)) |
| 178 | { |
| 179 | if (BIER_BP_INVALID == bp) |
| 180 | { |
| 181 | vlib_cli_output (vm, "%U", format_bier_table, bti, flags); |
| 182 | } |
| 183 | else |
| 184 | { |
| 185 | vlib_cli_output (vm, "%U", format_bier_table_entry, bti, bp); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | return (NULL); |
| 190 | } |
| 191 | |
| 192 | VLIB_CLI_COMMAND (show_bier_fib_command, static) = { |
| 193 | .path = "show bier fib", |
| 194 | .short_help = "show bier fib [table-index] [bit-position]", |
| 195 | .function = show_bier_fib_command_fn, |
| 196 | }; |