Plugin API Programming in VPP (2)-VPE vs. Plugin Messages ID

Source: Internet
Author: User

MsgId is the only identifier that identifies API functions, but when used, there are some differences between plugin and VPE, which need to be noted.
The code is displayed in Vl_api_xxx, and the specific value is determined at compile time.

VPE registration, using a global macro, the first MSG ID in the module is not 0

static clib_error_t *ipsec_api_hookup (vlib_main_t * vm){  api_main_t *am = &api_main;#define _(N,n)                                                      vl_msg_api_set_handlers(VL_API_##N, #n,                                                vl_api_##n##_t_handler,                                         vl_noop_handler,                                                vl_api_##n##_t_endian,                                          vl_api_##n##_t_print,                                           sizeof(vl_api_##n##_t), 1);  foreach_vpe_api_msg;#undef _  /*   * Set up the (msg_name, crc, message-id) table   */  setup_message_id_table (am);  return 0;}

Plugin registration, the base + offset is used, the first msg_id in the module is 0 and must be used with a base address.

staticvoid acl_vat_api_hookup (vat_main_t *vam){    acl_test_main_t * sm = &acl_test_main;    /* Hook up handlers for replies from the data plane plug-in */#define _(N,n)                                                      vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base),                                #n,                                                             vl_api_##n##_t_handler,                                         vl_noop_handler,                                                vl_api_##n##_t_endian,                                          vl_api_##n##_t_print,                                           sizeof(vl_api_##n##_t), 1);    foreach_vpe_api_reply_msg;#undef _}

Why there is such a difference, let's take a look.

Plugin Message ID generation offset

Plugin is an offset created by the way the header file is contained, that is, the vl_api_xxxx
Take ACL as an example
is achieved through these 3. h.

Acl_msg_enum.h-Defines the enumeration structure, with each module starting from 0
ACL_ALL_API_H.H--all ACL API related. h files are placed here
Acl.api.h--The vl_api_xxx used by the ACL are arranged sequentially

    • Acl_msg_enum.h
      An enumeration structure is created that contains the ACL_ALL_API_H.H
      20 #define vl_msg_id(n,h) n,21 typedef enum {22 #include <acl/acl_all_api_h.h>23     /* We‘ll want to know how many messages IDs we need... */24     VL_MSG_FIRST_AVAILABLE,25 } vl_msg_id_t;26 #undef vl_msg_id
+ acl_all_api_h.h  所有acl api有关头文件都放在这里,统一管理    包含了acl.api.h```c 16 #include <acl/acl.api.h> 17  18 #ifdef vl_printfun 19 #include <acl/manual_fns.h> 20 #endif
  • Acl.api.h
    Files generated by Acl.api, arranged in order vl_api_xxx
    /****** Message id/handler enum ******/19 #ifdef vl_msg_id21 vl_msg_id (Vl_api_acl_enable_config, vl_api_acl_enable _config_t_handler) vl_msg_id (vl_api_acl_enable_config_reply, Vl_api_acl_enable_config_reply_t_handler) vl_msg _id (Vl_api_acl_plugin_get_version, Vl_api_acl_plugin_get_version_t_handler) vl_msg_id (VL_API_ACL_PLUGIN_GET_ Version_reply, Vl_api_acl_plugin_get_version_reply_t_handler) vl_msg_id (vl_api_acl_plugin_control_ping, Vl_api_ Acl_plugin_control_ping_t_handler) vl_msg_id (vl_api_acl_plugin_control_ping_reply, Vl_api_acl_plugin_control_ Ping_reply_t_handler) *//Typeonly:acl_rule */28//Typeonly:macip_acl_rule */29 vl_msg_id (VL_API_ACL_ADD_REPLACE, VL _api_acl_add_replace_t_handler) vl_msg_id (vl_api_acl_add_replace_reply, Vl_api_acl_add_replace_reply_t_handler ) vl_msg_id (Vl_api_acl_del, Vl_api_acl_del_t_handler) vl_msg_id (vl_api_acl_del_reply, Vl_api_acl_del_reply_t_ Handler) vl_msg_id (Vl_api_acl_interface_add_del, Vl_api_acl_interface_add_del_t_handler) vl_msg_id (vl_api_acl_interface_add_del_reply, Vl_api_acl_interface_add_del_reply_t_handler) vl_msg_id (VL _api_acl_interface_set_acl_list, Vl_api_acl_interface_set_acl_list_t_handler) ... Wuyi #endif
 This generates an offset for the API functions within the module. # # # Get base call vl_msg_api_get_msg_ids function Get ' cu16vl_msg_api_get_msg_ids (const char *name, int n) {api_main_t *am = &api  _main;  U8 *name_copy;  vl_api_msg_range_t *RP;  Uword *p;  U16 RV;  if (Am->msg_range_by_name = = 0) am->msg_range_by_name = hash_create_string (0, sizeof (Uword));  Get a clean module name (countless numbers) name_copy = Format (0, "%s%c", name, 0);  Check if you have registered P = hash_get_mem (Am->msg_range_by_name, name_copy);      if (p) {clib_warning ("warning:duplicate Message Range registration for '%s '", name_copy);      Vec_free (name_copy);    Return ((U16) ~ 0);  The range of//msg is judged if (N < 0 | | n > 1024x768) {clib_warning ("Warning:bad Number of Message-ids (%d) Requested      By '%s ', n, name_copy);      Vec_free (name_copy);    Return ((U16) ~ 0);  }//am->msg_ranges This structure is important to manage the range of all msg//Get RP Vec_add2 (Am->msg_ranges, RP, 1); Gets the msg_id of the module.  This ID is used in the global first_available_msg_id//each time a module is loaded, it will increase the number of responses, so that all the msg_id string up. Rv = rp->first_msg_id = am->first_available_msg_id;  Increase the number of global msg_id for the next module using am->first_available_msg_id + = n;  rp->last_msg_id = am->first_available_msg_id-1;  Rp->name = name_copy; With the name of key, deposit.  Clinet will use this name to request index Hash_set_mem (am->msg_range_by_name, name_copy, rp-am->msg_ranges); return RV;}
Generate global msg_id using the message ID under VPE

VPE is also generated by the way the header file is contained
The first msg_id inside each module is not arranged from 0, but is global, because all of the header files are included

Take IPSec as an example
is achieved through these 3. h.
Vnet_msg_enum.h--Define enumeration structure
VNET_ALL_API_H.H--All VPE API-related. h files are placed here
Ipsec.api.h--The vl_api_xxx used by IPSec is arranged sequentially

    • Vnet_msg_enum.h
      Defines an enumeration structure that contains the VNET_ALL_API_H.H
      18 #include <vppinfra/byte_order.h>19 20 #define vl_msg_id(n,h) n,21 typedef enum22 {23   VL_ILLEGAL_MESSAGE_ID = 0,24 #include <vnet/vnet_all_api_h.h>25   VL_MSG_FIRST_AVAILABLE,26 } vl_msg_id_t;27 #undef vl_msg_id28 29 #endif /* included_vnet_msg_enum_h */
+ vnet_all_api_h.h  所有vnet的模块都在里面```c28 #ifndef included_from_layer_3 29 #include <vlibmemory/vl_memory_api_h.h> 30 #endif /* included_from_layer_3 */ 31  32 #include <vnet/devices/af_packet/af_packet.api.h> 33 #include <vnet/devices/netmap/netmap.api.h> 34 #include <vnet/devices/virtio/vhost_user.api.h> 35 #include <vnet/gre/gre.api.h> 36 #include <vnet/interface.api.h> 37 #include <vnet/map/map.api.h> 38 #include <vnet/l2/l2.api.h> 39 #include <vnet/l2tp/l2tp.api.h> 40 #include <vnet/span/span.api.h> 41 #include <vnet/ip/ip.api.h> 42 #include <vnet/unix/tap.api.h> 43 #include <vnet/vxlan/vxlan.api.h> 44 #include <vnet/lldp/lldp.api.h> 45 #include <vnet/vxlan-gpe/vxlan_gpe.api.h> 46 #include <vnet/bfd/bfd.api.h> 47 #include <vnet/ipsec/ipsec.api.h> 48 #include <vnet/ipsec-gre/ipsec_gre.api.h>
  • Ipsec.api.h
    The MSG ID required for IPSec
    /****** Message id/handler enum ******/19 #ifdef vl_msg_id21 vl_msg_id (Vl_api_ipsec_spd_add_del, Vl_api_ipsec_spd_ Add_del_t_handler) vl_msg_id (vl_api_ipsec_spd_add_del_reply, Vl_api_ipsec_spd_add_del_reply_t_handler) vl_msg _id (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD, Vl_api_ipsec_interface_add_del_spd_t_handler) vl_msg_id (VL_API_IPSEC_ Interface_add_del_spd_reply, Vl_api_ipsec_interface_add_del_spd_reply_t_handler) vl_msg_id (VL_API_IPSEC_SPD_ Add_del_entry, Vl_api_ipsec_spd_add_del_entry_t_handler) vl_msg_id (vl_api_ipsec_spd_add_del_entry_reply, Vl_api _ipsec_spd_add_del_entry_reply_t_handler) vl_msg_id (Vl_api_ipsec_sad_add_del_entry, Vl_api_ipsec_sad_add_del_ Entry_t_handler) vl_msg_id (vl_api_ipsec_sad_add_del_entry_reply, Vl_api_ipsec_sad_add_del_entry_reply_t_ Handler) vl_msg_id (Vl_api_ipsec_sa_set_key, Vl_api_ipsec_sa_set_key_t_handler) vl_msg_id (vl_api_ipsec_sa_set_ Key_reply, Vl_api_ipsec_sa_set_key_reply_t_handler) vl_msg_id (Vl_api_ikev2_profile_add_del, Vl_api_Ikev2_profile_add_del_t_handler) vl_msg_id (vl_api_ikev2_profile_add_del_reply, Vl_api_ikev2_profile_add_del_ Reply_t_handler)

    So all vpe about the global MSG ID is created.

Plugin API Programming in VPP (2)-VPE vs. Plugin Messages ID

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.