2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vlibapi/api.h>
17 #include <vlibmemory/api.h>
18 #include <vppinfra/error.h>
22 #define __plugin_msg_base stn_test_main.msg_id_base
23 #include <vlibapi/vat_helper_macros.h>
25 /* Declare message IDs */
26 #include <stn/stn_msg_enum.h>
28 /* Get CRC codes of the messages defined outside of this plugin */
29 #define vl_msg_name_crc_list
30 #include <vpp/api/vpe_all_api_h.h>
31 #undef vl_msg_name_crc_list
33 /* define message structures */
35 #include <vpp/api/vpe_all_api_h.h>
36 #include <stn/stn_all_api_h.h>
39 /* define message structures */
41 #include <stn/stn_all_api_h.h>
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...)
47 #include <stn/stn_all_api_h.h>
50 /* Get the API version number. */
51 #define vl_api_version(n,v) static u32 api_version=(v);
52 #include <stn/stn_all_api_h.h>
57 /* API message ID base */
63 stn_test_main_t stn_test_main;
66 * Table of message reply handlers, must include boilerplate handlers
69 #define foreach_stn_api_reply_msg \
70 _(STN_RULES_DETAILS, stn_rules_details)
73 api_stn_rules_dump (vat_main_t * vam)
75 stn_test_main_t *sm = &stn_test_main;
76 vl_api_stn_rules_dump_t *mp;
77 vl_api_control_ping_t *mp_ping;
80 if (!vam->json_output)
82 print (vam->ofp, "%=20s", "STN Rules");
85 M (STN_RULES_DUMP, mp);
89 /* Use a control ping for synchronization */
90 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
91 mp_ping->_vl_msg_id = htons (sm->ping_id);
92 mp_ping->client_index = vam->my_client_index;
94 fformat (vam->ofp, "Sending ping id=%d\n", sm->ping_id);
96 vam->result_ready = 0;
99 /* Wait for a reply... */
105 vl_api_stn_rules_details_t_handler (vl_api_stn_rules_details_t * mp)
107 vat_main_t *vam = stn_test_main.vat_main;
108 fformat (vam->ofp, "addr: %U sw_if_index: %u\n",
109 mp->is_ip4 ? format_ip4_address : format_ip6_address,
110 mp->ip_address, clib_net_to_host_u32 (mp->sw_if_index));
114 * List of messages that the api test plugin sends,
115 * and that the data plane plugin processes
117 #define foreach_stn_api_msg \
118 _(stn_rules_dump, "") \
121 stn_vat_api_hookup (vat_main_t * vam)
123 stn_test_main_t *sm = &stn_test_main;
124 /* Hook up handlers for replies from the data plane plug-in */
126 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
128 vl_api_##n##_t_handler, \
130 vl_api_##n##_t_endian, \
131 vl_api_##n##_t_print, \
132 sizeof(vl_api_##n##_t), 1);
133 foreach_stn_api_reply_msg;
136 /* API messages we can send */
137 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
142 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
148 vat_plugin_register (vat_main_t * vam)
150 stn_test_main_t *sm = &stn_test_main;
155 name = format (0, "stn_%08x%c", api_version, 0);
156 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
159 if (sm->msg_id_base == (u16) ~ 0)
160 return clib_error_return (0, "stn plugin not loaded...");
162 /* Get the control ping ID */
163 #define _(id,n,crc) \
164 const char *id ## _CRC __attribute__ ((unused)) = #n "_" #crc;
165 foreach_vl_msg_name_crc_vpe;
167 sm->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
169 if (sm->msg_id_base != (u16) ~ 0)
170 stn_vat_api_hookup (vam);
176 * fd.io coding-style-patch-verification: ON
179 * eval: (c-set-style "gnu")