X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=vpp%2Fapi%2Fapi.c;h=ea14bffb6bc4008caf47a48b0b39718a3b327602;hb=58f886ab9a2dd8d3f5bdcb34fd1c4fde212ede97;hp=0d5f224118e04a2d68c2f77bdeac3789dbf6c83f;hpb=195bceec5685cb367519e37f22b36f5f99819827;p=vpp.git diff --git a/vpp/api/api.c b/vpp/api/api.c index 0d5f224118e..ea14bffb6bc 100644 --- a/vpp/api/api.c +++ b/vpp/api/api.c @@ -74,6 +74,8 @@ #include #include #include +#include +#include #undef BIHASH_TYPE #undef __included_bihash_template_h__ @@ -289,7 +291,8 @@ _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \ _(SHOW_VERSION, show_version) \ _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \ _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \ -_(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \ +_(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \ +_(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \ _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \ _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \ _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \ @@ -327,6 +330,7 @@ _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \ _(LISP_ENABLE_DISABLE, lisp_enable_disable) \ _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \ _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \ +_(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \ _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \ _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \ _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \ @@ -335,7 +339,11 @@ _(LISP_ENABLE_DISABLE_STATUS_DUMP, \ lisp_enable_disable_status_dump) \ _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \ _(AF_PACKET_CREATE, af_packet_create) \ -_(AF_PACKET_DELETE, af_packet_delete) +_(AF_PACKET_DELETE, af_packet_delete) \ +_(POLICER_ADD_DEL, policer_add_del) \ +_(POLICER_DUMP, policer_dump) \ +_(NETMAP_CREATE, netmap_create) \ +_(NETMAP_DELETE, netmap_delete) #define QUOTE_(x) #x #define QUOTE(x) QUOTE_(x) @@ -4323,8 +4331,8 @@ static void vl_api_vxlan_add_del_tunnel_t_handler encap_fib_index = p[0]; /* Check src & dst are different */ - if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) || - (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) { + if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) || + (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) { rv = VNET_API_ERROR_SAME_SRC_DST; goto out; } @@ -4561,12 +4569,24 @@ vl_api_vxlan_gpe_add_del_tunnel_t_handler decap_fib_index = ntohl(mp->decap_vrf_id); } + /* Check src & dst are different */ + if ((mp->is_ipv6 && memcmp(mp->local, mp->remote, 16) == 0) || + (!mp->is_ipv6 && memcmp(mp->local, mp->remote, 4) == 0)) { + rv = VNET_API_ERROR_SAME_SRC_DST; + goto out; + } memset (a, 0, sizeof (*a)); a->is_add = mp->is_add; + a->is_ip6 = mp->is_ipv6; /* ip addresses sent in network byte order */ - a->local.as_u32 = ntohl(mp->local); - a->remote.as_u32 = ntohl(mp->remote); + if (a->is_ip6) { + clib_memcpy(&(a->local.ip6), mp->local, 16); + clib_memcpy(&(a->remote.ip6), mp->remote, 16); + } else { + clib_memcpy(&(a->local.ip4), mp->local, 4); + clib_memcpy(&(a->remote.ip4), mp->remote, 4); + } a->encap_fib_index = encap_fib_index; a->decap_fib_index = decap_fib_index; a->protocol = protocol; @@ -4580,6 +4600,67 @@ out: })); } +static void send_vxlan_gpe_tunnel_details +(vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context) +{ + vl_api_vxlan_gpe_tunnel_details_t * rmp; + ip4_main_t * im4 = &ip4_main; + ip6_main_t * im6 = &ip6_main; + u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4); + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs(VL_API_VXLAN_GPE_TUNNEL_DETAILS); + if (is_ipv6) { + memcpy(rmp->local, &(t->local.ip6), 16); + memcpy(rmp->remote, &(t->remote.ip6), 16); + rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id); + rmp->decap_vrf_id = htonl(im6->fibs[t->decap_fib_index].table_id); + } else { + memcpy(rmp->local, &(t->local.ip4), 4); + memcpy(rmp->remote, &(t->remote.ip4), 4); + rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id); + rmp->decap_vrf_id = htonl(im4->fibs[t->decap_fib_index].table_id); + } + rmp->vni = htonl(t->vni); + rmp->protocol = t->protocol; + rmp->sw_if_index = htonl(t->sw_if_index); + rmp->is_ipv6 = is_ipv6; + rmp->context = context; + + vl_msg_api_send_shmem (q, (u8 *)&rmp); +} + +static void vl_api_vxlan_gpe_tunnel_dump_t_handler +(vl_api_vxlan_gpe_tunnel_dump_t * mp) +{ + unix_shared_memory_queue_t * q; + vxlan_gpe_main_t * vgm = &vxlan_gpe_main; + vxlan_gpe_tunnel_t * t; + u32 sw_if_index; + + q = vl_api_client_index_to_input_queue (mp->client_index); + if (q == 0) { + return; + } + + sw_if_index = ntohl(mp->sw_if_index); + + if (~0 == sw_if_index) { + pool_foreach (t, vgm->tunnels, + ({ + send_vxlan_gpe_tunnel_details(t, q, mp->context); + })); + } else { + if ((sw_if_index >= vec_len(vgm->tunnel_index_by_sw_if_index)) || + (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index])) { + return; + } + t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]]; + send_vxlan_gpe_tunnel_details(t, q, mp->context); + } +} + static void vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp) { @@ -4598,7 +4679,7 @@ vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp) a->is_add = mp->is_add; a->local = 1; - rv = vnet_lisp_add_del_locator_set_name(a, &ls_index); + rv = vnet_lisp_add_del_locator_set(a, &ls_index); vec_free(locator_name); @@ -4632,7 +4713,7 @@ vl_api_lisp_add_del_locator_t_handler( a->is_add = mp->is_add; a->local = 1; - rv = vnet_lisp_add_del_locator(a, &ls_index); + rv = vnet_lisp_add_del_locator(a, NULL, &ls_index); vec_free(locators); vec_free(locator_name); @@ -4824,6 +4905,21 @@ vl_api_lisp_gpe_add_del_iface_t_handler( REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY); } +static void +vl_api_lisp_pitr_set_locator_set_t_handler( + vl_api_lisp_pitr_set_locator_set_t *mp) +{ + vl_api_lisp_pitr_set_locator_set_reply_t *rmp; + int rv = 0; + u8 * ls_name = 0; + + ls_name = format (0, "%s", mp->ls_name); + rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add); + vec_free (ls_name); + + REPLY_MACRO(VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY); +} + /** Used for transferring locators via VPP API */ typedef CLIB_PACKED(struct { @@ -4898,8 +4994,8 @@ vl_api_lisp_add_del_remote_mapping_t_handler ( vec_add1 (rlocs, rloc); } - rv = vnet_lisp_add_del_remote_mapping (deid, seid, rlocs, - mp->action, mp->is_add); + rv = vnet_lisp_add_del_remote_mapping (deid, seid, rlocs, mp->action, + mp->is_add, mp->del_all); vec_free (rlocs); REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY); } @@ -5822,13 +5918,15 @@ static void vl_api_get_node_graph_t_handler /* * Keep the number of memcpy ops to a minimum (e.g. 1). - * The current size of the serialized vector is - * slightly under 4K. */ - vec_validate (vector, 4095); + vec_validate (vector, 16384); vec_reset_length (vector); - vector = vlib_node_serialize (&vm->node_main, vector); + /* $$$$ FIXME */ + vector = vlib_node_serialize (&vm->node_main, vector, + (u32)~0 /* all threads */, + 1 /* include nexts */, + 1 /* include stats */); svm_pop_heap (oldheap); pthread_mutex_unlock (&am->vlib_rp->mutex); @@ -5906,7 +6004,7 @@ vl_api_af_packet_create_t_handler vec_add1 (host_if_name, 0); rv = af_packet_create_if(vm, host_if_name, - mp->use_random_hw_addr ? 0 : mp->hw_addr); + mp->use_random_hw_addr ? 0 : mp->hw_addr, 0); vec_free(host_if_name); @@ -5932,6 +6030,153 @@ vl_api_af_packet_delete_t_handler REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY); } +static void +vl_api_policer_add_del_t_handler +(vl_api_policer_add_del_t *mp) +{ + vlib_main_t * vm = vlib_get_main(); + vl_api_policer_add_del_reply_t *rmp; + int rv = 0; + u8 *name = NULL; + sse2_qos_pol_cfg_params_st cfg; + clib_error_t * error; + + name = format(0, "%s", mp->name); + + memset (&cfg, 0, sizeof (cfg)); + cfg.rfc = mp->type; + cfg.rnd_type = mp->round_type; + cfg.rate_type = mp->rate_type; + cfg.rb.kbps.cir_kbps = mp->cir; + cfg.rb.kbps.eir_kbps = mp->eir; + cfg.rb.kbps.cb_bytes = mp->cb; + cfg.rb.kbps.eb_bytes = mp->eb; + + error = policer_add_del(vm, name, &cfg, mp->is_add); + + if (error) + rv = VNET_API_ERROR_UNSPECIFIED; + + REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY); +} + +static void +send_policer_details (u8 *name, + sse2_qos_pol_cfg_params_st *config, + policer_read_response_type_st *templ, + unix_shared_memory_queue_t *q, + u32 context) +{ + vl_api_policer_details_t * mp; + + mp = vl_msg_api_alloc (sizeof (*mp)); + memset (mp, 0, sizeof (*mp)); + mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS); + mp->context = context; + mp->cir = htonl(config->rb.kbps.cir_kbps); + mp->eir = htonl(config->rb.kbps.eir_kbps); + mp->cb = htonl(config->rb.kbps.cb_bytes); + mp->eb = htonl(config->rb.kbps.eb_bytes); + mp->rate_type = config->rate_type; + mp->round_type = config->rnd_type; + mp->type = config->rfc; + mp->single_rate = templ->single_rate ? 1 : 0; + mp->color_aware = templ->color_aware ? 1 : 0; + mp->scale = htonl(templ->scale); + mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period); + mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period); + mp->current_limit = htonl(templ->current_limit); + mp->current_bucket = htonl(templ->current_bucket); + mp->extended_limit = htonl(templ->extended_limit); + mp->extended_bucket = htonl(templ->extended_bucket); + mp->last_update_time = clib_host_to_net_u64(templ->last_update_time); + + strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1); + + vl_msg_api_send_shmem (q, (u8 *)&mp); +} + +static void +vl_api_policer_dump_t_handler +(vl_api_policer_dump_t *mp) +{ + unix_shared_memory_queue_t * q; + vnet_policer_main_t * pm = &vnet_policer_main; + hash_pair_t * hp; + uword * p; + u32 pool_index; + u8 * match_name = 0; + u8 * name; + sse2_qos_pol_cfg_params_st *config; + policer_read_response_type_st *templ; + + q = vl_api_client_index_to_input_queue (mp->client_index); + if (q == 0) + return; + + if (mp->match_name_valid) { + match_name = format(0, "%s%c", mp->match_name, 0); + } + + if (mp->match_name_valid) { + p = hash_get_mem (pm->policer_config_by_name, match_name); + if (p) { + pool_index = p[0]; + config = pool_elt_at_index (pm->configs, pool_index); + templ = pool_elt_at_index (pm->policer_templates, pool_index); + send_policer_details(match_name, config, templ, q, mp->context); + } + } else { + hash_foreach_pair (hp, pm->policer_config_by_name, + ({ + name = (u8 *) hp->key; + pool_index = hp->value[0]; + config = pool_elt_at_index (pm->configs, pool_index); + templ = pool_elt_at_index (pm->policer_templates, pool_index); + send_policer_details(name, config, templ, q, mp->context); + })); + } +} + +static void +vl_api_netmap_create_t_handler +(vl_api_netmap_create_t *mp) +{ + vlib_main_t *vm = vlib_get_main(); + vl_api_netmap_create_reply_t *rmp; + int rv = 0; + u8 *if_name = NULL; + + if_name = format(0, "%s", mp->netmap_if_name); + vec_add1 (if_name, 0); + + rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr, + mp->is_pipe, mp->is_master, 0); + + vec_free(if_name); + + REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY); +} + +static void +vl_api_netmap_delete_t_handler +(vl_api_netmap_delete_t *mp) +{ + vlib_main_t * vm = vlib_get_main(); + vl_api_netmap_delete_reply_t *rmp; + int rv = 0; + u8 *if_name = NULL; + + if_name = format(0, "%s", mp->netmap_if_name); + vec_add1 (if_name, 0); + + rv = netmap_delete_if(vm, if_name); + + vec_free(if_name); + + REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY); +} + #define BOUNCE_HANDLER(nn) \ static void vl_api_##nn##_t_handler ( \ vl_api_##nn##_t *mp) \ @@ -6025,6 +6270,7 @@ vpe_api_hookup (vlib_main_t *vm) * Thread-safe API messages */ am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1; + am->is_mp_safe [VL_API_GET_NODE_GRAPH] = 1; return 0; }