Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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/lisp-cp/control.h> |
| 17 | #include <vnet/lisp-gpe/lisp_gpe.h> |
| 18 | |
| 19 | static clib_error_t * |
| 20 | lisp_show_adjacencies_command_fn (vlib_main_t * vm, |
| 21 | unformat_input_t * input, |
| 22 | vlib_cli_command_t * cmd) |
| 23 | { |
| 24 | lisp_adjacency_t *adjs, *adj; |
| 25 | vlib_cli_output (vm, "%s %40s\n", "leid", "reid"); |
| 26 | unformat_input_t _line_input, *line_input = &_line_input; |
| 27 | u32 vni = ~0; |
| 28 | |
| 29 | /* Get a line of input. */ |
| 30 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 31 | return 0; |
| 32 | |
| 33 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 34 | { |
| 35 | if (unformat (line_input, "vni %d", &vni)) |
| 36 | ; |
| 37 | else |
| 38 | { |
| 39 | vlib_cli_output (vm, "parse error: '%U'", |
| 40 | format_unformat_error, line_input); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 41 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 42 | return 0; |
| 43 | } |
| 44 | } |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 45 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 46 | |
| 47 | if (~0 == vni) |
| 48 | { |
| 49 | vlib_cli_output (vm, "error: no vni specified!"); |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | adjs = vnet_lisp_adjacencies_get_by_vni (vni); |
| 54 | |
| 55 | vec_foreach (adj, adjs) |
| 56 | { |
| 57 | vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid, |
| 58 | format_gid_address, &adj->reid); |
| 59 | } |
| 60 | vec_free (adjs); |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | /* *INDENT-OFF* */ |
| 66 | VLIB_CLI_COMMAND (one_show_adjacencies_command) = { |
| 67 | .path = "show one adjacencies", |
| 68 | .short_help = "show one adjacencies", |
| 69 | .function = lisp_show_adjacencies_command_fn, |
| 70 | }; |
| 71 | /* *INDENT-ON* */ |
| 72 | |
| 73 | static clib_error_t * |
| 74 | lisp_add_del_map_server_command_fn (vlib_main_t * vm, |
| 75 | unformat_input_t * input, |
| 76 | vlib_cli_command_t * cmd) |
| 77 | { |
| 78 | int rv = 0; |
| 79 | u8 is_add = 1, ip_set = 0; |
| 80 | ip_address_t ip; |
| 81 | unformat_input_t _line_input, *line_input = &_line_input; |
| 82 | |
| 83 | /* Get a line of input. */ |
| 84 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 85 | return 0; |
| 86 | |
| 87 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 88 | { |
| 89 | if (unformat (line_input, "add")) |
| 90 | is_add = 1; |
| 91 | else if (unformat (line_input, "del")) |
| 92 | is_add = 0; |
| 93 | else if (unformat (line_input, "%U", unformat_ip_address, &ip)) |
| 94 | ip_set = 1; |
| 95 | else |
| 96 | { |
| 97 | vlib_cli_output (vm, "parse error: '%U'", |
| 98 | format_unformat_error, line_input); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 99 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | } |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 103 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 104 | |
| 105 | if (!ip_set) |
| 106 | { |
| 107 | vlib_cli_output (vm, "map-server ip address not set!"); |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | rv = vnet_lisp_add_del_map_server (&ip, is_add); |
| 112 | if (!rv) |
| 113 | vlib_cli_output (vm, "failed to %s map-server!", |
| 114 | is_add ? "add" : "delete"); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | /* *INDENT-OFF* */ |
| 120 | VLIB_CLI_COMMAND (one_add_del_map_server_command) = { |
| 121 | .path = "one map-server", |
| 122 | .short_help = "one map-server add|del <ip>", |
| 123 | .function = lisp_add_del_map_server_command_fn, |
| 124 | }; |
| 125 | /* *INDENT-ON* */ |
| 126 | |
| 127 | |
| 128 | static clib_error_t * |
| 129 | lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 130 | vlib_cli_command_t * cmd) |
| 131 | { |
| 132 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 133 | unformat_input_t _line_input, *line_input = &_line_input; |
| 134 | u8 is_add = 1; |
| 135 | gid_address_t eid; |
| 136 | gid_address_t *eids = 0; |
| 137 | clib_error_t *error = 0; |
| 138 | u8 *locator_set_name = 0; |
| 139 | u32 locator_set_index = 0, map_index = 0; |
| 140 | uword *p; |
| 141 | vnet_lisp_add_del_mapping_args_t _a, *a = &_a; |
| 142 | int rv = 0; |
| 143 | u32 vni = 0; |
| 144 | u8 *key = 0; |
| 145 | u32 key_id = 0; |
| 146 | |
| 147 | memset (&eid, 0, sizeof (eid)); |
| 148 | memset (a, 0, sizeof (*a)); |
| 149 | |
| 150 | /* Get a line of input. */ |
| 151 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 152 | return 0; |
| 153 | |
| 154 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 155 | { |
| 156 | if (unformat (line_input, "add")) |
| 157 | is_add = 1; |
| 158 | else if (unformat (line_input, "del")) |
| 159 | is_add = 0; |
| 160 | else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) |
| 161 | ; |
| 162 | else if (unformat (line_input, "vni %d", &vni)) |
| 163 | gid_address_vni (&eid) = vni; |
| 164 | else if (unformat (line_input, "secret-key %_%v%_", &key)) |
| 165 | ; |
| 166 | else if (unformat (line_input, "key-id %U", unformat_hmac_key_id, |
| 167 | &key_id)) |
| 168 | ; |
| 169 | else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) |
| 170 | { |
| 171 | p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); |
| 172 | if (!p) |
| 173 | { |
| 174 | error = clib_error_return (0, "locator-set %s doesn't exist", |
| 175 | locator_set_name); |
| 176 | goto done; |
| 177 | } |
| 178 | locator_set_index = p[0]; |
| 179 | } |
| 180 | else |
| 181 | { |
| 182 | error = unformat_parse_error (line_input); |
| 183 | goto done; |
| 184 | } |
| 185 | } |
| 186 | /* XXX treat batch configuration */ |
| 187 | |
| 188 | if (GID_ADDR_SRC_DST == gid_address_type (&eid)) |
| 189 | { |
| 190 | error = |
| 191 | clib_error_return (0, "src/dst is not supported for local EIDs!"); |
| 192 | goto done; |
| 193 | } |
| 194 | |
| 195 | if (key && (0 == key_id)) |
| 196 | { |
| 197 | vlib_cli_output (vm, "invalid key_id!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 198 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | gid_address_copy (&a->eid, &eid); |
| 202 | a->is_add = is_add; |
| 203 | a->locator_set_index = locator_set_index; |
| 204 | a->local = 1; |
| 205 | a->key = key; |
| 206 | a->key_id = key_id; |
| 207 | |
| 208 | rv = vnet_lisp_add_del_local_mapping (a, &map_index); |
| 209 | if (0 != rv) |
| 210 | { |
| 211 | error = clib_error_return (0, "failed to %s local mapping!", |
| 212 | is_add ? "add" : "delete"); |
| 213 | } |
| 214 | done: |
| 215 | vec_free (eids); |
| 216 | if (locator_set_name) |
| 217 | vec_free (locator_set_name); |
| 218 | gid_address_free (&a->eid); |
| 219 | vec_free (a->key); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 220 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 221 | return error; |
| 222 | } |
| 223 | |
| 224 | /* *INDENT-OFF* */ |
| 225 | VLIB_CLI_COMMAND (one_add_del_local_eid_command) = { |
| 226 | .path = "one eid-table", |
| 227 | .short_help = "one eid-table add/del [vni <vni>] eid <eid> " |
| 228 | "locator-set <locator-set> [key <secret-key> key-id sha1|sha256 ]", |
| 229 | .function = lisp_add_del_local_eid_command_fn, |
| 230 | }; |
| 231 | /* *INDENT-ON* */ |
| 232 | |
| 233 | static clib_error_t * |
| 234 | lisp_eid_table_map_command_fn (vlib_main_t * vm, |
| 235 | unformat_input_t * input, |
| 236 | vlib_cli_command_t * cmd) |
| 237 | { |
| 238 | u8 is_add = 1, is_l2 = 0; |
| 239 | u32 vni = 0, dp_id = 0; |
| 240 | unformat_input_t _line_input, *line_input = &_line_input; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 241 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 242 | |
| 243 | /* Get a line of input. */ |
| 244 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 245 | return 0; |
| 246 | |
| 247 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 248 | { |
| 249 | if (unformat (line_input, "del")) |
| 250 | is_add = 0; |
| 251 | else if (unformat (line_input, "vni %d", &vni)) |
| 252 | ; |
| 253 | else if (unformat (line_input, "vrf %d", &dp_id)) |
| 254 | ; |
| 255 | else if (unformat (line_input, "bd %d", &dp_id)) |
| 256 | is_l2 = 1; |
| 257 | else |
| 258 | { |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 259 | error = unformat_parse_error (line_input); |
| 260 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 264 | |
| 265 | done: |
| 266 | unformat_free (line_input); |
| 267 | |
| 268 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /* *INDENT-OFF* */ |
| 272 | VLIB_CLI_COMMAND (one_eid_table_map_command) = { |
| 273 | .path = "one eid-table map", |
| 274 | .short_help = "one eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>", |
| 275 | .function = lisp_eid_table_map_command_fn, |
| 276 | }; |
| 277 | /* *INDENT-ON* */ |
| 278 | |
| 279 | /** |
| 280 | * Handler for add/del remote mapping CLI. |
| 281 | * |
| 282 | * @param vm vlib context |
| 283 | * @param input input from user |
| 284 | * @param cmd cmd |
| 285 | * @return pointer to clib error structure |
| 286 | */ |
| 287 | static clib_error_t * |
| 288 | lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm, |
| 289 | unformat_input_t * input, |
| 290 | vlib_cli_command_t * cmd) |
| 291 | { |
| 292 | clib_error_t *error = 0; |
| 293 | unformat_input_t _line_input, *line_input = &_line_input; |
| 294 | u8 is_add = 1, del_all = 0; |
| 295 | locator_t rloc, *rlocs = 0, *curr_rloc = 0; |
| 296 | gid_address_t eid; |
| 297 | u8 eid_set = 0; |
| 298 | u32 vni, action = ~0, p, w; |
| 299 | int rv; |
| 300 | |
| 301 | /* Get a line of input. */ |
| 302 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 303 | return 0; |
| 304 | |
| 305 | memset (&eid, 0, sizeof (eid)); |
| 306 | memset (&rloc, 0, sizeof (rloc)); |
| 307 | |
| 308 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 309 | { |
| 310 | if (unformat (line_input, "del-all")) |
| 311 | del_all = 1; |
| 312 | else if (unformat (line_input, "del")) |
| 313 | is_add = 0; |
| 314 | else if (unformat (line_input, "add")) |
| 315 | ; |
| 316 | else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) |
| 317 | eid_set = 1; |
| 318 | else if (unformat (line_input, "vni %u", &vni)) |
| 319 | { |
| 320 | gid_address_vni (&eid) = vni; |
| 321 | } |
| 322 | else if (unformat (line_input, "p %d w %d", &p, &w)) |
| 323 | { |
| 324 | if (!curr_rloc) |
| 325 | { |
| 326 | clib_warning |
| 327 | ("No RLOC configured for setting priority/weight!"); |
| 328 | goto done; |
| 329 | } |
| 330 | curr_rloc->priority = p; |
| 331 | curr_rloc->weight = w; |
| 332 | } |
| 333 | else if (unformat (line_input, "rloc %U", unformat_ip_address, |
| 334 | &gid_address_ip (&rloc.address))) |
| 335 | { |
| 336 | /* since rloc is stored in ip prefix we need to set prefix length */ |
| 337 | ip_prefix_t *pref = &gid_address_ippref (&rloc.address); |
| 338 | |
| 339 | u8 version = gid_address_ip_version (&rloc.address); |
| 340 | ip_prefix_len (pref) = ip_address_max_len (version); |
| 341 | |
| 342 | vec_add1 (rlocs, rloc); |
| 343 | curr_rloc = &rlocs[vec_len (rlocs) - 1]; |
| 344 | } |
| 345 | else if (unformat (line_input, "action %U", |
| 346 | unformat_negative_mapping_action, &action)) |
| 347 | ; |
| 348 | else |
| 349 | { |
| 350 | clib_warning ("parse error"); |
| 351 | goto done; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | if (!eid_set) |
| 356 | { |
| 357 | clib_warning ("missing eid!"); |
| 358 | goto done; |
| 359 | } |
| 360 | |
| 361 | if (!del_all) |
| 362 | { |
| 363 | if (is_add && (~0 == action) && 0 == vec_len (rlocs)) |
| 364 | { |
| 365 | clib_warning ("no action set for negative map-reply!"); |
| 366 | goto done; |
| 367 | } |
| 368 | } |
| 369 | else |
| 370 | { |
| 371 | vnet_lisp_clear_all_remote_adjacencies (); |
| 372 | goto done; |
| 373 | } |
| 374 | |
| 375 | /* TODO build src/dst with seid */ |
| 376 | |
| 377 | /* if it's a delete, clean forwarding */ |
| 378 | if (!is_add) |
| 379 | { |
| 380 | vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; |
| 381 | memset (a, 0, sizeof (a[0])); |
| 382 | gid_address_copy (&a->reid, &eid); |
| 383 | if (vnet_lisp_add_del_adjacency (a)) |
| 384 | { |
| 385 | clib_warning ("failed to delete adjacency!"); |
| 386 | goto done; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | /* add as static remote mapping, i.e., not authoritative and infinite |
| 391 | * ttl */ |
| 392 | rv = vnet_lisp_add_del_mapping (&eid, rlocs, action, 0, ~0, is_add, |
| 393 | 1 /* is_static */ , 0); |
| 394 | |
| 395 | if (rv) |
| 396 | clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete"); |
| 397 | |
| 398 | done: |
| 399 | vec_free (rlocs); |
| 400 | unformat_free (line_input); |
| 401 | return error; |
| 402 | } |
| 403 | |
| 404 | /* *INDENT-OFF* */ |
| 405 | VLIB_CLI_COMMAND (one_add_del_remote_mapping_command) = { |
| 406 | .path = "one remote-mapping", |
| 407 | .short_help = |
| 408 | "one remote-mapping add|del [del-all] vni <vni> " |
| 409 | "eid <est-eid> [action <no-action|natively-forward|" |
| 410 | "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> " |
| 411 | "[rloc <dst-locator> ... ]", |
| 412 | .function = lisp_add_del_remote_mapping_command_fn, |
| 413 | }; |
| 414 | /* *INDENT-ON* */ |
| 415 | |
| 416 | /** |
| 417 | * Handler for add/del adjacency CLI. |
| 418 | */ |
| 419 | static clib_error_t * |
| 420 | lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 421 | vlib_cli_command_t * cmd) |
| 422 | { |
| 423 | clib_error_t *error = 0; |
| 424 | unformat_input_t _line_input, *line_input = &_line_input; |
| 425 | vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; |
| 426 | u8 is_add = 1; |
| 427 | ip_prefix_t *reid_ippref, *leid_ippref; |
| 428 | gid_address_t leid, reid; |
| 429 | u8 *dmac = gid_address_mac (&reid); |
| 430 | u8 *smac = gid_address_mac (&leid); |
| 431 | u8 reid_set = 0, leid_set = 0; |
| 432 | u32 vni; |
| 433 | |
| 434 | /* Get a line of input. */ |
| 435 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 436 | return 0; |
| 437 | |
| 438 | memset (&reid, 0, sizeof (reid)); |
| 439 | memset (&leid, 0, sizeof (leid)); |
| 440 | |
| 441 | leid_ippref = &gid_address_ippref (&leid); |
| 442 | reid_ippref = &gid_address_ippref (&reid); |
| 443 | |
| 444 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 445 | { |
| 446 | if (unformat (line_input, "del")) |
| 447 | is_add = 0; |
| 448 | else if (unformat (line_input, "add")) |
| 449 | ; |
| 450 | else if (unformat (line_input, "reid %U", |
| 451 | unformat_ip_prefix, reid_ippref)) |
| 452 | { |
| 453 | gid_address_type (&reid) = GID_ADDR_IP_PREFIX; |
| 454 | reid_set = 1; |
| 455 | } |
| 456 | else if (unformat (line_input, "reid %U", unformat_mac_address, dmac)) |
| 457 | { |
| 458 | gid_address_type (&reid) = GID_ADDR_MAC; |
| 459 | reid_set = 1; |
| 460 | } |
| 461 | else if (unformat (line_input, "vni %u", &vni)) |
| 462 | { |
| 463 | gid_address_vni (&leid) = vni; |
| 464 | gid_address_vni (&reid) = vni; |
| 465 | } |
| 466 | else if (unformat (line_input, "leid %U", |
| 467 | unformat_ip_prefix, leid_ippref)) |
| 468 | { |
| 469 | gid_address_type (&leid) = GID_ADDR_IP_PREFIX; |
| 470 | leid_set = 1; |
| 471 | } |
| 472 | else if (unformat (line_input, "leid %U", unformat_mac_address, smac)) |
| 473 | { |
| 474 | gid_address_type (&leid) = GID_ADDR_MAC; |
| 475 | leid_set = 1; |
| 476 | } |
| 477 | else |
| 478 | { |
| 479 | clib_warning ("parse error"); |
| 480 | goto done; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | if (!reid_set || !leid_set) |
| 485 | { |
| 486 | clib_warning ("missing remote or local eid!"); |
| 487 | goto done; |
| 488 | } |
| 489 | |
| 490 | if ((gid_address_type (&leid) != gid_address_type (&reid)) |
| 491 | || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX |
| 492 | && ip_prefix_version (reid_ippref) |
| 493 | != ip_prefix_version (leid_ippref))) |
| 494 | { |
| 495 | clib_warning ("remote and local EIDs are of different types!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 496 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | memset (a, 0, sizeof (a[0])); |
| 500 | gid_address_copy (&a->leid, &leid); |
| 501 | gid_address_copy (&a->reid, &reid); |
| 502 | a->is_add = is_add; |
| 503 | |
| 504 | if (vnet_lisp_add_del_adjacency (a)) |
| 505 | clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete"); |
| 506 | |
| 507 | done: |
| 508 | unformat_free (line_input); |
| 509 | return error; |
| 510 | } |
| 511 | |
| 512 | /* *INDENT-OFF* */ |
| 513 | VLIB_CLI_COMMAND (one_add_del_adjacency_command) = { |
| 514 | .path = "one adjacency", |
| 515 | .short_help = "one adjacency add|del vni <vni> reid <remote-eid> " |
| 516 | "leid <local-eid>", |
| 517 | .function = lisp_add_del_adjacency_command_fn, |
| 518 | }; |
| 519 | /* *INDENT-ON* */ |
| 520 | |
| 521 | |
| 522 | static clib_error_t * |
| 523 | lisp_map_request_mode_command_fn (vlib_main_t * vm, |
| 524 | unformat_input_t * input, |
| 525 | vlib_cli_command_t * cmd) |
| 526 | { |
| 527 | unformat_input_t _i, *i = &_i; |
| 528 | map_request_mode_t mr_mode = _MR_MODE_MAX; |
| 529 | |
| 530 | /* Get a line of input. */ |
| 531 | if (!unformat_user (input, unformat_line_input, i)) |
| 532 | return 0; |
| 533 | |
| 534 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 535 | { |
| 536 | if (unformat (i, "dst-only")) |
| 537 | mr_mode = MR_MODE_DST_ONLY; |
| 538 | else if (unformat (i, "src-dst")) |
| 539 | mr_mode = MR_MODE_SRC_DST; |
| 540 | else |
| 541 | { |
| 542 | clib_warning ("parse error '%U'", format_unformat_error, i); |
| 543 | goto done; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | if (_MR_MODE_MAX == mr_mode) |
| 548 | { |
| 549 | clib_warning ("No map request mode entered!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 550 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | vnet_lisp_set_map_request_mode (mr_mode); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 554 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 555 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 556 | unformat_free (i); |
| 557 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | /* *INDENT-OFF* */ |
| 562 | VLIB_CLI_COMMAND (one_map_request_mode_command) = { |
| 563 | .path = "one map-request mode", |
| 564 | .short_help = "one map-request mode dst-only|src-dst", |
| 565 | .function = lisp_map_request_mode_command_fn, |
| 566 | }; |
| 567 | /* *INDENT-ON* */ |
| 568 | |
| 569 | |
| 570 | static u8 * |
| 571 | format_lisp_map_request_mode (u8 * s, va_list * args) |
| 572 | { |
| 573 | u32 mode = va_arg (*args, u32); |
| 574 | |
| 575 | switch (mode) |
| 576 | { |
| 577 | case 0: |
| 578 | return format (0, "dst-only"); |
| 579 | case 1: |
| 580 | return format (0, "src-dst"); |
| 581 | } |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | static clib_error_t * |
| 586 | lisp_show_map_request_mode_command_fn (vlib_main_t * vm, |
| 587 | unformat_input_t * input, |
| 588 | vlib_cli_command_t * cmd) |
| 589 | { |
| 590 | vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode, |
| 591 | vnet_lisp_get_map_request_mode ()); |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | /* *INDENT-OFF* */ |
| 596 | VLIB_CLI_COMMAND (one_show_map_request_mode_command) = { |
| 597 | .path = "show one map-request mode", |
| 598 | .short_help = "show one map-request mode", |
| 599 | .function = lisp_show_map_request_mode_command_fn, |
| 600 | }; |
| 601 | /* *INDENT-ON* */ |
| 602 | |
| 603 | static clib_error_t * |
| 604 | lisp_show_map_resolvers_command_fn (vlib_main_t * vm, |
| 605 | unformat_input_t * input, |
| 606 | vlib_cli_command_t * cmd) |
| 607 | { |
| 608 | lisp_msmr_t *mr; |
| 609 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 610 | |
| 611 | vec_foreach (mr, lcm->map_resolvers) |
| 612 | { |
| 613 | vlib_cli_output (vm, "%U", format_ip_address, &mr->address); |
| 614 | } |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | /* *INDENT-OFF* */ |
| 619 | VLIB_CLI_COMMAND (one_show_map_resolvers_command) = { |
| 620 | .path = "show one map-resolvers", |
| 621 | .short_help = "show one map-resolvers", |
| 622 | .function = lisp_show_map_resolvers_command_fn, |
| 623 | }; |
| 624 | /* *INDENT-ON* */ |
| 625 | |
| 626 | |
| 627 | static clib_error_t * |
| 628 | lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm, |
| 629 | unformat_input_t * input, |
| 630 | vlib_cli_command_t * cmd) |
| 631 | { |
| 632 | u8 locator_name_set = 0; |
| 633 | u8 *locator_set_name = 0; |
| 634 | u8 is_add = 1; |
| 635 | unformat_input_t _line_input, *line_input = &_line_input; |
| 636 | clib_error_t *error = 0; |
| 637 | int rv = 0; |
| 638 | |
| 639 | /* Get a line of input. */ |
| 640 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 641 | return 0; |
| 642 | |
| 643 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 644 | { |
| 645 | if (unformat (line_input, "ls %_%v%_", &locator_set_name)) |
| 646 | locator_name_set = 1; |
| 647 | else if (unformat (line_input, "disable")) |
| 648 | is_add = 0; |
| 649 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 650 | { |
| 651 | error = clib_error_return (0, "parse error"); |
| 652 | goto done; |
| 653 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | if (!locator_name_set) |
| 657 | { |
| 658 | clib_warning ("No locator set specified!"); |
| 659 | goto done; |
| 660 | } |
| 661 | rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add); |
| 662 | if (0 != rv) |
| 663 | { |
| 664 | error = clib_error_return (0, "failed to %s pitr!", |
| 665 | is_add ? "add" : "delete"); |
| 666 | } |
| 667 | |
| 668 | done: |
| 669 | if (locator_set_name) |
| 670 | vec_free (locator_set_name); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 671 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 672 | return error; |
| 673 | } |
| 674 | |
| 675 | /* *INDENT-OFF* */ |
| 676 | VLIB_CLI_COMMAND (one_pitr_set_locator_set_command) = { |
| 677 | .path = "one pitr", |
| 678 | .short_help = "one pitr [disable] ls <locator-set-name>", |
| 679 | .function = lisp_pitr_set_locator_set_command_fn, |
| 680 | }; |
| 681 | /* *INDENT-ON* */ |
| 682 | |
| 683 | static clib_error_t * |
| 684 | lisp_show_pitr_command_fn (vlib_main_t * vm, |
| 685 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 686 | { |
| 687 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 688 | mapping_t *m; |
| 689 | locator_set_t *ls; |
| 690 | u8 *tmp_str = 0; |
| 691 | |
| 692 | vlib_cli_output (vm, "%=20s%=16s", |
| 693 | "pitr", lcm->lisp_pitr ? "locator-set" : ""); |
| 694 | |
| 695 | if (!lcm->lisp_pitr) |
| 696 | { |
| 697 | vlib_cli_output (vm, "%=20s", "disable"); |
| 698 | return 0; |
| 699 | } |
| 700 | |
| 701 | if (~0 == lcm->pitr_map_index) |
| 702 | { |
| 703 | tmp_str = format (0, "N/A"); |
| 704 | } |
| 705 | else |
| 706 | { |
| 707 | m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); |
| 708 | if (~0 != m->locator_set_index) |
| 709 | { |
| 710 | ls = |
| 711 | pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); |
| 712 | tmp_str = format (0, "%s", ls->name); |
| 713 | } |
| 714 | else |
| 715 | { |
| 716 | tmp_str = format (0, "N/A"); |
| 717 | } |
| 718 | } |
| 719 | vec_add1 (tmp_str, 0); |
| 720 | |
| 721 | vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); |
| 722 | |
| 723 | vec_free (tmp_str); |
| 724 | |
| 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | /* *INDENT-OFF* */ |
| 729 | VLIB_CLI_COMMAND (one_show_pitr_command) = { |
| 730 | .path = "show one pitr", |
| 731 | .short_help = "Show pitr", |
| 732 | .function = lisp_show_pitr_command_fn, |
| 733 | }; |
| 734 | /* *INDENT-ON* */ |
| 735 | |
| 736 | static u8 * |
| 737 | format_eid_entry (u8 * s, va_list * args) |
| 738 | { |
| 739 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 740 | lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *); |
| 741 | mapping_t *mapit = va_arg (*args, mapping_t *); |
| 742 | locator_set_t *ls = va_arg (*args, locator_set_t *); |
| 743 | gid_address_t *gid = &mapit->eid; |
| 744 | u32 ttl = mapit->ttl; |
| 745 | u8 aut = mapit->authoritative; |
| 746 | u32 *loc_index; |
| 747 | u8 first_line = 1; |
| 748 | u8 *loc; |
| 749 | |
| 750 | u8 *type = ls->local ? format (0, "local(%s)", ls->name) |
| 751 | : format (0, "remote"); |
| 752 | |
| 753 | if (vec_len (ls->locator_indices) == 0) |
| 754 | { |
| 755 | s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid, |
| 756 | type, ttl, aut); |
| 757 | } |
| 758 | else |
| 759 | { |
| 760 | vec_foreach (loc_index, ls->locator_indices) |
| 761 | { |
| 762 | locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]); |
| 763 | if (l->local) |
| 764 | loc = format (0, "%U", format_vnet_sw_if_index_name, vnm, |
| 765 | l->sw_if_index); |
| 766 | else |
| 767 | loc = format (0, "%U", format_ip_address, |
| 768 | &gid_address_ip (&l->address)); |
| 769 | |
| 770 | if (first_line) |
| 771 | { |
| 772 | s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address, |
| 773 | gid, type, loc, ttl, aut); |
| 774 | first_line = 0; |
| 775 | } |
| 776 | else |
| 777 | s = format (s, "%55s%v\n", "", loc); |
| 778 | } |
| 779 | } |
| 780 | return s; |
| 781 | } |
| 782 | |
| 783 | static clib_error_t * |
| 784 | lisp_show_eid_table_command_fn (vlib_main_t * vm, |
| 785 | unformat_input_t * input, |
| 786 | vlib_cli_command_t * cmd) |
| 787 | { |
| 788 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 789 | mapping_t *mapit; |
| 790 | unformat_input_t _line_input, *line_input = &_line_input; |
| 791 | u32 mi; |
| 792 | gid_address_t eid; |
| 793 | u8 print_all = 1; |
| 794 | u8 filter = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 795 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 796 | |
| 797 | memset (&eid, 0, sizeof (eid)); |
| 798 | |
| 799 | /* Get a line of input. */ |
| 800 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 801 | return 0; |
| 802 | |
| 803 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 804 | { |
| 805 | if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) |
| 806 | print_all = 0; |
| 807 | else if (unformat (line_input, "local")) |
| 808 | filter = 1; |
| 809 | else if (unformat (line_input, "remote")) |
| 810 | filter = 2; |
| 811 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 812 | { |
| 813 | error = clib_error_return (0, "parse error: '%U'", |
| 814 | format_unformat_error, line_input); |
| 815 | goto done; |
| 816 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s", |
| 820 | "EID", "type", "locators", "ttl", "autoritative"); |
| 821 | |
| 822 | if (print_all) |
| 823 | { |
| 824 | /* *INDENT-OFF* */ |
| 825 | pool_foreach (mapit, lcm->mapping_pool, |
| 826 | ({ |
| 827 | locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool, |
| 828 | mapit->locator_set_index); |
| 829 | if (filter && !((1 == filter && ls->local) || |
| 830 | (2 == filter && !ls->local))) |
| 831 | { |
| 832 | continue; |
| 833 | } |
| 834 | vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main, |
| 835 | lcm, mapit, ls); |
| 836 | })); |
| 837 | /* *INDENT-ON* */ |
| 838 | } |
| 839 | else |
| 840 | { |
| 841 | mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid); |
| 842 | if ((u32) ~ 0 == mi) |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 843 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 844 | |
| 845 | mapit = pool_elt_at_index (lcm->mapping_pool, mi); |
| 846 | locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, |
| 847 | mapit->locator_set_index); |
| 848 | |
| 849 | if (filter && !((1 == filter && ls->local) || |
| 850 | (2 == filter && !ls->local))) |
| 851 | { |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 852 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main, |
| 856 | lcm, mapit, ls); |
| 857 | } |
| 858 | |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 859 | done: |
| 860 | unformat_free (line_input); |
| 861 | |
| 862 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | /* *INDENT-OFF* */ |
| 866 | VLIB_CLI_COMMAND (one_cp_show_eid_table_command) = { |
| 867 | .path = "show one eid-table", |
| 868 | .short_help = "Shows EID table", |
| 869 | .function = lisp_show_eid_table_command_fn, |
| 870 | }; |
| 871 | /* *INDENT-ON* */ |
| 872 | |
| 873 | |
| 874 | static clib_error_t * |
| 875 | lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 876 | vlib_cli_command_t * cmd) |
| 877 | { |
| 878 | unformat_input_t _line_input, *line_input = &_line_input; |
| 879 | u8 is_enabled = 0; |
| 880 | u8 is_set = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 881 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 882 | |
| 883 | /* Get a line of input. */ |
| 884 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 885 | return 0; |
| 886 | |
| 887 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 888 | { |
| 889 | if (unformat (line_input, "enable")) |
| 890 | { |
| 891 | is_set = 1; |
| 892 | is_enabled = 1; |
| 893 | } |
| 894 | else if (unformat (line_input, "disable")) |
| 895 | is_set = 1; |
| 896 | else |
| 897 | { |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 898 | error = clib_error_return (0, "parse error: '%U'", |
| 899 | format_unformat_error, line_input); |
| 900 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | |
| 904 | if (!is_set) |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 905 | { |
| 906 | error = clib_error_return (0, "state not set"); |
| 907 | goto done; |
| 908 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 909 | |
| 910 | vnet_lisp_enable_disable (is_enabled); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 911 | |
| 912 | done: |
| 913 | unformat_free (line_input); |
| 914 | |
| 915 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | /* *INDENT-OFF* */ |
| 919 | VLIB_CLI_COMMAND (one_cp_enable_disable_command) = { |
| 920 | .path = "one", |
| 921 | .short_help = "one [enable|disable]", |
| 922 | .function = lisp_enable_disable_command_fn, |
| 923 | }; |
| 924 | /* *INDENT-ON* */ |
| 925 | |
| 926 | static clib_error_t * |
| 927 | lisp_map_register_enable_disable_command_fn (vlib_main_t * vm, |
| 928 | unformat_input_t * input, |
| 929 | vlib_cli_command_t * cmd) |
| 930 | { |
| 931 | unformat_input_t _line_input, *line_input = &_line_input; |
| 932 | u8 is_enabled = 0; |
| 933 | u8 is_set = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 934 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 935 | |
| 936 | /* Get a line of input. */ |
| 937 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 938 | return 0; |
| 939 | |
| 940 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 941 | { |
| 942 | if (unformat (line_input, "enable")) |
| 943 | { |
| 944 | is_set = 1; |
| 945 | is_enabled = 1; |
| 946 | } |
| 947 | else if (unformat (line_input, "disable")) |
| 948 | is_set = 1; |
| 949 | else |
| 950 | { |
| 951 | vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, |
| 952 | line_input); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 953 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 954 | } |
| 955 | } |
| 956 | |
| 957 | if (!is_set) |
| 958 | { |
| 959 | vlib_cli_output (vm, "state not set!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 960 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | vnet_lisp_map_register_enable_disable (is_enabled); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 964 | |
| 965 | done: |
| 966 | unformat_free (line_input); |
| 967 | |
| 968 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | /* *INDENT-OFF* */ |
| 972 | VLIB_CLI_COMMAND (one_map_register_enable_disable_command) = { |
| 973 | .path = "one map-register", |
| 974 | .short_help = "one map-register [enable|disable]", |
| 975 | .function = lisp_map_register_enable_disable_command_fn, |
| 976 | }; |
| 977 | /* *INDENT-ON* */ |
| 978 | |
| 979 | static clib_error_t * |
| 980 | lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm, |
| 981 | unformat_input_t * input, |
| 982 | vlib_cli_command_t * cmd) |
| 983 | { |
| 984 | unformat_input_t _line_input, *line_input = &_line_input; |
| 985 | u8 is_enabled = 0; |
| 986 | u8 is_set = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 987 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 988 | |
| 989 | /* Get a line of input. */ |
| 990 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 991 | return 0; |
| 992 | |
| 993 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 994 | { |
| 995 | if (unformat (line_input, "enable")) |
| 996 | { |
| 997 | is_set = 1; |
| 998 | is_enabled = 1; |
| 999 | } |
| 1000 | else if (unformat (line_input, "disable")) |
| 1001 | is_set = 1; |
| 1002 | else |
| 1003 | { |
| 1004 | vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, |
| 1005 | line_input); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1006 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | if (!is_set) |
| 1011 | { |
| 1012 | vlib_cli_output (vm, "state not set!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1013 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | vnet_lisp_rloc_probe_enable_disable (is_enabled); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1017 | |
| 1018 | done: |
| 1019 | unformat_free (line_input); |
| 1020 | |
| 1021 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | /* *INDENT-OFF* */ |
| 1025 | VLIB_CLI_COMMAND (one_rloc_probe_enable_disable_command) = { |
| 1026 | .path = "one rloc-probe", |
| 1027 | .short_help = "one rloc-probe [enable|disable]", |
| 1028 | .function = lisp_rloc_probe_enable_disable_command_fn, |
| 1029 | }; |
| 1030 | /* *INDENT-ON* */ |
| 1031 | |
| 1032 | static u8 * |
| 1033 | format_lisp_status (u8 * s, va_list * args) |
| 1034 | { |
| 1035 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1036 | return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled"); |
| 1037 | } |
| 1038 | |
| 1039 | static clib_error_t * |
| 1040 | lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1041 | vlib_cli_command_t * cmd) |
| 1042 | { |
| 1043 | u8 *msg = 0; |
| 1044 | msg = format (msg, "feature: %U\ngpe: %U\n", |
| 1045 | format_lisp_status, format_vnet_lisp_gpe_status); |
| 1046 | vlib_cli_output (vm, "%v", msg); |
| 1047 | vec_free (msg); |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
| 1051 | /* *INDENT-OFF* */ |
| 1052 | VLIB_CLI_COMMAND (one_show_status_command) = { |
| 1053 | .path = "show one status", |
| 1054 | .short_help = "show one status", |
| 1055 | .function = lisp_show_status_command_fn, |
| 1056 | }; |
| 1057 | /* *INDENT-ON* */ |
| 1058 | |
| 1059 | static clib_error_t * |
| 1060 | lisp_show_eid_table_map_command_fn (vlib_main_t * vm, |
| 1061 | unformat_input_t * input, |
| 1062 | vlib_cli_command_t * cmd) |
| 1063 | { |
| 1064 | hash_pair_t *p; |
| 1065 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1066 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1067 | uword *vni_table = 0; |
| 1068 | u8 is_l2 = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1069 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1070 | |
| 1071 | /* Get a line of input. */ |
| 1072 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1073 | return 0; |
| 1074 | |
| 1075 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1076 | { |
| 1077 | if (unformat (line_input, "l2")) |
| 1078 | { |
| 1079 | vni_table = lcm->bd_id_by_vni; |
| 1080 | is_l2 = 1; |
| 1081 | } |
| 1082 | else if (unformat (line_input, "l3")) |
| 1083 | { |
| 1084 | vni_table = lcm->table_id_by_vni; |
| 1085 | is_l2 = 0; |
| 1086 | } |
| 1087 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1088 | { |
| 1089 | error = clib_error_return (0, "parse error: '%U'", |
| 1090 | format_unformat_error, line_input); |
| 1091 | goto done; |
| 1092 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | if (!vni_table) |
| 1096 | { |
| 1097 | vlib_cli_output (vm, "Error: expected l2|l3 param!\n"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1098 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); |
| 1102 | |
| 1103 | /* *INDENT-OFF* */ |
| 1104 | hash_foreach_pair (p, vni_table, |
| 1105 | ({ |
| 1106 | vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); |
| 1107 | })); |
| 1108 | /* *INDENT-ON* */ |
| 1109 | |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1110 | done: |
| 1111 | unformat_free (line_input); |
| 1112 | |
| 1113 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | /* *INDENT-OFF* */ |
| 1117 | VLIB_CLI_COMMAND (one_show_eid_table_map_command) = { |
| 1118 | .path = "show one eid-table map", |
| 1119 | .short_help = "show one eid-table l2|l3", |
| 1120 | .function = lisp_show_eid_table_map_command_fn, |
| 1121 | }; |
| 1122 | /* *INDENT-ON* */ |
| 1123 | |
| 1124 | |
| 1125 | static clib_error_t * |
| 1126 | lisp_add_del_locator_set_command_fn (vlib_main_t * vm, |
| 1127 | unformat_input_t * input, |
| 1128 | vlib_cli_command_t * cmd) |
| 1129 | { |
| 1130 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
| 1131 | vnet_main_t *vnm = lgm->vnet_main; |
| 1132 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1133 | u8 is_add = 1; |
| 1134 | clib_error_t *error = 0; |
| 1135 | u8 *locator_set_name = 0; |
| 1136 | locator_t locator, *locators = 0; |
| 1137 | vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; |
| 1138 | u32 ls_index = 0; |
| 1139 | int rv = 0; |
| 1140 | |
| 1141 | memset (&locator, 0, sizeof (locator)); |
| 1142 | memset (a, 0, sizeof (a[0])); |
| 1143 | |
| 1144 | /* Get a line of input. */ |
| 1145 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1146 | return 0; |
| 1147 | |
| 1148 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1149 | { |
| 1150 | if (unformat (line_input, "add %_%v%_", &locator_set_name)) |
| 1151 | is_add = 1; |
| 1152 | else if (unformat (line_input, "del %_%v%_", &locator_set_name)) |
| 1153 | is_add = 0; |
| 1154 | else if (unformat (line_input, "iface %U p %d w %d", |
| 1155 | unformat_vnet_sw_interface, vnm, |
| 1156 | &locator.sw_if_index, &locator.priority, |
| 1157 | &locator.weight)) |
| 1158 | { |
| 1159 | locator.local = 1; |
| 1160 | vec_add1 (locators, locator); |
| 1161 | } |
| 1162 | else |
| 1163 | { |
| 1164 | error = unformat_parse_error (line_input); |
| 1165 | goto done; |
| 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | a->name = locator_set_name; |
| 1170 | a->locators = locators; |
| 1171 | a->is_add = is_add; |
| 1172 | a->local = 1; |
| 1173 | |
| 1174 | rv = vnet_lisp_add_del_locator_set (a, &ls_index); |
| 1175 | if (0 != rv) |
| 1176 | { |
| 1177 | error = clib_error_return (0, "failed to %s locator-set!", |
| 1178 | is_add ? "add" : "delete"); |
| 1179 | } |
| 1180 | |
| 1181 | done: |
| 1182 | vec_free (locators); |
| 1183 | if (locator_set_name) |
| 1184 | vec_free (locator_set_name); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1185 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1186 | return error; |
| 1187 | } |
| 1188 | |
| 1189 | /* *INDENT-OFF* */ |
| 1190 | VLIB_CLI_COMMAND (one_cp_add_del_locator_set_command) = { |
| 1191 | .path = "one locator-set", |
| 1192 | .short_help = "one locator-set add/del <name> [iface <iface-name> " |
| 1193 | "p <priority> w <weight>]", |
| 1194 | .function = lisp_add_del_locator_set_command_fn, |
| 1195 | }; |
| 1196 | /* *INDENT-ON* */ |
| 1197 | |
| 1198 | static clib_error_t * |
| 1199 | lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm, |
| 1200 | unformat_input_t * input, |
| 1201 | vlib_cli_command_t * cmd) |
| 1202 | { |
| 1203 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
| 1204 | vnet_main_t *vnm = lgm->vnet_main; |
| 1205 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1206 | u8 is_add = 1; |
| 1207 | clib_error_t *error = 0; |
| 1208 | u8 *locator_set_name = 0; |
| 1209 | u8 locator_set_name_set = 0; |
| 1210 | locator_t locator, *locators = 0; |
| 1211 | vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; |
| 1212 | u32 ls_index = 0; |
| 1213 | |
| 1214 | memset (&locator, 0, sizeof (locator)); |
| 1215 | memset (a, 0, sizeof (a[0])); |
| 1216 | |
| 1217 | /* Get a line of input. */ |
| 1218 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1219 | return 0; |
| 1220 | |
| 1221 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1222 | { |
| 1223 | if (unformat (line_input, "add")) |
| 1224 | is_add = 1; |
| 1225 | else if (unformat (line_input, "del")) |
| 1226 | is_add = 0; |
| 1227 | else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) |
| 1228 | locator_set_name_set = 1; |
| 1229 | else if (unformat (line_input, "iface %U p %d w %d", |
| 1230 | unformat_vnet_sw_interface, vnm, |
| 1231 | &locator.sw_if_index, &locator.priority, |
| 1232 | &locator.weight)) |
| 1233 | { |
| 1234 | locator.local = 1; |
| 1235 | vec_add1 (locators, locator); |
| 1236 | } |
| 1237 | else |
| 1238 | { |
| 1239 | error = unformat_parse_error (line_input); |
| 1240 | goto done; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | if (!locator_set_name_set) |
| 1245 | { |
| 1246 | error = clib_error_return (0, "locator_set name not set!"); |
| 1247 | goto done; |
| 1248 | } |
| 1249 | |
| 1250 | a->name = locator_set_name; |
| 1251 | a->locators = locators; |
| 1252 | a->is_add = is_add; |
| 1253 | a->local = 1; |
| 1254 | |
| 1255 | vnet_lisp_add_del_locator (a, 0, &ls_index); |
| 1256 | |
| 1257 | done: |
| 1258 | vec_free (locators); |
| 1259 | vec_free (locator_set_name); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1260 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1261 | return error; |
| 1262 | } |
| 1263 | |
| 1264 | /* *INDENT-OFF* */ |
| 1265 | VLIB_CLI_COMMAND (one_cp_add_del_locator_in_set_command) = { |
| 1266 | .path = "one locator", |
| 1267 | .short_help = "one locator add/del locator-set <name> iface <iface-name> " |
| 1268 | "p <priority> w <weight>", |
| 1269 | .function = lisp_add_del_locator_in_set_command_fn, |
| 1270 | }; |
| 1271 | /* *INDENT-ON* */ |
| 1272 | |
| 1273 | static clib_error_t * |
| 1274 | lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm, |
| 1275 | unformat_input_t * input, |
| 1276 | vlib_cli_command_t * cmd) |
| 1277 | { |
| 1278 | locator_set_t *lsit; |
| 1279 | locator_t *loc; |
| 1280 | u32 *locit; |
| 1281 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1282 | |
| 1283 | vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator", |
| 1284 | "Priority", "Weight"); |
| 1285 | |
| 1286 | /* *INDENT-OFF* */ |
| 1287 | pool_foreach (lsit, lcm->locator_set_pool, |
| 1288 | ({ |
| 1289 | u8 * msg = 0; |
| 1290 | int next_line = 0; |
| 1291 | if (lsit->local) |
| 1292 | { |
| 1293 | msg = format (msg, "%v", lsit->name); |
| 1294 | } |
| 1295 | else |
| 1296 | { |
| 1297 | msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool); |
| 1298 | } |
| 1299 | vec_foreach (locit, lsit->locator_indices) |
| 1300 | { |
| 1301 | if (next_line) |
| 1302 | { |
| 1303 | msg = format (msg, "%16s", " "); |
| 1304 | } |
| 1305 | loc = pool_elt_at_index (lcm->locator_pool, locit[0]); |
| 1306 | if (loc->local) |
| 1307 | msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority, |
| 1308 | loc->weight); |
| 1309 | else |
| 1310 | msg = format (msg, "%16U%16d%16d\n", format_ip_address, |
| 1311 | &gid_address_ip(&loc->address), loc->priority, |
| 1312 | loc->weight); |
| 1313 | next_line = 1; |
| 1314 | } |
| 1315 | vlib_cli_output (vm, "%v", msg); |
| 1316 | vec_free (msg); |
| 1317 | })); |
| 1318 | /* *INDENT-ON* */ |
| 1319 | return 0; |
| 1320 | } |
| 1321 | |
| 1322 | /* *INDENT-OFF* */ |
| 1323 | VLIB_CLI_COMMAND (one_cp_show_locator_sets_command) = { |
| 1324 | .path = "show one locator-set", |
| 1325 | .short_help = "Shows locator-sets", |
| 1326 | .function = lisp_cp_show_locator_sets_command_fn, |
| 1327 | }; |
| 1328 | /* *INDENT-ON* */ |
| 1329 | |
| 1330 | |
| 1331 | static clib_error_t * |
| 1332 | lisp_add_del_map_resolver_command_fn (vlib_main_t * vm, |
| 1333 | unformat_input_t * input, |
| 1334 | vlib_cli_command_t * cmd) |
| 1335 | { |
| 1336 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1337 | u8 is_add = 1, addr_set = 0; |
| 1338 | ip_address_t ip_addr; |
| 1339 | clib_error_t *error = 0; |
| 1340 | int rv = 0; |
| 1341 | vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; |
| 1342 | |
| 1343 | /* Get a line of input. */ |
| 1344 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1345 | return 0; |
| 1346 | |
| 1347 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1348 | { |
| 1349 | if (unformat (line_input, "add")) |
| 1350 | is_add = 1; |
| 1351 | else if (unformat (line_input, "del")) |
| 1352 | is_add = 0; |
| 1353 | else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr)) |
| 1354 | addr_set = 1; |
| 1355 | else |
| 1356 | { |
| 1357 | error = unformat_parse_error (line_input); |
| 1358 | goto done; |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | if (!addr_set) |
| 1363 | { |
| 1364 | error = clib_error_return (0, "Map-resolver address must be set!"); |
| 1365 | goto done; |
| 1366 | } |
| 1367 | |
| 1368 | a->is_add = is_add; |
| 1369 | a->address = ip_addr; |
| 1370 | rv = vnet_lisp_add_del_map_resolver (a); |
| 1371 | if (0 != rv) |
| 1372 | { |
| 1373 | error = clib_error_return (0, "failed to %s map-resolver!", |
| 1374 | is_add ? "add" : "delete"); |
| 1375 | } |
| 1376 | |
| 1377 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1378 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1379 | return error; |
| 1380 | } |
| 1381 | |
| 1382 | /* *INDENT-OFF* */ |
| 1383 | VLIB_CLI_COMMAND (one_add_del_map_resolver_command) = { |
| 1384 | .path = "one map-resolver", |
| 1385 | .short_help = "one map-resolver add/del <ip_address>", |
| 1386 | .function = lisp_add_del_map_resolver_command_fn, |
| 1387 | }; |
| 1388 | /* *INDENT-ON* */ |
| 1389 | |
| 1390 | |
| 1391 | static clib_error_t * |
| 1392 | lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm, |
| 1393 | unformat_input_t * input, |
| 1394 | vlib_cli_command_t * cmd) |
| 1395 | { |
| 1396 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1397 | u8 is_add = 1; |
| 1398 | u8 *locator_set_name = 0; |
| 1399 | clib_error_t *error = 0; |
| 1400 | int rv = 0; |
| 1401 | vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; |
| 1402 | |
| 1403 | /* Get a line of input. */ |
| 1404 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1405 | return 0; |
| 1406 | |
| 1407 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1408 | { |
| 1409 | if (unformat (line_input, "del")) |
| 1410 | is_add = 0; |
| 1411 | else if (unformat (line_input, "add %_%v%_", &locator_set_name)) |
| 1412 | is_add = 1; |
| 1413 | else |
| 1414 | { |
| 1415 | error = unformat_parse_error (line_input); |
| 1416 | goto done; |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | a->is_add = is_add; |
| 1421 | a->locator_set_name = locator_set_name; |
| 1422 | rv = vnet_lisp_add_del_mreq_itr_rlocs (a); |
| 1423 | if (0 != rv) |
| 1424 | { |
| 1425 | error = clib_error_return (0, "failed to %s map-request itr-rlocs!", |
| 1426 | is_add ? "add" : "delete"); |
| 1427 | } |
| 1428 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1429 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1430 | vec_free (locator_set_name); |
| 1431 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1432 | return error; |
| 1433 | |
| 1434 | } |
| 1435 | |
| 1436 | /* *INDENT-OFF* */ |
| 1437 | VLIB_CLI_COMMAND (one_add_del_map_request_command) = { |
| 1438 | .path = "one map-request itr-rlocs", |
| 1439 | .short_help = "one map-request itr-rlocs add/del <locator_set_name>", |
| 1440 | .function = lisp_add_del_mreq_itr_rlocs_command_fn, |
| 1441 | }; |
| 1442 | /* *INDENT-ON* */ |
| 1443 | |
| 1444 | static clib_error_t * |
| 1445 | lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm, |
| 1446 | unformat_input_t * input, |
| 1447 | vlib_cli_command_t * cmd) |
| 1448 | { |
| 1449 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1450 | locator_set_t *loc_set; |
| 1451 | |
| 1452 | vlib_cli_output (vm, "%=20s", "itr-rlocs"); |
| 1453 | |
| 1454 | if (~0 == lcm->mreq_itr_rlocs) |
| 1455 | { |
| 1456 | return 0; |
| 1457 | } |
| 1458 | |
| 1459 | loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); |
| 1460 | |
| 1461 | vlib_cli_output (vm, "%=20s", loc_set->name); |
| 1462 | |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
| 1466 | /* *INDENT-OFF* */ |
| 1467 | VLIB_CLI_COMMAND (one_show_map_request_command) = { |
| 1468 | .path = "show one map-request itr-rlocs", |
| 1469 | .short_help = "Shows map-request itr-rlocs", |
| 1470 | .function = lisp_show_mreq_itr_rlocs_command_fn, |
| 1471 | }; |
| 1472 | /* *INDENT-ON* */ |
| 1473 | |
| 1474 | static clib_error_t * |
| 1475 | lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm, |
| 1476 | unformat_input_t * input, |
| 1477 | vlib_cli_command_t * cmd) |
| 1478 | { |
| 1479 | u8 is_add = 1, ip_set = 0; |
| 1480 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1481 | clib_error_t *error = 0; |
| 1482 | ip_address_t ip; |
| 1483 | |
| 1484 | /* Get a line of input. */ |
| 1485 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1486 | return 0; |
| 1487 | |
| 1488 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1489 | { |
| 1490 | if (unformat (line_input, "%U", unformat_ip_address, &ip)) |
| 1491 | ip_set = 1; |
| 1492 | else if (unformat (line_input, "disable")) |
| 1493 | is_add = 0; |
| 1494 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1495 | { |
| 1496 | error = clib_error_return (0, "parse error"); |
| 1497 | goto done; |
| 1498 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | if (!ip_set) |
| 1502 | { |
| 1503 | clib_warning ("No petr IP specified!"); |
| 1504 | goto done; |
| 1505 | } |
| 1506 | |
| 1507 | if (vnet_lisp_use_petr (&ip, is_add)) |
| 1508 | { |
| 1509 | error = clib_error_return (0, "failed to %s petr!", |
| 1510 | is_add ? "add" : "delete"); |
| 1511 | } |
| 1512 | |
| 1513 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame^] | 1514 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1515 | return error; |
| 1516 | } |
| 1517 | |
| 1518 | /* *INDENT-OFF* */ |
| 1519 | VLIB_CLI_COMMAND (one_use_petr_set_locator_set_command) = { |
| 1520 | .path = "one use-petr", |
| 1521 | .short_help = "one use-petr [disable] <petr-ip>", |
| 1522 | .function = lisp_use_petr_set_locator_set_command_fn, |
| 1523 | }; |
| 1524 | |
| 1525 | static clib_error_t * |
| 1526 | lisp_show_petr_command_fn (vlib_main_t * vm, |
| 1527 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1528 | { |
| 1529 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1530 | mapping_t *m; |
| 1531 | locator_set_t *ls; |
| 1532 | locator_t *loc; |
| 1533 | u8 *tmp_str = 0; |
| 1534 | u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR; |
| 1535 | vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : ""); |
| 1536 | |
| 1537 | if (!use_petr) |
| 1538 | { |
| 1539 | vlib_cli_output (vm, "%=20s", "disable"); |
| 1540 | return 0; |
| 1541 | } |
| 1542 | |
| 1543 | if (~0 == lcm->petr_map_index) |
| 1544 | { |
| 1545 | tmp_str = format (0, "N/A"); |
| 1546 | } |
| 1547 | else |
| 1548 | { |
| 1549 | m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); |
| 1550 | if (~0 != m->locator_set_index) |
| 1551 | { |
| 1552 | ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index); |
| 1553 | loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); |
| 1554 | tmp_str = format (0, "%U", format_ip_address, &loc->address); |
| 1555 | } |
| 1556 | else |
| 1557 | { |
| 1558 | tmp_str = format (0, "N/A"); |
| 1559 | } |
| 1560 | } |
| 1561 | vec_add1 (tmp_str, 0); |
| 1562 | |
| 1563 | vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); |
| 1564 | |
| 1565 | vec_free (tmp_str); |
| 1566 | |
| 1567 | return 0; |
| 1568 | } |
| 1569 | |
| 1570 | /* *INDENT-OFF* */ |
| 1571 | VLIB_CLI_COMMAND (one_show_petr_command) = { |
| 1572 | .path = "show one petr", |
| 1573 | .short_help = "Show petr", |
| 1574 | .function = lisp_show_petr_command_fn, |
| 1575 | }; |
| 1576 | /* *INDENT-ON* */ |
| 1577 | |
| 1578 | static clib_error_t * |
| 1579 | lisp_show_map_servers_command_fn (vlib_main_t * vm, |
| 1580 | unformat_input_t * input, |
| 1581 | vlib_cli_command_t * cmd) |
| 1582 | { |
| 1583 | lisp_msmr_t *ms; |
| 1584 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1585 | |
| 1586 | vec_foreach (ms, lcm->map_servers) |
| 1587 | { |
| 1588 | vlib_cli_output (vm, "%U", format_ip_address, &ms->address); |
| 1589 | } |
| 1590 | return 0; |
| 1591 | } |
| 1592 | |
| 1593 | /* *INDENT-OFF* */ |
| 1594 | VLIB_CLI_COMMAND (one_show_map_servers_command) = { |
| 1595 | .path = "show one map-servers", |
| 1596 | .short_help = "show one map servers", |
| 1597 | .function = lisp_show_map_servers_command_fn, |
| 1598 | }; |
| 1599 | /* *INDENT-ON* */ |
| 1600 | |
| 1601 | static clib_error_t * |
| 1602 | lisp_show_map_register_state_command_fn (vlib_main_t * vm, |
| 1603 | unformat_input_t * input, |
| 1604 | vlib_cli_command_t * cmd) |
| 1605 | { |
| 1606 | u8 *msg = 0; |
| 1607 | u8 is_enabled = vnet_lisp_map_register_state_get (); |
| 1608 | |
| 1609 | msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); |
| 1610 | vlib_cli_output (vm, "%v", msg); |
| 1611 | vec_free (msg); |
| 1612 | return 0; |
| 1613 | } |
| 1614 | |
| 1615 | /* *INDENT-OFF* */ |
| 1616 | VLIB_CLI_COMMAND (one_show_map_register_state_command) = { |
| 1617 | .path = "show one map-register state", |
| 1618 | .short_help = "show one map-register state", |
| 1619 | .function = lisp_show_map_register_state_command_fn, |
| 1620 | }; |
| 1621 | /* *INDENT-ON* */ |
| 1622 | |
| 1623 | static clib_error_t * |
| 1624 | lisp_show_rloc_probe_state_command_fn (vlib_main_t * vm, |
| 1625 | unformat_input_t * input, |
| 1626 | vlib_cli_command_t * cmd) |
| 1627 | { |
| 1628 | u8 *msg = 0; |
| 1629 | u8 is_enabled = vnet_lisp_rloc_probe_state_get (); |
| 1630 | |
| 1631 | msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); |
| 1632 | vlib_cli_output (vm, "%v", msg); |
| 1633 | vec_free (msg); |
| 1634 | return 0; |
| 1635 | } |
| 1636 | |
| 1637 | /* *INDENT-OFF* */ |
| 1638 | VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = { |
| 1639 | .path = "show one rloc state", |
| 1640 | .short_help = "show one RLOC state", |
| 1641 | .function = lisp_show_rloc_probe_state_command_fn, |
| 1642 | }; |
| 1643 | /* *INDENT-ON* */ |
| 1644 | |
| 1645 | /* |
| 1646 | * fd.io coding-style-patch-verification: ON |
| 1647 | * |
| 1648 | * Local Variables: |
| 1649 | * eval: (c-set-style "gnu") |
| 1650 | * End: |
| 1651 | */ |