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 | |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 355 | if (!del_all && !eid_set) |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 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 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 375 | /* if it's a delete, clean forwarding */ |
| 376 | if (!is_add) |
| 377 | { |
| 378 | vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; |
| 379 | memset (a, 0, sizeof (a[0])); |
| 380 | gid_address_copy (&a->reid, &eid); |
| 381 | if (vnet_lisp_add_del_adjacency (a)) |
| 382 | { |
| 383 | clib_warning ("failed to delete adjacency!"); |
| 384 | goto done; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | /* add as static remote mapping, i.e., not authoritative and infinite |
| 389 | * ttl */ |
| 390 | rv = vnet_lisp_add_del_mapping (&eid, rlocs, action, 0, ~0, is_add, |
| 391 | 1 /* is_static */ , 0); |
| 392 | |
| 393 | if (rv) |
| 394 | clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete"); |
| 395 | |
| 396 | done: |
| 397 | vec_free (rlocs); |
| 398 | unformat_free (line_input); |
| 399 | return error; |
| 400 | } |
| 401 | |
| 402 | /* *INDENT-OFF* */ |
| 403 | VLIB_CLI_COMMAND (one_add_del_remote_mapping_command) = { |
| 404 | .path = "one remote-mapping", |
| 405 | .short_help = |
| 406 | "one remote-mapping add|del [del-all] vni <vni> " |
| 407 | "eid <est-eid> [action <no-action|natively-forward|" |
| 408 | "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> " |
| 409 | "[rloc <dst-locator> ... ]", |
| 410 | .function = lisp_add_del_remote_mapping_command_fn, |
| 411 | }; |
| 412 | /* *INDENT-ON* */ |
| 413 | |
| 414 | /** |
| 415 | * Handler for add/del adjacency CLI. |
| 416 | */ |
| 417 | static clib_error_t * |
| 418 | lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 419 | vlib_cli_command_t * cmd) |
| 420 | { |
| 421 | clib_error_t *error = 0; |
| 422 | unformat_input_t _line_input, *line_input = &_line_input; |
| 423 | vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; |
| 424 | u8 is_add = 1; |
| 425 | ip_prefix_t *reid_ippref, *leid_ippref; |
| 426 | gid_address_t leid, reid; |
| 427 | u8 *dmac = gid_address_mac (&reid); |
| 428 | u8 *smac = gid_address_mac (&leid); |
| 429 | u8 reid_set = 0, leid_set = 0; |
| 430 | u32 vni; |
| 431 | |
| 432 | /* Get a line of input. */ |
| 433 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 434 | return 0; |
| 435 | |
| 436 | memset (&reid, 0, sizeof (reid)); |
| 437 | memset (&leid, 0, sizeof (leid)); |
| 438 | |
| 439 | leid_ippref = &gid_address_ippref (&leid); |
| 440 | reid_ippref = &gid_address_ippref (&reid); |
| 441 | |
| 442 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 443 | { |
| 444 | if (unformat (line_input, "del")) |
| 445 | is_add = 0; |
| 446 | else if (unformat (line_input, "add")) |
| 447 | ; |
| 448 | else if (unformat (line_input, "reid %U", |
| 449 | unformat_ip_prefix, reid_ippref)) |
| 450 | { |
| 451 | gid_address_type (&reid) = GID_ADDR_IP_PREFIX; |
| 452 | reid_set = 1; |
| 453 | } |
| 454 | else if (unformat (line_input, "reid %U", unformat_mac_address, dmac)) |
| 455 | { |
| 456 | gid_address_type (&reid) = GID_ADDR_MAC; |
| 457 | reid_set = 1; |
| 458 | } |
| 459 | else if (unformat (line_input, "vni %u", &vni)) |
| 460 | { |
| 461 | gid_address_vni (&leid) = vni; |
| 462 | gid_address_vni (&reid) = vni; |
| 463 | } |
| 464 | else if (unformat (line_input, "leid %U", |
| 465 | unformat_ip_prefix, leid_ippref)) |
| 466 | { |
| 467 | gid_address_type (&leid) = GID_ADDR_IP_PREFIX; |
| 468 | leid_set = 1; |
| 469 | } |
| 470 | else if (unformat (line_input, "leid %U", unformat_mac_address, smac)) |
| 471 | { |
| 472 | gid_address_type (&leid) = GID_ADDR_MAC; |
| 473 | leid_set = 1; |
| 474 | } |
| 475 | else |
| 476 | { |
| 477 | clib_warning ("parse error"); |
| 478 | goto done; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | if (!reid_set || !leid_set) |
| 483 | { |
| 484 | clib_warning ("missing remote or local eid!"); |
| 485 | goto done; |
| 486 | } |
| 487 | |
| 488 | if ((gid_address_type (&leid) != gid_address_type (&reid)) |
| 489 | || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX |
| 490 | && ip_prefix_version (reid_ippref) |
| 491 | != ip_prefix_version (leid_ippref))) |
| 492 | { |
| 493 | clib_warning ("remote and local EIDs are of different types!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 494 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | memset (a, 0, sizeof (a[0])); |
| 498 | gid_address_copy (&a->leid, &leid); |
| 499 | gid_address_copy (&a->reid, &reid); |
| 500 | a->is_add = is_add; |
| 501 | |
| 502 | if (vnet_lisp_add_del_adjacency (a)) |
| 503 | clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete"); |
| 504 | |
| 505 | done: |
| 506 | unformat_free (line_input); |
| 507 | return error; |
| 508 | } |
| 509 | |
| 510 | /* *INDENT-OFF* */ |
| 511 | VLIB_CLI_COMMAND (one_add_del_adjacency_command) = { |
| 512 | .path = "one adjacency", |
| 513 | .short_help = "one adjacency add|del vni <vni> reid <remote-eid> " |
| 514 | "leid <local-eid>", |
| 515 | .function = lisp_add_del_adjacency_command_fn, |
| 516 | }; |
| 517 | /* *INDENT-ON* */ |
| 518 | |
| 519 | |
| 520 | static clib_error_t * |
| 521 | lisp_map_request_mode_command_fn (vlib_main_t * vm, |
| 522 | unformat_input_t * input, |
| 523 | vlib_cli_command_t * cmd) |
| 524 | { |
| 525 | unformat_input_t _i, *i = &_i; |
| 526 | map_request_mode_t mr_mode = _MR_MODE_MAX; |
| 527 | |
| 528 | /* Get a line of input. */ |
| 529 | if (!unformat_user (input, unformat_line_input, i)) |
| 530 | return 0; |
| 531 | |
| 532 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 533 | { |
| 534 | if (unformat (i, "dst-only")) |
| 535 | mr_mode = MR_MODE_DST_ONLY; |
| 536 | else if (unformat (i, "src-dst")) |
| 537 | mr_mode = MR_MODE_SRC_DST; |
| 538 | else |
| 539 | { |
| 540 | clib_warning ("parse error '%U'", format_unformat_error, i); |
| 541 | goto done; |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | if (_MR_MODE_MAX == mr_mode) |
| 546 | { |
| 547 | clib_warning ("No map request mode entered!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 548 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | vnet_lisp_set_map_request_mode (mr_mode); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 552 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 553 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 554 | unformat_free (i); |
| 555 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | /* *INDENT-OFF* */ |
| 560 | VLIB_CLI_COMMAND (one_map_request_mode_command) = { |
| 561 | .path = "one map-request mode", |
| 562 | .short_help = "one map-request mode dst-only|src-dst", |
| 563 | .function = lisp_map_request_mode_command_fn, |
| 564 | }; |
| 565 | /* *INDENT-ON* */ |
| 566 | |
| 567 | |
| 568 | static u8 * |
| 569 | format_lisp_map_request_mode (u8 * s, va_list * args) |
| 570 | { |
| 571 | u32 mode = va_arg (*args, u32); |
| 572 | |
| 573 | switch (mode) |
| 574 | { |
| 575 | case 0: |
| 576 | return format (0, "dst-only"); |
| 577 | case 1: |
| 578 | return format (0, "src-dst"); |
| 579 | } |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | static clib_error_t * |
| 584 | lisp_show_map_request_mode_command_fn (vlib_main_t * vm, |
| 585 | unformat_input_t * input, |
| 586 | vlib_cli_command_t * cmd) |
| 587 | { |
| 588 | vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode, |
| 589 | vnet_lisp_get_map_request_mode ()); |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | /* *INDENT-OFF* */ |
| 594 | VLIB_CLI_COMMAND (one_show_map_request_mode_command) = { |
| 595 | .path = "show one map-request mode", |
| 596 | .short_help = "show one map-request mode", |
| 597 | .function = lisp_show_map_request_mode_command_fn, |
| 598 | }; |
| 599 | /* *INDENT-ON* */ |
| 600 | |
| 601 | static clib_error_t * |
| 602 | lisp_show_map_resolvers_command_fn (vlib_main_t * vm, |
| 603 | unformat_input_t * input, |
| 604 | vlib_cli_command_t * cmd) |
| 605 | { |
| 606 | lisp_msmr_t *mr; |
| 607 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 608 | |
| 609 | vec_foreach (mr, lcm->map_resolvers) |
| 610 | { |
| 611 | vlib_cli_output (vm, "%U", format_ip_address, &mr->address); |
| 612 | } |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | /* *INDENT-OFF* */ |
| 617 | VLIB_CLI_COMMAND (one_show_map_resolvers_command) = { |
| 618 | .path = "show one map-resolvers", |
| 619 | .short_help = "show one map-resolvers", |
| 620 | .function = lisp_show_map_resolvers_command_fn, |
| 621 | }; |
| 622 | /* *INDENT-ON* */ |
| 623 | |
| 624 | |
| 625 | static clib_error_t * |
| 626 | lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm, |
| 627 | unformat_input_t * input, |
| 628 | vlib_cli_command_t * cmd) |
| 629 | { |
| 630 | u8 locator_name_set = 0; |
| 631 | u8 *locator_set_name = 0; |
| 632 | u8 is_add = 1; |
| 633 | unformat_input_t _line_input, *line_input = &_line_input; |
| 634 | clib_error_t *error = 0; |
| 635 | int rv = 0; |
| 636 | |
| 637 | /* Get a line of input. */ |
| 638 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 639 | return 0; |
| 640 | |
| 641 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 642 | { |
| 643 | if (unformat (line_input, "ls %_%v%_", &locator_set_name)) |
| 644 | locator_name_set = 1; |
| 645 | else if (unformat (line_input, "disable")) |
| 646 | is_add = 0; |
| 647 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 648 | { |
| 649 | error = clib_error_return (0, "parse error"); |
| 650 | goto done; |
| 651 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | if (!locator_name_set) |
| 655 | { |
| 656 | clib_warning ("No locator set specified!"); |
| 657 | goto done; |
| 658 | } |
| 659 | rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add); |
| 660 | if (0 != rv) |
| 661 | { |
| 662 | error = clib_error_return (0, "failed to %s pitr!", |
| 663 | is_add ? "add" : "delete"); |
| 664 | } |
| 665 | |
| 666 | done: |
| 667 | if (locator_set_name) |
| 668 | vec_free (locator_set_name); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 669 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 670 | return error; |
| 671 | } |
| 672 | |
| 673 | /* *INDENT-OFF* */ |
| 674 | VLIB_CLI_COMMAND (one_pitr_set_locator_set_command) = { |
| 675 | .path = "one pitr", |
| 676 | .short_help = "one pitr [disable] ls <locator-set-name>", |
| 677 | .function = lisp_pitr_set_locator_set_command_fn, |
| 678 | }; |
| 679 | /* *INDENT-ON* */ |
| 680 | |
| 681 | static clib_error_t * |
| 682 | lisp_show_pitr_command_fn (vlib_main_t * vm, |
| 683 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 684 | { |
| 685 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 686 | mapping_t *m; |
| 687 | locator_set_t *ls; |
| 688 | u8 *tmp_str = 0; |
| 689 | |
| 690 | vlib_cli_output (vm, "%=20s%=16s", |
| 691 | "pitr", lcm->lisp_pitr ? "locator-set" : ""); |
| 692 | |
| 693 | if (!lcm->lisp_pitr) |
| 694 | { |
| 695 | vlib_cli_output (vm, "%=20s", "disable"); |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | if (~0 == lcm->pitr_map_index) |
| 700 | { |
| 701 | tmp_str = format (0, "N/A"); |
| 702 | } |
| 703 | else |
| 704 | { |
| 705 | m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); |
| 706 | if (~0 != m->locator_set_index) |
| 707 | { |
| 708 | ls = |
| 709 | pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); |
| 710 | tmp_str = format (0, "%s", ls->name); |
| 711 | } |
| 712 | else |
| 713 | { |
| 714 | tmp_str = format (0, "N/A"); |
| 715 | } |
| 716 | } |
| 717 | vec_add1 (tmp_str, 0); |
| 718 | |
| 719 | vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); |
| 720 | |
| 721 | vec_free (tmp_str); |
| 722 | |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | /* *INDENT-OFF* */ |
| 727 | VLIB_CLI_COMMAND (one_show_pitr_command) = { |
| 728 | .path = "show one pitr", |
| 729 | .short_help = "Show pitr", |
| 730 | .function = lisp_show_pitr_command_fn, |
| 731 | }; |
| 732 | /* *INDENT-ON* */ |
| 733 | |
| 734 | static u8 * |
| 735 | format_eid_entry (u8 * s, va_list * args) |
| 736 | { |
| 737 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 738 | lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *); |
| 739 | mapping_t *mapit = va_arg (*args, mapping_t *); |
| 740 | locator_set_t *ls = va_arg (*args, locator_set_t *); |
| 741 | gid_address_t *gid = &mapit->eid; |
| 742 | u32 ttl = mapit->ttl; |
| 743 | u8 aut = mapit->authoritative; |
| 744 | u32 *loc_index; |
| 745 | u8 first_line = 1; |
| 746 | u8 *loc; |
| 747 | |
| 748 | u8 *type = ls->local ? format (0, "local(%s)", ls->name) |
| 749 | : format (0, "remote"); |
| 750 | |
| 751 | if (vec_len (ls->locator_indices) == 0) |
| 752 | { |
Filip Tehlar | d89b604 | 2017-04-11 14:00:58 +0200 | [diff] [blame] | 753 | s = format (s, "%-35U%-20saction:%-30U%-20u%-u", format_gid_address, |
| 754 | gid, type, format_negative_mapping_action, mapit->action, |
| 755 | ttl, aut); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 756 | } |
| 757 | else |
| 758 | { |
| 759 | vec_foreach (loc_index, ls->locator_indices) |
| 760 | { |
| 761 | locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]); |
| 762 | if (l->local) |
| 763 | loc = format (0, "%U", format_vnet_sw_if_index_name, vnm, |
| 764 | l->sw_if_index); |
| 765 | else |
| 766 | loc = format (0, "%U", format_ip_address, |
| 767 | &gid_address_ip (&l->address)); |
| 768 | |
| 769 | if (first_line) |
| 770 | { |
| 771 | s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address, |
| 772 | gid, type, loc, ttl, aut); |
| 773 | first_line = 0; |
| 774 | } |
| 775 | else |
| 776 | s = format (s, "%55s%v\n", "", loc); |
| 777 | } |
| 778 | } |
| 779 | return s; |
| 780 | } |
| 781 | |
| 782 | static clib_error_t * |
| 783 | lisp_show_eid_table_command_fn (vlib_main_t * vm, |
| 784 | unformat_input_t * input, |
| 785 | vlib_cli_command_t * cmd) |
| 786 | { |
| 787 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 788 | mapping_t *mapit; |
| 789 | unformat_input_t _line_input, *line_input = &_line_input; |
| 790 | u32 mi; |
| 791 | gid_address_t eid; |
| 792 | u8 print_all = 1; |
| 793 | u8 filter = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 794 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 795 | |
| 796 | memset (&eid, 0, sizeof (eid)); |
| 797 | |
| 798 | /* Get a line of input. */ |
| 799 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 800 | return 0; |
| 801 | |
| 802 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 803 | { |
| 804 | if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) |
| 805 | print_all = 0; |
| 806 | else if (unformat (line_input, "local")) |
| 807 | filter = 1; |
| 808 | else if (unformat (line_input, "remote")) |
| 809 | filter = 2; |
| 810 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 811 | { |
| 812 | error = clib_error_return (0, "parse error: '%U'", |
| 813 | format_unformat_error, line_input); |
| 814 | goto done; |
| 815 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s", |
| 819 | "EID", "type", "locators", "ttl", "autoritative"); |
| 820 | |
| 821 | if (print_all) |
| 822 | { |
| 823 | /* *INDENT-OFF* */ |
| 824 | pool_foreach (mapit, lcm->mapping_pool, |
| 825 | ({ |
Filip Tehlar | 1e8d01f | 2017-03-30 15:17:01 +0200 | [diff] [blame] | 826 | if (mapit->pitr_set) |
| 827 | continue; |
| 828 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 829 | locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool, |
| 830 | mapit->locator_set_index); |
| 831 | if (filter && !((1 == filter && ls->local) || |
| 832 | (2 == filter && !ls->local))) |
| 833 | { |
| 834 | continue; |
| 835 | } |
| 836 | vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main, |
| 837 | lcm, mapit, ls); |
| 838 | })); |
| 839 | /* *INDENT-ON* */ |
| 840 | } |
| 841 | else |
| 842 | { |
| 843 | mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid); |
| 844 | if ((u32) ~ 0 == mi) |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 845 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 846 | |
| 847 | mapit = pool_elt_at_index (lcm->mapping_pool, mi); |
| 848 | locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, |
| 849 | mapit->locator_set_index); |
| 850 | |
| 851 | if (filter && !((1 == filter && ls->local) || |
| 852 | (2 == filter && !ls->local))) |
| 853 | { |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 854 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main, |
| 858 | lcm, mapit, ls); |
| 859 | } |
| 860 | |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 861 | done: |
| 862 | unformat_free (line_input); |
| 863 | |
| 864 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | /* *INDENT-OFF* */ |
| 868 | VLIB_CLI_COMMAND (one_cp_show_eid_table_command) = { |
| 869 | .path = "show one eid-table", |
| 870 | .short_help = "Shows EID table", |
| 871 | .function = lisp_show_eid_table_command_fn, |
| 872 | }; |
| 873 | /* *INDENT-ON* */ |
| 874 | |
| 875 | |
| 876 | static clib_error_t * |
| 877 | lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 878 | vlib_cli_command_t * cmd) |
| 879 | { |
| 880 | unformat_input_t _line_input, *line_input = &_line_input; |
| 881 | u8 is_enabled = 0; |
| 882 | u8 is_set = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 883 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 884 | |
| 885 | /* Get a line of input. */ |
| 886 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 887 | return 0; |
| 888 | |
| 889 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 890 | { |
| 891 | if (unformat (line_input, "enable")) |
| 892 | { |
| 893 | is_set = 1; |
| 894 | is_enabled = 1; |
| 895 | } |
| 896 | else if (unformat (line_input, "disable")) |
| 897 | is_set = 1; |
| 898 | else |
| 899 | { |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 900 | error = clib_error_return (0, "parse error: '%U'", |
| 901 | format_unformat_error, line_input); |
| 902 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | |
| 906 | if (!is_set) |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 907 | { |
| 908 | error = clib_error_return (0, "state not set"); |
| 909 | goto done; |
| 910 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 911 | |
| 912 | vnet_lisp_enable_disable (is_enabled); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 913 | |
| 914 | done: |
| 915 | unformat_free (line_input); |
| 916 | |
| 917 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | /* *INDENT-OFF* */ |
| 921 | VLIB_CLI_COMMAND (one_cp_enable_disable_command) = { |
| 922 | .path = "one", |
| 923 | .short_help = "one [enable|disable]", |
| 924 | .function = lisp_enable_disable_command_fn, |
| 925 | }; |
| 926 | /* *INDENT-ON* */ |
| 927 | |
| 928 | static clib_error_t * |
| 929 | lisp_map_register_enable_disable_command_fn (vlib_main_t * vm, |
| 930 | unformat_input_t * input, |
| 931 | vlib_cli_command_t * cmd) |
| 932 | { |
| 933 | unformat_input_t _line_input, *line_input = &_line_input; |
| 934 | u8 is_enabled = 0; |
| 935 | u8 is_set = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 936 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 937 | |
| 938 | /* Get a line of input. */ |
| 939 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 940 | return 0; |
| 941 | |
| 942 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 943 | { |
| 944 | if (unformat (line_input, "enable")) |
| 945 | { |
| 946 | is_set = 1; |
| 947 | is_enabled = 1; |
| 948 | } |
| 949 | else if (unformat (line_input, "disable")) |
| 950 | is_set = 1; |
| 951 | else |
| 952 | { |
| 953 | vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, |
| 954 | line_input); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 955 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | |
| 959 | if (!is_set) |
| 960 | { |
| 961 | vlib_cli_output (vm, "state not set!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 962 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | vnet_lisp_map_register_enable_disable (is_enabled); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 966 | |
| 967 | done: |
| 968 | unformat_free (line_input); |
| 969 | |
| 970 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | /* *INDENT-OFF* */ |
| 974 | VLIB_CLI_COMMAND (one_map_register_enable_disable_command) = { |
| 975 | .path = "one map-register", |
| 976 | .short_help = "one map-register [enable|disable]", |
| 977 | .function = lisp_map_register_enable_disable_command_fn, |
| 978 | }; |
| 979 | /* *INDENT-ON* */ |
| 980 | |
| 981 | static clib_error_t * |
| 982 | lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm, |
| 983 | unformat_input_t * input, |
| 984 | vlib_cli_command_t * cmd) |
| 985 | { |
| 986 | unformat_input_t _line_input, *line_input = &_line_input; |
| 987 | u8 is_enabled = 0; |
| 988 | u8 is_set = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 989 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 990 | |
| 991 | /* Get a line of input. */ |
| 992 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 993 | return 0; |
| 994 | |
| 995 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 996 | { |
| 997 | if (unformat (line_input, "enable")) |
| 998 | { |
| 999 | is_set = 1; |
| 1000 | is_enabled = 1; |
| 1001 | } |
| 1002 | else if (unformat (line_input, "disable")) |
| 1003 | is_set = 1; |
| 1004 | else |
| 1005 | { |
| 1006 | vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, |
| 1007 | line_input); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1008 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | if (!is_set) |
| 1013 | { |
| 1014 | vlib_cli_output (vm, "state not set!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1015 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | vnet_lisp_rloc_probe_enable_disable (is_enabled); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1019 | |
| 1020 | done: |
| 1021 | unformat_free (line_input); |
| 1022 | |
| 1023 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | /* *INDENT-OFF* */ |
| 1027 | VLIB_CLI_COMMAND (one_rloc_probe_enable_disable_command) = { |
| 1028 | .path = "one rloc-probe", |
| 1029 | .short_help = "one rloc-probe [enable|disable]", |
| 1030 | .function = lisp_rloc_probe_enable_disable_command_fn, |
| 1031 | }; |
| 1032 | /* *INDENT-ON* */ |
| 1033 | |
| 1034 | static u8 * |
| 1035 | format_lisp_status (u8 * s, va_list * args) |
| 1036 | { |
| 1037 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1038 | return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled"); |
| 1039 | } |
| 1040 | |
| 1041 | static clib_error_t * |
| 1042 | lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1043 | vlib_cli_command_t * cmd) |
| 1044 | { |
| 1045 | u8 *msg = 0; |
| 1046 | msg = format (msg, "feature: %U\ngpe: %U\n", |
| 1047 | format_lisp_status, format_vnet_lisp_gpe_status); |
| 1048 | vlib_cli_output (vm, "%v", msg); |
| 1049 | vec_free (msg); |
| 1050 | return 0; |
| 1051 | } |
| 1052 | |
| 1053 | /* *INDENT-OFF* */ |
| 1054 | VLIB_CLI_COMMAND (one_show_status_command) = { |
| 1055 | .path = "show one status", |
| 1056 | .short_help = "show one status", |
| 1057 | .function = lisp_show_status_command_fn, |
| 1058 | }; |
| 1059 | /* *INDENT-ON* */ |
| 1060 | |
| 1061 | static clib_error_t * |
| 1062 | lisp_show_eid_table_map_command_fn (vlib_main_t * vm, |
| 1063 | unformat_input_t * input, |
| 1064 | vlib_cli_command_t * cmd) |
| 1065 | { |
| 1066 | hash_pair_t *p; |
| 1067 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1068 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1069 | uword *vni_table = 0; |
| 1070 | u8 is_l2 = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1071 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1072 | |
| 1073 | /* Get a line of input. */ |
| 1074 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1075 | return 0; |
| 1076 | |
| 1077 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1078 | { |
| 1079 | if (unformat (line_input, "l2")) |
| 1080 | { |
| 1081 | vni_table = lcm->bd_id_by_vni; |
| 1082 | is_l2 = 1; |
| 1083 | } |
| 1084 | else if (unformat (line_input, "l3")) |
| 1085 | { |
| 1086 | vni_table = lcm->table_id_by_vni; |
| 1087 | is_l2 = 0; |
| 1088 | } |
| 1089 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1090 | { |
| 1091 | error = clib_error_return (0, "parse error: '%U'", |
| 1092 | format_unformat_error, line_input); |
| 1093 | goto done; |
| 1094 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | if (!vni_table) |
| 1098 | { |
| 1099 | vlib_cli_output (vm, "Error: expected l2|l3 param!\n"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1100 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); |
| 1104 | |
| 1105 | /* *INDENT-OFF* */ |
| 1106 | hash_foreach_pair (p, vni_table, |
| 1107 | ({ |
| 1108 | vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); |
| 1109 | })); |
| 1110 | /* *INDENT-ON* */ |
| 1111 | |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1112 | done: |
| 1113 | unformat_free (line_input); |
| 1114 | |
| 1115 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | /* *INDENT-OFF* */ |
| 1119 | VLIB_CLI_COMMAND (one_show_eid_table_map_command) = { |
| 1120 | .path = "show one eid-table map", |
| 1121 | .short_help = "show one eid-table l2|l3", |
| 1122 | .function = lisp_show_eid_table_map_command_fn, |
| 1123 | }; |
| 1124 | /* *INDENT-ON* */ |
| 1125 | |
| 1126 | |
| 1127 | static clib_error_t * |
| 1128 | lisp_add_del_locator_set_command_fn (vlib_main_t * vm, |
| 1129 | unformat_input_t * input, |
| 1130 | vlib_cli_command_t * cmd) |
| 1131 | { |
| 1132 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
| 1133 | vnet_main_t *vnm = lgm->vnet_main; |
| 1134 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1135 | u8 is_add = 1; |
| 1136 | clib_error_t *error = 0; |
| 1137 | u8 *locator_set_name = 0; |
| 1138 | locator_t locator, *locators = 0; |
| 1139 | vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; |
| 1140 | u32 ls_index = 0; |
| 1141 | int rv = 0; |
| 1142 | |
| 1143 | memset (&locator, 0, sizeof (locator)); |
| 1144 | memset (a, 0, sizeof (a[0])); |
| 1145 | |
| 1146 | /* Get a line of input. */ |
| 1147 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1148 | return 0; |
| 1149 | |
| 1150 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1151 | { |
| 1152 | if (unformat (line_input, "add %_%v%_", &locator_set_name)) |
| 1153 | is_add = 1; |
| 1154 | else if (unformat (line_input, "del %_%v%_", &locator_set_name)) |
| 1155 | is_add = 0; |
| 1156 | else if (unformat (line_input, "iface %U p %d w %d", |
| 1157 | unformat_vnet_sw_interface, vnm, |
| 1158 | &locator.sw_if_index, &locator.priority, |
| 1159 | &locator.weight)) |
| 1160 | { |
| 1161 | locator.local = 1; |
| 1162 | vec_add1 (locators, locator); |
| 1163 | } |
| 1164 | else |
| 1165 | { |
| 1166 | error = unformat_parse_error (line_input); |
| 1167 | goto done; |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | a->name = locator_set_name; |
| 1172 | a->locators = locators; |
| 1173 | a->is_add = is_add; |
| 1174 | a->local = 1; |
| 1175 | |
| 1176 | rv = vnet_lisp_add_del_locator_set (a, &ls_index); |
| 1177 | if (0 != rv) |
| 1178 | { |
| 1179 | error = clib_error_return (0, "failed to %s locator-set!", |
| 1180 | is_add ? "add" : "delete"); |
| 1181 | } |
| 1182 | |
| 1183 | done: |
| 1184 | vec_free (locators); |
| 1185 | if (locator_set_name) |
| 1186 | vec_free (locator_set_name); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1187 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1188 | return error; |
| 1189 | } |
| 1190 | |
| 1191 | /* *INDENT-OFF* */ |
| 1192 | VLIB_CLI_COMMAND (one_cp_add_del_locator_set_command) = { |
| 1193 | .path = "one locator-set", |
| 1194 | .short_help = "one locator-set add/del <name> [iface <iface-name> " |
| 1195 | "p <priority> w <weight>]", |
| 1196 | .function = lisp_add_del_locator_set_command_fn, |
| 1197 | }; |
| 1198 | /* *INDENT-ON* */ |
| 1199 | |
| 1200 | static clib_error_t * |
| 1201 | lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm, |
| 1202 | unformat_input_t * input, |
| 1203 | vlib_cli_command_t * cmd) |
| 1204 | { |
| 1205 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
| 1206 | vnet_main_t *vnm = lgm->vnet_main; |
| 1207 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1208 | u8 is_add = 1; |
| 1209 | clib_error_t *error = 0; |
| 1210 | u8 *locator_set_name = 0; |
| 1211 | u8 locator_set_name_set = 0; |
| 1212 | locator_t locator, *locators = 0; |
| 1213 | vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; |
| 1214 | u32 ls_index = 0; |
| 1215 | |
| 1216 | memset (&locator, 0, sizeof (locator)); |
| 1217 | memset (a, 0, sizeof (a[0])); |
| 1218 | |
| 1219 | /* Get a line of input. */ |
| 1220 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1221 | return 0; |
| 1222 | |
| 1223 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1224 | { |
| 1225 | if (unformat (line_input, "add")) |
| 1226 | is_add = 1; |
| 1227 | else if (unformat (line_input, "del")) |
| 1228 | is_add = 0; |
| 1229 | else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) |
| 1230 | locator_set_name_set = 1; |
| 1231 | else if (unformat (line_input, "iface %U p %d w %d", |
| 1232 | unformat_vnet_sw_interface, vnm, |
| 1233 | &locator.sw_if_index, &locator.priority, |
| 1234 | &locator.weight)) |
| 1235 | { |
| 1236 | locator.local = 1; |
| 1237 | vec_add1 (locators, locator); |
| 1238 | } |
| 1239 | else |
| 1240 | { |
| 1241 | error = unformat_parse_error (line_input); |
| 1242 | goto done; |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | if (!locator_set_name_set) |
| 1247 | { |
| 1248 | error = clib_error_return (0, "locator_set name not set!"); |
| 1249 | goto done; |
| 1250 | } |
| 1251 | |
| 1252 | a->name = locator_set_name; |
| 1253 | a->locators = locators; |
| 1254 | a->is_add = is_add; |
| 1255 | a->local = 1; |
| 1256 | |
| 1257 | vnet_lisp_add_del_locator (a, 0, &ls_index); |
| 1258 | |
| 1259 | done: |
| 1260 | vec_free (locators); |
| 1261 | vec_free (locator_set_name); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1262 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1263 | return error; |
| 1264 | } |
| 1265 | |
| 1266 | /* *INDENT-OFF* */ |
| 1267 | VLIB_CLI_COMMAND (one_cp_add_del_locator_in_set_command) = { |
| 1268 | .path = "one locator", |
| 1269 | .short_help = "one locator add/del locator-set <name> iface <iface-name> " |
| 1270 | "p <priority> w <weight>", |
| 1271 | .function = lisp_add_del_locator_in_set_command_fn, |
| 1272 | }; |
| 1273 | /* *INDENT-ON* */ |
| 1274 | |
| 1275 | static clib_error_t * |
| 1276 | lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm, |
| 1277 | unformat_input_t * input, |
| 1278 | vlib_cli_command_t * cmd) |
| 1279 | { |
| 1280 | locator_set_t *lsit; |
| 1281 | locator_t *loc; |
| 1282 | u32 *locit; |
| 1283 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1284 | |
| 1285 | vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator", |
| 1286 | "Priority", "Weight"); |
| 1287 | |
| 1288 | /* *INDENT-OFF* */ |
| 1289 | pool_foreach (lsit, lcm->locator_set_pool, |
| 1290 | ({ |
| 1291 | u8 * msg = 0; |
| 1292 | int next_line = 0; |
| 1293 | if (lsit->local) |
| 1294 | { |
| 1295 | msg = format (msg, "%v", lsit->name); |
| 1296 | } |
| 1297 | else |
| 1298 | { |
| 1299 | msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool); |
| 1300 | } |
| 1301 | vec_foreach (locit, lsit->locator_indices) |
| 1302 | { |
| 1303 | if (next_line) |
| 1304 | { |
| 1305 | msg = format (msg, "%16s", " "); |
| 1306 | } |
| 1307 | loc = pool_elt_at_index (lcm->locator_pool, locit[0]); |
| 1308 | if (loc->local) |
| 1309 | msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority, |
| 1310 | loc->weight); |
| 1311 | else |
| 1312 | msg = format (msg, "%16U%16d%16d\n", format_ip_address, |
| 1313 | &gid_address_ip(&loc->address), loc->priority, |
| 1314 | loc->weight); |
| 1315 | next_line = 1; |
| 1316 | } |
| 1317 | vlib_cli_output (vm, "%v", msg); |
| 1318 | vec_free (msg); |
| 1319 | })); |
| 1320 | /* *INDENT-ON* */ |
| 1321 | return 0; |
| 1322 | } |
| 1323 | |
| 1324 | /* *INDENT-OFF* */ |
| 1325 | VLIB_CLI_COMMAND (one_cp_show_locator_sets_command) = { |
| 1326 | .path = "show one locator-set", |
| 1327 | .short_help = "Shows locator-sets", |
| 1328 | .function = lisp_cp_show_locator_sets_command_fn, |
| 1329 | }; |
| 1330 | /* *INDENT-ON* */ |
| 1331 | |
| 1332 | |
| 1333 | static clib_error_t * |
| 1334 | lisp_add_del_map_resolver_command_fn (vlib_main_t * vm, |
| 1335 | unformat_input_t * input, |
| 1336 | vlib_cli_command_t * cmd) |
| 1337 | { |
| 1338 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1339 | u8 is_add = 1, addr_set = 0; |
| 1340 | ip_address_t ip_addr; |
| 1341 | clib_error_t *error = 0; |
| 1342 | int rv = 0; |
| 1343 | vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; |
| 1344 | |
| 1345 | /* Get a line of input. */ |
| 1346 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1347 | return 0; |
| 1348 | |
| 1349 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1350 | { |
| 1351 | if (unformat (line_input, "add")) |
| 1352 | is_add = 1; |
| 1353 | else if (unformat (line_input, "del")) |
| 1354 | is_add = 0; |
| 1355 | else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr)) |
| 1356 | addr_set = 1; |
| 1357 | else |
| 1358 | { |
| 1359 | error = unformat_parse_error (line_input); |
| 1360 | goto done; |
| 1361 | } |
| 1362 | } |
| 1363 | |
| 1364 | if (!addr_set) |
| 1365 | { |
| 1366 | error = clib_error_return (0, "Map-resolver address must be set!"); |
| 1367 | goto done; |
| 1368 | } |
| 1369 | |
| 1370 | a->is_add = is_add; |
| 1371 | a->address = ip_addr; |
| 1372 | rv = vnet_lisp_add_del_map_resolver (a); |
| 1373 | if (0 != rv) |
| 1374 | { |
| 1375 | error = clib_error_return (0, "failed to %s map-resolver!", |
| 1376 | is_add ? "add" : "delete"); |
| 1377 | } |
| 1378 | |
| 1379 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1380 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1381 | return error; |
| 1382 | } |
| 1383 | |
| 1384 | /* *INDENT-OFF* */ |
| 1385 | VLIB_CLI_COMMAND (one_add_del_map_resolver_command) = { |
| 1386 | .path = "one map-resolver", |
| 1387 | .short_help = "one map-resolver add/del <ip_address>", |
| 1388 | .function = lisp_add_del_map_resolver_command_fn, |
| 1389 | }; |
| 1390 | /* *INDENT-ON* */ |
| 1391 | |
| 1392 | |
| 1393 | static clib_error_t * |
| 1394 | lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm, |
| 1395 | unformat_input_t * input, |
| 1396 | vlib_cli_command_t * cmd) |
| 1397 | { |
| 1398 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1399 | u8 is_add = 1; |
| 1400 | u8 *locator_set_name = 0; |
| 1401 | clib_error_t *error = 0; |
| 1402 | int rv = 0; |
| 1403 | vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; |
| 1404 | |
| 1405 | /* Get a line of input. */ |
| 1406 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1407 | return 0; |
| 1408 | |
| 1409 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1410 | { |
| 1411 | if (unformat (line_input, "del")) |
| 1412 | is_add = 0; |
| 1413 | else if (unformat (line_input, "add %_%v%_", &locator_set_name)) |
| 1414 | is_add = 1; |
| 1415 | else |
| 1416 | { |
| 1417 | error = unformat_parse_error (line_input); |
| 1418 | goto done; |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | a->is_add = is_add; |
| 1423 | a->locator_set_name = locator_set_name; |
| 1424 | rv = vnet_lisp_add_del_mreq_itr_rlocs (a); |
| 1425 | if (0 != rv) |
| 1426 | { |
| 1427 | error = clib_error_return (0, "failed to %s map-request itr-rlocs!", |
| 1428 | is_add ? "add" : "delete"); |
| 1429 | } |
| 1430 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1431 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1432 | vec_free (locator_set_name); |
| 1433 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1434 | return error; |
| 1435 | |
| 1436 | } |
| 1437 | |
| 1438 | /* *INDENT-OFF* */ |
| 1439 | VLIB_CLI_COMMAND (one_add_del_map_request_command) = { |
| 1440 | .path = "one map-request itr-rlocs", |
| 1441 | .short_help = "one map-request itr-rlocs add/del <locator_set_name>", |
| 1442 | .function = lisp_add_del_mreq_itr_rlocs_command_fn, |
| 1443 | }; |
| 1444 | /* *INDENT-ON* */ |
| 1445 | |
| 1446 | static clib_error_t * |
| 1447 | lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm, |
| 1448 | unformat_input_t * input, |
| 1449 | vlib_cli_command_t * cmd) |
| 1450 | { |
| 1451 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1452 | locator_set_t *loc_set; |
| 1453 | |
| 1454 | vlib_cli_output (vm, "%=20s", "itr-rlocs"); |
| 1455 | |
| 1456 | if (~0 == lcm->mreq_itr_rlocs) |
| 1457 | { |
| 1458 | return 0; |
| 1459 | } |
| 1460 | |
| 1461 | loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); |
| 1462 | |
| 1463 | vlib_cli_output (vm, "%=20s", loc_set->name); |
| 1464 | |
| 1465 | return 0; |
| 1466 | } |
| 1467 | |
| 1468 | /* *INDENT-OFF* */ |
| 1469 | VLIB_CLI_COMMAND (one_show_map_request_command) = { |
| 1470 | .path = "show one map-request itr-rlocs", |
| 1471 | .short_help = "Shows map-request itr-rlocs", |
| 1472 | .function = lisp_show_mreq_itr_rlocs_command_fn, |
| 1473 | }; |
| 1474 | /* *INDENT-ON* */ |
| 1475 | |
| 1476 | static clib_error_t * |
| 1477 | lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm, |
| 1478 | unformat_input_t * input, |
| 1479 | vlib_cli_command_t * cmd) |
| 1480 | { |
| 1481 | u8 is_add = 1, ip_set = 0; |
| 1482 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1483 | clib_error_t *error = 0; |
| 1484 | ip_address_t ip; |
| 1485 | |
| 1486 | /* Get a line of input. */ |
| 1487 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1488 | return 0; |
| 1489 | |
| 1490 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1491 | { |
| 1492 | if (unformat (line_input, "%U", unformat_ip_address, &ip)) |
| 1493 | ip_set = 1; |
| 1494 | else if (unformat (line_input, "disable")) |
| 1495 | is_add = 0; |
| 1496 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1497 | { |
| 1498 | error = clib_error_return (0, "parse error"); |
| 1499 | goto done; |
| 1500 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | if (!ip_set) |
| 1504 | { |
| 1505 | clib_warning ("No petr IP specified!"); |
| 1506 | goto done; |
| 1507 | } |
| 1508 | |
| 1509 | if (vnet_lisp_use_petr (&ip, is_add)) |
| 1510 | { |
| 1511 | error = clib_error_return (0, "failed to %s petr!", |
| 1512 | is_add ? "add" : "delete"); |
| 1513 | } |
| 1514 | |
| 1515 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1516 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1517 | return error; |
| 1518 | } |
| 1519 | |
| 1520 | /* *INDENT-OFF* */ |
| 1521 | VLIB_CLI_COMMAND (one_use_petr_set_locator_set_command) = { |
| 1522 | .path = "one use-petr", |
| 1523 | .short_help = "one use-petr [disable] <petr-ip>", |
| 1524 | .function = lisp_use_petr_set_locator_set_command_fn, |
| 1525 | }; |
| 1526 | |
| 1527 | static clib_error_t * |
| 1528 | lisp_show_petr_command_fn (vlib_main_t * vm, |
| 1529 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1530 | { |
| 1531 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1532 | mapping_t *m; |
| 1533 | locator_set_t *ls; |
| 1534 | locator_t *loc; |
| 1535 | u8 *tmp_str = 0; |
| 1536 | u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR; |
| 1537 | vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : ""); |
| 1538 | |
| 1539 | if (!use_petr) |
| 1540 | { |
| 1541 | vlib_cli_output (vm, "%=20s", "disable"); |
| 1542 | return 0; |
| 1543 | } |
| 1544 | |
| 1545 | if (~0 == lcm->petr_map_index) |
| 1546 | { |
| 1547 | tmp_str = format (0, "N/A"); |
| 1548 | } |
| 1549 | else |
| 1550 | { |
| 1551 | m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); |
| 1552 | if (~0 != m->locator_set_index) |
| 1553 | { |
| 1554 | ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index); |
| 1555 | loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); |
| 1556 | tmp_str = format (0, "%U", format_ip_address, &loc->address); |
| 1557 | } |
| 1558 | else |
| 1559 | { |
| 1560 | tmp_str = format (0, "N/A"); |
| 1561 | } |
| 1562 | } |
| 1563 | vec_add1 (tmp_str, 0); |
| 1564 | |
| 1565 | vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); |
| 1566 | |
| 1567 | vec_free (tmp_str); |
| 1568 | |
| 1569 | return 0; |
| 1570 | } |
| 1571 | |
| 1572 | /* *INDENT-OFF* */ |
| 1573 | VLIB_CLI_COMMAND (one_show_petr_command) = { |
| 1574 | .path = "show one petr", |
| 1575 | .short_help = "Show petr", |
| 1576 | .function = lisp_show_petr_command_fn, |
| 1577 | }; |
| 1578 | /* *INDENT-ON* */ |
| 1579 | |
| 1580 | static clib_error_t * |
| 1581 | lisp_show_map_servers_command_fn (vlib_main_t * vm, |
| 1582 | unformat_input_t * input, |
| 1583 | vlib_cli_command_t * cmd) |
| 1584 | { |
| 1585 | lisp_msmr_t *ms; |
| 1586 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1587 | |
| 1588 | vec_foreach (ms, lcm->map_servers) |
| 1589 | { |
| 1590 | vlib_cli_output (vm, "%U", format_ip_address, &ms->address); |
| 1591 | } |
| 1592 | return 0; |
| 1593 | } |
| 1594 | |
| 1595 | /* *INDENT-OFF* */ |
| 1596 | VLIB_CLI_COMMAND (one_show_map_servers_command) = { |
| 1597 | .path = "show one map-servers", |
| 1598 | .short_help = "show one map servers", |
| 1599 | .function = lisp_show_map_servers_command_fn, |
| 1600 | }; |
| 1601 | /* *INDENT-ON* */ |
| 1602 | |
| 1603 | static clib_error_t * |
| 1604 | lisp_show_map_register_state_command_fn (vlib_main_t * vm, |
| 1605 | unformat_input_t * input, |
| 1606 | vlib_cli_command_t * cmd) |
| 1607 | { |
| 1608 | u8 *msg = 0; |
| 1609 | u8 is_enabled = vnet_lisp_map_register_state_get (); |
| 1610 | |
| 1611 | msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); |
| 1612 | vlib_cli_output (vm, "%v", msg); |
| 1613 | vec_free (msg); |
| 1614 | return 0; |
| 1615 | } |
| 1616 | |
| 1617 | /* *INDENT-OFF* */ |
| 1618 | VLIB_CLI_COMMAND (one_show_map_register_state_command) = { |
| 1619 | .path = "show one map-register state", |
| 1620 | .short_help = "show one map-register state", |
| 1621 | .function = lisp_show_map_register_state_command_fn, |
| 1622 | }; |
| 1623 | /* *INDENT-ON* */ |
| 1624 | |
| 1625 | static clib_error_t * |
| 1626 | lisp_show_rloc_probe_state_command_fn (vlib_main_t * vm, |
| 1627 | unformat_input_t * input, |
| 1628 | vlib_cli_command_t * cmd) |
| 1629 | { |
| 1630 | u8 *msg = 0; |
| 1631 | u8 is_enabled = vnet_lisp_rloc_probe_state_get (); |
| 1632 | |
| 1633 | msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); |
| 1634 | vlib_cli_output (vm, "%v", msg); |
| 1635 | vec_free (msg); |
| 1636 | return 0; |
| 1637 | } |
| 1638 | |
| 1639 | /* *INDENT-OFF* */ |
| 1640 | VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = { |
| 1641 | .path = "show one rloc state", |
| 1642 | .short_help = "show one RLOC state", |
| 1643 | .function = lisp_show_rloc_probe_state_command_fn, |
| 1644 | }; |
| 1645 | /* *INDENT-ON* */ |
| 1646 | |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 1647 | static clib_error_t * |
| 1648 | lisp_show_stats_command_fn (vlib_main_t * vm, |
| 1649 | unformat_input_t * input, |
| 1650 | vlib_cli_command_t * cmd) |
| 1651 | { |
| 1652 | u8 is_enabled = vnet_lisp_stats_enable_disable_state (); |
| 1653 | vlib_cli_output (vm, "%s\n", is_enabled ? "enabled" : "disabled"); |
| 1654 | return 0; |
| 1655 | } |
| 1656 | |
| 1657 | /* *INDENT-OFF* */ |
| 1658 | VLIB_CLI_COMMAND (one_show_stats_command) = { |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 1659 | .path = "show one statistics status", |
| 1660 | .short_help = "show ONE statistics enable/disable status", |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 1661 | .function = lisp_show_stats_command_fn, |
| 1662 | }; |
| 1663 | /* *INDENT-ON* */ |
| 1664 | |
| 1665 | static clib_error_t * |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 1666 | lisp_show_stats_details_command_fn (vlib_main_t * vm, |
| 1667 | unformat_input_t * input, |
| 1668 | vlib_cli_command_t * cmd) |
| 1669 | { |
| 1670 | lisp_api_stats_t *stat, *stats = vnet_lisp_get_stats (); |
| 1671 | |
| 1672 | if (vec_len (stats) > 0) |
| 1673 | vlib_cli_output (vm, |
| 1674 | "[src-EID, dst-EID] [loc-rloc, rmt-rloc] count bytes\n"); |
| 1675 | else |
| 1676 | vlib_cli_output (vm, "No statistics found.\n"); |
| 1677 | |
| 1678 | vec_foreach (stat, stats) |
| 1679 | { |
| 1680 | vlib_cli_output (vm, "[%U, %U] [%U, %U] %7u %7u\n", |
| 1681 | format_fid_address, &stat->seid, |
| 1682 | format_fid_address, &stat->deid, |
| 1683 | format_ip_address, &stat->loc_rloc, |
| 1684 | format_ip_address, &stat->rmt_rloc, |
Filip Tehlar | 2151191 | 2017-04-07 10:41:42 +0200 | [diff] [blame] | 1685 | stat->counters.packets, stat->counters.bytes); |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 1686 | } |
| 1687 | vec_free (stats); |
| 1688 | return 0; |
| 1689 | } |
| 1690 | |
| 1691 | /* *INDENT-OFF* */ |
| 1692 | VLIB_CLI_COMMAND (one_show_stats_details_command) = { |
| 1693 | .path = "show one statistics details", |
| 1694 | .short_help = "show ONE statistics", |
| 1695 | .function = lisp_show_stats_details_command_fn, |
| 1696 | }; |
| 1697 | /* *INDENT-ON* */ |
| 1698 | |
| 1699 | static clib_error_t * |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 1700 | lisp_stats_enable_disable_command_fn (vlib_main_t * vm, |
| 1701 | unformat_input_t * input, |
| 1702 | vlib_cli_command_t * cmd) |
| 1703 | { |
| 1704 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1705 | u8 enable = 0; |
| 1706 | |
| 1707 | /* Get a line of input. */ |
| 1708 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1709 | return 0; |
| 1710 | |
| 1711 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1712 | { |
| 1713 | if (unformat (line_input, "enable")) |
| 1714 | enable = 1; |
| 1715 | else if (unformat (line_input, "disable")) |
| 1716 | enable = 0; |
| 1717 | else |
| 1718 | { |
| 1719 | clib_warning ("Error: expected enable/disable!"); |
| 1720 | goto done; |
| 1721 | } |
| 1722 | } |
| 1723 | vnet_lisp_stats_enable_disable (enable); |
| 1724 | done: |
| 1725 | unformat_free (line_input); |
| 1726 | return 0; |
| 1727 | } |
| 1728 | |
| 1729 | /* *INDENT-OFF* */ |
| 1730 | VLIB_CLI_COMMAND (one_stats_enable_disable_command) = { |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 1731 | .path = "one statistics", |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 1732 | .short_help = "enable/disable ONE statistics collecting", |
| 1733 | .function = lisp_stats_enable_disable_command_fn, |
| 1734 | }; |
| 1735 | /* *INDENT-ON* */ |
| 1736 | |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 1737 | static clib_error_t * |
| 1738 | lisp_stats_flush_command_fn (vlib_main_t * vm, |
| 1739 | unformat_input_t * input, |
| 1740 | vlib_cli_command_t * cmd) |
| 1741 | { |
| 1742 | vnet_lisp_flush_stats (); |
| 1743 | return 0; |
| 1744 | } |
| 1745 | |
| 1746 | /* *INDENT-OFF* */ |
| 1747 | VLIB_CLI_COMMAND (one_stats_flush_command) = { |
| 1748 | .path = "one statistics flush", |
| 1749 | .short_help = "Flush ONE statistics", |
| 1750 | .function = lisp_stats_flush_command_fn, |
| 1751 | }; |
| 1752 | /* *INDENT-ON* */ |
| 1753 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1754 | /* |
| 1755 | * fd.io coding-style-patch-verification: ON |
| 1756 | * |
| 1757 | * Local Variables: |
| 1758 | * eval: (c-set-style "gnu") |
| 1759 | * End: |
| 1760 | */ |