diff options
Diffstat (limited to 'hicn-plugin/src/cli.c')
-rw-r--r-- | hicn-plugin/src/cli.c | 441 |
1 files changed, 75 insertions, 366 deletions
diff --git a/hicn-plugin/src/cli.c b/hicn-plugin/src/cli.c index fd1c68169..15ea90c96 100644 --- a/hicn-plugin/src/cli.c +++ b/hicn-plugin/src/cli.c @@ -33,12 +33,8 @@ #include "error.h" #include "faces/face.h" #include "route.h" -#include "punt.h" #include "hicn_api.h" -extern ip_version_t ipv4; -extern ip_version_t ipv6; - static vl_api_hicn_api_node_params_set_t node_ctl_params = { .pit_max_size = -1, .pit_max_lifetime_sec = -1.0f, @@ -53,26 +49,6 @@ typedef enum } interface_type_t; /* - * Supporting function that return if the interface is IP or ethernet - */ -static interface_type_t -hicn_cli_is_ip_interface (vlib_main_t * vm, - vnet_main_t * vnm, u32 sw_if_index) -{ - - vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, sw_if_index); - - vnet_device_class_t *dev_class = - vnet_get_device_class (vnm, hi->dev_class_index); - if (!strcmp (dev_class->name, "Loopback")) - { - return IP; - } - return ETHERNET; - -} - -/* * cli handler for 'control start' */ static clib_error_t * @@ -84,7 +60,8 @@ hicn_cli_node_ctl_start_set_command_fn (vlib_main_t * vm, ret = hicn_infra_plugin_enable_disable (1 /* enable */ , node_ctl_params.pit_max_size, - node_ctl_params.pit_max_lifetime_sec, + node_ctl_params. + pit_max_lifetime_sec, node_ctl_params.cs_max_size, node_ctl_params.cs_reserved_app); @@ -127,7 +104,8 @@ hicn_cli_node_ctl_stop_set_command_fn (vlib_main_t * vm, } ret = hicn_infra_plugin_enable_disable (0 /* !enable */ , node_ctl_params.pit_max_size, - node_ctl_params.pit_max_lifetime_sec, + node_ctl_params. + pit_max_lifetime_sec, node_ctl_params.cs_max_size, node_ctl_params.cs_reserved_app); @@ -460,11 +438,12 @@ hicn_cli_fib_set_command_fn (vlib_main_t * vm, unformat_input_t * main_input, } } - fib_prefix_from_ip46_addr(&address, &prefix); - prefix.fp_len=plen; + fib_prefix_from_ip46_addr (&address, &prefix); + prefix.fp_len = plen; /* Check parse */ if (addpfx <= 1 - && ((ip46_address_is_zero (&prefix.fp_addr)) || faceid == HICN_FACE_NULL)) + && ((ip46_address_is_zero (&prefix.fp_addr)) + || faceid == HICN_FACE_NULL)) { cl_err = clib_error_return (0, "Please specify prefix and a valid faceid..."); @@ -524,154 +503,6 @@ done: return (cl_err); } -static clib_error_t * -hicn_cli_punting_command_fn (vlib_main_t * vm, unformat_input_t * main_input, - vlib_cli_command_t * cmd) -{ - hicn_mgmt_punting_op_e punting_op = HICN_MGMT_PUNTING_OP_NONE; - unsigned int subnet_mask = 0; - ip46_address_t address; - u32 sw_if_index = ~0; - int ret = 0; - vnet_main_t *vnm = NULL; - u8 type = HICN_PUNT_IP_TYPE; - u32 src_port = HICN_PUNT_INVALID_PORT, dst_port = HICN_PUNT_INVALID_PORT; - vnm = vnet_get_main (); - u8 sport = 0; - u8 dport = 0; - fib_prefix_t prefix; - - 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, "add")) - { - punting_op = HICN_MGMT_PUNTING_OP_CREATE; - } - else if (unformat (line_input, "delete")) - { - punting_op = HICN_MGMT_PUNTING_OP_DELETE; - } - else if (unformat (line_input, "intfc %U", - unformat_vnet_sw_interface, vnm, &sw_if_index)) - {; - } - else if (unformat - (line_input, "prefix %U/%d", unformat_ip46_address, - &address, IP46_TYPE_ANY, &subnet_mask)) - {; - } - else if (unformat (line_input, "type ip")) - { - type = HICN_PUNT_IP_TYPE; - } - else if (unformat (line_input, "type")) - { - if (unformat (line_input, "udp4")) - { - type = HICN_PUNT_UDP4_TYPE; - } - else if (unformat (line_input, "udp6")) - { - type = HICN_PUNT_UDP6_TYPE; - } - - if (unformat (line_input, "src_port %u", &src_port)) - { - sport = 1; - } - if (unformat (line_input, "dst_port %u", &dst_port)) - { - dport = 1; - } - } - else - { - return (clib_error_return (0, "invalid option")); - } - } - - fib_prefix_from_ip46_addr(&address, &prefix); - prefix.fp_len = subnet_mask; - if (punting_op == HICN_MGMT_PUNTING_OP_CREATE - && (ip46_address_is_zero (&prefix.fp_addr) || sw_if_index == ~0)) - { - return (clib_error_return - (0, "Please specify valid prefix and interface")); - } - else if ((punting_op == HICN_MGMT_PUNTING_OP_DELETE) && - ip46_address_is_zero (&prefix.fp_addr)) - { - return (clib_error_return - (0, "Please specify valid prefix and optionally an interface")); - } - else if (punting_op == HICN_MGMT_PUNTING_OP_NONE) - { - return (clib_error_return - (0, "Please specify valid operation, add or delete")); - } - switch (punting_op) - { - case HICN_MGMT_PUNTING_OP_CREATE: - { - if (type == HICN_PUNT_UDP4_TYPE || type == HICN_PUNT_UDP6_TYPE) - { - if (sport != 0 || dport != 0) - ret = - hicn_punt_interest_data_for_udp (vm, &prefix, - sw_if_index, type, - clib_host_to_net_u16 - (src_port), - clib_host_to_net_u16 - (dst_port), NO_L2); - else - return (clib_error_return - (0, - "Please specify valid source and destination udp port")); - } - else - { - ret = - hicn_punt_interest_data_for_ip (vm, &prefix, sw_if_index, type, NO_L2); - } - } - break; - case HICN_MGMT_PUNTING_OP_DELETE: - { - if (sw_if_index != ~0) - { - ip46_address_is_ip4 (&prefix.fp_addr) ? - hicn_punt_enable_disable_vnet_ip4_table_on_intf (vm, - sw_if_index, - 0) : - hicn_punt_enable_disable_vnet_ip6_table_on_intf (vm, - sw_if_index, - 0); - } - else if (!(ip46_address_is_zero (&prefix.fp_addr))) - { - ret = ip46_address_is_ip4 (&prefix.fp_addr) ? - hicn_punt_remove_ip4_address (vm, &prefix, 1, - sw_if_index, - 0, NO_L2) : - hicn_punt_remove_ip6_address (vm, &prefix, 1, sw_if_index, 0, - NO_L2); - } - } - break; - default: - break; - } - - return (ret == HICN_ERROR_NONE) ? 0 : clib_error_return (0, - get_error_string - (ret)); -} - /* * cli handler for 'pgen' */ @@ -680,19 +511,16 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, unformat_input_t * main_input, vlib_cli_command_t * cmd) { - hicn_main_t *sm = &hicn_main; hicnpg_main_t *hpgm = &hicnpg_main; ip46_address_t src_addr; - fib_prefix_t prefix; + fib_prefix_t *prefix = malloc (sizeof (fib_prefix_t)); vnet_main_t *vnm = vnet_get_main (); u32 sw_if_index = ~0; u16 lifetime = 4000; int rv = VNET_API_ERROR_UNIMPLEMENTED; u32 max_seq = ~0; u32 n_flows = ~0; - u16 mask = 0; u32 n_ifaces = 1; - u32 hicn_underneath = ~0; /* Get a line of input. */ unformat_input_t _line_input, *line_input = &_line_input; @@ -700,13 +528,6 @@ 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, "fwd")) - { - if (unformat (line_input, "ip")) - hicn_underneath = 0; - else if (unformat (line_input, "hicn")) - hicn_underneath = 1; - } if (unformat (line_input, "intfc %U", unformat_vnet_sw_interface, vnm, &sw_if_index)) @@ -723,8 +544,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)) + unformat_ip46_address, &prefix->fp_addr, + IP46_TYPE_ANY, &prefix->fp_len)) { ; } @@ -750,72 +571,49 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, } } hpgm->interest_lifetime = lifetime; - mask = prefix.fp_len; if (sw_if_index == ~0) { return (clib_error_return (0, "Packet generator interface missing")); } - if (hicn_underneath == ~0) - { - return (clib_error_return - (0, "Choose the underlying forwarder type ip|hicn")); - } - else if (hicn_underneath && !sm->is_enabled) + + //Remove bits that are out of the subnet + if (ip46_address_is_ip4 (&prefix->fp_addr)) { - return (clib_error_return (0, "hICN not enabled in VPP")); + 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; } - else if (!hicn_underneath && sm->is_enabled) + else { - return (clib_error_return (0, "hICN enabled in VPP")); + 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; } - int skip = 1; - int base_offset = ETH_L2; - u8 use_current_data = HICN_CLASSIFY_NO_CURRENT_DATA_FLAG; - - if (hicn_cli_is_ip_interface (vm, vnm, sw_if_index) == IP) - { - skip = 0; - base_offset = NO_L2; - use_current_data = HICN_CLASSIFY_CURRENT_DATA_FLAG; - } /* - * Register punting on src address generated by pg and data punting - * on the name + * 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. */ - 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; - /* Add data node to the vpp graph */ - u32 next_hit_node = vlib_node_add_next (vm, - hicn_punt_glb. - hicn_node_info.ip4_inacl_node_index, - hicn_pg_data_node.index); + prefix->fp_proto = FIB_PROTOCOL_IP4; + + 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); - /* Create the punting table if it does not exist */ - hicn_punt_add_vnettbl (&ipv4, &ipv4_src, mask, ~0, sw_if_index, - base_offset, use_current_data); - hicn_punt_add_vnettbl (&ipv4, &ipv4_dst, mask, - hicn_punt_glb.ip4_vnet_tbl_idx[sw_if_index][skip] - [HICN_PUNT_SRC][mask], sw_if_index, base_offset, - use_current_data); - - /* Add a session to the table */ - hicn_punt_add_vnetssn (&ipv4, &ipv4_src, - &prefix, - next_hit_node, sw_if_index, base_offset); - - hicn_punt_add_vnetssn (&ipv4, &ipv4_src, - &prefix, - next_hit_node, sw_if_index, base_offset); - - hicn_punt_enable_disable_vnet_ip4_table_on_intf (vm, sw_if_index, - OP_ENABLE); pg_node_t *pn; pn = pg_get_node (hicn_pg_interest_node.index); @@ -823,39 +621,17 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, } else if (!ip46_address_is_ip4 (&src_addr) - && !ip46_address_is_ip4 (&prefix.fp_addr)) + && !ip46_address_is_ip4 (&prefix->fp_addr)) { - prefix.fp_proto = FIB_PROTOCOL_IP6; - /* Add node to the vpp graph */ - u32 next_hit_node = vlib_node_add_next (vm, - hicn_punt_glb.hicn_node_info. - ip6_inacl_node_index, - hicn_pg_data_node.index); + prefix->fp_proto = FIB_PROTOCOL_IP6; + + 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, hicn_pg_interest_node.index); - /* Create the punting table if it does not exist */ - hicn_punt_add_vnettbl (&ipv6, &ipv6_src, mask, ~0, sw_if_index, - base_offset, use_current_data); - hicn_punt_add_vnettbl (&ipv6, &ipv6_dst, mask, - hicn_punt_glb.ip6_vnet_tbl_idx[sw_if_index][skip] - [HICN_PUNT_SRC][mask], sw_if_index, base_offset, - use_current_data); - - /* Add a session to the table */ - hicn_punt_add_vnetssn (&ipv6, &ipv6_src, - &prefix, - next_hit_node, sw_if_index, base_offset); - - hicn_punt_add_vnetssn (&ipv6, &ipv6_src, - &prefix, - next_hit_node, sw_if_index, base_offset); - - hicn_punt_enable_disable_vnet_ip6_table_on_intf (vm, sw_if_index, - OP_ENABLE); - pg_node_t *pn; pn = pg_get_node (hicn_pg_interest_node.index); pn->unformat_edit = unformat_pg_ip6_header; @@ -869,11 +645,11 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, hpgm->pgen_clt_src_addr = src_addr; - hpgm->pgen_clt_hicn_name = prefix.fp_addr; + hpgm->pgen_clt_hicn_name = prefix; hpgm->max_seq_number = max_seq; hpgm->n_flows = n_flows; hpgm->n_ifaces = n_ifaces; - hpgm->hicn_underneath = hicn_underneath; + hpgm->sw_if = sw_if_index; vlib_cli_output (vm, "ifaces %d", hpgm->n_ifaces); rv = 0; @@ -904,13 +680,10 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t * vm, clib_error_t *cl_err; int rv = HICN_ERROR_NONE; hicnpg_server_main_t *pg_main = &hicnpg_server_main; - hicn_main_t *sm = &hicn_main; - fib_prefix_t prefix; - u32 subnet_mask; - int payload_size = 0; + int payload_size = 1440; u32 sw_if_index = ~0; vnet_main_t *vnm = vnet_get_main (); - u32 hicn_underneath = ~0; + fib_prefix_t *prefix = calloc (1, sizeof (fib_prefix_t)); /* Get a line of input. */ unformat_input_t _line_input, *line_input = &_line_input; @@ -919,16 +692,9 @@ 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, "fwd")) - { - if (unformat (line_input, "ip")) - hicn_underneath = 0; - else if (unformat (line_input, "hicn")) - hicn_underneath = 1; - } if (unformat (line_input, "name %U/%d", - unformat_ip46_address, &prefix.fp_addr, IP46_TYPE_ANY, - &prefix.fp_len)) + unformat_ip46_address, &prefix->fp_addr, + IP46_TYPE_ANY, &prefix->fp_len)) {; } else if (unformat (line_input, "size %d", &payload_size)) @@ -955,99 +721,50 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t * vm, } } } - prefix.fp_proto = ip46_address_is_ip4(&prefix.fp_addr) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; - subnet_mask = prefix.fp_len; + /* Attach our packet-gen node for ip4 udp local traffic */ - if (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) { return clib_error_return (0, - "Error: must supply local port, payload size and incoming interface"); + "Error: must supply local port, payload size and incoming hICN prefix"); } - if (hicn_underneath == ~0) - { - return (clib_error_return - (0, "Choose the underlying forwarder type ip|hicn")); - } - else if (hicn_underneath && !sm->is_enabled) + + //Remove bits that are out of the subnet + if (ip46_address_is_ip4 (&prefix->fp_addr)) { - return (clib_error_return (0, "hICN not enabled in VPP")); + 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; } - else if (!hicn_underneath && sm->is_enabled) + else { - return (clib_error_return (0, "hICN enabled in VPP")); + 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; } - pg_main->hicn_underneath = hicn_underneath; /* Allocate the buffer with the actual content payload TLV */ vlib_buffer_alloc (vm, &pg_main->pgen_svr_buffer_idx, 1); 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; - int skip = 2; - int base_offset = ETH_L2; - u8 use_current_data = HICN_CLASSIFY_NO_CURRENT_DATA_FLAG; - - if (hicn_cli_is_ip_interface (vm, vnm, sw_if_index) == IP) - { - skip = 1; - base_offset = NO_L2; - use_current_data = HICN_CLASSIFY_CURRENT_DATA_FLAG; - } - if (ip46_address_is_ip4 (&prefix.fp_addr)) - { - /* Add node to the vpp graph */ - u32 next_hit_node = vlib_node_add_next (vm, - hicn_punt_glb. - hicn_node_info.ip4_inacl_node_index, - hicn_pg_server_node.index); - - /* Create the punting table if it does not exist */ - hicn_punt_add_vnettbl (&ipv4, &ipv4_src, subnet_mask, ~0, sw_if_index, - base_offset, use_current_data); - hicn_punt_add_vnettbl (&ipv4, &ipv4_dst, subnet_mask, - hicn_punt_glb.ip4_vnet_tbl_idx[sw_if_index][skip] - [HICN_PUNT_SRC][subnet_mask - 1], sw_if_index, - base_offset, use_current_data); - - - /* Add a session to the table */ - hicn_punt_add_vnetssn (&ipv4, &ipv4_dst, - &prefix, next_hit_node, sw_if_index, - base_offset); - - hicn_punt_enable_disable_vnet_ip4_table_on_intf (vm, sw_if_index, - OP_ENABLE); - - } - else - { - /* Add node to the vpp graph */ - u32 next_hit_node = vlib_node_add_next (vm, - hicn_punt_glb.hicn_node_info. - ip6_inacl_node_index, - hicn_pg_server_node.index); - - /* Create the punting table if it does not exist */ - hicn_punt_add_vnettbl (&ipv6, &ipv6_src, subnet_mask, ~0, sw_if_index, - base_offset, use_current_data); - hicn_punt_add_vnettbl (&ipv6, &ipv6_dst, subnet_mask, - hicn_punt_glb.ip6_vnet_tbl_idx[sw_if_index][skip] - [HICN_PUNT_SRC][subnet_mask - 1], sw_if_index, - base_offset, use_current_data); - - - /* Add a session to the table */ - hicn_punt_add_vnetssn (&ipv6, &ipv6_dst, - &prefix, next_hit_node, sw_if_index, - base_offset); - - hicn_punt_enable_disable_vnet_ip6_table_on_intf (vm, sw_if_index, - OP_ENABLE); - } + 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) { @@ -1119,19 +836,11 @@ VLIB_CLI_COMMAND(hicn_cli_show_command, static)= .function = hicn_cli_show_command_fn, }; -/* cli declaration for 'punting' */ -VLIB_CLI_COMMAND(hicn_cli_punting_command, static)= -{ - .path = "hicn punting", - .short_help = "hicn punting {add|delete} prefix <prefix> intfc <sw_if> {type ip | type <udp4|udp6> src_port <port> dst_port <port>}", - .function = hicn_cli_punting_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 fwd <ip|hicn> src <src_addr> n_ifaces <n_ifaces> name <prefix> lifetime <interest-lifetime> intfc <data in-interface> max_seq <max sequence number> n_flows <number of flows>", + .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, }; @@ -1140,7 +849,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 fwd <ip|hicn> name <prefix> intfc <interest in-interface> size <payload_size>", + .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, }; |