diff options
Diffstat (limited to 'hicn-plugin/src/cli.c')
-rw-r--r-- | hicn-plugin/src/cli.c | 642 |
1 files changed, 341 insertions, 301 deletions
diff --git a/hicn-plugin/src/cli.c b/hicn-plugin/src/cli.c index 1adf3595c..64ebf61a4 100644 --- a/hicn-plugin/src/cli.c +++ b/hicn-plugin/src/cli.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 Cisco and/or its affiliates. + * Copyright (c) 2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -19,9 +19,12 @@ #include <vlibmemory/api.h> #include <vnet/udp/udp.h> // port registration -#include <vnet/ip/ip6_packet.h> // ip46_address_t +#include <vnet/ip/ip6_packet.h> // ip46_address_t #include <vnet/ip/format.h> #include <vnet/fib/fib_types.h> +#include <vnet/pg/pg.h> + +#include <vpp_plugins/hicn/hicn_api.h> #include "hicn.h" #include "infra.h" @@ -33,7 +36,7 @@ #include "error.h" #include "faces/face.h" #include "route.h" -#include "hicn_api.h" +#include "mapme.h" static vl_api_hicn_api_node_params_set_t node_ctl_params = { .pit_max_size = -1, @@ -51,32 +54,31 @@ typedef enum * cli handler for 'control start' */ static clib_error_t * -hicn_cli_node_ctl_start_set_command_fn (vlib_main_t * vm, - unformat_input_t * main_input, - vlib_cli_command_t * cmd) +hicn_cli_node_ctl_start_set_command_fn (vlib_main_t *vm, + unformat_input_t *main_input, + vlib_cli_command_t *cmd) { int ret; - ret = hicn_infra_plugin_enable_disable (1 /* enable */ , - node_ctl_params.pit_max_size, - node_ctl_params.pit_max_lifetime_sec, - node_ctl_params.cs_max_size, ~0); + ret = hicn_infra_plugin_enable_disable ( + 1 /* enable */, node_ctl_params.pit_max_size, + node_ctl_params.pit_max_lifetime_sec, node_ctl_params.cs_max_size, ~0); vlib_cli_output (vm, "hicn: fwdr initialize => %s\n", get_error_string (ret)); - return (ret == HICN_ERROR_NONE) ? 0 : clib_error_return (0, - get_error_string - (ret)); + return (ret == HICN_ERROR_NONE) ? + 0 : + clib_error_return (0, get_error_string (ret)); } /* * cli handler for 'control stop' */ static clib_error_t * -hicn_cli_node_ctl_stop_set_command_fn (vlib_main_t * vm, - unformat_input_t * main_input, - vlib_cli_command_t * cmd) +hicn_cli_node_ctl_stop_set_command_fn (vlib_main_t *vm, + unformat_input_t *main_input, + vlib_cli_command_t *cmd) { int ret; @@ -92,39 +94,37 @@ hicn_cli_node_ctl_stop_set_command_fn (vlib_main_t * vm, { return (0); } - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + if (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { return clib_error_return (0, "%s '%U'", get_error_string (HICN_ERROR_CLI_INVAL), format_unformat_error, line_input); } } - ret = hicn_infra_plugin_enable_disable (0 /* !enable */ , - node_ctl_params.pit_max_size, - node_ctl_params.pit_max_lifetime_sec, - node_ctl_params.cs_max_size, ~0); + ret = hicn_infra_plugin_enable_disable ( + 0 /* !enable */, node_ctl_params.pit_max_size, + node_ctl_params.pit_max_lifetime_sec, node_ctl_params.cs_max_size, ~0); - return (ret == HICN_ERROR_NONE) ? 0 : clib_error_return (0, - get_error_string - (ret)); + return (ret == HICN_ERROR_NONE) ? + 0 : + clib_error_return (0, get_error_string (ret)); } -#define DFLTD_RANGE_OK(val, min, max) \ -({ \ - __typeof__ (val) _val = (val); \ - __typeof__ (min) _min = (min); \ - __typeof__ (max) _max = (max); \ - (_val == -1) || \ - (_val >= _min && _val <= _max); \ -}) +#define DFLTD_RANGE_OK(val, min, max) \ + ({ \ + __typeof__ (val) _val = (val); \ + __typeof__ (min) _min = (min); \ + __typeof__ (max) _max = (max); \ + (_val == -1) || (_val >= _min && _val <= _max); \ + }) /* * cli handler for 'control param' */ static clib_error_t * -hicn_cli_node_ctl_param_set_command_fn (vlib_main_t * vm, - unformat_input_t * main_input, - vlib_cli_command_t * cmd) +hicn_cli_node_ctl_param_set_command_fn (vlib_main_t *vm, + unformat_input_t *main_input, + vlib_cli_command_t *cmd) { int rv = 0; @@ -133,16 +133,15 @@ hicn_cli_node_ctl_param_set_command_fn (vlib_main_t * vm, if (hicn_main.is_enabled) { - return (clib_error_return - (0, "params cannot be altered once hicn started")); + return ( + clib_error_return (0, "params cannot be altered once hicn started")); } /* Get a line of input. */ unformat_input_t _line_input, *line_input = &_line_input; if (!unformat_user (main_input, unformat_line_input, line_input)) { - return clib_error_return (0, - get_error_string - (HICN_ERROR_FWD_ALREADY_ENABLED)); + return clib_error_return ( + 0, get_error_string (HICN_ERROR_FWD_ALREADY_ENABLED)); } while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { @@ -160,9 +159,9 @@ hicn_cli_node_ctl_param_set_command_fn (vlib_main_t * vm, } else if (unformat (line_input, "maxlife %f", &lifetime)) { - if (!DFLTD_RANGE_OK - (lifetime, HICN_PARAM_PIT_LIFETIME_BOUND_MIN_SEC, - HICN_PARAM_PIT_LIFETIME_BOUND_MAX_SEC)) + if (!DFLTD_RANGE_OK (lifetime, + HICN_PARAM_PIT_LIFETIME_BOUND_MIN_SEC, + HICN_PARAM_PIT_LIFETIME_BOUND_MAX_SEC)) { rv = HICN_ERROR_PIT_CONFIG_MAXLT_OOB; break; @@ -201,25 +200,24 @@ hicn_cli_node_ctl_param_set_command_fn (vlib_main_t * vm, } if (node_ctl_params.cs_max_size == 0) - vlib_cli_output (vm, - "CS size set to 0. Consider disable CS at compilation time for better performances\n"); - - return (rv == HICN_ERROR_NONE) ? 0 : clib_error_return (0, "%s '%U'", - get_error_string - (rv), - format_unformat_error, - line_input); + vlib_cli_output (vm, "CS size set to 0. Consider disable CS at " + "compilation time for better performances\n"); + + return (rv == HICN_ERROR_NONE) ? + 0 : + clib_error_return (0, "%s '%U'", get_error_string (rv), + format_unformat_error, line_input); } /* * cli handler for 'hicn show' */ static clib_error_t * -hicn_cli_show_command_fn (vlib_main_t * vm, unformat_input_t * main_input, - vlib_cli_command_t * cmd) +hicn_cli_show_command_fn (vlib_main_t *vm, unformat_input_t *main_input, + vlib_cli_command_t *cmd) { - int face_p = 0, fib_p = 0, all_p, internal_p = 0, strategies_p = 0, ret = - HICN_ERROR_NONE; + int face_p = 0, fib_p = 0, all_p = 0, strategies_p = 0, + ret = HICN_ERROR_NONE; /* Get a line of input. */ unformat_input_t _line_input, *line_input = &_line_input; @@ -231,14 +229,6 @@ hicn_cli_show_command_fn (vlib_main_t * vm, unformat_input_t * main_input, { face_p = 1; } - else if (unformat (line_input, "internal")) - { - /* - * We consider 'internal' a superset, so - * include 'detail' too - */ - internal_p = 1; - } else if (unformat (line_input, "strategies")) { /* @@ -294,8 +284,7 @@ hicn_cli_show_command_fn (vlib_main_t * vm, unformat_input_t * main_input, " PIT:: max entries:%d," " lifetime default: max:%05.3f\n" " CS:: max entries:%d\n", - hicn_main.is_enabled ? "en" : "dis", - hicn_infra_pit_size, + hicn_main.is_enabled ? "en" : "dis", hicn_infra_pit_size, ((f64) hicn_main.pit_lifetime_max_ms) / SEC_MS, hicn_infra_cs_size); @@ -303,25 +292,26 @@ hicn_cli_show_command_fn (vlib_main_t * vm, unformat_input_t * main_input, , *rmp = &rm; if (hicn_mgmt_node_stats_get (&rm) == HICN_ERROR_NONE) { - vlib_cli_output (vm, //compare vl_api_hicn_api_node_stats_get_reply_t_handler block - " PIT entries (now): %d\n" - " CS total entries (now): %d, network entries (now): %d\n" - " Forwarding statistics:\n" - " pkts_processed: %d\n" - " pkts_interest_count: %d\n" - " pkts_data_count: %d\n" - " pkts_from_cache_count: %d\n" - " interests_aggregated: %d\n" - " interests_retransmitted: %d\n", - clib_net_to_host_u64 (rmp->pit_entries_count), - clib_net_to_host_u64 (rmp->cs_entries_count), - clib_net_to_host_u64 (rmp->cs_entries_ntw_count), - clib_net_to_host_u64 (rmp->pkts_processed), - clib_net_to_host_u64 (rmp->pkts_interest_count), - clib_net_to_host_u64 (rmp->pkts_data_count), - clib_net_to_host_u64 (rmp->pkts_from_cache_count), - clib_net_to_host_u64 (rmp->interests_aggregated), - clib_net_to_host_u64 (rmp->interests_retx)); + vlib_cli_output ( + vm, // compare vl_api_hicn_api_node_stats_get_reply_t_handler block + " PIT entries (now): %d\n" + " CS total entries (now): %d, network entries (now): %d\n" + " Forwarding statistics:\n" + " pkts_processed: %d\n" + " pkts_interest_count: %d\n" + " pkts_data_count: %d\n" + " pkts_from_cache_count: %d\n" + " interests_aggregated: %d\n" + " interests_retransmitted: %d\n", + clib_net_to_host_u64 (rmp->pit_entries_count), + clib_net_to_host_u64 (rmp->cs_entries_count), + clib_net_to_host_u64 (rmp->cs_entries_ntw_count), + clib_net_to_host_u64 (rmp->pkts_processed), + clib_net_to_host_u64 (rmp->pkts_interest_count), + clib_net_to_host_u64 (rmp->pkts_data_count), + clib_net_to_host_u64 (rmp->pkts_from_cache_count), + clib_net_to_host_u64 (rmp->interests_aggregated), + clib_net_to_host_u64 (rmp->interests_retx)); } if (face_p || all_p) { @@ -329,7 +319,6 @@ hicn_cli_show_command_fn (vlib_main_t * vm, unformat_input_t * main_input, strbuf = format_hicn_face_all (strbuf, 1, 0); vlib_cli_output (vm, "%s", strbuf); - } if (strategies_p || all_p) { @@ -339,32 +328,95 @@ hicn_cli_show_command_fn (vlib_main_t * vm, unformat_input_t * main_input, vlib_cli_output (vm, (char *) strbuf); } done: - if (all_p && internal_p && ret == HICN_ERROR_NONE) - { - vlib_cli_output (vm, "Plugin features: cs:%d\n", HICN_FEATURE_CS); - vlib_cli_output (vm, - "Removed CS entries (and freed vlib buffers) %d, Removed PIT entries %d\n", - hicn_main.pitcs.pcs_cs_dealloc, - hicn_main.pitcs.pcs_pit_dealloc); - vlib_cli_output (vm, - "Bucke count %d, Overflow buckets count %d, used %d\n", - hicn_main.pitcs.pcs_table->ht_bucket_count, - hicn_main.pitcs.pcs_table->ht_overflow_bucket_count, - hicn_main.pitcs.pcs_table->ht_overflow_buckets_used); - - } - return (ret == HICN_ERROR_NONE) ? 0 : clib_error_return (0, "%s\n", - get_error_string - (ret)); + return (ret == HICN_ERROR_NONE) ? + 0 : + clib_error_return (0, "%s\n", get_error_string (ret)); +} + +/* + * cli handler for 'mapme' + */ +static clib_error_t * +hicn_cli_mapme_set_command_fn (vlib_main_t *vm, unformat_input_t *main_input, + vlib_cli_command_t *cmd) +{ + clib_error_t *cl_err = 0; + fib_prefix_t prefix; + + /* Get a line of input. */ + unformat_input_t _line_input, *line_input = &_line_input; + if (!unformat_user (main_input, unformat_line_input, line_input)) + { + return (0); + } + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "default-route %U/%d", unformat_ip46_address, + &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len)) + { + ; + } + else + { + return clib_error_return (0, "%s '%U'", + get_error_string (HICN_ERROR_CLI_INVAL), + format_unformat_error, line_input); + } + } + + prefix.fp_proto = ip46_address_is_ip4 (&prefix.fp_addr) ? FIB_PROTOCOL_IP4 : + FIB_PROTOCOL_IP6; + + hicn_mapme_main_t *mapme_main = hicn_mapme_get_main (); + mapme_main->default_route = prefix; + + return (cl_err); +} + +static clib_error_t * +hicn_cli_mapme_get_command_fn (vlib_main_t *vm, unformat_input_t *main_input, + vlib_cli_command_t *cmd) +{ + hicn_mapme_main_t *mm = hicn_mapme_get_main (); + int default_route = 0; + clib_error_t *cl_err = 0; + + /* Get a line of input. */ + unformat_input_t _line_input, *line_input = &_line_input; + if (!unformat_user (main_input, unformat_line_input, line_input)) + { + return (0); + } + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "default-route")) + { + default_route = 1; + } + else + { + return clib_error_return (0, "%s '%U'", + get_error_string (HICN_ERROR_CLI_INVAL), + format_unformat_error, line_input); + } + } + + if (default_route) + { + vlib_cli_output (vm, "Mapme default route: '%U'", format_fib_prefix, + &mm->default_route); + } + + return cl_err; } /* * cli handler for 'fib' */ static clib_error_t * -hicn_cli_strategy_set_command_fn (vlib_main_t * vm, - unformat_input_t * main_input, - vlib_cli_command_t * cmd) +hicn_cli_strategy_set_command_fn (vlib_main_t *vm, + unformat_input_t *main_input, + vlib_cli_command_t *cmd) { clib_error_t *cl_err = 0; @@ -387,10 +439,11 @@ hicn_cli_strategy_set_command_fn (vlib_main_t * vm, { addpfx = 2; } - else if (addpfx != -1 - && unformat (line_input, "prefix %U/%d", unformat_ip46_address, - &address, IP46_TYPE_ANY, &plen)) - {; + else if (addpfx != -1 && + unformat (line_input, "prefix %U/%d", unformat_ip46_address, + &address, IP46_TYPE_ANY, &plen)) + { + ; } else { @@ -412,10 +465,9 @@ hicn_cli_strategy_set_command_fn (vlib_main_t * vm, } rv = hicn_route_set_strategy (&prefix, strategy_id); - cl_err = - (rv == HICN_ERROR_NONE) ? NULL : clib_error_return (0, - get_error_string - (rv)); + cl_err = (rv == HICN_ERROR_NONE) ? + NULL : + clib_error_return (0, get_error_string (rv)); done: return (cl_err); @@ -425,9 +477,9 @@ done: * cli handler for 'pgen' */ static clib_error_t * -hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, - unformat_input_t * main_input, - vlib_cli_command_t * cmd) +hicn_cli_pgen_client_set_command_fn (vlib_main_t *vm, + unformat_input_t *main_input, + vlib_cli_command_t *cmd) { hicnpg_main_t *hpgm = &hicnpg_main; ip46_address_t src_addr; @@ -446,14 +498,13 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, { while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat - (line_input, "intfc %U", unformat_vnet_sw_interface, vnm, - &sw_if_index)) + if (unformat (line_input, "intfc %U", unformat_vnet_sw_interface, + vnm, &sw_if_index)) { ; } - else if (unformat (line_input, "src %U", - unformat_ip46_address, &src_addr)) + else if (unformat (line_input, "src %U", unformat_ip46_address, + &src_addr)) { ; } @@ -461,9 +512,8 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, { ; } - else if (unformat (line_input, "name %U/%d", - unformat_ip46_address, &prefix->fp_addr, - IP46_TYPE_ANY, &prefix->fp_len)) + else if (unformat (line_input, "name %U/%d", unformat_ip46_address, + &prefix->fp_addr, IP46_TYPE_ANY, &prefix->fp_len)) { ; } @@ -481,9 +531,8 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, } else { - return (clib_error_return - (0, "Unknown input '%U'", format_unformat_error, - line_input)); + return (clib_error_return (0, "Unknown input '%U'", + format_unformat_error, line_input)); break; } } @@ -495,7 +544,7 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, return (clib_error_return (0, "Packet generator interface missing")); } - //Remove bits that are out of the subnet + // Remove bits that are out of the subnet if (ip46_address_is_ip4 (&prefix->fp_addr)) { ip4_address_t mask; @@ -517,34 +566,32 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, /* * Enable the feature to divert data packet to the hicnpg-data node to count * how many data packets have been received. - * Diver all the packets from the packet-generator to the hicn-pg-interest node - * to generate valid interests. + * Diver all the packets from the packet-generator to the hicn-pg-interest + * node to generate valid interests. */ - if (ip46_address_is_ip4 (&src_addr) - && ip46_address_is_ip4 (&prefix->fp_addr)) + if (ip46_address_is_ip4 (&src_addr) && + ip46_address_is_ip4 (&prefix->fp_addr)) { prefix->fp_proto = FIB_PROTOCOL_IP4; - vnet_feature_enable_disable ("ip4-unicast", "hicnpg-data", - sw_if_index, 1, 0, 0); + vnet_feature_enable_disable ("ip4-unicast", "hicnpg-data", sw_if_index, + 1, 0, 0); /* Add pgen_client node to the vpp graph */ - vlib_node_add_next (vm, - pg_input_node.index, hicn_pg_interest_node.index); - + vlib_node_add_next (vm, pg_input_node.index, + hicn_pg_interest_node.index); pg_node_t *pn; pn = pg_get_node (hicn_pg_interest_node.index); pn->unformat_edit = unformat_pg_ip4_header; - } - else if (!ip46_address_is_ip4 (&src_addr) - && !ip46_address_is_ip4 (&prefix->fp_addr)) + else if (!ip46_address_is_ip4 (&src_addr) && + !ip46_address_is_ip4 (&prefix->fp_addr)) { prefix->fp_proto = FIB_PROTOCOL_IP6; - vnet_feature_enable_disable ("ip6-unicast", "hicnpg-data", - sw_if_index, 1, 0, 0); + vnet_feature_enable_disable ("ip6-unicast", "hicnpg-data", sw_if_index, + 1, 0, 0); /* Add pgen_client node to the vpp graph */ vlib_node_add_next (vm, pg_input_node.index, @@ -556,12 +603,11 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, } else { - return (clib_error_return - (0, - "pg interface source address, source address and hicn name must be of the same type IPv4 or IPv6")); + return (clib_error_return ( + 0, "pg interface source address, source address and hicn name must be " + "of the same type IPv4 or IPv6")); } - hpgm->pgen_clt_src_addr = src_addr; hpgm->pgen_clt_hicn_name = prefix; hpgm->max_seq_number = max_seq; @@ -591,17 +637,19 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, * cli handler for 'pgen' */ static clib_error_t * -hicn_cli_pgen_server_set_command_fn (vlib_main_t * vm, - unformat_input_t * main_input, - vlib_cli_command_t * cmd) +hicn_cli_pgen_server_set_command_fn (vlib_main_t *vm, + unformat_input_t *main_input, + vlib_cli_command_t *cmd) { - clib_error_t *cl_err; - int rv = HICN_ERROR_NONE; - hicnpg_server_main_t *pg_main = &hicnpg_server_main; int payload_size = 1440; u32 sw_if_index = ~0; vnet_main_t *vnm = vnet_get_main (); - fib_prefix_t *prefix = calloc (1, sizeof (fib_prefix_t)); + fib_prefix_t prefix = {}; + u32 hicnpg_server_index; + ip46_address_t locator; + + locator.as_u64[0] = 0; + locator.as_u64[1] = 0; /* Get a line of input. */ unformat_input_t _line_input, *line_input = &_line_input; @@ -610,106 +658,83 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t * vm, /* Parse the arguments */ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "name %U/%d", - unformat_ip46_address, &prefix->fp_addr, - IP46_TYPE_ANY, &prefix->fp_len)) - {; + if (unformat (line_input, "name %U/%d", unformat_ip46_address, + &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len)) + { + ; } else if (unformat (line_input, "size %d", &payload_size)) { if (payload_size > 1440) { - return (clib_error_return (0, - "Payload size must be <= 1440 bytes...")); + return (clib_error_return ( + 0, "Payload size must be <= 1440 bytes...")); } } - else - if (unformat - (line_input, "intfc %U", unformat_vnet_sw_interface, vnm, - &sw_if_index)) + else if (unformat (line_input, "intfc %U", + unformat_vnet_sw_interface, vnm, &sw_if_index)) + { + ; + } + else if (unformat (line_input, "dst %U", unformat_ip46_address, + &locator, IP46_TYPE_ANY)) { ; } else { - return (clib_error_return - (0, "Unknown input '%U'", format_unformat_error, - line_input)); + return (clib_error_return (0, "Unknown input '%U'", + format_unformat_error, line_input)); break; } } } /* Attach our packet-gen node for ip4 udp local traffic */ - if ((prefix->fp_addr.ip6.as_u64[0] == (u64) 0 - && prefix->fp_addr.ip6.as_u64[1] == 0) || payload_size == 0 - || sw_if_index == ~0) + if ((prefix.fp_addr.ip6.as_u64[0] == (u64) 0 && + prefix.fp_addr.ip6.as_u64[1] == 0) || + payload_size == 0 || sw_if_index == ~0 || + ip46_address_is_zero (&locator)) { - return clib_error_return (0, - "Error: must supply local port, payload size and incoming hICN prefix"); + return clib_error_return (0, "Error: must supply locator, payload " + "size and incoming hICN prefix"); } - //Remove bits that are out of the subnet - if (ip46_address_is_ip4 (&prefix->fp_addr)) + // Remove bits that are out of the subnet + if (ip46_address_is_ip4 (&prefix.fp_addr)) { ip4_address_t mask; - ip4_preflen_to_mask (prefix->fp_len, &mask); - prefix->fp_addr.ip4.as_u32 = prefix->fp_addr.ip4.as_u32 & mask.as_u32; - prefix->fp_proto = FIB_PROTOCOL_IP4; + ip4_preflen_to_mask (prefix.fp_len, &mask); + prefix.fp_addr.ip4.as_u32 = prefix.fp_addr.ip4.as_u32 & mask.as_u32; + prefix.fp_proto = FIB_PROTOCOL_IP4; } else { ip6_address_t mask; - ip6_preflen_to_mask (prefix->fp_len, &mask); - prefix->fp_addr.ip6.as_u64[0] = - prefix->fp_addr.ip6.as_u64[0] & mask.as_u64[0]; - prefix->fp_addr.ip6.as_u64[1] = - prefix->fp_addr.ip6.as_u64[1] & mask.as_u64[1]; - prefix->fp_proto = FIB_PROTOCOL_IP6; + ip6_preflen_to_mask (prefix.fp_len, &mask); + prefix.fp_addr.ip6.as_u64[0] = + prefix.fp_addr.ip6.as_u64[0] & mask.as_u64[0]; + prefix.fp_addr.ip6.as_u64[1] = + prefix.fp_addr.ip6.as_u64[1] & mask.as_u64[1]; + prefix.fp_proto = FIB_PROTOCOL_IP6; } - /* Allocate the buffer with the actual content payload TLV */ - int n_buf = vlib_buffer_alloc (vm, &pg_main->pgen_svr_buffer_idx, 1); - - if (n_buf == 0) + fib_protocol_t dest_proto = + ip46_address_is_ip4 (&locator) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; + if (prefix.fp_proto != dest_proto) { - return (clib_error_return (0, "Impossible to allocate paylod buffer.")); + return clib_error_return (0, "Error: prefix and locator must be of the " + "same protocol"); } - vlib_buffer_t *rb = NULL; - rb = vlib_get_buffer (vm, pg_main->pgen_svr_buffer_idx); - - pg_main->pgen_srv_hicn_name = prefix; - - /* Initialize the buffer data with zeros */ - memset (rb->data, 0, payload_size); - rb->current_length = payload_size; - - vnet_feature_enable_disable ("ip4-unicast", "hicnpg-server", - sw_if_index, 1, 0, 0); - vnet_feature_enable_disable ("ip6-unicast", "hicnpg-server", - sw_if_index, 1, 0, 0); - - switch (rv) - { - case 0: - cl_err = 0; - break; - - case VNET_API_ERROR_UNIMPLEMENTED: - cl_err = clib_error_return (0, "Unimplemented, NYI"); - break; - - default: - cl_err = clib_error_return (0, "hicn pgen server returned %d", rv); - } - - return cl_err; + // Create hicnpg_server + return hicnpg_server_add_and_lock (&prefix, &hicnpg_server_index, &locator, + payload_size); } static clib_error_t * -hicn_enable_command_fn (vlib_main_t * vm, unformat_input_t * main_input, - vlib_cli_command_t * cmd) +hicn_enable_command_fn (vlib_main_t *vm, unformat_input_t *main_input, + vlib_cli_command_t *cmd) { clib_error_t *cl_err = 0; @@ -724,13 +749,13 @@ hicn_enable_command_fn (vlib_main_t * vm, unformat_input_t * main_input, } while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "%U/%d", - unformat_ip4_address, &pfx.fp_addr.ip4, &pfx.fp_len)) + if (unformat (line_input, "%U/%d", unformat_ip4_address, + &pfx.fp_addr.ip4, &pfx.fp_len)) { pfx.fp_proto = FIB_PROTOCOL_IP4; } - else if (unformat (line_input, "%U/%d", - unformat_ip6_address, &pfx.fp_addr.ip6, &pfx.fp_len)) + else if (unformat (line_input, "%U/%d", unformat_ip6_address, + &pfx.fp_addr.ip6, &pfx.fp_len)) { pfx.fp_proto = FIB_PROTOCOL_IP6; } @@ -742,19 +767,33 @@ hicn_enable_command_fn (vlib_main_t * vm, unformat_input_t * main_input, goto done; } } - rv = hicn_route_enable (&pfx); + + hicn_face_id_t *vec_faces = NULL; + fib_node_index_t hicn_fib_index; + rv = hicn_route_enable (&pfx, &hicn_fib_index, &vec_faces); + + if (vec_faces != NULL) + { + hicn_face_id_t *face_id; + u8 *str = 0; + vec_foreach (face_id, vec_faces) + { + str = format (str, " %d", *face_id); + } + vec_free (vec_faces); + vlib_cli_output (vm, "Faces for this prefix: %s", str); + } done: - cl_err = - (rv == HICN_ERROR_NONE) ? NULL : clib_error_return (0, - get_error_string - (rv)); + cl_err = (rv == HICN_ERROR_NONE) ? + NULL : + clib_error_return (0, get_error_string (rv)); return cl_err; } static clib_error_t * -hicn_disable_command_fn (vlib_main_t * vm, unformat_input_t * main_input, - vlib_cli_command_t * cmd) +hicn_disable_command_fn (vlib_main_t *vm, unformat_input_t *main_input, + vlib_cli_command_t *cmd) { clib_error_t *cl_err = 0; @@ -769,13 +808,13 @@ hicn_disable_command_fn (vlib_main_t * vm, unformat_input_t * main_input, } while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "%U/%d", - unformat_ip4_address, &pfx.fp_addr.ip4, &pfx.fp_len)) + if (unformat (line_input, "%U/%d", unformat_ip4_address, + &pfx.fp_addr.ip4, &pfx.fp_len)) { pfx.fp_proto = FIB_PROTOCOL_IP4; } - else if (unformat (line_input, "%U/%d", - unformat_ip6_address, &pfx.fp_addr.ip6, &pfx.fp_len)) + else if (unformat (line_input, "%U/%d", unformat_ip6_address, + &pfx.fp_addr.ip6, &pfx.fp_len)) { pfx.fp_proto = FIB_PROTOCOL_IP6; } @@ -791,103 +830,104 @@ hicn_disable_command_fn (vlib_main_t * vm, unformat_input_t * main_input, rv = hicn_route_disable (&pfx); done: - cl_err = - (rv == HICN_ERROR_NONE) ? NULL : clib_error_return (0, - get_error_string - (rv)); + cl_err = (rv == HICN_ERROR_NONE) ? + NULL : + clib_error_return (0, get_error_string (rv)); return cl_err; } +/* cli declaration for 'mapme set default_route' */ +VLIB_CLI_COMMAND (hicn_cli_mapme_set_command, static) = { + .path = "hicn mapme set", + .short_help = "hicn mapme set default-route <prefix>", + .function = hicn_cli_mapme_set_command_fn, +}; -/* cli declaration for 'control start' */ -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND(hicn_cli_node_ctl_start_set_command, static)= -{ - .path = "hicn control start", - .short_help = "hicn control start", - .function = hicn_cli_node_ctl_start_set_command_fn, +VLIB_CLI_COMMAND (hicn_cli_mapme_get_command, static) = { + .path = "hicn mapme get", + .short_help = "hicn mapme get default-route", + .function = hicn_cli_mapme_get_command_fn, }; +/* cli declaration for 'control start' */ +VLIB_CLI_COMMAND (hicn_cli_node_ctl_start_set_command, static) = { + .path = "hicn control start", + .short_help = "hicn control start", + .function = hicn_cli_node_ctl_start_set_command_fn, +}; /* cli declaration for 'control stop' */ -VLIB_CLI_COMMAND(hicn_cli_node_ctl_stop_set_command, static)= -{ - .path = "hicn control stop", - .short_help = "hicn control stop", - .function = hicn_cli_node_ctl_stop_set_command_fn, +VLIB_CLI_COMMAND (hicn_cli_node_ctl_stop_set_command, static) = { + .path = "hicn control stop", + .short_help = "hicn control stop", + .function = hicn_cli_node_ctl_stop_set_command_fn, }; - /* cli declaration for 'control param' */ -VLIB_CLI_COMMAND(hicn_cli_node_ctl_param_set_command, static)= -{ - .path = "hicn control param", - .short_help = "hicn control param { pit { size <entries> | { dfltlife | minlife | maxlife } <seconds> } | fib size <entries> | cs {size <entries> | app <portion to reserved to app>} }\n", - .function = hicn_cli_node_ctl_param_set_command_fn, +VLIB_CLI_COMMAND (hicn_cli_node_ctl_param_set_command, static) = { + .path = "hicn control param", + .short_help = "hicn control param { pit { size <entries> | { dfltlife | " + "minlife | maxlife } <seconds> } | fib size <entries> | cs " + "{size <entries> | app <portion to reserved to app>} }\n", + .function = hicn_cli_node_ctl_param_set_command_fn, }; /* cli declaration for 'control' (root path of multiple commands, for help) */ -VLIB_CLI_COMMAND(hicn_cli_node_ctl_command, static)= -{ - .path = "hicn control", - .short_help = "hicn control" -}; +VLIB_CLI_COMMAND (hicn_cli_node_ctl_command, + static) = { .path = "hicn control", + .short_help = "hicn control" }; /* cli declaration for 'fib' */ -VLIB_CLI_COMMAND(hicn_cli_strategy_set_command, static)= - { - .path = "hicn strategy", - .short_help = "hicn strategy set <strategy_id> prefix <prefix>", - .function = hicn_cli_strategy_set_command_fn, - }; +VLIB_CLI_COMMAND (hicn_cli_strategy_set_command, static) = { + .path = "hicn strategy", + .short_help = "hicn strategy set <strategy_id> prefix <prefix>", + .function = hicn_cli_strategy_set_command_fn, +}; /* cli declaration for 'show' */ -VLIB_CLI_COMMAND(hicn_cli_show_command, static)= -{ - .path = "hicn show", - .short_help = "hicn show " - "[internal]" - "[strategies]", - .function = hicn_cli_show_command_fn, +VLIB_CLI_COMMAND (hicn_cli_show_command, static) = { + .path = "hicn show", + .short_help = "hicn show " + "[internal]" + "[strategies]", + .function = hicn_cli_show_command_fn, }; /* cli declaration for 'hicn pgen client' */ -VLIB_CLI_COMMAND(hicn_cli_pgen_client_set_command, static)= -{ - .path = "hicn pgen client", - .short_help = "hicn pgen client src <src_addr> name <prefix> { n_ifaces <n_ifaces> lifetime <interest-lifetime> intfc <data in-interface> max_seq <max sequence number> n_flows <number of flows>}", - .long_help = "Run hicn in packet-gen client mode\n", - .function = hicn_cli_pgen_client_set_command_fn, +VLIB_CLI_COMMAND (hicn_cli_pgen_client_set_command, static) = { + .path = "hicn pgen client", + .short_help = + "hicn pgen client src <src_addr> name <prefix> { n_ifaces <n_ifaces> " + "lifetime <interest-lifetime> intfc <data in-interface> max_seq <max " + "sequence number> n_flows <number of flows>}", + .long_help = "Run hicn in packet-gen client mode\n", + .function = hicn_cli_pgen_client_set_command_fn, }; /* cli declaration for 'hicn pgen client' */ -VLIB_CLI_COMMAND(hicn_cli_pgen_server_set_command, static)= -{ - .path = "hicn pgen server", - .short_help = "hicn pgen server name <prefix> intfc <interest in-interface> size <payload_size>", - .long_help = "Run hicn in packet-gen server mode\n", - .function = hicn_cli_pgen_server_set_command_fn, +VLIB_CLI_COMMAND (hicn_cli_pgen_server_set_command, static) = { + .path = "hicn pgen server", + .short_help = "hicn pgen server name <prefix> intfc <interest in-interface> " + "dst <ip_address> size <payload_size>", + .long_help = "Run hicn in packet-gen server mode\n", + .function = hicn_cli_pgen_server_set_command_fn, }; /* cli declaration for 'hicn pgen client' */ -VLIB_CLI_COMMAND(hicn_enable_command, static)= - { - .path = "hicn enable", - .short_help = "hicn enable <prefix>", - .long_help = "Enable hicn for the give prefix\n", - .function = hicn_enable_command_fn, - }; +VLIB_CLI_COMMAND (hicn_enable_command, static) = { + .path = "hicn enable", + .short_help = "hicn enable <prefix>", + .long_help = "Enable hicn for the give prefix\n", + .function = hicn_enable_command_fn, +}; /* cli declaration for 'hicn pgen client' */ -VLIB_CLI_COMMAND(hicn_disable_command, static)= - { - .path = "hicn disable", - .short_help = "hicn disable <prefix>", - .long_help = "Disable hicn for the give prefix\n", - .function = hicn_disable_command_fn, - }; - -/* *INDENT-ON* */ +VLIB_CLI_COMMAND (hicn_disable_command, static) = { + .path = "hicn disable", + .short_help = "hicn disable <prefix>", + .long_help = "Disable hicn for the give prefix\n", + .function = hicn_disable_command_fn, +}; /* * fd.io coding-style-patch-verification: ON |