Reorganize source tree to use single autotools instance
[vpp.git] / src / vnet / l2 / l2_api.c
1 /*
2  *------------------------------------------------------------------
3  * l2_api.c - layer 2 forwarding api
4  *
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:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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  *------------------------------------------------------------------
18  */
19
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/l2/l2_input.h>
26
27 #include <vnet/vnet_msg_enum.h>
28
29 #define vl_typedefs             /* define message structures */
30 #include <vnet/vnet_all_api_h.h>
31 #undef vl_typedefs
32
33 #define vl_endianfun            /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
35 #undef vl_endianfun
36
37 /* instantiate all the print functions we know about */
38 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
39 #define vl_printfun
40 #include <vnet/vnet_all_api_h.h>
41 #undef vl_printfun
42
43 #include <vlibapi/api_helper_macros.h>
44
45 #define foreach_vpe_api_msg                             \
46 _(L2_XCONNECT_DUMP, l2_xconnect_dump)
47
48 static void
49 send_l2_xconnect_details (unix_shared_memory_queue_t * q, u32 context,
50                           u32 rx_sw_if_index, u32 tx_sw_if_index)
51 {
52   vl_api_l2_xconnect_details_t *mp;
53
54   mp = vl_msg_api_alloc (sizeof (*mp));
55   memset (mp, 0, sizeof (*mp));
56   mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
57   mp->context = context;
58   mp->rx_sw_if_index = htonl (rx_sw_if_index);
59   mp->tx_sw_if_index = htonl (tx_sw_if_index);
60
61   vl_msg_api_send_shmem (q, (u8 *) & mp);
62 }
63
64 static void
65 vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp)
66 {
67   unix_shared_memory_queue_t *q;
68   vnet_main_t *vnm = vnet_get_main ();
69   vnet_interface_main_t *im = &vnm->interface_main;
70   l2input_main_t *l2im = &l2input_main;
71   vnet_sw_interface_t *swif;
72   l2_input_config_t *config;
73
74   q = vl_api_client_index_to_input_queue (mp->client_index);
75   if (q == 0)
76     return;
77
78   /* *INDENT-OFF* */
79   pool_foreach (swif, im->sw_interfaces,
80   ({
81     config = vec_elt_at_index (l2im->configs, swif->sw_if_index);
82     if (config->xconnect)
83       send_l2_xconnect_details (q, mp->context, swif->sw_if_index,
84                                 config->output_sw_if_index);
85   }));
86   /* *INDENT-ON* */
87 }
88
89
90 /*
91  * vpe_api_hookup
92  * Add vpe's API message handlers to the table.
93  * vlib has alread mapped shared memory and
94  * added the client registration handlers.
95  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
96  */
97 #define vl_msg_name_crc_list
98 #include <vnet/vnet_all_api_h.h>
99 #undef vl_msg_name_crc_list
100
101 static void
102 setup_message_id_table (api_main_t * am)
103 {
104 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
105   foreach_vl_msg_name_crc_l2;
106 #undef _
107 }
108
109 static clib_error_t *
110 l2_api_hookup (vlib_main_t * vm)
111 {
112   api_main_t *am = &api_main;
113
114 #define _(N,n)                                                  \
115     vl_msg_api_set_handlers(VL_API_##N, #n,                     \
116                            vl_api_##n##_t_handler,              \
117                            vl_noop_handler,                     \
118                            vl_api_##n##_t_endian,               \
119                            vl_api_##n##_t_print,                \
120                            sizeof(vl_api_##n##_t), 1);
121   foreach_vpe_api_msg;
122 #undef _
123
124   /*
125    * Set up the (msg_name, crc, message-id) table
126    */
127   setup_message_id_table (am);
128
129   return 0;
130 }
131
132 VLIB_API_INIT_FUNCTION (l2_api_hookup);
133
134 /*
135  * fd.io coding-style-patch-verification: ON
136  *
137  * Local Variables:
138  * eval: (c-set-style "gnu")
139  * End:
140  */