2 *------------------------------------------------------------------
3 * l2e_api.c - layer 2 emulation api
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #include <vnet/vnet.h>
21 #include <vnet/plugin/plugin.h>
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vpp/app/version.h>
29 #include <vlibapi/api.h>
30 #include <vlibmemory/api.h>
32 /* define message IDs */
33 #include <l2e/l2e_msg_enum.h>
35 #define vl_typedefs /* define message structures */
36 #include <l2e/l2e_all_api_h.h>
39 #define vl_endianfun /* define message structures */
40 #include <l2e/l2e_all_api_h.h>
43 /* instantiate all the print functions we know about */
44 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
46 #include <l2e/l2e_all_api_h.h>
49 /* Get the API version number */
50 #define vl_api_version(n,v) static u32 api_version=(v);
51 #include <l2e/l2e_all_api_h.h>
54 #include <vlibapi/api_helper_macros.h>
56 #define foreach_l2e_api_msg \
57 _(L2_EMULATION, l2_emulation)
62 typedef struct l2_emulation_main_t_
65 } l2_emulation_main_t;
67 static l2_emulation_main_t l2_emulation_main;
69 #define L2E_MSG_BASE l2_emulation_main.msg_id_base
72 vl_api_l2_emulation_t_handler (vl_api_l2_emulation_t * mp)
74 vl_api_l2_emulation_reply_t *rmp;
77 VALIDATE_SW_IF_INDEX (mp);
79 u32 sw_if_index = ntohl (mp->sw_if_index);
82 l2_emulation_enable (sw_if_index);
84 l2_emulation_disable (sw_if_index);
86 BAD_SW_IF_INDEX_LABEL;
88 REPLY_MACRO (VL_API_L2_EMULATION_REPLY + L2E_MSG_BASE);
93 * Add vpe's API message handlers to the table.
94 * vlib has alread mapped shared memory and
95 * added the client registration handlers.
96 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
98 #define vl_msg_name_crc_list
99 #include <l2e/l2e_all_api_h.h>
100 #undef vl_msg_name_crc_list
103 setup_message_id_table (api_main_t * am)
105 #define _(id,n,crc) \
106 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + L2E_MSG_BASE);
107 foreach_vl_msg_name_crc_l2e;
112 l2e_api_hookup (vlib_main_t * vm)
115 vl_msg_api_set_handlers(VL_API_##N + L2E_MSG_BASE, \
117 vl_api_##n##_t_handler, \
119 vl_api_##n##_t_endian, \
120 vl_api_##n##_t_print, \
121 sizeof(vl_api_##n##_t), 1);
126 static clib_error_t *
127 l2e_init (vlib_main_t * vm)
129 api_main_t *am = &api_main;
130 l2_emulation_main_t *l2em = &l2_emulation_main;
131 u8 *name = format (0, "l2e_%08x%c", api_version, 0);
133 /* Ask for a correctly-sized block of API message decode slots */
134 l2em->msg_id_base = vl_msg_api_get_msg_ids ((char *) name,
135 VL_MSG_FIRST_AVAILABLE);
139 /* Add our API messages to the global name_crc hash table */
140 setup_message_id_table (am);
146 VLIB_API_INIT_FUNCTION (l2e_init);
149 VLIB_PLUGIN_REGISTER () = {
150 .version = VPP_BUILD_VER,
151 .description = "L2 Emulation",
157 * fd.io coding-style-patch-verification: ON
160 * eval: (c-set-style "gnu")