FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
l2_api.c
Go to the documentation of this file.
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 
44 
45 #define foreach_vpe_api_msg \
46 _(L2_XCONNECT_DUMP, l2_xconnect_dump)
47 
48 static void
50  u32 rx_sw_if_index, u32 tx_sw_if_index)
51 {
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
66 {
68  vnet_main_t *vnm = vnet_get_main ();
71  vnet_sw_interface_t *swif;
72  l2_input_config_t *config;
73 
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
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 *
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);
122 #undef _
123 
124  /*
125  * Set up the (msg_name, crc, message-id) table
126  */
128 
129  return 0;
130 }
131 
133 
134 /*
135  * fd.io coding-style-patch-verification: ON
136  *
137  * Local Variables:
138  * eval: (c-set-style "gnu")
139  * End:
140  */
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
vnet_interface_main_t interface_main
Definition: vnet.h:57
VLIB_API_INIT_FUNCTION(l2_api_hookup)
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
Dump L2 XConnects.
Definition: l2.api:33
Reply to l2_xconnect_dump.
Definition: l2.api:22
static void send_l2_xconnect_details(unix_shared_memory_queue_t *q, u32 context, u32 rx_sw_if_index, u32 tx_sw_if_index)
Definition: l2_api.c:49
api_main_t api_main
Definition: api_shared.c:39
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:348
static clib_error_t * l2_api_hookup(vlib_main_t *vm)
Definition: l2_api.c:110
void * vl_msg_api_alloc(int nbytes)
static void vl_api_l2_xconnect_dump_t_handler(vl_api_l2_xconnect_dump_t *mp)
Definition: l2_api.c:65
#define foreach_vpe_api_msg
Definition: l2_api.c:45
static void setup_message_id_table(api_main_t *am)
Definition: l2_api.c:102
unsigned int u32
Definition: types.h:88
l2input_main_t l2input_main
Definition: l2_input.c:87
unsigned char u8
Definition: types.h:56
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:606
struct _unix_shared_memory_queue unix_shared_memory_queue_t