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 | { |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 171 | vec_terminate_c_string (locator_set_name); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 172 | p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); |
| 173 | if (!p) |
| 174 | { |
| 175 | error = clib_error_return (0, "locator-set %s doesn't exist", |
| 176 | locator_set_name); |
| 177 | goto done; |
| 178 | } |
| 179 | locator_set_index = p[0]; |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | error = unformat_parse_error (line_input); |
| 184 | goto done; |
| 185 | } |
| 186 | } |
| 187 | /* XXX treat batch configuration */ |
| 188 | |
| 189 | if (GID_ADDR_SRC_DST == gid_address_type (&eid)) |
| 190 | { |
| 191 | error = |
| 192 | clib_error_return (0, "src/dst is not supported for local EIDs!"); |
| 193 | goto done; |
| 194 | } |
| 195 | |
| 196 | if (key && (0 == key_id)) |
| 197 | { |
| 198 | vlib_cli_output (vm, "invalid key_id!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 199 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | gid_address_copy (&a->eid, &eid); |
| 203 | a->is_add = is_add; |
| 204 | a->locator_set_index = locator_set_index; |
| 205 | a->local = 1; |
| 206 | a->key = key; |
| 207 | a->key_id = key_id; |
| 208 | |
| 209 | rv = vnet_lisp_add_del_local_mapping (a, &map_index); |
| 210 | if (0 != rv) |
| 211 | { |
| 212 | error = clib_error_return (0, "failed to %s local mapping!", |
| 213 | is_add ? "add" : "delete"); |
| 214 | } |
| 215 | done: |
| 216 | vec_free (eids); |
| 217 | if (locator_set_name) |
| 218 | vec_free (locator_set_name); |
| 219 | gid_address_free (&a->eid); |
| 220 | vec_free (a->key); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 221 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 222 | return error; |
| 223 | } |
| 224 | |
| 225 | /* *INDENT-OFF* */ |
| 226 | VLIB_CLI_COMMAND (one_add_del_local_eid_command) = { |
| 227 | .path = "one eid-table", |
| 228 | .short_help = "one eid-table add/del [vni <vni>] eid <eid> " |
| 229 | "locator-set <locator-set> [key <secret-key> key-id sha1|sha256 ]", |
| 230 | .function = lisp_add_del_local_eid_command_fn, |
| 231 | }; |
| 232 | /* *INDENT-ON* */ |
| 233 | |
| 234 | static clib_error_t * |
| 235 | lisp_eid_table_map_command_fn (vlib_main_t * vm, |
| 236 | unformat_input_t * input, |
| 237 | vlib_cli_command_t * cmd) |
| 238 | { |
| 239 | u8 is_add = 1, is_l2 = 0; |
| 240 | u32 vni = 0, dp_id = 0; |
| 241 | unformat_input_t _line_input, *line_input = &_line_input; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 242 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 243 | |
| 244 | /* Get a line of input. */ |
| 245 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 246 | return 0; |
| 247 | |
| 248 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 249 | { |
| 250 | if (unformat (line_input, "del")) |
| 251 | is_add = 0; |
| 252 | else if (unformat (line_input, "vni %d", &vni)) |
| 253 | ; |
| 254 | else if (unformat (line_input, "vrf %d", &dp_id)) |
| 255 | ; |
| 256 | else if (unformat (line_input, "bd %d", &dp_id)) |
| 257 | is_l2 = 1; |
| 258 | else |
| 259 | { |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 260 | error = unformat_parse_error (line_input); |
| 261 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 265 | |
| 266 | done: |
| 267 | unformat_free (line_input); |
| 268 | |
| 269 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* *INDENT-OFF* */ |
| 273 | VLIB_CLI_COMMAND (one_eid_table_map_command) = { |
| 274 | .path = "one eid-table map", |
| 275 | .short_help = "one eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>", |
| 276 | .function = lisp_eid_table_map_command_fn, |
| 277 | }; |
| 278 | /* *INDENT-ON* */ |
| 279 | |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 280 | static clib_error_t * |
Filip Tehlar | 6492964 | 2017-09-20 08:41:23 +0200 | [diff] [blame] | 281 | lisp_add_del_ndp_entry_command_fn (vlib_main_t * vm, |
| 282 | unformat_input_t * input, |
| 283 | vlib_cli_command_t * cmd) |
| 284 | { |
| 285 | unformat_input_t _line_input, *line_input = &_line_input; |
| 286 | clib_error_t *error = NULL; |
| 287 | int rc = 0; |
| 288 | u8 hw_addr[6], bd = 0; |
| 289 | ip6_address_t ip6; |
| 290 | u32 hw_addr_set = 0, ip_set = 0, is_add = 1; |
| 291 | gid_address_t _g, *g = &_g; |
| 292 | |
| 293 | memset (&ip6, 0, sizeof (ip6)); |
| 294 | memset (hw_addr, 0, sizeof (hw_addr)); |
| 295 | memset (g, 0, sizeof (*g)); |
| 296 | |
| 297 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 298 | return 0; |
| 299 | |
| 300 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 301 | { |
| 302 | if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr)) |
| 303 | hw_addr_set = 1; |
| 304 | else if (unformat (line_input, "ip %U", unformat_ip6_address, &ip6)) |
| 305 | ip_set = 1; |
| 306 | else if (unformat (line_input, "del")) |
| 307 | is_add = 0; |
| 308 | else if (unformat (line_input, "bd %d", &bd)) |
| 309 | ; |
| 310 | else |
| 311 | { |
| 312 | error = clib_error_return (0, "parse error"); |
| 313 | goto done; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | if (!ip_set || (!hw_addr_set && is_add)) |
| 318 | { |
| 319 | vlib_cli_output (vm, "expected IP and MAC addresses!"); |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | /* build GID address */ |
| 324 | ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, IP6); |
| 325 | gid_address_ndp_bd (g) = bd; |
| 326 | gid_address_type (g) = GID_ADDR_NDP; |
| 327 | rc = vnet_lisp_add_del_l2_arp_ndp_entry (g, hw_addr, is_add); |
| 328 | if (rc) |
| 329 | clib_warning ("Failed to %s ndp entry!", is_add ? "add" : "delete"); |
| 330 | |
| 331 | done: |
| 332 | unformat_free (line_input); |
| 333 | return error; |
| 334 | } |
| 335 | |
| 336 | /* *INDENT-OFF* */ |
| 337 | VLIB_CLI_COMMAND (one_add_del_ndp_entry_command) = { |
| 338 | .path = "one ndp", |
| 339 | .short_help = "one ndp [del] bd <bd> mac <mac> ip <ipv6>", |
| 340 | .function = lisp_add_del_ndp_entry_command_fn, |
| 341 | }; |
| 342 | /* *INDENT-ON* */ |
| 343 | |
| 344 | static clib_error_t * |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 345 | lisp_add_del_l2_arp_entry_command_fn (vlib_main_t * vm, |
| 346 | unformat_input_t * input, |
| 347 | vlib_cli_command_t * cmd) |
| 348 | { |
| 349 | unformat_input_t _line_input, *line_input = &_line_input; |
| 350 | clib_error_t *error = NULL; |
| 351 | int rc = 0; |
| 352 | u8 hw_addr[6], bd = 0; |
| 353 | ip4_address_t ip4; |
| 354 | u32 hw_addr_set = 0, ip_set = 0, is_add = 1; |
| 355 | gid_address_t _arp, *arp = &_arp; |
| 356 | |
| 357 | memset (&ip4, 0, sizeof (ip4)); |
| 358 | memset (hw_addr, 0, sizeof (hw_addr)); |
| 359 | memset (arp, 0, sizeof (*arp)); |
| 360 | |
| 361 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 362 | return 0; |
| 363 | |
| 364 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 365 | { |
| 366 | if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr)) |
| 367 | hw_addr_set = 1; |
| 368 | else if (unformat (line_input, "ip %U", unformat_ip4_address, &ip4)) |
| 369 | ip_set = 1; |
| 370 | else if (unformat (line_input, "del")) |
| 371 | is_add = 0; |
| 372 | else if (unformat (line_input, "bd %d", &bd)) |
| 373 | ; |
| 374 | else |
| 375 | { |
| 376 | error = clib_error_return (0, "parse error"); |
| 377 | goto done; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | if (!ip_set || (!hw_addr_set && is_add)) |
| 382 | { |
| 383 | vlib_cli_output (vm, "expected IP and MAC addresses!"); |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | /* build GID address */ |
| 388 | gid_address_arp_ip4 (arp) = ip4; |
| 389 | gid_address_arp_bd (arp) = bd; |
| 390 | gid_address_type (arp) = GID_ADDR_ARP; |
Filip Tehlar | 6492964 | 2017-09-20 08:41:23 +0200 | [diff] [blame] | 391 | rc = vnet_lisp_add_del_l2_arp_ndp_entry (arp, hw_addr, is_add); |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 392 | if (rc) |
| 393 | clib_warning ("Failed to %s l2 arp entry!", is_add ? "add" : "delete"); |
| 394 | |
| 395 | done: |
| 396 | unformat_free (line_input); |
| 397 | return error; |
| 398 | } |
| 399 | |
| 400 | /* *INDENT-OFF* */ |
| 401 | VLIB_CLI_COMMAND (one_add_del_l2_arp_entry_command) = { |
| 402 | .path = "one l2 arp", |
| 403 | .short_help = "one l2 arp [del] bd <bd> mac <mac> ip <ipv4>", |
| 404 | .function = lisp_add_del_l2_arp_entry_command_fn, |
| 405 | }; |
| 406 | /* *INDENT-ON* */ |
| 407 | |
| 408 | static clib_error_t * |
| 409 | lisp_show_l2_arp_entries_command_fn (vlib_main_t * vm, |
| 410 | unformat_input_t * input, |
| 411 | vlib_cli_command_t * cmd) |
| 412 | { |
| 413 | u32 *ht = vnet_lisp_l2_arp_bds_get (); |
| 414 | lisp_api_l2_arp_entry_t *entries, *e; |
| 415 | hash_pair_t *p; |
| 416 | |
| 417 | /* *INDENT-OFF* */ |
| 418 | hash_foreach_pair (p, ht, |
| 419 | ({ |
| 420 | entries = vnet_lisp_l2_arp_entries_get_by_bd (p->key); |
| 421 | vlib_cli_output (vm, "Table: %d", p->key); |
| 422 | |
| 423 | vec_foreach (e, entries) |
| 424 | { |
| 425 | vlib_cli_output (vm, "\t%U -> %U", format_ip4_address, &e->ip4, |
| 426 | format_mac_address, e->mac); |
| 427 | } |
| 428 | vec_free (entries); |
| 429 | })); |
| 430 | /* *INDENT-ON* */ |
| 431 | |
| 432 | hash_free (ht); |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | /* *INDENT-OFF* */ |
| 437 | VLIB_CLI_COMMAND (one_show_l2_arp_entries_command) = { |
| 438 | .path = "show one l2 arp entries", |
| 439 | .short_help = "Show ONE L2 ARP entries", |
| 440 | .function = lisp_show_l2_arp_entries_command_fn, |
| 441 | }; |
| 442 | /* *INDENT-ON* */ |
| 443 | |
Filip Tehlar | 0587999 | 2017-09-05 15:46:09 +0200 | [diff] [blame] | 444 | static clib_error_t * |
| 445 | lisp_show_ndp_entries_command_fn (vlib_main_t * vm, |
| 446 | unformat_input_t * input, |
| 447 | vlib_cli_command_t * cmd) |
| 448 | { |
| 449 | u32 *ht = vnet_lisp_ndp_bds_get (); |
| 450 | lisp_api_ndp_entry_t *entries, *e; |
| 451 | hash_pair_t *p; |
| 452 | |
| 453 | /* *INDENT-OFF* */ |
| 454 | hash_foreach_pair (p, ht, |
| 455 | ({ |
| 456 | entries = vnet_lisp_ndp_entries_get_by_bd (p->key); |
| 457 | vlib_cli_output (vm, "Table: %d", p->key); |
| 458 | |
| 459 | vec_foreach (e, entries) |
| 460 | { |
| 461 | vlib_cli_output (vm, "\t%U -> %U", format_ip6_address, &e->ip6, |
| 462 | format_mac_address, e->mac); |
| 463 | } |
| 464 | vec_free (entries); |
| 465 | })); |
| 466 | /* *INDENT-ON* */ |
| 467 | |
| 468 | hash_free (ht); |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | /* *INDENT-OFF* */ |
| 473 | VLIB_CLI_COMMAND (one_show_ndp_entries_command) = { |
| 474 | .path = "show one ndp entries", |
| 475 | .short_help = "Show ONE NDP entries", |
| 476 | .function = lisp_show_ndp_entries_command_fn, |
| 477 | }; |
| 478 | /* *INDENT-ON* */ |
| 479 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 480 | /** |
| 481 | * Handler for add/del remote mapping CLI. |
| 482 | * |
| 483 | * @param vm vlib context |
| 484 | * @param input input from user |
| 485 | * @param cmd cmd |
| 486 | * @return pointer to clib error structure |
| 487 | */ |
| 488 | static clib_error_t * |
| 489 | lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm, |
| 490 | unformat_input_t * input, |
| 491 | vlib_cli_command_t * cmd) |
| 492 | { |
| 493 | clib_error_t *error = 0; |
| 494 | unformat_input_t _line_input, *line_input = &_line_input; |
| 495 | u8 is_add = 1, del_all = 0; |
| 496 | locator_t rloc, *rlocs = 0, *curr_rloc = 0; |
| 497 | gid_address_t eid; |
| 498 | u8 eid_set = 0; |
| 499 | u32 vni, action = ~0, p, w; |
| 500 | int rv; |
| 501 | |
| 502 | /* Get a line of input. */ |
| 503 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 504 | return 0; |
| 505 | |
| 506 | memset (&eid, 0, sizeof (eid)); |
| 507 | memset (&rloc, 0, sizeof (rloc)); |
| 508 | |
| 509 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 510 | { |
| 511 | if (unformat (line_input, "del-all")) |
| 512 | del_all = 1; |
| 513 | else if (unformat (line_input, "del")) |
| 514 | is_add = 0; |
| 515 | else if (unformat (line_input, "add")) |
| 516 | ; |
| 517 | else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) |
| 518 | eid_set = 1; |
| 519 | else if (unformat (line_input, "vni %u", &vni)) |
| 520 | { |
| 521 | gid_address_vni (&eid) = vni; |
| 522 | } |
| 523 | else if (unformat (line_input, "p %d w %d", &p, &w)) |
| 524 | { |
| 525 | if (!curr_rloc) |
| 526 | { |
| 527 | clib_warning |
| 528 | ("No RLOC configured for setting priority/weight!"); |
| 529 | goto done; |
| 530 | } |
| 531 | curr_rloc->priority = p; |
| 532 | curr_rloc->weight = w; |
| 533 | } |
| 534 | else if (unformat (line_input, "rloc %U", unformat_ip_address, |
| 535 | &gid_address_ip (&rloc.address))) |
| 536 | { |
| 537 | /* since rloc is stored in ip prefix we need to set prefix length */ |
| 538 | ip_prefix_t *pref = &gid_address_ippref (&rloc.address); |
| 539 | |
| 540 | u8 version = gid_address_ip_version (&rloc.address); |
| 541 | ip_prefix_len (pref) = ip_address_max_len (version); |
| 542 | |
| 543 | vec_add1 (rlocs, rloc); |
| 544 | curr_rloc = &rlocs[vec_len (rlocs) - 1]; |
| 545 | } |
| 546 | else if (unformat (line_input, "action %U", |
| 547 | unformat_negative_mapping_action, &action)) |
| 548 | ; |
| 549 | else |
| 550 | { |
| 551 | clib_warning ("parse error"); |
| 552 | goto done; |
| 553 | } |
| 554 | } |
| 555 | |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 556 | if (!del_all && !eid_set) |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 557 | { |
| 558 | clib_warning ("missing eid!"); |
| 559 | goto done; |
| 560 | } |
| 561 | |
| 562 | if (!del_all) |
| 563 | { |
| 564 | if (is_add && (~0 == action) && 0 == vec_len (rlocs)) |
| 565 | { |
| 566 | clib_warning ("no action set for negative map-reply!"); |
| 567 | goto done; |
| 568 | } |
| 569 | } |
| 570 | else |
| 571 | { |
| 572 | vnet_lisp_clear_all_remote_adjacencies (); |
| 573 | goto done; |
| 574 | } |
| 575 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 576 | /* if it's a delete, clean forwarding */ |
| 577 | if (!is_add) |
| 578 | { |
| 579 | vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; |
| 580 | memset (a, 0, sizeof (a[0])); |
| 581 | gid_address_copy (&a->reid, &eid); |
| 582 | if (vnet_lisp_add_del_adjacency (a)) |
| 583 | { |
| 584 | clib_warning ("failed to delete adjacency!"); |
| 585 | goto done; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | /* add as static remote mapping, i.e., not authoritative and infinite |
| 590 | * ttl */ |
Filip Tehlar | 809bc74 | 2017-08-14 19:15:36 +0200 | [diff] [blame] | 591 | if (is_add) |
| 592 | { |
| 593 | vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args; |
| 594 | memset (map_args, 0, sizeof (map_args[0])); |
| 595 | gid_address_copy (&map_args->eid, &eid); |
| 596 | map_args->action = action; |
| 597 | map_args->is_static = 1; |
| 598 | map_args->authoritative = 0; |
| 599 | map_args->ttl = ~0; |
| 600 | rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL); |
| 601 | } |
| 602 | else |
| 603 | rv = vnet_lisp_del_mapping (&eid, NULL); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 604 | |
| 605 | if (rv) |
| 606 | clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete"); |
| 607 | |
| 608 | done: |
| 609 | vec_free (rlocs); |
| 610 | unformat_free (line_input); |
| 611 | return error; |
| 612 | } |
| 613 | |
| 614 | /* *INDENT-OFF* */ |
| 615 | VLIB_CLI_COMMAND (one_add_del_remote_mapping_command) = { |
| 616 | .path = "one remote-mapping", |
| 617 | .short_help = |
| 618 | "one remote-mapping add|del [del-all] vni <vni> " |
| 619 | "eid <est-eid> [action <no-action|natively-forward|" |
| 620 | "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> " |
| 621 | "[rloc <dst-locator> ... ]", |
| 622 | .function = lisp_add_del_remote_mapping_command_fn, |
| 623 | }; |
| 624 | /* *INDENT-ON* */ |
| 625 | |
| 626 | /** |
| 627 | * Handler for add/del adjacency CLI. |
| 628 | */ |
| 629 | static clib_error_t * |
| 630 | lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 631 | vlib_cli_command_t * cmd) |
| 632 | { |
| 633 | clib_error_t *error = 0; |
| 634 | unformat_input_t _line_input, *line_input = &_line_input; |
| 635 | vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; |
| 636 | u8 is_add = 1; |
| 637 | ip_prefix_t *reid_ippref, *leid_ippref; |
| 638 | gid_address_t leid, reid; |
| 639 | u8 *dmac = gid_address_mac (&reid); |
| 640 | u8 *smac = gid_address_mac (&leid); |
| 641 | u8 reid_set = 0, leid_set = 0; |
| 642 | u32 vni; |
| 643 | |
| 644 | /* Get a line of input. */ |
| 645 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 646 | return 0; |
| 647 | |
| 648 | memset (&reid, 0, sizeof (reid)); |
| 649 | memset (&leid, 0, sizeof (leid)); |
| 650 | |
| 651 | leid_ippref = &gid_address_ippref (&leid); |
| 652 | reid_ippref = &gid_address_ippref (&reid); |
| 653 | |
| 654 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 655 | { |
| 656 | if (unformat (line_input, "del")) |
| 657 | is_add = 0; |
| 658 | else if (unformat (line_input, "add")) |
| 659 | ; |
| 660 | else if (unformat (line_input, "reid %U", |
| 661 | unformat_ip_prefix, reid_ippref)) |
| 662 | { |
| 663 | gid_address_type (&reid) = GID_ADDR_IP_PREFIX; |
| 664 | reid_set = 1; |
| 665 | } |
| 666 | else if (unformat (line_input, "reid %U", unformat_mac_address, dmac)) |
| 667 | { |
| 668 | gid_address_type (&reid) = GID_ADDR_MAC; |
| 669 | reid_set = 1; |
| 670 | } |
| 671 | else if (unformat (line_input, "vni %u", &vni)) |
| 672 | { |
| 673 | gid_address_vni (&leid) = vni; |
| 674 | gid_address_vni (&reid) = vni; |
| 675 | } |
| 676 | else if (unformat (line_input, "leid %U", |
| 677 | unformat_ip_prefix, leid_ippref)) |
| 678 | { |
| 679 | gid_address_type (&leid) = GID_ADDR_IP_PREFIX; |
| 680 | leid_set = 1; |
| 681 | } |
| 682 | else if (unformat (line_input, "leid %U", unformat_mac_address, smac)) |
| 683 | { |
| 684 | gid_address_type (&leid) = GID_ADDR_MAC; |
| 685 | leid_set = 1; |
| 686 | } |
| 687 | else |
| 688 | { |
| 689 | clib_warning ("parse error"); |
| 690 | goto done; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | if (!reid_set || !leid_set) |
| 695 | { |
| 696 | clib_warning ("missing remote or local eid!"); |
| 697 | goto done; |
| 698 | } |
| 699 | |
| 700 | if ((gid_address_type (&leid) != gid_address_type (&reid)) |
| 701 | || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX |
| 702 | && ip_prefix_version (reid_ippref) |
| 703 | != ip_prefix_version (leid_ippref))) |
| 704 | { |
| 705 | clib_warning ("remote and local EIDs are of different types!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 706 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | memset (a, 0, sizeof (a[0])); |
| 710 | gid_address_copy (&a->leid, &leid); |
| 711 | gid_address_copy (&a->reid, &reid); |
| 712 | a->is_add = is_add; |
| 713 | |
| 714 | if (vnet_lisp_add_del_adjacency (a)) |
| 715 | clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete"); |
| 716 | |
| 717 | done: |
| 718 | unformat_free (line_input); |
| 719 | return error; |
| 720 | } |
| 721 | |
| 722 | /* *INDENT-OFF* */ |
| 723 | VLIB_CLI_COMMAND (one_add_del_adjacency_command) = { |
| 724 | .path = "one adjacency", |
| 725 | .short_help = "one adjacency add|del vni <vni> reid <remote-eid> " |
| 726 | "leid <local-eid>", |
| 727 | .function = lisp_add_del_adjacency_command_fn, |
| 728 | }; |
| 729 | /* *INDENT-ON* */ |
| 730 | |
| 731 | |
| 732 | static clib_error_t * |
| 733 | lisp_map_request_mode_command_fn (vlib_main_t * vm, |
| 734 | unformat_input_t * input, |
| 735 | vlib_cli_command_t * cmd) |
| 736 | { |
| 737 | unformat_input_t _i, *i = &_i; |
| 738 | map_request_mode_t mr_mode = _MR_MODE_MAX; |
| 739 | |
| 740 | /* Get a line of input. */ |
| 741 | if (!unformat_user (input, unformat_line_input, i)) |
| 742 | return 0; |
| 743 | |
| 744 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 745 | { |
| 746 | if (unformat (i, "dst-only")) |
| 747 | mr_mode = MR_MODE_DST_ONLY; |
| 748 | else if (unformat (i, "src-dst")) |
| 749 | mr_mode = MR_MODE_SRC_DST; |
| 750 | else |
| 751 | { |
| 752 | clib_warning ("parse error '%U'", format_unformat_error, i); |
| 753 | goto done; |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | if (_MR_MODE_MAX == mr_mode) |
| 758 | { |
| 759 | clib_warning ("No map request mode entered!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 760 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | vnet_lisp_set_map_request_mode (mr_mode); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 764 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 765 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 766 | unformat_free (i); |
| 767 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | /* *INDENT-OFF* */ |
| 772 | VLIB_CLI_COMMAND (one_map_request_mode_command) = { |
| 773 | .path = "one map-request mode", |
| 774 | .short_help = "one map-request mode dst-only|src-dst", |
| 775 | .function = lisp_map_request_mode_command_fn, |
| 776 | }; |
| 777 | /* *INDENT-ON* */ |
| 778 | |
| 779 | |
| 780 | static u8 * |
| 781 | format_lisp_map_request_mode (u8 * s, va_list * args) |
| 782 | { |
| 783 | u32 mode = va_arg (*args, u32); |
| 784 | |
| 785 | switch (mode) |
| 786 | { |
| 787 | case 0: |
| 788 | return format (0, "dst-only"); |
| 789 | case 1: |
| 790 | return format (0, "src-dst"); |
| 791 | } |
| 792 | return 0; |
| 793 | } |
| 794 | |
| 795 | static clib_error_t * |
| 796 | lisp_show_map_request_mode_command_fn (vlib_main_t * vm, |
| 797 | unformat_input_t * input, |
| 798 | vlib_cli_command_t * cmd) |
| 799 | { |
| 800 | vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode, |
| 801 | vnet_lisp_get_map_request_mode ()); |
| 802 | return 0; |
| 803 | } |
| 804 | |
| 805 | /* *INDENT-OFF* */ |
| 806 | VLIB_CLI_COMMAND (one_show_map_request_mode_command) = { |
| 807 | .path = "show one map-request mode", |
| 808 | .short_help = "show one map-request mode", |
| 809 | .function = lisp_show_map_request_mode_command_fn, |
| 810 | }; |
| 811 | /* *INDENT-ON* */ |
| 812 | |
| 813 | static clib_error_t * |
| 814 | lisp_show_map_resolvers_command_fn (vlib_main_t * vm, |
| 815 | unformat_input_t * input, |
| 816 | vlib_cli_command_t * cmd) |
| 817 | { |
| 818 | lisp_msmr_t *mr; |
| 819 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 820 | |
| 821 | vec_foreach (mr, lcm->map_resolvers) |
| 822 | { |
| 823 | vlib_cli_output (vm, "%U", format_ip_address, &mr->address); |
| 824 | } |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | /* *INDENT-OFF* */ |
| 829 | VLIB_CLI_COMMAND (one_show_map_resolvers_command) = { |
| 830 | .path = "show one map-resolvers", |
| 831 | .short_help = "show one map-resolvers", |
| 832 | .function = lisp_show_map_resolvers_command_fn, |
| 833 | }; |
| 834 | /* *INDENT-ON* */ |
| 835 | |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 836 | static clib_error_t * |
| 837 | lisp_nsh_set_locator_set_command_fn (vlib_main_t * vm, |
| 838 | unformat_input_t * input, |
| 839 | vlib_cli_command_t * cmd) |
| 840 | { |
| 841 | u8 locator_name_set = 0; |
| 842 | u8 *locator_set_name = 0; |
| 843 | u8 is_add = 1; |
| 844 | unformat_input_t _line_input, *line_input = &_line_input; |
| 845 | clib_error_t *error = 0; |
| 846 | int rv = 0; |
| 847 | |
| 848 | /* Get a line of input. */ |
| 849 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 850 | return 0; |
| 851 | |
| 852 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 853 | { |
| 854 | if (unformat (line_input, "ls %_%v%_", &locator_set_name)) |
| 855 | locator_name_set = 1; |
| 856 | else if (unformat (line_input, "disable")) |
| 857 | is_add = 0; |
| 858 | else |
| 859 | { |
| 860 | error = clib_error_return (0, "parse error"); |
| 861 | goto done; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | if (!locator_name_set) |
| 866 | { |
| 867 | clib_warning ("No locator set specified!"); |
| 868 | goto done; |
| 869 | } |
| 870 | |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 871 | vec_terminate_c_string (locator_set_name); |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 872 | rv = vnet_lisp_nsh_set_locator_set (locator_set_name, is_add); |
| 873 | if (0 != rv) |
| 874 | { |
| 875 | error = clib_error_return (0, "failed to %s NSH mapping!", |
| 876 | is_add ? "add" : "delete"); |
| 877 | } |
| 878 | |
| 879 | done: |
| 880 | vec_free (locator_set_name); |
| 881 | unformat_free (line_input); |
| 882 | return error; |
| 883 | } |
| 884 | |
| 885 | /* *INDENT-OFF* */ |
| 886 | VLIB_CLI_COMMAND (one_nsh_set_locator_set_command) = { |
| 887 | .path = "one nsh-mapping", |
| 888 | .short_help = "one nsh-mapping [del] ls <locator-set-name>", |
| 889 | .function = lisp_nsh_set_locator_set_command_fn, |
| 890 | }; |
| 891 | /* *INDENT-ON* */ |
| 892 | |
Filip Tehlar | 7048ff1 | 2017-07-27 08:09:14 +0200 | [diff] [blame] | 893 | static clib_error_t * |
| 894 | lisp_map_register_fallback_threshold_show_command_fn (vlib_main_t * vm, |
| 895 | unformat_input_t * |
| 896 | input, |
| 897 | vlib_cli_command_t * |
| 898 | cmd) |
| 899 | { |
| 900 | u32 val = vnet_lisp_map_register_fallback_threshold_get (); |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame^] | 901 | vlib_cli_output (vm, "map register fallback threshold value: %d", val); |
Filip Tehlar | 7048ff1 | 2017-07-27 08:09:14 +0200 | [diff] [blame] | 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | /* *INDENT-OFF* */ |
| 906 | VLIB_CLI_COMMAND (one_map_register_fallback_threshold_show_command) = { |
| 907 | .path = "show one map-register fallback-threshold", |
| 908 | .short_help = "show one map-register fallback-threshold", |
| 909 | .function = lisp_map_register_fallback_threshold_show_command_fn, |
| 910 | }; |
| 911 | |
| 912 | /* *INDENT-ON* */ |
| 913 | |
| 914 | static clib_error_t * |
| 915 | lisp_map_register_fallback_threshold_command_fn (vlib_main_t * vm, |
| 916 | unformat_input_t * input, |
| 917 | vlib_cli_command_t * cmd) |
| 918 | { |
| 919 | unformat_input_t _line_input, *line_input = &_line_input; |
| 920 | clib_error_t *error = 0; |
| 921 | u32 val = 0; |
| 922 | int rv = 0; |
| 923 | |
| 924 | /* Get a line of input. */ |
| 925 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 926 | return 0; |
| 927 | |
| 928 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 929 | { |
| 930 | if (unformat (line_input, "%d", &val)) |
| 931 | ; |
| 932 | else |
| 933 | { |
| 934 | error = clib_error_return (0, "parse error"); |
| 935 | goto done; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | rv = vnet_lisp_map_register_fallback_threshold_set (val); |
| 940 | if (rv) |
| 941 | { |
| 942 | error = clib_error_return (0, "setting fallback threshold failed!"); |
| 943 | } |
| 944 | |
| 945 | done: |
| 946 | unformat_free (line_input); |
| 947 | return error; |
| 948 | } |
| 949 | |
| 950 | /* *INDENT-OFF* */ |
| 951 | VLIB_CLI_COMMAND (one_map_register_fallback_threshold_command) = { |
| 952 | .path = "one map-register fallback-threshold", |
| 953 | .short_help = "one map-register fallback-threshold <count>", |
| 954 | .function = lisp_map_register_fallback_threshold_command_fn, |
| 955 | }; |
| 956 | /* *INDENT-ON* */ |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 957 | |
| 958 | static clib_error_t * |
| 959 | lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm, |
| 960 | unformat_input_t * input, |
| 961 | vlib_cli_command_t * cmd) |
| 962 | { |
| 963 | u8 locator_name_set = 0; |
| 964 | u8 *locator_set_name = 0; |
| 965 | u8 is_add = 1; |
| 966 | unformat_input_t _line_input, *line_input = &_line_input; |
| 967 | clib_error_t *error = 0; |
| 968 | int rv = 0; |
| 969 | |
| 970 | /* Get a line of input. */ |
| 971 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 972 | return 0; |
| 973 | |
| 974 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 975 | { |
| 976 | if (unformat (line_input, "ls %_%v%_", &locator_set_name)) |
| 977 | locator_name_set = 1; |
| 978 | else if (unformat (line_input, "disable")) |
| 979 | is_add = 0; |
| 980 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 981 | { |
| 982 | error = clib_error_return (0, "parse error"); |
| 983 | goto done; |
| 984 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | if (!locator_name_set) |
| 988 | { |
| 989 | clib_warning ("No locator set specified!"); |
| 990 | goto done; |
| 991 | } |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 992 | vec_terminate_c_string (locator_set_name); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 993 | rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add); |
| 994 | if (0 != rv) |
| 995 | { |
| 996 | error = clib_error_return (0, "failed to %s pitr!", |
| 997 | is_add ? "add" : "delete"); |
| 998 | } |
| 999 | |
| 1000 | done: |
| 1001 | if (locator_set_name) |
| 1002 | vec_free (locator_set_name); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1003 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1004 | return error; |
| 1005 | } |
| 1006 | |
| 1007 | /* *INDENT-OFF* */ |
| 1008 | VLIB_CLI_COMMAND (one_pitr_set_locator_set_command) = { |
| 1009 | .path = "one pitr", |
| 1010 | .short_help = "one pitr [disable] ls <locator-set-name>", |
| 1011 | .function = lisp_pitr_set_locator_set_command_fn, |
| 1012 | }; |
| 1013 | /* *INDENT-ON* */ |
| 1014 | |
| 1015 | static clib_error_t * |
| 1016 | lisp_show_pitr_command_fn (vlib_main_t * vm, |
| 1017 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1018 | { |
| 1019 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1020 | mapping_t *m; |
| 1021 | locator_set_t *ls; |
| 1022 | u8 *tmp_str = 0; |
Filip Tehlar | 0a8840d | 2017-10-16 05:48:23 -0700 | [diff] [blame] | 1023 | u8 status = lcm->flags & LISP_FLAG_PITR_MODE; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1024 | |
Filip Tehlar | 0a8840d | 2017-10-16 05:48:23 -0700 | [diff] [blame] | 1025 | vlib_cli_output (vm, "%=20s%=16s", "pitr", status ? "locator-set" : ""); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1026 | |
Filip Tehlar | 0a8840d | 2017-10-16 05:48:23 -0700 | [diff] [blame] | 1027 | if (!status) |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1028 | { |
| 1029 | vlib_cli_output (vm, "%=20s", "disable"); |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | if (~0 == lcm->pitr_map_index) |
| 1034 | { |
| 1035 | tmp_str = format (0, "N/A"); |
| 1036 | } |
| 1037 | else |
| 1038 | { |
| 1039 | m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); |
| 1040 | if (~0 != m->locator_set_index) |
| 1041 | { |
| 1042 | ls = |
| 1043 | pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); |
| 1044 | tmp_str = format (0, "%s", ls->name); |
| 1045 | } |
| 1046 | else |
| 1047 | { |
| 1048 | tmp_str = format (0, "N/A"); |
| 1049 | } |
| 1050 | } |
| 1051 | vec_add1 (tmp_str, 0); |
| 1052 | |
| 1053 | vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); |
| 1054 | |
| 1055 | vec_free (tmp_str); |
| 1056 | |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | /* *INDENT-OFF* */ |
| 1061 | VLIB_CLI_COMMAND (one_show_pitr_command) = { |
| 1062 | .path = "show one pitr", |
| 1063 | .short_help = "Show pitr", |
| 1064 | .function = lisp_show_pitr_command_fn, |
| 1065 | }; |
| 1066 | /* *INDENT-ON* */ |
| 1067 | |
| 1068 | static u8 * |
| 1069 | format_eid_entry (u8 * s, va_list * args) |
| 1070 | { |
| 1071 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 1072 | lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *); |
| 1073 | mapping_t *mapit = va_arg (*args, mapping_t *); |
| 1074 | locator_set_t *ls = va_arg (*args, locator_set_t *); |
| 1075 | gid_address_t *gid = &mapit->eid; |
| 1076 | u32 ttl = mapit->ttl; |
| 1077 | u8 aut = mapit->authoritative; |
| 1078 | u32 *loc_index; |
| 1079 | u8 first_line = 1; |
| 1080 | u8 *loc; |
| 1081 | |
| 1082 | u8 *type = ls->local ? format (0, "local(%s)", ls->name) |
| 1083 | : format (0, "remote"); |
| 1084 | |
| 1085 | if (vec_len (ls->locator_indices) == 0) |
| 1086 | { |
Filip Tehlar | d89b604 | 2017-04-11 14:00:58 +0200 | [diff] [blame] | 1087 | s = format (s, "%-35U%-20saction:%-30U%-20u%-u", format_gid_address, |
| 1088 | gid, type, format_negative_mapping_action, mapit->action, |
| 1089 | ttl, aut); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1090 | } |
| 1091 | else |
| 1092 | { |
| 1093 | vec_foreach (loc_index, ls->locator_indices) |
| 1094 | { |
| 1095 | locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]); |
| 1096 | if (l->local) |
| 1097 | loc = format (0, "%U", format_vnet_sw_if_index_name, vnm, |
| 1098 | l->sw_if_index); |
| 1099 | else |
| 1100 | loc = format (0, "%U", format_ip_address, |
| 1101 | &gid_address_ip (&l->address)); |
| 1102 | |
| 1103 | if (first_line) |
| 1104 | { |
| 1105 | s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address, |
| 1106 | gid, type, loc, ttl, aut); |
| 1107 | first_line = 0; |
| 1108 | } |
| 1109 | else |
| 1110 | s = format (s, "%55s%v\n", "", loc); |
| 1111 | } |
| 1112 | } |
| 1113 | return s; |
| 1114 | } |
| 1115 | |
| 1116 | static clib_error_t * |
| 1117 | lisp_show_eid_table_command_fn (vlib_main_t * vm, |
| 1118 | unformat_input_t * input, |
| 1119 | vlib_cli_command_t * cmd) |
| 1120 | { |
| 1121 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1122 | mapping_t *mapit; |
| 1123 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1124 | u32 mi; |
| 1125 | gid_address_t eid; |
| 1126 | u8 print_all = 1; |
| 1127 | u8 filter = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1128 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1129 | |
| 1130 | memset (&eid, 0, sizeof (eid)); |
| 1131 | |
| 1132 | /* Get a line of input. */ |
| 1133 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1134 | return 0; |
| 1135 | |
| 1136 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1137 | { |
| 1138 | if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) |
| 1139 | print_all = 0; |
| 1140 | else if (unformat (line_input, "local")) |
| 1141 | filter = 1; |
| 1142 | else if (unformat (line_input, "remote")) |
| 1143 | filter = 2; |
| 1144 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1145 | { |
| 1146 | error = clib_error_return (0, "parse error: '%U'", |
| 1147 | format_unformat_error, line_input); |
| 1148 | goto done; |
| 1149 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s", |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame^] | 1153 | "EID", "type", "locators", "ttl", "authoritative"); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1154 | |
| 1155 | if (print_all) |
| 1156 | { |
| 1157 | /* *INDENT-OFF* */ |
| 1158 | pool_foreach (mapit, lcm->mapping_pool, |
| 1159 | ({ |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 1160 | if (mapit->pitr_set || mapit->nsh_set) |
Filip Tehlar | 1e8d01f | 2017-03-30 15:17:01 +0200 | [diff] [blame] | 1161 | continue; |
| 1162 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1163 | locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool, |
| 1164 | mapit->locator_set_index); |
| 1165 | if (filter && !((1 == filter && ls->local) || |
| 1166 | (2 == filter && !ls->local))) |
| 1167 | { |
| 1168 | continue; |
| 1169 | } |
| 1170 | vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main, |
| 1171 | lcm, mapit, ls); |
| 1172 | })); |
| 1173 | /* *INDENT-ON* */ |
| 1174 | } |
| 1175 | else |
| 1176 | { |
| 1177 | mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid); |
| 1178 | if ((u32) ~ 0 == mi) |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1179 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1180 | |
| 1181 | mapit = pool_elt_at_index (lcm->mapping_pool, mi); |
| 1182 | locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, |
| 1183 | mapit->locator_set_index); |
| 1184 | |
| 1185 | if (filter && !((1 == filter && ls->local) || |
| 1186 | (2 == filter && !ls->local))) |
| 1187 | { |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1188 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main, |
| 1192 | lcm, mapit, ls); |
| 1193 | } |
| 1194 | |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1195 | done: |
| 1196 | unformat_free (line_input); |
| 1197 | |
| 1198 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | /* *INDENT-OFF* */ |
| 1202 | VLIB_CLI_COMMAND (one_cp_show_eid_table_command) = { |
| 1203 | .path = "show one eid-table", |
| 1204 | .short_help = "Shows EID table", |
| 1205 | .function = lisp_show_eid_table_command_fn, |
| 1206 | }; |
| 1207 | /* *INDENT-ON* */ |
| 1208 | |
Filip Tehlar | 0a8840d | 2017-10-16 05:48:23 -0700 | [diff] [blame] | 1209 | static clib_error_t * |
| 1210 | lisp_enable_disable_pitr_mode_command_fn (vlib_main_t * vm, |
| 1211 | unformat_input_t * input, |
| 1212 | vlib_cli_command_t * cmd) |
| 1213 | { |
| 1214 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1215 | u8 is_enabled = 0; |
| 1216 | u8 is_set = 0; |
| 1217 | clib_error_t *error = NULL; |
| 1218 | |
| 1219 | /* Get a line of input. */ |
| 1220 | if (!unformat_user (input, unformat_line_input, line_input)) |
Swarup Nayak | 82d8ec2 | 2017-12-04 11:54:43 +0530 | [diff] [blame] | 1221 | return clib_error_return (0, "expected enable | disable"); |
Filip Tehlar | 0a8840d | 2017-10-16 05:48:23 -0700 | [diff] [blame] | 1222 | |
| 1223 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1224 | { |
| 1225 | if (unformat (line_input, "enable")) |
| 1226 | { |
| 1227 | is_set = 1; |
| 1228 | is_enabled = 1; |
| 1229 | } |
| 1230 | else if (unformat (line_input, "disable")) |
| 1231 | is_set = 1; |
| 1232 | else |
| 1233 | { |
| 1234 | error = clib_error_return (0, "parse error: '%U'", |
| 1235 | format_unformat_error, line_input); |
| 1236 | goto done; |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | if (!is_set) |
| 1241 | { |
| 1242 | error = clib_error_return (0, "state not set"); |
| 1243 | goto done; |
| 1244 | } |
| 1245 | |
| 1246 | vnet_lisp_enable_disable_pitr_mode (is_enabled); |
| 1247 | |
| 1248 | done: |
| 1249 | unformat_free (line_input); |
| 1250 | |
| 1251 | return error; |
| 1252 | } |
| 1253 | |
| 1254 | /* *INDENT-OFF* */ |
| 1255 | VLIB_CLI_COMMAND (one_cp_enable_disable_pitr_mode_command) = { |
| 1256 | .path = "one pitr mode", |
| 1257 | .short_help = "one pitr mode [enable|disable]", |
| 1258 | .function = lisp_enable_disable_pitr_mode_command_fn, |
| 1259 | }; |
| 1260 | /* *INDENT-ON* */ |
| 1261 | |
| 1262 | |
| 1263 | static clib_error_t * |
| 1264 | lisp_enable_disable_petr_mode_command_fn (vlib_main_t * vm, |
| 1265 | unformat_input_t * input, |
| 1266 | vlib_cli_command_t * cmd) |
| 1267 | { |
| 1268 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1269 | u8 is_enabled = 0; |
| 1270 | u8 is_set = 0; |
| 1271 | clib_error_t *error = NULL; |
| 1272 | |
| 1273 | /* Get a line of input. */ |
| 1274 | if (!unformat_user (input, unformat_line_input, line_input)) |
Swarup Nayak | 82d8ec2 | 2017-12-04 11:54:43 +0530 | [diff] [blame] | 1275 | return clib_error_return (0, "expected enable | disable"); |
Filip Tehlar | 0a8840d | 2017-10-16 05:48:23 -0700 | [diff] [blame] | 1276 | |
| 1277 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1278 | { |
| 1279 | if (unformat (line_input, "enable")) |
| 1280 | { |
| 1281 | is_set = 1; |
| 1282 | is_enabled = 1; |
| 1283 | } |
| 1284 | else if (unformat (line_input, "disable")) |
| 1285 | is_set = 1; |
| 1286 | else |
| 1287 | { |
| 1288 | error = clib_error_return (0, "parse error: '%U'", |
| 1289 | format_unformat_error, line_input); |
| 1290 | goto done; |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | if (!is_set) |
| 1295 | { |
| 1296 | error = clib_error_return (0, "state not set"); |
| 1297 | goto done; |
| 1298 | } |
| 1299 | |
| 1300 | vnet_lisp_enable_disable_petr_mode (is_enabled); |
| 1301 | |
| 1302 | done: |
| 1303 | unformat_free (line_input); |
| 1304 | |
| 1305 | return error; |
| 1306 | } |
| 1307 | |
| 1308 | /* *INDENT-OFF* */ |
| 1309 | VLIB_CLI_COMMAND (one_cp_enable_disable_petr_mode_command) = { |
| 1310 | .path = "one petr mode", |
| 1311 | .short_help = "one petr mode [enable|disable]", |
| 1312 | .function = lisp_enable_disable_petr_mode_command_fn, |
| 1313 | }; |
| 1314 | /* *INDENT-ON* */ |
| 1315 | |
| 1316 | static clib_error_t * |
| 1317 | lisp_enable_disable_xtr_mode_command_fn (vlib_main_t * vm, |
| 1318 | unformat_input_t * input, |
| 1319 | vlib_cli_command_t * cmd) |
| 1320 | { |
| 1321 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1322 | u8 is_enabled = 0; |
| 1323 | u8 is_set = 0; |
| 1324 | clib_error_t *error = NULL; |
| 1325 | |
| 1326 | /* Get a line of input. */ |
| 1327 | if (!unformat_user (input, unformat_line_input, line_input)) |
Swarup Nayak | 82d8ec2 | 2017-12-04 11:54:43 +0530 | [diff] [blame] | 1328 | return clib_error_return (0, "expected enable | disable"); |
Filip Tehlar | 0a8840d | 2017-10-16 05:48:23 -0700 | [diff] [blame] | 1329 | |
| 1330 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1331 | { |
| 1332 | if (unformat (line_input, "enable")) |
| 1333 | { |
| 1334 | is_set = 1; |
| 1335 | is_enabled = 1; |
| 1336 | } |
| 1337 | else if (unformat (line_input, "disable")) |
| 1338 | is_set = 1; |
| 1339 | else |
| 1340 | { |
| 1341 | error = clib_error_return (0, "parse error: '%U'", |
| 1342 | format_unformat_error, line_input); |
| 1343 | goto done; |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | if (!is_set) |
| 1348 | { |
| 1349 | error = clib_error_return (0, "state not set"); |
| 1350 | goto done; |
| 1351 | } |
| 1352 | |
| 1353 | vnet_lisp_enable_disable_xtr_mode (is_enabled); |
| 1354 | |
| 1355 | done: |
| 1356 | unformat_free (line_input); |
| 1357 | |
| 1358 | return error; |
| 1359 | } |
| 1360 | |
| 1361 | /* *INDENT-OFF* */ |
| 1362 | VLIB_CLI_COMMAND (one_cp_enable_disable_xtr_mode_command) = { |
| 1363 | .path = "one xtr mode", |
| 1364 | .short_help = "one xtr mode [enable|disable]", |
| 1365 | .function = lisp_enable_disable_xtr_mode_command_fn, |
| 1366 | }; |
| 1367 | /* *INDENT-ON* */ |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1368 | |
| 1369 | static clib_error_t * |
| 1370 | lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1371 | vlib_cli_command_t * cmd) |
| 1372 | { |
| 1373 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1374 | u8 is_enabled = 0; |
| 1375 | u8 is_set = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1376 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1377 | |
| 1378 | /* Get a line of input. */ |
| 1379 | if (!unformat_user (input, unformat_line_input, line_input)) |
Swarup Nayak | 82d8ec2 | 2017-12-04 11:54:43 +0530 | [diff] [blame] | 1380 | return clib_error_return (0, "expected enable | disable"); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1381 | |
| 1382 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1383 | { |
| 1384 | if (unformat (line_input, "enable")) |
| 1385 | { |
| 1386 | is_set = 1; |
| 1387 | is_enabled = 1; |
| 1388 | } |
| 1389 | else if (unformat (line_input, "disable")) |
| 1390 | is_set = 1; |
| 1391 | else |
| 1392 | { |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1393 | error = clib_error_return (0, "parse error: '%U'", |
| 1394 | format_unformat_error, line_input); |
| 1395 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | if (!is_set) |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1400 | { |
| 1401 | error = clib_error_return (0, "state not set"); |
| 1402 | goto done; |
| 1403 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1404 | |
| 1405 | vnet_lisp_enable_disable (is_enabled); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1406 | |
| 1407 | done: |
| 1408 | unformat_free (line_input); |
| 1409 | |
| 1410 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | /* *INDENT-OFF* */ |
| 1414 | VLIB_CLI_COMMAND (one_cp_enable_disable_command) = { |
| 1415 | .path = "one", |
| 1416 | .short_help = "one [enable|disable]", |
| 1417 | .function = lisp_enable_disable_command_fn, |
| 1418 | }; |
| 1419 | /* *INDENT-ON* */ |
| 1420 | |
| 1421 | static clib_error_t * |
Filip Tehlar | 1e553a0 | 2017-08-02 12:45:07 +0200 | [diff] [blame] | 1422 | lisp_map_register_set_ttl_command_fn (vlib_main_t * vm, |
| 1423 | unformat_input_t * input, |
| 1424 | vlib_cli_command_t * cmd) |
| 1425 | { |
| 1426 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1427 | u32 ttl = 0; |
| 1428 | u8 is_set = 0; |
| 1429 | clib_error_t *error = NULL; |
| 1430 | |
| 1431 | /* Get a line of input. */ |
| 1432 | if (!unformat_user (input, unformat_line_input, line_input)) |
Swarup Nayak | 82d8ec2 | 2017-12-04 11:54:43 +0530 | [diff] [blame] | 1433 | return clib_error_return (0, "expected enable | disable"); |
Filip Tehlar | 1e553a0 | 2017-08-02 12:45:07 +0200 | [diff] [blame] | 1434 | |
| 1435 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1436 | { |
| 1437 | if (unformat (line_input, "%u", &ttl)) |
| 1438 | is_set = 1; |
| 1439 | else |
| 1440 | { |
| 1441 | vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, |
| 1442 | line_input); |
| 1443 | goto done; |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | if (!is_set) |
| 1448 | { |
| 1449 | vlib_cli_output (vm, "expected integer value for TTL!"); |
| 1450 | goto done; |
| 1451 | } |
| 1452 | |
| 1453 | vnet_lisp_map_register_set_ttl (ttl); |
| 1454 | |
| 1455 | done: |
| 1456 | unformat_free (line_input); |
| 1457 | return error; |
| 1458 | } |
| 1459 | |
| 1460 | /* *INDENT-OFF* */ |
| 1461 | VLIB_CLI_COMMAND (one_map_register_set_ttl_command) = { |
| 1462 | .path = "one map-register ttl", |
| 1463 | .short_help = "one map-register ttl", |
| 1464 | .function = lisp_map_register_set_ttl_command_fn, |
| 1465 | }; |
| 1466 | /* *INDENT-ON* */ |
| 1467 | |
| 1468 | static clib_error_t * |
| 1469 | lisp_map_register_show_ttl_command_fn (vlib_main_t * vm, |
| 1470 | unformat_input_t * input, |
| 1471 | vlib_cli_command_t * cmd) |
| 1472 | { |
| 1473 | u32 ttl = vnet_lisp_map_register_get_ttl (); |
| 1474 | |
| 1475 | vlib_cli_output (vm, "map-register TTL: %u", ttl); |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
| 1479 | /* *INDENT-OFF* */ |
| 1480 | VLIB_CLI_COMMAND (one_map_register_show_ttl_command) = { |
| 1481 | .path = "show one map-register ttl", |
| 1482 | .short_help = "show one map-register ttl", |
| 1483 | .function = lisp_map_register_show_ttl_command_fn, |
| 1484 | }; |
| 1485 | |
| 1486 | /* *INDENT-ON* */ |
| 1487 | |
| 1488 | static clib_error_t * |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1489 | lisp_map_register_enable_disable_command_fn (vlib_main_t * vm, |
| 1490 | unformat_input_t * input, |
| 1491 | vlib_cli_command_t * cmd) |
| 1492 | { |
| 1493 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1494 | u8 is_enabled = 0; |
| 1495 | u8 is_set = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1496 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1497 | |
| 1498 | /* Get a line of input. */ |
| 1499 | if (!unformat_user (input, unformat_line_input, line_input)) |
Swarup Nayak | 82d8ec2 | 2017-12-04 11:54:43 +0530 | [diff] [blame] | 1500 | return clib_error_return (0, "expected enable | disable"); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1501 | |
| 1502 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1503 | { |
| 1504 | if (unformat (line_input, "enable")) |
| 1505 | { |
| 1506 | is_set = 1; |
| 1507 | is_enabled = 1; |
| 1508 | } |
| 1509 | else if (unformat (line_input, "disable")) |
| 1510 | is_set = 1; |
| 1511 | else |
| 1512 | { |
| 1513 | vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, |
| 1514 | line_input); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1515 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | if (!is_set) |
| 1520 | { |
| 1521 | vlib_cli_output (vm, "state not set!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1522 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | vnet_lisp_map_register_enable_disable (is_enabled); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1526 | |
| 1527 | done: |
| 1528 | unformat_free (line_input); |
| 1529 | |
| 1530 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | /* *INDENT-OFF* */ |
| 1534 | VLIB_CLI_COMMAND (one_map_register_enable_disable_command) = { |
| 1535 | .path = "one map-register", |
| 1536 | .short_help = "one map-register [enable|disable]", |
| 1537 | .function = lisp_map_register_enable_disable_command_fn, |
| 1538 | }; |
| 1539 | /* *INDENT-ON* */ |
| 1540 | |
| 1541 | static clib_error_t * |
| 1542 | lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm, |
| 1543 | unformat_input_t * input, |
| 1544 | vlib_cli_command_t * cmd) |
| 1545 | { |
| 1546 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1547 | u8 is_enabled = 0; |
| 1548 | u8 is_set = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1549 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1550 | |
| 1551 | /* Get a line of input. */ |
| 1552 | if (!unformat_user (input, unformat_line_input, line_input)) |
Swarup Nayak | 82d8ec2 | 2017-12-04 11:54:43 +0530 | [diff] [blame] | 1553 | return clib_error_return (0, "expected enable | disable"); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1554 | |
| 1555 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1556 | { |
| 1557 | if (unformat (line_input, "enable")) |
| 1558 | { |
| 1559 | is_set = 1; |
| 1560 | is_enabled = 1; |
| 1561 | } |
| 1562 | else if (unformat (line_input, "disable")) |
| 1563 | is_set = 1; |
| 1564 | else |
| 1565 | { |
| 1566 | vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, |
| 1567 | line_input); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1568 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | if (!is_set) |
| 1573 | { |
| 1574 | vlib_cli_output (vm, "state not set!"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1575 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | vnet_lisp_rloc_probe_enable_disable (is_enabled); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1579 | |
| 1580 | done: |
| 1581 | unformat_free (line_input); |
| 1582 | |
| 1583 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | /* *INDENT-OFF* */ |
| 1587 | VLIB_CLI_COMMAND (one_rloc_probe_enable_disable_command) = { |
| 1588 | .path = "one rloc-probe", |
| 1589 | .short_help = "one rloc-probe [enable|disable]", |
| 1590 | .function = lisp_rloc_probe_enable_disable_command_fn, |
| 1591 | }; |
| 1592 | /* *INDENT-ON* */ |
| 1593 | |
| 1594 | static u8 * |
| 1595 | format_lisp_status (u8 * s, va_list * args) |
| 1596 | { |
| 1597 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1598 | return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled"); |
| 1599 | } |
| 1600 | |
| 1601 | static clib_error_t * |
| 1602 | lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1603 | vlib_cli_command_t * cmd) |
| 1604 | { |
| 1605 | u8 *msg = 0; |
| 1606 | msg = format (msg, "feature: %U\ngpe: %U\n", |
| 1607 | format_lisp_status, format_vnet_lisp_gpe_status); |
| 1608 | vlib_cli_output (vm, "%v", msg); |
| 1609 | vec_free (msg); |
| 1610 | return 0; |
| 1611 | } |
| 1612 | |
| 1613 | /* *INDENT-OFF* */ |
| 1614 | VLIB_CLI_COMMAND (one_show_status_command) = { |
| 1615 | .path = "show one status", |
| 1616 | .short_help = "show one status", |
| 1617 | .function = lisp_show_status_command_fn, |
| 1618 | }; |
| 1619 | /* *INDENT-ON* */ |
| 1620 | |
| 1621 | static clib_error_t * |
| 1622 | lisp_show_eid_table_map_command_fn (vlib_main_t * vm, |
| 1623 | unformat_input_t * input, |
| 1624 | vlib_cli_command_t * cmd) |
| 1625 | { |
| 1626 | hash_pair_t *p; |
| 1627 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1628 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1629 | uword *vni_table = 0; |
| 1630 | u8 is_l2 = 0; |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1631 | clib_error_t *error = NULL; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1632 | |
| 1633 | /* Get a line of input. */ |
| 1634 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1635 | return 0; |
| 1636 | |
| 1637 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1638 | { |
| 1639 | if (unformat (line_input, "l2")) |
| 1640 | { |
| 1641 | vni_table = lcm->bd_id_by_vni; |
| 1642 | is_l2 = 1; |
| 1643 | } |
| 1644 | else if (unformat (line_input, "l3")) |
| 1645 | { |
| 1646 | vni_table = lcm->table_id_by_vni; |
| 1647 | is_l2 = 0; |
| 1648 | } |
| 1649 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1650 | { |
| 1651 | error = clib_error_return (0, "parse error: '%U'", |
| 1652 | format_unformat_error, line_input); |
| 1653 | goto done; |
| 1654 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | if (!vni_table) |
| 1658 | { |
| 1659 | vlib_cli_output (vm, "Error: expected l2|l3 param!\n"); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1660 | goto done; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); |
| 1664 | |
| 1665 | /* *INDENT-OFF* */ |
| 1666 | hash_foreach_pair (p, vni_table, |
| 1667 | ({ |
| 1668 | vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); |
| 1669 | })); |
| 1670 | /* *INDENT-ON* */ |
| 1671 | |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1672 | done: |
| 1673 | unformat_free (line_input); |
| 1674 | |
| 1675 | return error; |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | /* *INDENT-OFF* */ |
| 1679 | VLIB_CLI_COMMAND (one_show_eid_table_map_command) = { |
| 1680 | .path = "show one eid-table map", |
| 1681 | .short_help = "show one eid-table l2|l3", |
| 1682 | .function = lisp_show_eid_table_map_command_fn, |
| 1683 | }; |
| 1684 | /* *INDENT-ON* */ |
| 1685 | |
| 1686 | |
| 1687 | static clib_error_t * |
| 1688 | lisp_add_del_locator_set_command_fn (vlib_main_t * vm, |
| 1689 | unformat_input_t * input, |
| 1690 | vlib_cli_command_t * cmd) |
| 1691 | { |
| 1692 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
| 1693 | vnet_main_t *vnm = lgm->vnet_main; |
| 1694 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1695 | u8 is_add = 1; |
| 1696 | clib_error_t *error = 0; |
| 1697 | u8 *locator_set_name = 0; |
| 1698 | locator_t locator, *locators = 0; |
| 1699 | vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; |
| 1700 | u32 ls_index = 0; |
| 1701 | int rv = 0; |
| 1702 | |
| 1703 | memset (&locator, 0, sizeof (locator)); |
| 1704 | memset (a, 0, sizeof (a[0])); |
| 1705 | |
| 1706 | /* Get a line of input. */ |
| 1707 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1708 | return 0; |
| 1709 | |
| 1710 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1711 | { |
| 1712 | if (unformat (line_input, "add %_%v%_", &locator_set_name)) |
| 1713 | is_add = 1; |
| 1714 | else if (unformat (line_input, "del %_%v%_", &locator_set_name)) |
| 1715 | is_add = 0; |
| 1716 | else if (unformat (line_input, "iface %U p %d w %d", |
| 1717 | unformat_vnet_sw_interface, vnm, |
| 1718 | &locator.sw_if_index, &locator.priority, |
| 1719 | &locator.weight)) |
| 1720 | { |
| 1721 | locator.local = 1; |
| 1722 | vec_add1 (locators, locator); |
| 1723 | } |
| 1724 | else |
| 1725 | { |
| 1726 | error = unformat_parse_error (line_input); |
| 1727 | goto done; |
| 1728 | } |
| 1729 | } |
| 1730 | |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 1731 | vec_terminate_c_string (locator_set_name); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1732 | a->name = locator_set_name; |
| 1733 | a->locators = locators; |
| 1734 | a->is_add = is_add; |
| 1735 | a->local = 1; |
| 1736 | |
| 1737 | rv = vnet_lisp_add_del_locator_set (a, &ls_index); |
| 1738 | if (0 != rv) |
| 1739 | { |
| 1740 | error = clib_error_return (0, "failed to %s locator-set!", |
| 1741 | is_add ? "add" : "delete"); |
| 1742 | } |
| 1743 | |
| 1744 | done: |
| 1745 | vec_free (locators); |
| 1746 | if (locator_set_name) |
| 1747 | vec_free (locator_set_name); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1748 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1749 | return error; |
| 1750 | } |
| 1751 | |
| 1752 | /* *INDENT-OFF* */ |
| 1753 | VLIB_CLI_COMMAND (one_cp_add_del_locator_set_command) = { |
| 1754 | .path = "one locator-set", |
| 1755 | .short_help = "one locator-set add/del <name> [iface <iface-name> " |
| 1756 | "p <priority> w <weight>]", |
| 1757 | .function = lisp_add_del_locator_set_command_fn, |
| 1758 | }; |
| 1759 | /* *INDENT-ON* */ |
| 1760 | |
| 1761 | static clib_error_t * |
| 1762 | lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm, |
| 1763 | unformat_input_t * input, |
| 1764 | vlib_cli_command_t * cmd) |
| 1765 | { |
| 1766 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
| 1767 | vnet_main_t *vnm = lgm->vnet_main; |
| 1768 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1769 | u8 is_add = 1; |
| 1770 | clib_error_t *error = 0; |
| 1771 | u8 *locator_set_name = 0; |
| 1772 | u8 locator_set_name_set = 0; |
| 1773 | locator_t locator, *locators = 0; |
| 1774 | vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; |
| 1775 | u32 ls_index = 0; |
| 1776 | |
| 1777 | memset (&locator, 0, sizeof (locator)); |
| 1778 | memset (a, 0, sizeof (a[0])); |
| 1779 | |
| 1780 | /* Get a line of input. */ |
| 1781 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1782 | return 0; |
| 1783 | |
| 1784 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1785 | { |
| 1786 | if (unformat (line_input, "add")) |
| 1787 | is_add = 1; |
| 1788 | else if (unformat (line_input, "del")) |
| 1789 | is_add = 0; |
| 1790 | else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) |
| 1791 | locator_set_name_set = 1; |
| 1792 | else if (unformat (line_input, "iface %U p %d w %d", |
| 1793 | unformat_vnet_sw_interface, vnm, |
| 1794 | &locator.sw_if_index, &locator.priority, |
| 1795 | &locator.weight)) |
| 1796 | { |
| 1797 | locator.local = 1; |
| 1798 | vec_add1 (locators, locator); |
| 1799 | } |
| 1800 | else |
| 1801 | { |
| 1802 | error = unformat_parse_error (line_input); |
| 1803 | goto done; |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | if (!locator_set_name_set) |
| 1808 | { |
| 1809 | error = clib_error_return (0, "locator_set name not set!"); |
| 1810 | goto done; |
| 1811 | } |
| 1812 | |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 1813 | vec_terminate_c_string (locator_set_name); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1814 | a->name = locator_set_name; |
| 1815 | a->locators = locators; |
| 1816 | a->is_add = is_add; |
| 1817 | a->local = 1; |
| 1818 | |
| 1819 | vnet_lisp_add_del_locator (a, 0, &ls_index); |
| 1820 | |
| 1821 | done: |
| 1822 | vec_free (locators); |
| 1823 | vec_free (locator_set_name); |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1824 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1825 | return error; |
| 1826 | } |
| 1827 | |
| 1828 | /* *INDENT-OFF* */ |
| 1829 | VLIB_CLI_COMMAND (one_cp_add_del_locator_in_set_command) = { |
| 1830 | .path = "one locator", |
| 1831 | .short_help = "one locator add/del locator-set <name> iface <iface-name> " |
| 1832 | "p <priority> w <weight>", |
| 1833 | .function = lisp_add_del_locator_in_set_command_fn, |
| 1834 | }; |
| 1835 | /* *INDENT-ON* */ |
| 1836 | |
| 1837 | static clib_error_t * |
| 1838 | lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm, |
| 1839 | unformat_input_t * input, |
| 1840 | vlib_cli_command_t * cmd) |
| 1841 | { |
| 1842 | locator_set_t *lsit; |
| 1843 | locator_t *loc; |
| 1844 | u32 *locit; |
| 1845 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1846 | |
| 1847 | vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator", |
| 1848 | "Priority", "Weight"); |
| 1849 | |
| 1850 | /* *INDENT-OFF* */ |
| 1851 | pool_foreach (lsit, lcm->locator_set_pool, |
| 1852 | ({ |
| 1853 | u8 * msg = 0; |
| 1854 | int next_line = 0; |
| 1855 | if (lsit->local) |
| 1856 | { |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 1857 | msg = format (msg, "%s", lsit->name); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1858 | } |
| 1859 | else |
| 1860 | { |
| 1861 | msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool); |
| 1862 | } |
| 1863 | vec_foreach (locit, lsit->locator_indices) |
| 1864 | { |
| 1865 | if (next_line) |
| 1866 | { |
| 1867 | msg = format (msg, "%16s", " "); |
| 1868 | } |
| 1869 | loc = pool_elt_at_index (lcm->locator_pool, locit[0]); |
| 1870 | if (loc->local) |
| 1871 | msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority, |
| 1872 | loc->weight); |
| 1873 | else |
| 1874 | msg = format (msg, "%16U%16d%16d\n", format_ip_address, |
| 1875 | &gid_address_ip(&loc->address), loc->priority, |
| 1876 | loc->weight); |
| 1877 | next_line = 1; |
| 1878 | } |
| 1879 | vlib_cli_output (vm, "%v", msg); |
| 1880 | vec_free (msg); |
| 1881 | })); |
| 1882 | /* *INDENT-ON* */ |
| 1883 | return 0; |
| 1884 | } |
| 1885 | |
| 1886 | /* *INDENT-OFF* */ |
| 1887 | VLIB_CLI_COMMAND (one_cp_show_locator_sets_command) = { |
| 1888 | .path = "show one locator-set", |
| 1889 | .short_help = "Shows locator-sets", |
| 1890 | .function = lisp_cp_show_locator_sets_command_fn, |
| 1891 | }; |
| 1892 | /* *INDENT-ON* */ |
| 1893 | |
| 1894 | |
| 1895 | static clib_error_t * |
| 1896 | lisp_add_del_map_resolver_command_fn (vlib_main_t * vm, |
| 1897 | unformat_input_t * input, |
| 1898 | vlib_cli_command_t * cmd) |
| 1899 | { |
| 1900 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1901 | u8 is_add = 1, addr_set = 0; |
| 1902 | ip_address_t ip_addr; |
| 1903 | clib_error_t *error = 0; |
| 1904 | int rv = 0; |
| 1905 | vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; |
| 1906 | |
| 1907 | /* Get a line of input. */ |
| 1908 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1909 | return 0; |
| 1910 | |
| 1911 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1912 | { |
| 1913 | if (unformat (line_input, "add")) |
| 1914 | is_add = 1; |
| 1915 | else if (unformat (line_input, "del")) |
| 1916 | is_add = 0; |
| 1917 | else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr)) |
| 1918 | addr_set = 1; |
| 1919 | else |
| 1920 | { |
| 1921 | error = unformat_parse_error (line_input); |
| 1922 | goto done; |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | if (!addr_set) |
| 1927 | { |
| 1928 | error = clib_error_return (0, "Map-resolver address must be set!"); |
| 1929 | goto done; |
| 1930 | } |
| 1931 | |
| 1932 | a->is_add = is_add; |
| 1933 | a->address = ip_addr; |
| 1934 | rv = vnet_lisp_add_del_map_resolver (a); |
| 1935 | if (0 != rv) |
| 1936 | { |
| 1937 | error = clib_error_return (0, "failed to %s map-resolver!", |
| 1938 | is_add ? "add" : "delete"); |
| 1939 | } |
| 1940 | |
| 1941 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1942 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1943 | return error; |
| 1944 | } |
| 1945 | |
| 1946 | /* *INDENT-OFF* */ |
| 1947 | VLIB_CLI_COMMAND (one_add_del_map_resolver_command) = { |
| 1948 | .path = "one map-resolver", |
| 1949 | .short_help = "one map-resolver add/del <ip_address>", |
| 1950 | .function = lisp_add_del_map_resolver_command_fn, |
| 1951 | }; |
| 1952 | /* *INDENT-ON* */ |
| 1953 | |
| 1954 | |
| 1955 | static clib_error_t * |
| 1956 | lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm, |
| 1957 | unformat_input_t * input, |
| 1958 | vlib_cli_command_t * cmd) |
| 1959 | { |
| 1960 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1961 | u8 is_add = 1; |
| 1962 | u8 *locator_set_name = 0; |
| 1963 | clib_error_t *error = 0; |
| 1964 | int rv = 0; |
| 1965 | vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; |
| 1966 | |
| 1967 | /* Get a line of input. */ |
| 1968 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1969 | return 0; |
| 1970 | |
| 1971 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1972 | { |
| 1973 | if (unformat (line_input, "del")) |
| 1974 | is_add = 0; |
| 1975 | else if (unformat (line_input, "add %_%v%_", &locator_set_name)) |
| 1976 | is_add = 1; |
| 1977 | else |
| 1978 | { |
| 1979 | error = unformat_parse_error (line_input); |
| 1980 | goto done; |
| 1981 | } |
| 1982 | } |
| 1983 | |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 1984 | vec_terminate_c_string (locator_set_name); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1985 | a->is_add = is_add; |
| 1986 | a->locator_set_name = locator_set_name; |
| 1987 | rv = vnet_lisp_add_del_mreq_itr_rlocs (a); |
| 1988 | if (0 != rv) |
| 1989 | { |
| 1990 | error = clib_error_return (0, "failed to %s map-request itr-rlocs!", |
| 1991 | is_add ? "add" : "delete"); |
| 1992 | } |
| 1993 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1994 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 1995 | vec_free (locator_set_name); |
| 1996 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 1997 | return error; |
| 1998 | |
| 1999 | } |
| 2000 | |
| 2001 | /* *INDENT-OFF* */ |
| 2002 | VLIB_CLI_COMMAND (one_add_del_map_request_command) = { |
| 2003 | .path = "one map-request itr-rlocs", |
| 2004 | .short_help = "one map-request itr-rlocs add/del <locator_set_name>", |
| 2005 | .function = lisp_add_del_mreq_itr_rlocs_command_fn, |
| 2006 | }; |
| 2007 | /* *INDENT-ON* */ |
| 2008 | |
| 2009 | static clib_error_t * |
| 2010 | lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm, |
| 2011 | unformat_input_t * input, |
| 2012 | vlib_cli_command_t * cmd) |
| 2013 | { |
| 2014 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 2015 | locator_set_t *loc_set; |
| 2016 | |
| 2017 | vlib_cli_output (vm, "%=20s", "itr-rlocs"); |
| 2018 | |
| 2019 | if (~0 == lcm->mreq_itr_rlocs) |
| 2020 | { |
| 2021 | return 0; |
| 2022 | } |
| 2023 | |
| 2024 | loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); |
| 2025 | |
| 2026 | vlib_cli_output (vm, "%=20s", loc_set->name); |
| 2027 | |
| 2028 | return 0; |
| 2029 | } |
| 2030 | |
| 2031 | /* *INDENT-OFF* */ |
| 2032 | VLIB_CLI_COMMAND (one_show_map_request_command) = { |
| 2033 | .path = "show one map-request itr-rlocs", |
| 2034 | .short_help = "Shows map-request itr-rlocs", |
| 2035 | .function = lisp_show_mreq_itr_rlocs_command_fn, |
| 2036 | }; |
| 2037 | /* *INDENT-ON* */ |
| 2038 | |
| 2039 | static clib_error_t * |
| 2040 | lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm, |
| 2041 | unformat_input_t * input, |
| 2042 | vlib_cli_command_t * cmd) |
| 2043 | { |
| 2044 | u8 is_add = 1, ip_set = 0; |
| 2045 | unformat_input_t _line_input, *line_input = &_line_input; |
| 2046 | clib_error_t *error = 0; |
| 2047 | ip_address_t ip; |
| 2048 | |
| 2049 | /* Get a line of input. */ |
| 2050 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 2051 | return 0; |
| 2052 | |
| 2053 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 2054 | { |
| 2055 | if (unformat (line_input, "%U", unformat_ip_address, &ip)) |
| 2056 | ip_set = 1; |
| 2057 | else if (unformat (line_input, "disable")) |
| 2058 | is_add = 0; |
| 2059 | else |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 2060 | { |
| 2061 | error = clib_error_return (0, "parse error"); |
| 2062 | goto done; |
| 2063 | } |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | if (!ip_set) |
| 2067 | { |
| 2068 | clib_warning ("No petr IP specified!"); |
| 2069 | goto done; |
| 2070 | } |
| 2071 | |
| 2072 | if (vnet_lisp_use_petr (&ip, is_add)) |
| 2073 | { |
| 2074 | error = clib_error_return (0, "failed to %s petr!", |
| 2075 | is_add ? "add" : "delete"); |
| 2076 | } |
| 2077 | |
| 2078 | done: |
Billy McFall | 614c131 | 2017-03-01 17:01:06 -0500 | [diff] [blame] | 2079 | unformat_free (line_input); |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 2080 | return error; |
| 2081 | } |
| 2082 | |
| 2083 | /* *INDENT-OFF* */ |
| 2084 | VLIB_CLI_COMMAND (one_use_petr_set_locator_set_command) = { |
| 2085 | .path = "one use-petr", |
| 2086 | .short_help = "one use-petr [disable] <petr-ip>", |
| 2087 | .function = lisp_use_petr_set_locator_set_command_fn, |
| 2088 | }; |
| 2089 | |
| 2090 | static clib_error_t * |
| 2091 | lisp_show_petr_command_fn (vlib_main_t * vm, |
| 2092 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 2093 | { |
| 2094 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 2095 | mapping_t *m; |
| 2096 | locator_set_t *ls; |
| 2097 | locator_t *loc; |
| 2098 | u8 *tmp_str = 0; |
| 2099 | u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR; |
| 2100 | vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : ""); |
| 2101 | |
| 2102 | if (!use_petr) |
| 2103 | { |
| 2104 | vlib_cli_output (vm, "%=20s", "disable"); |
| 2105 | return 0; |
| 2106 | } |
| 2107 | |
| 2108 | if (~0 == lcm->petr_map_index) |
| 2109 | { |
| 2110 | tmp_str = format (0, "N/A"); |
| 2111 | } |
| 2112 | else |
| 2113 | { |
| 2114 | m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); |
| 2115 | if (~0 != m->locator_set_index) |
| 2116 | { |
| 2117 | ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index); |
| 2118 | loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); |
| 2119 | tmp_str = format (0, "%U", format_ip_address, &loc->address); |
| 2120 | } |
| 2121 | else |
| 2122 | { |
| 2123 | tmp_str = format (0, "N/A"); |
| 2124 | } |
| 2125 | } |
| 2126 | vec_add1 (tmp_str, 0); |
| 2127 | |
| 2128 | vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); |
| 2129 | |
| 2130 | vec_free (tmp_str); |
| 2131 | |
| 2132 | return 0; |
| 2133 | } |
| 2134 | |
| 2135 | /* *INDENT-OFF* */ |
| 2136 | VLIB_CLI_COMMAND (one_show_petr_command) = { |
| 2137 | .path = "show one petr", |
| 2138 | .short_help = "Show petr", |
| 2139 | .function = lisp_show_petr_command_fn, |
| 2140 | }; |
| 2141 | /* *INDENT-ON* */ |
| 2142 | |
| 2143 | static clib_error_t * |
| 2144 | lisp_show_map_servers_command_fn (vlib_main_t * vm, |
| 2145 | unformat_input_t * input, |
| 2146 | vlib_cli_command_t * cmd) |
| 2147 | { |
| 2148 | lisp_msmr_t *ms; |
| 2149 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 2150 | |
| 2151 | vec_foreach (ms, lcm->map_servers) |
| 2152 | { |
| 2153 | vlib_cli_output (vm, "%U", format_ip_address, &ms->address); |
| 2154 | } |
| 2155 | return 0; |
| 2156 | } |
| 2157 | |
| 2158 | /* *INDENT-OFF* */ |
| 2159 | VLIB_CLI_COMMAND (one_show_map_servers_command) = { |
| 2160 | .path = "show one map-servers", |
| 2161 | .short_help = "show one map servers", |
| 2162 | .function = lisp_show_map_servers_command_fn, |
| 2163 | }; |
| 2164 | /* *INDENT-ON* */ |
| 2165 | |
| 2166 | static clib_error_t * |
| 2167 | lisp_show_map_register_state_command_fn (vlib_main_t * vm, |
| 2168 | unformat_input_t * input, |
| 2169 | vlib_cli_command_t * cmd) |
| 2170 | { |
| 2171 | u8 *msg = 0; |
| 2172 | u8 is_enabled = vnet_lisp_map_register_state_get (); |
| 2173 | |
| 2174 | msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); |
| 2175 | vlib_cli_output (vm, "%v", msg); |
| 2176 | vec_free (msg); |
| 2177 | return 0; |
| 2178 | } |
| 2179 | |
| 2180 | /* *INDENT-OFF* */ |
| 2181 | VLIB_CLI_COMMAND (one_show_map_register_state_command) = { |
| 2182 | .path = "show one map-register state", |
| 2183 | .short_help = "show one map-register state", |
| 2184 | .function = lisp_show_map_register_state_command_fn, |
| 2185 | }; |
| 2186 | /* *INDENT-ON* */ |
| 2187 | |
| 2188 | static clib_error_t * |
| 2189 | lisp_show_rloc_probe_state_command_fn (vlib_main_t * vm, |
| 2190 | unformat_input_t * input, |
| 2191 | vlib_cli_command_t * cmd) |
| 2192 | { |
| 2193 | u8 *msg = 0; |
| 2194 | u8 is_enabled = vnet_lisp_rloc_probe_state_get (); |
| 2195 | |
| 2196 | msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); |
| 2197 | vlib_cli_output (vm, "%v", msg); |
| 2198 | vec_free (msg); |
| 2199 | return 0; |
| 2200 | } |
| 2201 | |
| 2202 | /* *INDENT-OFF* */ |
| 2203 | VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = { |
| 2204 | .path = "show one rloc state", |
| 2205 | .short_help = "show one RLOC state", |
| 2206 | .function = lisp_show_rloc_probe_state_command_fn, |
| 2207 | }; |
| 2208 | /* *INDENT-ON* */ |
| 2209 | |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 2210 | static clib_error_t * |
| 2211 | lisp_show_stats_command_fn (vlib_main_t * vm, |
| 2212 | unformat_input_t * input, |
| 2213 | vlib_cli_command_t * cmd) |
| 2214 | { |
| 2215 | u8 is_enabled = vnet_lisp_stats_enable_disable_state (); |
| 2216 | vlib_cli_output (vm, "%s\n", is_enabled ? "enabled" : "disabled"); |
| 2217 | return 0; |
| 2218 | } |
| 2219 | |
| 2220 | /* *INDENT-OFF* */ |
| 2221 | VLIB_CLI_COMMAND (one_show_stats_command) = { |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 2222 | .path = "show one statistics status", |
| 2223 | .short_help = "show ONE statistics enable/disable status", |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 2224 | .function = lisp_show_stats_command_fn, |
| 2225 | }; |
| 2226 | /* *INDENT-ON* */ |
| 2227 | |
| 2228 | static clib_error_t * |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 2229 | lisp_show_stats_details_command_fn (vlib_main_t * vm, |
| 2230 | unformat_input_t * input, |
| 2231 | vlib_cli_command_t * cmd) |
| 2232 | { |
| 2233 | lisp_api_stats_t *stat, *stats = vnet_lisp_get_stats (); |
| 2234 | |
| 2235 | if (vec_len (stats) > 0) |
| 2236 | vlib_cli_output (vm, |
| 2237 | "[src-EID, dst-EID] [loc-rloc, rmt-rloc] count bytes\n"); |
| 2238 | else |
| 2239 | vlib_cli_output (vm, "No statistics found.\n"); |
| 2240 | |
| 2241 | vec_foreach (stat, stats) |
| 2242 | { |
| 2243 | vlib_cli_output (vm, "[%U, %U] [%U, %U] %7u %7u\n", |
| 2244 | format_fid_address, &stat->seid, |
| 2245 | format_fid_address, &stat->deid, |
| 2246 | format_ip_address, &stat->loc_rloc, |
| 2247 | format_ip_address, &stat->rmt_rloc, |
Filip Tehlar | 2151191 | 2017-04-07 10:41:42 +0200 | [diff] [blame] | 2248 | stat->counters.packets, stat->counters.bytes); |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 2249 | } |
| 2250 | vec_free (stats); |
| 2251 | return 0; |
| 2252 | } |
| 2253 | |
| 2254 | /* *INDENT-OFF* */ |
| 2255 | VLIB_CLI_COMMAND (one_show_stats_details_command) = { |
| 2256 | .path = "show one statistics details", |
| 2257 | .short_help = "show ONE statistics", |
| 2258 | .function = lisp_show_stats_details_command_fn, |
| 2259 | }; |
| 2260 | /* *INDENT-ON* */ |
| 2261 | |
| 2262 | static clib_error_t * |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 2263 | lisp_stats_enable_disable_command_fn (vlib_main_t * vm, |
| 2264 | unformat_input_t * input, |
| 2265 | vlib_cli_command_t * cmd) |
| 2266 | { |
| 2267 | unformat_input_t _line_input, *line_input = &_line_input; |
| 2268 | u8 enable = 0; |
| 2269 | |
| 2270 | /* Get a line of input. */ |
| 2271 | if (!unformat_user (input, unformat_line_input, line_input)) |
Swarup Nayak | 82d8ec2 | 2017-12-04 11:54:43 +0530 | [diff] [blame] | 2272 | return clib_error_return (0, "expected enable | disable"); |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 2273 | |
| 2274 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 2275 | { |
| 2276 | if (unformat (line_input, "enable")) |
| 2277 | enable = 1; |
| 2278 | else if (unformat (line_input, "disable")) |
| 2279 | enable = 0; |
| 2280 | else |
| 2281 | { |
| 2282 | clib_warning ("Error: expected enable/disable!"); |
| 2283 | goto done; |
| 2284 | } |
| 2285 | } |
| 2286 | vnet_lisp_stats_enable_disable (enable); |
| 2287 | done: |
| 2288 | unformat_free (line_input); |
| 2289 | return 0; |
| 2290 | } |
| 2291 | |
| 2292 | /* *INDENT-OFF* */ |
| 2293 | VLIB_CLI_COMMAND (one_stats_enable_disable_command) = { |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 2294 | .path = "one statistics", |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 2295 | .short_help = "enable/disable ONE statistics collecting", |
| 2296 | .function = lisp_stats_enable_disable_command_fn, |
| 2297 | }; |
| 2298 | /* *INDENT-ON* */ |
| 2299 | |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 2300 | static clib_error_t * |
| 2301 | lisp_stats_flush_command_fn (vlib_main_t * vm, |
| 2302 | unformat_input_t * input, |
| 2303 | vlib_cli_command_t * cmd) |
| 2304 | { |
| 2305 | vnet_lisp_flush_stats (); |
| 2306 | return 0; |
| 2307 | } |
| 2308 | |
| 2309 | /* *INDENT-OFF* */ |
| 2310 | VLIB_CLI_COMMAND (one_stats_flush_command) = { |
| 2311 | .path = "one statistics flush", |
| 2312 | .short_help = "Flush ONE statistics", |
| 2313 | .function = lisp_stats_flush_command_fn, |
| 2314 | }; |
| 2315 | /* *INDENT-ON* */ |
| 2316 | |
Filip Tehlar | 0a8840d | 2017-10-16 05:48:23 -0700 | [diff] [blame] | 2317 | static clib_error_t * |
| 2318 | lisp_show_one_modes_command_fn (vlib_main_t * vm, |
| 2319 | unformat_input_t * input, |
| 2320 | vlib_cli_command_t * cmd) |
| 2321 | { |
| 2322 | u8 pitr_mode = vnet_lisp_get_pitr_mode (); |
| 2323 | u8 petr_mode = vnet_lisp_get_petr_mode (); |
| 2324 | u8 xtr_mode = vnet_lisp_get_xtr_mode (); |
| 2325 | |
| 2326 | vlib_cli_output (vm, "xTR: %s\n", xtr_mode ? "enabled" : "disabled"); |
| 2327 | vlib_cli_output (vm, "P-ITR: %s\n", pitr_mode ? "enabled" : "disabled"); |
| 2328 | vlib_cli_output (vm, "P-ETR: %s\n", petr_mode ? "enabled" : "disabled"); |
| 2329 | |
| 2330 | return 0; |
| 2331 | } |
| 2332 | |
| 2333 | /* *INDENT-OFF* */ |
| 2334 | VLIB_CLI_COMMAND (one_cp_show_one_modes_modes_command) = { |
| 2335 | .path = "show one modes", |
| 2336 | .short_help = "show one modes", |
| 2337 | .function = lisp_show_one_modes_command_fn, |
| 2338 | }; |
| 2339 | /* *INDENT-ON* */ |
| 2340 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 2341 | /* |
| 2342 | * fd.io coding-style-patch-verification: ON |
| 2343 | * |
| 2344 | * Local Variables: |
| 2345 | * eval: (c-set-style "gnu") |
| 2346 | * End: |
| 2347 | */ |