Hi Wei, I suspect you wanted to register CREATE_LOOPBACK_REPLY instead of CREATE_LOOPBACK in foreach_vpe_api_reply_msg
Regards, Florin > On Mar 7, 2022, at 9:07 AM, Wei Huang <wei.hu.hu...@oracle.com> wrote: > > I used the following program to test API functions. For sw_interface_dump, I > got the reply with all the interfaces information, but for the > create_loopback message, I don't get any reply, although the loopback is > successfully created. I also tried ip_route_add_del, ip_route_add_del_v2, > same thing, the reply handler function never got called. > Anybody knows why the reply handler not get called? > > Thanks, > Wei > ========================================= > #include <stdio.h> > > #include <vlibmemory/api.h> > #include <svm/fifo_segment.h> > #include <svm/message_queue.h> > #include <vpp/api/vpe_msg_enum.h> > > #define vl_typedefs > #include <vpp/api/vpe_all_api_h.h> > #undef vl_typedefs > > #define vl_endianfun > #include <vpp/api/vpe_all_api_h.h> > #undef vl_endianfun > > #define vl_print(handle, ...) > #define vl_printfun > #include <vpp/api/vpe_all_api_h.h> > #undef vl_printfun > > #define DEFAULT_QUEUE_SIZE 1024 > > typedef struct > { > svm_queue_t *vl_input_queue; /* vpe input queue */ > u32 my_client_index; /* API client handle */ > } vpp_api_agent_main_t; > > vpp_api_agent_main_t agent_main; > > static void > vl_api_sw_interface_details_t_handler(vl_api_sw_interface_details_t * mp) > { > printf("Received: sw_interface_details interface_index:%u > interface_name:%s context:0x%x\n", > ntohl(mp->sw_if_index), mp->interface_name, ntohl(mp->context)); > } > > static void vl_api_create_loopback_reply_t_handler( > vl_api_create_loopback_reply_t * mp) { > printf("\tCreate loopback reply received, message id: %d, with retval: > %d, new interface index: %d\n", > clib_net_to_host_u32(mp->context), mp->retval, > clib_net_to_host_u32(mp->sw_if_index)); > } > > #define foreach_vpe_api_reply_msg \ > _(SW_INTERFACE_DETAILS, sw_interface_details) \ > _(CREATE_LOOPBACK, create_loopback_reply) > > void agent_api_hookup(vpp_api_agent_main_t * agentm) > { > #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_reply_msg; > #undef _ > } > > > void send_sw_interface_dump() > { > vl_api_sw_interface_dump_t * mp; > > mp = vl_msg_api_alloc(sizeof(*mp)); > memset(mp, 0, sizeof(*mp)); > mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DUMP); > mp->client_index = agent_main.my_client_index; > mp->context = htonl (0x1234); > > vl_msg_api_send_shmem(agent_main.vl_input_queue, (u8 *) &mp); > printf("Sent: sw_interface_dump context:0x%x\n", ntohl(mp->context)); > > } > > static void create_loopback() > { > vl_api_create_loopback_t * mp; > > // Allocate create loopback message > mp = vl_msg_api_alloc(sizeof(*mp)); > memset(mp, 0, sizeof(*mp)); > // Set the message ID to create_loopback ID reported by VPP > mp->_vl_msg_id = ntohs(VL_API_CREATE_LOOPBACK); > // Set our client index > mp->client_index = agent_main.my_client_index; > // Set context (context is an arbitrary number that can help matching > request/reply pairs) > mp->context = htonl (0x1235); > // We could also set mac address > > // send messagee to VPP > vl_msg_api_send_shmem(agent_main.vl_input_queue, (u8 *) &mp); > printf("Sending create loopback. Create loopback msg \n"); > } > > void main() > { > // Initialization > clib_mem_init_thread_safe(0, 256 << 20); > clib_memset(&agent_main, 0, sizeof (vpp_api_agent_main_t)); > > // Create shared mem with vpp > api_main_t *am = vlibapi_get_main(); > > if (vl_client_connect_to_vlib("/vpe-api", "t3_app", DEFAULT_QUEUE_SIZE) < > 0) > { > printf("Shmem connect failed\n"); > svm_region_exit(); > } > else > { > agent_main.vl_input_queue = am->shmem_hdr->vl_input_queue; > agent_main.my_client_index = am->my_client_index; > > printf("Connected to vpp!!!\n"); > } > > // Register callback functions > agent_api_hookup(&agent_main); > > send_sw_interface_dump(); > sleep(1); > > create_loopback(); > sleep(3); > } > >
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#20974): https://lists.fd.io/g/vpp-dev/message/20974 Mute This Topic: https://lists.fd.io/mt/89617291/21656 Group Owner: vpp-dev+ow...@lists.fd.io Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-