aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-plugin/src/cli.c
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-plugin/src/cli.c')
-rw-r--r--hicn-plugin/src/cli.c258
1 files changed, 163 insertions, 95 deletions
diff --git a/hicn-plugin/src/cli.c b/hicn-plugin/src/cli.c
index 8ecbf7a95..64ebf61a4 100644
--- a/hicn-plugin/src/cli.c
+++ b/hicn-plugin/src/cli.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2021 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:
@@ -22,6 +22,9 @@
#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,
@@ -65,8 +68,8 @@ hicn_cli_node_ctl_start_set_command_fn (vlib_main_t *vm,
get_error_string (ret));
return (ret == HICN_ERROR_NONE) ?
- 0 :
- clib_error_return (0, get_error_string (ret));
+ 0 :
+ clib_error_return (0, get_error_string (ret));
}
/*
@@ -91,7 +94,7 @@ 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),
@@ -103,8 +106,8 @@ hicn_cli_node_ctl_stop_set_command_fn (vlib_main_t *vm,
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));
+ 0 :
+ clib_error_return (0, get_error_string (ret));
}
#define DFLTD_RANGE_OK(val, min, max) \
@@ -201,8 +204,8 @@ hicn_cli_node_ctl_param_set_command_fn (vlib_main_t *vm,
"compilation time for better performances\n");
return (rv == HICN_ERROR_NONE) ?
- 0 :
- clib_error_return (0, "%s '%U'", get_error_string (rv),
+ 0 :
+ clib_error_return (0, "%s '%U'", get_error_string (rv),
format_unformat_error, line_input);
}
@@ -213,7 +216,7 @@ static clib_error_t *
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,
+ int face_p = 0, fib_p = 0, all_p = 0, strategies_p = 0,
ret = HICN_ERROR_NONE;
/* Get a line of input. */
@@ -226,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"))
{
/*
@@ -333,23 +328,86 @@ 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));
+ 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;
}
/*
@@ -408,8 +466,8 @@ 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));
+ NULL :
+ clib_error_return (0, get_error_string (rv));
done:
return (cl_err);
@@ -583,13 +641,15 @@ 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;
@@ -599,7 +659,7 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t *vm,
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))
+ &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len))
{
;
}
@@ -616,6 +676,11 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t *vm,
{
;
}
+ else if (unformat (line_input, "dst %U", unformat_ip46_address,
+ &locator, IP46_TYPE_ANY))
+ {
+ ;
+ }
else
{
return (clib_error_return (0, "Unknown input '%U'",
@@ -626,70 +691,45 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t *vm,
}
/* 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 "
+ 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))
+ 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 *
@@ -727,12 +767,27 @@ 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));
+ NULL :
+ clib_error_return (0, get_error_string (rv));
return cl_err;
}
@@ -776,11 +831,24 @@ hicn_disable_command_fn (vlib_main_t *vm, unformat_input_t *main_input,
done:
cl_err = (rv == HICN_ERROR_NONE) ?
- NULL :
- clib_error_return (0, get_error_string (rv));
+ 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,
+};
+
+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",
@@ -840,7 +908,7 @@ VLIB_CLI_COMMAND (hicn_cli_pgen_client_set_command, static) = {
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>",
+ "dst <ip_address> size <payload_size>",
.long_help = "Run hicn in packet-gen server mode\n",
.function = hicn_cli_pgen_server_set_command_fn,
};